From d54e2bc7818468827a41cd5728ce9344869986d6 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Thu, 6 May 2021 14:11:14 +0200 Subject: [PATCH] [liftoff] Make RegsUnusedByParams constexpr After dropping support for older GCC versions, we can now assume full c++14 constexpr support, and can hence resolve a TODO to make a LiftoffCompiler method constexpr. This is also a proof-of-concept to verify that this indeed works on all bots now. R=ahaas@chromium.org Bug: v8:9686, v8:11384 Change-Id: I9b7da91152b0af98778312d653aebbf4236fed0d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2876850 Reviewed-by: Andreas Haas Commit-Queue: Clemens Backes Cr-Commit-Position: refs/heads/master@{#74407} --- src/wasm/baseline/liftoff-compiler.cc | 6 +++--- src/wasm/baseline/liftoff-register.h | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/wasm/baseline/liftoff-compiler.cc b/src/wasm/baseline/liftoff-compiler.cc index a89e60cfa4..adbb979f40 100644 --- a/src/wasm/baseline/liftoff-compiler.cc +++ b/src/wasm/baseline/liftoff-compiler.cc @@ -593,8 +593,7 @@ class LiftoffCompiler { } } - // TODO(ahaas): Make this function constexpr once GCC allows it. - LiftoffRegList RegsUnusedByParams() { + constexpr static LiftoffRegList RegsUnusedByParams() { LiftoffRegList regs = kGpCacheRegList; for (auto reg : kGpParamRegisters) { regs.clear(reg); @@ -619,8 +618,9 @@ class LiftoffCompiler { // For reference type parameters we have to use registers that were not // used for parameters because some reference type stack parameters may // get processed before some value type register parameters. + static constexpr auto kRegsUnusedByParams = RegsUnusedByParams(); LiftoffRegister reg = is_reference(reg_kind) - ? __ GetUnusedRegister(RegsUnusedByParams()) + ? __ GetUnusedRegister(kRegsUnusedByParams) : __ GetUnusedRegister(rc, pinned); __ LoadCallerFrameSlot(reg, -location.AsCallerFrameSlot(), reg_kind); return reg; diff --git a/src/wasm/baseline/liftoff-register.h b/src/wasm/baseline/liftoff-register.h index bb27b99dc2..63ac2acf8b 100644 --- a/src/wasm/baseline/liftoff-register.h +++ b/src/wasm/baseline/liftoff-register.h @@ -152,11 +152,12 @@ class LiftoffRegister { "chosen type is small enough"); public: - explicit LiftoffRegister(Register reg) : LiftoffRegister(reg.code()) { + constexpr explicit LiftoffRegister(Register reg) + : LiftoffRegister(reg.code()) { DCHECK_NE(0, kLiftoffAssemblerGpCacheRegs & reg.bit()); DCHECK_EQ(reg, gp()); } - explicit LiftoffRegister(DoubleRegister reg) + constexpr explicit LiftoffRegister(DoubleRegister reg) : LiftoffRegister(kAfterMaxLiftoffGpRegCode + reg.code()) { DCHECK_NE(0, kLiftoffAssemblerFpCacheRegs & reg.bit()); DCHECK_EQ(reg, fp()); @@ -275,22 +276,22 @@ class LiftoffRegister { return DoubleRegister::from_code((code_ & kCodeMask) + 1); } - Register gp() const { + constexpr Register gp() const { DCHECK(is_gp()); return Register::from_code(code_); } - DoubleRegister fp() const { + constexpr DoubleRegister fp() const { DCHECK(is_fp()); return DoubleRegister::from_code(code_ - kAfterMaxLiftoffGpRegCode); } - int liftoff_code() const { + constexpr int liftoff_code() const { STATIC_ASSERT(sizeof(int) >= sizeof(storage_t)); return static_cast(code_); } - RegClass reg_class() const { + constexpr RegClass reg_class() const { return is_fp_pair() ? kFpRegPair : is_gp_pair() ? kGpRegPair : is_gp() ? kGpReg : kFpReg; } @@ -364,7 +365,7 @@ class LiftoffRegList { return reg; } - LiftoffRegister clear(LiftoffRegister reg) { + constexpr LiftoffRegister clear(LiftoffRegister reg) { if (reg.is_pair()) { regs_ &= ~(storage_t{1} << reg.low().liftoff_code()); regs_ &= ~(storage_t{1} << reg.high().liftoff_code()); @@ -373,8 +374,10 @@ class LiftoffRegList { } return reg; } - Register clear(Register reg) { return clear(LiftoffRegister{reg}).gp(); } - DoubleRegister clear(DoubleRegister reg) { + constexpr Register clear(Register reg) { + return clear(LiftoffRegister{reg}).gp(); + } + constexpr DoubleRegister clear(DoubleRegister reg) { return clear(LiftoffRegister{reg}).fp(); }