Commit c8543c1f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [cleanup] More constexpr, less lazy initialization

The allocator for determining the location (reg/stack) for parameters
and return values can be constexpr. This avoids lazy initialization,
saving code size and execution time, and simplifying the implementation
significantly.

R=ahaas@chromium.org
CC=titzer@chromium.org

Change-Id: I295623cb1dad0f1537f7292dcf044f3d509588bb
Reviewed-on: https://chromium-review.googlesource.com/635163Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47602}
parent b6158eb6
......@@ -128,13 +128,19 @@ LinkageLocation stackloc(int i, MachineType type) {
// ===========================================================================
// == unknown ================================================================
// ===========================================================================
// Don't define anything. We'll just always use the stack.
// Do not use any registers, we will just always use the stack.
#define GP_PARAM_REGISTERS
#define GP_RETURN_REGISTERS
#define FP_PARAM_REGISTERS
#define FP_RETURN_REGISTERS
#endif
// Helper for allocating either an GP or FP reg, or the next stack slot.
struct Allocator {
Allocator(const Register* gp, int gpc, const DoubleRegister* fp, int fpc)
constexpr Allocator(const Register* gp, int gpc, const DoubleRegister* fp,
int fpc)
: gp_count(gpc),
gp_offset(0),
gp_regs(gp),
......@@ -199,70 +205,28 @@ struct Allocator {
return 1;
}
};
} // namespace
struct ParameterRegistersCreateTrait {
static void Construct(Allocator* allocated_ptr) {
#ifdef GP_PARAM_REGISTERS
static const Register kGPParamRegisters[] = {GP_PARAM_REGISTERS};
static const int kGPParamRegistersCount =
static_cast<int>(arraysize(kGPParamRegisters));
#else
static const Register* kGPParamRegisters = nullptr;
static const int kGPParamRegistersCount = 0;
#endif
#ifdef FP_PARAM_REGISTERS
static const DoubleRegister kFPParamRegisters[] = {FP_PARAM_REGISTERS};
static const int kFPParamRegistersCount =
static_cast<int>(arraysize(kFPParamRegisters));
#else
static const DoubleRegister* kFPParamRegisters = nullptr;
static const int kFPParamRegistersCount = 0;
#endif
new (allocated_ptr) Allocator(kGPParamRegisters, kGPParamRegistersCount,
kFPParamRegisters, kFPParamRegistersCount);
}
};
static base::LazyInstance<Allocator, ParameterRegistersCreateTrait>::type
parameter_registers = LAZY_INSTANCE_INITIALIZER;
static constexpr Register kGPReturnRegisters[] = {GP_RETURN_REGISTERS};
static constexpr DoubleRegister kFPReturnRegisters[] = {FP_RETURN_REGISTERS};
static constexpr Register kGPParamRegisters[] = {GP_PARAM_REGISTERS};
static constexpr DoubleRegister kFPParamRegisters[] = {FP_PARAM_REGISTERS};
static constexpr Allocator return_registers(kGPReturnRegisters,
arraysize(kGPReturnRegisters),
kFPReturnRegisters,
arraysize(kFPReturnRegisters));
static constexpr Allocator parameter_registers(kGPParamRegisters,
arraysize(kGPParamRegisters),
kFPParamRegisters,
arraysize(kFPParamRegisters));
struct ReturnRegistersCreateTrait {
static void Construct(Allocator* allocated_ptr) {
#ifdef GP_RETURN_REGISTERS
static const Register kGPReturnRegisters[] = {GP_RETURN_REGISTERS};
static const int kGPReturnRegistersCount =
static_cast<int>(arraysize(kGPReturnRegisters));
#else
static const Register* kGPReturnRegisters = nullptr;
static const int kGPReturnRegistersCount = 0;
#endif
#ifdef FP_RETURN_REGISTERS
static const DoubleRegister kFPReturnRegisters[] = {FP_RETURN_REGISTERS};
static const int kFPReturnRegistersCount =
static_cast<int>(arraysize(kFPReturnRegisters));
#else
static const DoubleRegister* kFPReturnRegisters = nullptr;
static const int kFPReturnRegistersCount = 0;
#endif
new (allocated_ptr) Allocator(kGPReturnRegisters, kGPReturnRegistersCount,
kFPReturnRegisters, kFPReturnRegistersCount);
}
};
static base::LazyInstance<Allocator, ReturnRegistersCreateTrait>::type
return_registers = LAZY_INSTANCE_INITIALIZER;
} // namespace
// General code uses the above configuration data.
CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig) {
LocationSignature::Builder locations(zone, fsig->return_count(),
fsig->parameter_count());
Allocator rets = return_registers.Get();
Allocator rets = return_registers;
// Add return location(s).
const int return_count = static_cast<int>(locations.return_count_);
......@@ -271,7 +235,7 @@ CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig) {
locations.AddReturn(rets.Next(ret));
}
Allocator params = parameter_registers.Get();
Allocator params = parameter_registers;
// Add register and/or stack parameter(s).
const int parameter_count = static_cast<int>(fsig->parameter_count());
......@@ -322,7 +286,7 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
LocationSignature::Builder locations(zone, return_count, parameter_count);
Allocator rets = return_registers.Get();
Allocator rets = return_registers;
for (size_t i = 0; i < descriptor->ReturnCount(); i++) {
if (descriptor->GetReturnType(i) == input_type) {
......@@ -335,7 +299,7 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
}
}
Allocator params = parameter_registers.Get();
Allocator params = parameter_registers;
for (size_t i = 0; i < descriptor->ParameterCount(); i++) {
if (descriptor->GetParameterType(i) == input_type) {
......
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