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[] = {
nullptr, FOREACH_SIGNATURE(DECLARE_SIG_ENTRY)};
#undef DECLARE_SIG_ENTRY
// The following constexpr functions are used to initialize the constant arrays
// defined below. They must have exactly one return statement, and no switch.
constexpr WasmOpcodeSig GetOpcodeSigIndex(byte opcode) {
return
// gcc 4.7 - 4.9 has a bug which causes the constexpr attribute to get lost when
// passing functions (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892). Hence
// encapsulate these constexpr functions in functors.
// 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:
FOREACH_SIMPLE_OPCODE(CASE)
return FOREACH_SIMPLE_OPCODE(CASE) kSigEnum_None;
#undef CASE
kSigEnum_None;
}
}
};
constexpr WasmOpcodeSig GetAsmJsOpcodeSigIndex(byte opcode) {
return
struct GetAsmJsOpcodeSigIndex {
constexpr WasmOpcodeSig operator()(byte opcode) const {
#define CASE(name, opc, sig) opcode == opc ? kSigEnum_##sig:
FOREACH_ASMJS_COMPAT_OPCODE(CASE)
return FOREACH_ASMJS_COMPAT_OPCODE(CASE) kSigEnum_None;
#undef CASE
kSigEnum_None;
}
}
};
constexpr WasmOpcodeSig GetSimdOpcodeSigIndex(byte opcode) {
return
struct GetSimdOpcodeSigIndex {
constexpr WasmOpcodeSig operator()(byte opcode) const {
#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
kSigEnum_None;
}
}
};
constexpr WasmOpcodeSig GetAtomicOpcodeSigIndex(byte opcode) {
return
struct GetAtomicOpcodeSigIndex {
constexpr WasmOpcodeSig operator()(byte opcode) const {
#define CASE(name, opc, sig) opcode == (opc & 0xff) ? kSigEnum_##sig:
FOREACH_ATOMIC_OPCODE(CASE)
return FOREACH_ATOMIC_OPCODE(CASE) kSigEnum_None;
#undef CASE
kSigEnum_None;
}
};
// gcc 4.7 - 4.9 have a bug which prohibits marking the array constexpr
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892).
// TODO(clemensh): Remove this once we require gcc >= 5.0.
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 4
#define CONSTEXPR_IF_NOT_GCC_4
#else
#define CONSTEXPR_IF_NOT_GCC_4 constexpr
#endif
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
constexpr std::array<WasmOpcodeSig, 256> kSimpleExprSigTable =
base::make_array<256>(GetOpcodeSigIndex{});
constexpr std::array<WasmOpcodeSig, 256> kSimpleAsmjsExprSigTable =
base::make_array<256>(GetAsmJsOpcodeSigIndex{});
constexpr std::array<WasmOpcodeSig, 256> kSimdExprSigTable =
base::make_array<256>(GetSimdOpcodeSigIndex{});
constexpr std::array<WasmOpcodeSig, 256> kAtomicExprSigTable =
base::make_array<256>(GetAtomicOpcodeSigIndex{});
} // 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