Commit 49369fa7 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [cleanup] Construct constexpr arrays even on gcc

Due to a bug in gcc<5, we could not make some arrays constexpr. This CL
fixes this by encapsulating the respective functions in functors.

R=tebbi@chromium.org

Change-Id: I9947e38f7fd9b801f85623663849699c0f8ffd75
Reviewed-on: https://chromium-review.googlesource.com/730303
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48779}
parent bd6b1086
...@@ -353,59 +353,51 @@ constexpr const FunctionSig* kSimpleExprSigs[] = { ...@@ -353,59 +353,51 @@ constexpr const FunctionSig* kSimpleExprSigs[] = {
nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)}; nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
#undef DECLARE_SIG_ENTRY #undef DECLARE_SIG_ENTRY
// The following constexpr functions are used to initialize the constant arrays // gcc 4.7 - 4.9 has a bug which causes the constexpr attribute to get lost when
// defined below. They must have exactly one return statement, and no switch. // passing functions (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892). Hence
constexpr WasmOpcodeSig GetOpcodeSigIndex(byte opcode) { // encapsulate these constexpr functions in functors.
return // TODO(clemensh): Remove this once we require gcc >= 5.0.
struct GetOpcodeSigIndex {
constexpr WasmOpcodeSig operator()(byte opcode) const {
#define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig: #define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
FOREACH_SIMPLE_OPCODE(CASE) return FOREACH_SIMPLE_OPCODE(CASE) kSigEnum_None;
#undef CASE #undef CASE
kSigEnum_None; }
} };
constexpr WasmOpcodeSig GetAsmJsOpcodeSigIndex(byte opcode) { struct GetAsmJsOpcodeSigIndex {
return constexpr WasmOpcodeSig operator()(byte opcode) const {
#define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig: #define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
FOREACH_ASMJS_COMPAT_OPCODE(CASE) return FOREACH_ASMJS_COMPAT_OPCODE(CASE) kSigEnum_None;
#undef CASE #undef CASE
kSigEnum_None; }
} };
constexpr WasmOpcodeSig GetSimdOpcodeSigIndex(byte opcode) { struct GetSimdOpcodeSigIndex {
return constexpr WasmOpcodeSig operator()(byte opcode) const {
#define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig: #define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig:
FOREACH_SIMD_0_OPERAND_OPCODE(CASE) return FOREACH_SIMD_0_OPERAND_OPCODE(CASE) kSigEnum_None;
#undef CASE #undef CASE
kSigEnum_None; }
} };
constexpr WasmOpcodeSig GetAtomicOpcodeSigIndex(byte opcode) { struct GetAtomicOpcodeSigIndex {
return constexpr WasmOpcodeSig operator()(byte opcode) const {
#define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig: #define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig:
FOREACH_ATOMIC_OPCODE(CASE) return FOREACH_ATOMIC_OPCODE(CASE) kSigEnum_None;
#undef CASE #undef CASE
kSigEnum_None;
} }
};
// gcc 4.7 - 4.9 have a bug which prohibits marking the array constexpr constexpr std::array<WasmOpcodeSig, 256> kSimpleExprSigTable =
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892). base::make_array<256>(GetOpcodeSigIndex{});
// TODO(clemensh): Remove this once we require gcc >= 5.0. constexpr std::array<WasmOpcodeSig, 256> kSimpleAsmjsExprSigTable =
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 4 base::make_array<256>(GetAsmJsOpcodeSigIndex{});
#define CONSTEXPR_IF_NOT_GCC_4 constexpr std::array<WasmOpcodeSig, 256> kSimdExprSigTable =
#else base::make_array<256>(GetSimdOpcodeSigIndex{});
#define CONSTEXPR_IF_NOT_GCC_4 constexpr constexpr std::array<WasmOpcodeSig, 256> kAtomicExprSigTable =
#endif base::make_array<256>(GetAtomicOpcodeSigIndex{});
CONSTEXPR_IF_NOT_GCC_4 std::array<WasmOpcodeSig, 256> kSimpleExprSigTable =
base::make_array<256>(GetOpcodeSigIndex);
CONSTEXPR_IF_NOT_GCC_4 std::array<WasmOpcodeSig, 256> kSimpleAsmjsExprSigTable =
base::make_array<256>(GetAsmJsOpcodeSigIndex);
CONSTEXPR_IF_NOT_GCC_4 std::array<WasmOpcodeSig, 256> kSimdExprSigTable =
base::make_array<256>(GetSimdOpcodeSigIndex);
CONSTEXPR_IF_NOT_GCC_4 std::array<WasmOpcodeSig, 256> kAtomicExprSigTable =
base::make_array<256>(GetAtomicOpcodeSigIndex);
#undef CONSTEXPR_IF_NOT_GCC_4
} // namespace } // namespace
......
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