mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
make RegisterMask a class
This commit is contained in:
parent
87465e890b
commit
94761711c9
@ -45,7 +45,7 @@ class OperandMask {
|
||||
{
|
||||
}
|
||||
|
||||
OperandMask() : typeMask(~0), lowRegisterMask(~static_cast<RegisterMask>(0)), highRegisterMask(~static_cast<RegisterMask>(0))
|
||||
OperandMask() : typeMask(~0), lowRegisterMask(RegisterMask::Any), highRegisterMask(RegisterMask::Any)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Assembler {
|
||||
public:
|
||||
class Client {
|
||||
public:
|
||||
virtual Register acquireTemporary(RegisterMask mask = ~static_cast<RegisterMask>(0)) = 0;
|
||||
virtual Register acquireTemporary(RegisterMask mask = RegisterMask::Any) = 0;
|
||||
virtual void releaseTemporary(Register r) = 0;
|
||||
|
||||
virtual void save(Register r) = 0;
|
||||
|
@ -16,9 +16,47 @@
|
||||
namespace avian {
|
||||
namespace codegen {
|
||||
|
||||
typedef uint64_t RegisterMask;
|
||||
typedef int Register;
|
||||
|
||||
class RegisterMask {
|
||||
private:
|
||||
uint64_t mask;
|
||||
public:
|
||||
RegisterMask(uint64_t mask) : mask(mask) {}
|
||||
RegisterMask() : mask(0) {}
|
||||
|
||||
RegisterMask operator &(RegisterMask o) const {
|
||||
return RegisterMask(mask & o.mask);
|
||||
}
|
||||
|
||||
RegisterMask operator &=(RegisterMask o) {
|
||||
mask &= o.mask;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RegisterMask operator |(RegisterMask o) const {
|
||||
return RegisterMask(mask | o.mask);
|
||||
}
|
||||
|
||||
bool contains(Register reg) const {
|
||||
return (mask & (static_cast<uint64_t>(1) << reg)) != 0;
|
||||
}
|
||||
|
||||
bool containsExactly(Register reg) const {
|
||||
return mask == (mask & (static_cast<uint64_t>(1) << reg));
|
||||
}
|
||||
|
||||
explicit operator uint64_t() const {
|
||||
return mask;
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
return mask != 0;
|
||||
}
|
||||
|
||||
static RegisterMask Any;
|
||||
};
|
||||
|
||||
class BoundedRegisterMask {
|
||||
public:
|
||||
RegisterMask mask;
|
||||
@ -68,7 +106,7 @@ class RegisterIterator {
|
||||
int r = index;
|
||||
do {
|
||||
index++;
|
||||
} while (index < mask.limit && !(mask.mask & (1 << index)));
|
||||
} while (index < mask.limit && !(mask.mask.contains(index)));
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ bool pickRegisterTarget(Context* c,
|
||||
unsigned* cost,
|
||||
CostCalculator* costCalculator)
|
||||
{
|
||||
if ((1 << i) & mask) {
|
||||
if (mask.contains(i)) {
|
||||
RegisterResource* r = c->registerResources + i;
|
||||
unsigned myCost
|
||||
= resourceCost(
|
||||
@ -74,7 +74,7 @@ bool pickRegisterTarget(Context* c,
|
||||
SiteMask(1 << lir::RegisterOperand, 1 << i, NoFrameIndex),
|
||||
costCalculator) + Target::MinimumRegisterCost;
|
||||
|
||||
if ((static_cast<RegisterMask>(1) << i) == mask) {
|
||||
if (mask.containsExactly(i)) {
|
||||
*cost = myCost;
|
||||
return true;
|
||||
} else if (myCost < *cost) {
|
||||
@ -235,7 +235,7 @@ Target pickTarget(Context* c,
|
||||
Value* value = read->value;
|
||||
|
||||
RegisterMask registerMask
|
||||
= (isFloatValue(value) ? ~0 : c->regFile->generalRegisters.mask);
|
||||
= (isFloatValue(value) ? RegisterMask::Any : c->regFile->generalRegisters.mask);
|
||||
|
||||
SiteMask mask(~0, registerMask, AnyFrameIndex);
|
||||
read->intersect(&mask);
|
||||
@ -275,7 +275,7 @@ Target pickTarget(Context* c,
|
||||
fprintf(stderr,
|
||||
"mask type %d reg %" LLD " frame %d\n",
|
||||
mask.typeMask,
|
||||
mask.registerMask,
|
||||
(uint64_t)mask.registerMask,
|
||||
mask.frameIndex);
|
||||
abort(c);
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ void RegisterResource::freeze(Context* c, Value* v)
|
||||
freezeResource(c, this, v);
|
||||
|
||||
if (freezeCount == 1
|
||||
and ((1 << index(c)) & c->regFile->generalRegisters.mask)) {
|
||||
and c->regFile->generalRegisters.mask.contains(index(c))) {
|
||||
decrementAvailableGeneralRegisterCount(c);
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ void RegisterResource::thaw(Context* c, Value* v)
|
||||
thawResource(c, this, v);
|
||||
|
||||
if (freezeCount == 0
|
||||
and ((1 << index(c)) & c->regFile->generalRegisters.mask)) {
|
||||
and c->regFile->generalRegisters.mask.contains(index(c))) {
|
||||
incrementAvailableGeneralRegisterCount(c);
|
||||
}
|
||||
}
|
||||
@ -130,7 +130,7 @@ void RegisterResource::increment(Context* c)
|
||||
++this->referenceCount;
|
||||
|
||||
if (this->referenceCount == 1
|
||||
and ((1 << this->index(c)) & c->regFile->generalRegisters.mask)) {
|
||||
and c->regFile->generalRegisters.mask.contains(this->index(c))) {
|
||||
decrementAvailableGeneralRegisterCount(c);
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ void RegisterResource::decrement(Context* c)
|
||||
--this->referenceCount;
|
||||
|
||||
if (this->referenceCount == 0
|
||||
and ((1 << this->index(c)) & c->regFile->generalRegisters.mask)) {
|
||||
and c->regFile->generalRegisters.mask.contains(this->index(c))) {
|
||||
incrementAvailableGeneralRegisterCount(c);
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ unsigned RegisterSite::copyCost(Context* c, Site* s)
|
||||
|
||||
if (s and (this == s
|
||||
or (s->type(c) == lir::RegisterOperand
|
||||
and (static_cast<RegisterSite*>(s)->mask_ & (1 << number))))) {
|
||||
and (static_cast<RegisterSite*>(s)->mask_.contains(number))))) {
|
||||
return 0;
|
||||
} else {
|
||||
return RegisterCopyCost;
|
||||
@ -250,7 +250,7 @@ bool RegisterSite::match(Context* c UNUSED, const SiteMask& mask)
|
||||
assertT(c, number != lir::NoRegister);
|
||||
|
||||
if ((mask.typeMask & (1 << lir::RegisterOperand))) {
|
||||
return ((static_cast<uint64_t>(1) << number) & mask.registerMask);
|
||||
return mask.registerMask.contains(number);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -261,7 +261,7 @@ bool RegisterSite::loneMatch(Context* c UNUSED, const SiteMask& mask)
|
||||
assertT(c, number != lir::NoRegister);
|
||||
|
||||
if ((mask.typeMask & (1 << lir::RegisterOperand))) {
|
||||
return ((static_cast<uint64_t>(1) << number) == mask.registerMask);
|
||||
return mask.registerMask.containsExactly(number);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -282,7 +282,7 @@ bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned)
|
||||
return number == rs->number;
|
||||
} else {
|
||||
RegisterMask mask = c->regFile->generalRegisters.mask;
|
||||
return ((1 << number) & mask) and ((1 << rs->number) & mask);
|
||||
return mask.contains(number) and mask.contains(rs->number);
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ Site* RegisterSite::copyHigh(Context* c)
|
||||
Site* RegisterSite::makeNextWord(Context* c, unsigned)
|
||||
{
|
||||
assertT(c, number != lir::NoRegister);
|
||||
assertT(c, ((1 << number) & c->regFile->generalRegisters.mask));
|
||||
assertT(c, c->regFile->generalRegisters.mask.contains(number));
|
||||
|
||||
return freeRegisterSite(c, c->regFile->generalRegisters.mask);
|
||||
}
|
||||
@ -405,7 +405,7 @@ unsigned RegisterSite::registerSize(Context* c)
|
||||
{
|
||||
assertT(c, number != lir::NoRegister);
|
||||
|
||||
if ((1 << number) & c->regFile->floatRegisters.mask) {
|
||||
if (c->regFile->floatRegisters.mask.contains(number)) {
|
||||
return c->arch->floatRegisterSize();
|
||||
} else {
|
||||
return c->targetInfo.pointerSize;
|
||||
@ -423,8 +423,8 @@ Site* registerSite(Context* c, int number)
|
||||
{
|
||||
assertT(c, number >= 0);
|
||||
assertT(c,
|
||||
(1 << number) & (c->regFile->generalRegisters.mask
|
||||
| c->regFile->floatRegisters.mask));
|
||||
(c->regFile->generalRegisters.mask
|
||||
| c->regFile->floatRegisters.mask).contains(number));
|
||||
|
||||
return new (c->zone) RegisterSite(1 << number, number);
|
||||
}
|
||||
@ -467,9 +467,9 @@ unsigned MemorySite::copyCost(Context* c, Site* s)
|
||||
bool MemorySite::conflicts(const SiteMask& mask)
|
||||
{
|
||||
return (mask.typeMask & (1 << lir::RegisterOperand)) != 0
|
||||
and (((1 << base) & mask.registerMask) == 0
|
||||
and (!mask.registerMask.contains(base)
|
||||
or (index != lir::NoRegister
|
||||
and ((1 << index) & mask.registerMask) == 0));
|
||||
and !mask.registerMask.contains(index)));
|
||||
}
|
||||
|
||||
bool MemorySite::match(Context* c, const SiteMask& mask)
|
||||
|
@ -16,7 +16,7 @@ namespace codegen {
|
||||
unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
|
||||
{
|
||||
for (int i = 0; i <= 31; ++i) {
|
||||
if (mask & (1 << i))
|
||||
if (mask.contains(i))
|
||||
return i;
|
||||
}
|
||||
return 32;
|
||||
@ -25,11 +25,13 @@ unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
|
||||
unsigned BoundedRegisterMask::maskLimit(RegisterMask mask)
|
||||
{
|
||||
for (int i = 31; i >= 0; --i) {
|
||||
if (mask & (1 << i))
|
||||
if (mask.contains(i))
|
||||
return i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RegisterMask RegisterMask::Any(~static_cast<uint64_t>(0));
|
||||
|
||||
} // namespace codegen
|
||||
} // namespace avian
|
||||
|
@ -79,6 +79,6 @@ TEST(ArchitecturePlan)
|
||||
(lir::UnaryOperation)op, vm::TargetBytesPerWord, mask, &thunk);
|
||||
assertFalse(thunk);
|
||||
assertNotEqual(static_cast<uint8_t>(0), mask.typeMask);
|
||||
assertNotEqual(static_cast<uint64_t>(0), mask.lowRegisterMask);
|
||||
assertNotEqual(static_cast<uint64_t>(0), (uint64_t)mask.lowRegisterMask);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user