Commit 3fc930f1 by Nicolas Capens Committed by Nicolas Capens

Define constant static template members as constexpr

The static Opcode and Emitter members of the InstImpl<> template class have constant values, so we can make them constexpr and define them in the header. Note that we can't make them constexpr in the template class definition, since that requires in-class initialization, and GCC considers the definition of the static members of the concrete instantiations to be doing duplicate initialization (this might be a compiler bug, since Clang and MSVC allow it). Fortunately, constexpr is a specifier, which implies const, a qualifier, meaning a definition which is constexpr is compatible with a declaration which is only const. Declaring them as const in the class has the added benefit that if we instantiated the template without providing initialization of these members, we'd get a compilation error instead of using the in-class initializer of the primary template. Note also that defining these static members in the header doesn't lead to multiple definition errors because in C++17, static constexpr member variables are implicitly inline. Lastly, constexpr applied to a pointer affects the pointer value itself, not the pointee, so "constexpr const char *s" is a constexpr pointer to const characters. Thus while constexpr implies const, the second const isn't redundant because it applies to the pointee type. Bug: b/192890685 Change-Id: Ia7c6a889d08007d42393979f3b08bcfc5fa8c614 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/55428 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent fddd4f20
......@@ -346,5 +346,3 @@ void TargetX8632Traits::VariableSplit::dump(const Cfg *Func,
} // namespace X8632
} // end of namespace Ice
X86INSTS_DEFINE_STATIC_DATA(X8632, X8632::Traits)
......@@ -34,6 +34,6 @@
#include "IceOperand.h"
#include "IceTargetLoweringX8632Traits.h"
X86INSTS_DECLARE_STATIC_DATA(X8632, X8632::Traits)
X86INSTS_DEFINE_STATIC_DATA(X8632, X8632::Traits)
#endif // SUBZERO_SRC_ICEINSTX8632_H
......@@ -355,5 +355,3 @@ void TargetX8664Traits::VariableSplit::dump(const Cfg *Func,
} // namespace X8664
} // end of namespace Ice
X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits)
......@@ -32,6 +32,6 @@
#include "IceOperand.h"
#include "IceTargetLoweringX8664Traits.h"
X86INSTS_DECLARE_STATIC_DATA(X8664, X8664::Traits)
X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits)
#endif // SUBZERO_SRC_ICEINSTX8664_H
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment