From 76197e1f1d1b979a3b98b9e39081cfc4f08c00e9 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 4 Dec 2014 15:26:47 -0700 Subject: [PATCH] typedef RegisterMask --- include/avian/codegen/architecture.h | 15 ++++++++------- include/avian/codegen/assembler.h | 3 ++- include/avian/codegen/registers.h | 12 +++++++----- src/codegen/compiler.cpp | 2 +- src/codegen/compiler/event.cpp | 2 +- src/codegen/compiler/regalloc.cpp | 14 +++++++------- src/codegen/compiler/regalloc.h | 6 +++--- src/codegen/compiler/site.cpp | 8 ++++---- src/codegen/compiler/site.h | 12 ++++++------ src/codegen/registers.cpp | 4 ++-- src/codegen/target/arm/registers.h | 4 ++-- src/codegen/target/x86/operations.cpp | 2 +- 12 files changed, 44 insertions(+), 40 deletions(-) diff --git a/include/avian/codegen/architecture.h b/include/avian/codegen/architecture.h index e4fa825af3..b43582cfe4 100644 --- a/include/avian/codegen/architecture.h +++ b/include/avian/codegen/architecture.h @@ -12,6 +12,7 @@ #define AVIAN_CODEGEN_ARCHITECTURE_H #include "ir.h" +#include "registers.h" namespace vm { class Zone; @@ -32,12 +33,12 @@ class RegisterFile; class OperandMask { public: uint8_t typeMask; - uint64_t lowRegisterMask; - uint64_t highRegisterMask; + RegisterMask lowRegisterMask; + RegisterMask highRegisterMask; OperandMask(uint8_t typeMask, - uint64_t lowRegisterMask, - uint64_t highRegisterMask) + RegisterMask lowRegisterMask, + RegisterMask highRegisterMask) : typeMask(typeMask), lowRegisterMask(lowRegisterMask), highRegisterMask(highRegisterMask) @@ -46,18 +47,18 @@ class OperandMask { // TEMPORARY! OperandMask(uint8_t typeMask, - uint64_t registerMask) + RegisterMask registerMask) : typeMask(typeMask), lowRegisterMask(registerMask), highRegisterMask(registerMask >> 32) { } - OperandMask() : typeMask(~0), lowRegisterMask(~static_cast(0)), highRegisterMask(~static_cast(0)) + OperandMask() : typeMask(~0), lowRegisterMask(~static_cast(0)), highRegisterMask(~static_cast(0)) { } - void setLowHighRegisterMasks(uint64_t lowRegisterMask, uint64_t highRegisterMask) { + void setLowHighRegisterMasks(RegisterMask lowRegisterMask, RegisterMask highRegisterMask) { this->lowRegisterMask = lowRegisterMask | (highRegisterMask << 32); this->highRegisterMask = highRegisterMask; } diff --git a/include/avian/codegen/assembler.h b/include/avian/codegen/assembler.h index 66e7ed53d6..a233fa82bf 100644 --- a/include/avian/codegen/assembler.h +++ b/include/avian/codegen/assembler.h @@ -15,6 +15,7 @@ #include "avian/zone.h" #include +#include #include namespace avian { @@ -52,7 +53,7 @@ class Assembler { public: class Client { public: - virtual int acquireTemporary(uint32_t mask = ~static_cast(0)) = 0; + virtual int acquireTemporary(RegisterMask mask = ~static_cast(0)) = 0; virtual void releaseTemporary(int r) = 0; virtual void save(int r) = 0; diff --git a/include/avian/codegen/registers.h b/include/avian/codegen/registers.h index b5f58c3111..0ddbf6e7dd 100644 --- a/include/avian/codegen/registers.h +++ b/include/avian/codegen/registers.h @@ -16,16 +16,18 @@ namespace avian { namespace codegen { +typedef uint64_t RegisterMask; + class BoundedRegisterMask { public: - uint32_t mask; + RegisterMask mask; uint8_t start; uint8_t limit; - static unsigned maskStart(uint32_t mask); - static unsigned maskLimit(uint32_t mask); + static unsigned maskStart(RegisterMask mask); + static unsigned maskLimit(RegisterMask mask); - inline BoundedRegisterMask(uint32_t mask) + inline BoundedRegisterMask(RegisterMask mask) : mask(mask), start(maskStart(mask)), limit(maskLimit(mask)) { } @@ -37,7 +39,7 @@ class RegisterFile { BoundedRegisterMask generalRegisters; BoundedRegisterMask floatRegisters; - inline RegisterFile(uint32_t generalRegisterMask, uint32_t floatRegisterMask) + inline RegisterFile(RegisterMask generalRegisterMask, RegisterMask floatRegisterMask) : allRegisters(generalRegisterMask | floatRegisterMask), generalRegisters(generalRegisterMask), floatRegisters(floatRegisterMask) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index eabe367586..1f5a23f0fe 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2210,7 +2210,7 @@ class Client : public Assembler::Client { { } - virtual int acquireTemporary(uint32_t mask) + virtual int acquireTemporary(RegisterMask mask) { unsigned cost; int r = pickRegisterTarget(c, 0, mask, &cost); diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 9668897547..d49ec49a2f 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -372,7 +372,7 @@ class CallEvent : public Event { ? arguments.count : 0) { - uint32_t registerMask = c->regFile->generalRegisters.mask; + RegisterMask registerMask = c->regFile->generalRegisters.mask; if (callingConvention == ir::CallingConvention::Native) { assertT(c, (flags & Compiler::TailJump) == 0); diff --git a/src/codegen/compiler/regalloc.cpp b/src/codegen/compiler/regalloc.cpp index 6f716df770..52ff8f8da5 100644 --- a/src/codegen/compiler/regalloc.cpp +++ b/src/codegen/compiler/regalloc.cpp @@ -59,7 +59,7 @@ unsigned resourceCost(Context* c, bool pickRegisterTarget(Context* c, int i, Value* v, - uint32_t mask, + RegisterMask mask, int* target, unsigned* cost, CostCalculator* costCalculator) @@ -74,7 +74,7 @@ bool pickRegisterTarget(Context* c, SiteMask(1 << lir::RegisterOperand, 1 << i, NoFrameIndex), costCalculator) + Target::MinimumRegisterCost; - if ((static_cast(1) << i) == mask) { + if ((static_cast(1) << i) == mask) { *cost = myCost; return true; } else if (myCost < *cost) { @@ -87,7 +87,7 @@ bool pickRegisterTarget(Context* c, int pickRegisterTarget(Context* c, Value* v, - uint32_t mask, + RegisterMask mask, unsigned* cost, CostCalculator* costCalculator) { @@ -119,7 +119,7 @@ int pickRegisterTarget(Context* c, Target pickRegisterTarget(Context* c, Value* v, - uint32_t mask, + RegisterMask mask, CostCalculator* costCalculator) { unsigned cost; @@ -234,14 +234,14 @@ Target pickTarget(Context* c, Value* value = read->value; - uint32_t registerMask + RegisterMask registerMask = (isFloatValue(value) ? ~0 : c->regFile->generalRegisters.mask); SiteMask mask(~0, registerMask, AnyFrameIndex); read->intersect(&mask); if (isFloatValue(value)) { - uint32_t floatMask = mask.registerMask & c->regFile->floatRegisters.mask; + RegisterMask floatMask = mask.registerMask & c->regFile->floatRegisters.mask; if (floatMask) { mask.registerMask = floatMask; } @@ -273,7 +273,7 @@ Target pickTarget(Context* c, if (intersectRead) { if (best.cost == Target::Impossible) { fprintf(stderr, - "mask type %d reg %d frame %d\n", + "mask type %d reg %" LLD " frame %d\n", mask.typeMask, mask.registerMask, mask.frameIndex); diff --git a/src/codegen/compiler/regalloc.h b/src/codegen/compiler/regalloc.h index 3c87b20c00..6aa782ab04 100644 --- a/src/codegen/compiler/regalloc.h +++ b/src/codegen/compiler/regalloc.h @@ -79,20 +79,20 @@ unsigned resourceCost(Context* c, bool pickRegisterTarget(Context* c, int i, Value* v, - uint32_t mask, + RegisterMask mask, int* target, unsigned* cost, CostCalculator* costCalculator = 0); int pickRegisterTarget(Context* c, Value* v, - uint32_t mask, + RegisterMask mask, unsigned* cost, CostCalculator* costCalculator = 0); Target pickRegisterTarget(Context* c, Value* v, - uint32_t mask, + RegisterMask mask, CostCalculator* costCalculator = 0); unsigned frameCost(Context* c, diff --git a/src/codegen/compiler/site.cpp b/src/codegen/compiler/site.cpp index ea762a851f..f5dd0e0ad9 100644 --- a/src/codegen/compiler/site.cpp +++ b/src/codegen/compiler/site.cpp @@ -217,7 +217,7 @@ Site* addressSite(Context* c, Promise* address) return new (c->zone) AddressSite(address); } -RegisterSite::RegisterSite(uint32_t mask, int number) +RegisterSite::RegisterSite(RegisterMask mask, int number) : mask_(mask), number(number) { } @@ -281,7 +281,7 @@ bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned) assertT(c, number != lir::NoRegister); return number == rs->number; } else { - uint32_t mask = c->regFile->generalRegisters.mask; + RegisterMask mask = c->regFile->generalRegisters.mask; return ((1 << number) & mask) and ((1 << rs->number) & mask); } } @@ -354,7 +354,7 @@ void RegisterSite::asAssemblerOperand(Context* c UNUSED, Site* RegisterSite::copy(Context* c) { - uint32_t mask; + RegisterMask mask; if (number != lir::NoRegister) { mask = 1 << number; @@ -429,7 +429,7 @@ Site* registerSite(Context* c, int number) return new (c->zone) RegisterSite(1 << number, number); } -Site* freeRegisterSite(Context* c, uint32_t mask) +Site* freeRegisterSite(Context* c, RegisterMask mask) { return new (c->zone) RegisterSite(mask, lir::NoRegister); } diff --git a/src/codegen/compiler/site.h b/src/codegen/compiler/site.h index 5c5e9daa35..a01a4f35e0 100644 --- a/src/codegen/compiler/site.h +++ b/src/codegen/compiler/site.h @@ -34,8 +34,8 @@ class SiteMask { { } - SiteMask(uint8_t typeMask, uint32_t registerMask, int frameIndex) - : typeMask(typeMask), registerMask(registerMask), frameIndex(frameIndex) + SiteMask(uint8_t typeMask, RegisterMask registerMask, int frameIndex) + : typeMask(typeMask), registerMask(/*TODO: REMOVE CAST!!! */(uint32_t)registerMask), frameIndex(frameIndex) { } @@ -57,7 +57,7 @@ class SiteMask { } uint8_t typeMask; - uint32_t registerMask; + RegisterMask registerMask; int frameIndex; }; @@ -251,7 +251,7 @@ Site* addressSite(Context* c, Promise* address); class RegisterSite : public Site { public: - RegisterSite(uint32_t mask, int number); + RegisterSite(RegisterMask mask, int number); virtual unsigned toString(Context*, char* buffer, unsigned bufferSize); @@ -295,12 +295,12 @@ class RegisterSite : public Site { virtual unsigned registerMask(Context* c UNUSED); - uint32_t mask_; + RegisterMask mask_; int number; }; Site* registerSite(Context* c, int number); -Site* freeRegisterSite(Context* c, uint32_t mask); +Site* freeRegisterSite(Context* c, RegisterMask mask); class MemorySite : public Site { public: diff --git a/src/codegen/registers.cpp b/src/codegen/registers.cpp index 0404670f37..b2b6c9f607 100644 --- a/src/codegen/registers.cpp +++ b/src/codegen/registers.cpp @@ -13,7 +13,7 @@ namespace avian { namespace codegen { -unsigned BoundedRegisterMask::maskStart(uint32_t mask) +unsigned BoundedRegisterMask::maskStart(RegisterMask mask) { for (int i = 0; i <= 31; ++i) { if (mask & (1 << i)) @@ -22,7 +22,7 @@ unsigned BoundedRegisterMask::maskStart(uint32_t mask) return 32; } -unsigned BoundedRegisterMask::maskLimit(uint32_t mask) +unsigned BoundedRegisterMask::maskLimit(RegisterMask mask) { for (int i = 31; i >= 0; --i) { if (mask & (1 << i)) diff --git a/src/codegen/target/arm/registers.h b/src/codegen/target/arm/registers.h index 4cd7fb9da4..c47f2ae8c5 100644 --- a/src/codegen/target/arm/registers.h +++ b/src/codegen/target/arm/registers.h @@ -23,8 +23,8 @@ const unsigned MASK_LO8 = 0xff; const int N_GPRS = 16; const int N_FPRS = 16; -const uint32_t GPR_MASK = 0xffff; -const uint32_t FPR_MASK = 0xffff0000; +const RegisterMask GPR_MASK = 0xffff; +const RegisterMask FPR_MASK = 0xffff0000; inline bool isFpr(lir::Register* reg) { diff --git a/src/codegen/target/x86/operations.cpp b/src/codegen/target/x86/operations.cpp index 0301cda1eb..863d1cf5bf 100644 --- a/src/codegen/target/x86/operations.cpp +++ b/src/codegen/target/x86/operations.cpp @@ -1274,7 +1274,7 @@ void multiplyCR(Context* c, assertT(c, aSize == bSize); if (vm::TargetBytesPerWord == 4 and aSize == 8) { - const uint32_t mask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); + const RegisterMask mask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); lir::Register tmp(c->client->acquireTemporary(mask), c->client->acquireTemporary(mask));