add back NoRegister and remove some implicit int->Register casts

This commit is contained in:
joshuawarner32@gmail.com 2014-12-04 22:01:16 -07:00 committed by Joshua Warner
parent 998a5168b7
commit 3bad154602
16 changed files with 97 additions and 97 deletions

View File

@ -83,8 +83,6 @@ const unsigned BranchOperationCount = JumpIfFloatGreaterOrEqualOrUnordered
enum ValueType { ValueGeneral, ValueFloat };
const int NoRegister = -1;
inline bool isBranch(lir::TernaryOperation op)
{
return op > FloatMin;

View File

@ -20,33 +20,33 @@ class Register {
private:
int8_t index;
public:
Register(int8_t index) : index(index) {}
Register() : index(0xff) {}
constexpr Register(int8_t index) : index(index) {}
constexpr Register() : index(-1) {}
bool operator == (Register o) const {
constexpr bool operator == (Register o) const {
return index == o.index;
}
bool operator != (Register o) const {
constexpr bool operator != (Register o) const {
return !(*this == o);
}
explicit operator int8_t() const {
constexpr explicit operator int8_t() const {
return index;
}
static Register None;
};
constexpr Register NoRegister;
class RegisterMask {
private:
uint64_t mask;
public:
RegisterMask(uint64_t mask) : mask(mask) {}
RegisterMask() : mask(0) {}
RegisterMask(Register reg) : mask(static_cast<uint64_t>(1) << (int8_t)reg) {}
constexpr RegisterMask(uint64_t mask) : mask(mask) {}
constexpr RegisterMask() : mask(0) {}
constexpr RegisterMask(Register reg) : mask(static_cast<uint64_t>(1) << (int8_t)reg) {}
RegisterMask operator &(RegisterMask o) const {
constexpr RegisterMask operator &(RegisterMask o) const {
return RegisterMask(mask & o.mask);
}
@ -55,27 +55,31 @@ public:
return *this;
}
RegisterMask operator |(RegisterMask o) const {
constexpr RegisterMask operator |(RegisterMask o) const {
return RegisterMask(mask | o.mask);
}
bool contains(Register reg) const {
constexpr bool contains(Register reg) const {
return (mask & (static_cast<uint64_t>(1) << (int8_t)reg)) != 0;
}
bool containsExactly(Register reg) const {
constexpr bool containsExactly(Register reg) const {
return mask == (mask & (static_cast<uint64_t>(1) << (int8_t)reg));
}
RegisterMask excluding(Register reg) const {
constexpr RegisterMask excluding(Register reg) const {
return RegisterMask(mask & ~(static_cast<uint64_t>(1) << (int8_t)reg));
}
explicit operator uint64_t() const {
constexpr RegisterMask including(Register reg) const {
return RegisterMask(mask | (static_cast<uint64_t>(1) << (int8_t)reg));
}
constexpr explicit operator uint64_t() const {
return mask;
}
explicit operator bool() const {
constexpr explicit operator bool() const {
return mask != 0;
}
@ -132,8 +136,8 @@ class RegisterIterator {
int r = index;
do {
index++;
} while (index < mask.limit && !(mask.mask.contains(index)));
return r;
} while (index < mask.limit && !(mask.mask.contains(Register(index))));
return Register(r);
}
};

View File

@ -259,7 +259,7 @@ Site* pickTargetSite(Context* c,
if (target.type == lir::Operand::Type::Memory) {
return frameSite(c, target.index);
} else {
return registerSite(c, target.index);
return registerSite(c, Register(target.index));
}
}

View File

@ -56,7 +56,7 @@ Context::Context(vm::System* system,
for (unsigned i = regFile->generalRegisters.start;
i < regFile->generalRegisters.limit;
++i) {
new (registerResources + i) RegisterResource(arch->reserved(i));
new (registerResources + i) RegisterResource(arch->reserved(Register(i)));
if (registerResources[i].reserved) {
--availableGeneralRegisterCount;
@ -65,7 +65,7 @@ Context::Context(vm::System* system,
for (unsigned i = regFile->floatRegisters.start;
i < regFile->floatRegisters.limit;
++i) {
new (registerResources + i) RegisterResource(arch->reserved(i));
new (registerResources + i) RegisterResource(arch->reserved(Register(i)));
}
}

View File

@ -594,7 +594,7 @@ class CallEvent : public Event {
ras = static_cast<RegisterSite*>(returnAddressSurrogate->source)
->number;
} else {
ras = Register::None;
ras = NoRegister;
}
Register fps;
@ -603,7 +603,7 @@ class CallEvent : public Event {
fps = static_cast<RegisterSite*>(framePointerSurrogate->source)->number;
} else {
fps = Register::None;
fps = NoRegister;
}
int offset = static_cast<int>(footprint)
@ -1505,7 +1505,7 @@ class MemoryEvent : public Event {
ConstantSite* constant = findConstantSite(c, index);
if (constant) {
indexRegister = Register::None;
indexRegister = NoRegister;
displacement += (constant->value->value() * scale);
scale = 1;
} else {
@ -1513,14 +1513,14 @@ class MemoryEvent : public Event {
indexRegister = static_cast<RegisterSite*>(index->source)->number;
}
} else {
indexRegister = Register::None;
indexRegister = NoRegister;
}
assertT(c, base->source->type(c) == lir::Operand::Type::RegisterPair);
Register baseRegister = static_cast<RegisterSite*>(base->source)->number;
popRead(c, this, base);
if (index) {
if (c->targetInfo.pointerSize == 8 and indexRegister != Register::None) {
if (c->targetInfo.pointerSize == 8 and indexRegister != NoRegister) {
apply(c,
lir::Move,
4,
@ -2035,7 +2035,7 @@ class BoundsCheckEvent : public Event {
assertT(c, object->source->type(c) == lir::Operand::Type::RegisterPair);
MemorySite length(static_cast<RegisterSite*>(object->source)->number,
lengthOffset,
Register::None,
NoRegister,
1);
length.acquired = true;

View File

@ -91,13 +91,13 @@ Register pickRegisterTarget(Context* c,
unsigned* cost,
CostCalculator* costCalculator)
{
Register target = Register::None;
Register target = NoRegister;
*cost = Target::Impossible;
if (mask & c->regFile->generalRegisters.mask) {
for (Register i = c->regFile->generalRegisters.limit - 1;
for (Register i = Register(c->regFile->generalRegisters.limit - 1);
(int8_t)i >= c->regFile->generalRegisters.start;
i = (int8_t)i - 1) {
i = Register((int8_t)i - 1)) {
if (pickRegisterTarget(c, i, v, mask, &target, cost, costCalculator)) {
return i;
}
@ -105,9 +105,9 @@ Register pickRegisterTarget(Context* c,
}
if (mask & c->regFile->floatRegisters.mask) {
for (Register i = c->regFile->floatRegisters.start;
for (Register i = Register(c->regFile->floatRegisters.start);
(int8_t)i < c->regFile->floatRegisters.limit;
i = (int8_t)i + 1) {
i = Register((int8_t)i + 1)) {
if (pickRegisterTarget(c, i, v, mask, &target, cost, costCalculator)) {
return i;
}

View File

@ -113,9 +113,9 @@ unsigned RegisterResource::toString(Context* c,
return vm::snprintf(buffer, bufferSize, "register %d", index(c));
}
unsigned RegisterResource::index(Context* c)
Register RegisterResource::index(Context* c)
{
return this - c->registerResources;
return Register(this - c->registerResources);
}
void RegisterResource::increment(Context* c)

View File

@ -48,7 +48,7 @@ class RegisterResource : public Resource {
virtual unsigned toString(Context* c, char* buffer, unsigned bufferSize);
virtual unsigned index(Context*);
virtual Register index(Context*);
void increment(Context*);

View File

@ -224,7 +224,7 @@ RegisterSite::RegisterSite(RegisterMask mask, Register number)
unsigned RegisterSite::toString(Context*, char* buffer, unsigned bufferSize)
{
if (number != Register::None) {
if (number != NoRegister) {
return vm::snprintf(buffer, bufferSize, "%p register %d", this, number);
} else {
return vm::snprintf(
@ -234,7 +234,7 @@ unsigned RegisterSite::toString(Context*, char* buffer, unsigned bufferSize)
unsigned RegisterSite::copyCost(Context* c, Site* s)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
if (s and (this == s
or (s->type(c) == lir::Operand::Type::RegisterPair
@ -247,7 +247,7 @@ unsigned RegisterSite::copyCost(Context* c, Site* s)
bool RegisterSite::match(Context* c UNUSED, const SiteMask& mask)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
if ((mask.typeMask & (1 << (unsigned)lir::Operand::Type::RegisterPair))) {
return mask.registerMask.contains(number);
@ -258,7 +258,7 @@ bool RegisterSite::match(Context* c UNUSED, const SiteMask& mask)
bool RegisterSite::loneMatch(Context* c UNUSED, const SiteMask& mask)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
if ((mask.typeMask & (1 << (unsigned)lir::Operand::Type::RegisterPair))) {
return mask.registerMask.containsExactly(number);
@ -269,7 +269,7 @@ bool RegisterSite::loneMatch(Context* c UNUSED, const SiteMask& mask)
bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
if (s->type(c) != lir::Operand::Type::RegisterPair) {
return false;
@ -278,7 +278,7 @@ bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned)
RegisterSite* rs = static_cast<RegisterSite*>(s);
unsigned size = rs->registerSize(c);
if (size > c->targetInfo.pointerSize) {
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
return number == rs->number;
} else {
RegisterMask mask = c->regFile->generalRegisters.mask;
@ -289,7 +289,7 @@ bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned)
void RegisterSite::acquire(Context* c, Value* v)
{
Target target;
if (number != Register::None) {
if (number != NoRegister) {
target = Target(number, 0);
} else {
target = pickRegisterTarget(c, v, mask_);
@ -299,33 +299,33 @@ void RegisterSite::acquire(Context* c, Value* v)
RegisterResource* resource = c->registerResources + target.index;
compiler::acquire(c, resource, v, this);
number = target.index;
number = Register(target.index);
}
void RegisterSite::release(Context* c, Value* v)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
compiler::release(c, c->registerResources + (int8_t)number, v, this);
}
void RegisterSite::freeze(Context* c, Value* v)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
c->registerResources[(int8_t)number].freeze(c, v);
}
void RegisterSite::thaw(Context* c, Value* v)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
c->registerResources[(int8_t)number].thaw(c, v);
}
bool RegisterSite::frozen(Context* c UNUSED)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
return c->registerResources[(int8_t)number].freezeCount != 0;
}
@ -339,14 +339,14 @@ void RegisterSite::asAssemblerOperand(Context* c UNUSED,
Site* high,
lir::Operand* result)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
Register highNumber;
if (high != this) {
highNumber = static_cast<RegisterSite*>(high)->number;
assertT(c, highNumber != Register::None);
assertT(c, highNumber != NoRegister);
} else {
highNumber = Register::None;
highNumber = NoRegister;
}
new (result) lir::RegisterPair(number, highNumber);
@ -356,7 +356,7 @@ Site* RegisterSite::copy(Context* c)
{
RegisterMask mask;
if (number != Register::None) {
if (number != NoRegister) {
mask = RegisterMask(number);
} else {
mask = mask_;
@ -377,7 +377,7 @@ Site* RegisterSite::copyHigh(Context* c)
Site* RegisterSite::makeNextWord(Context* c, unsigned)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
assertT(c, c->regFile->generalRegisters.mask.contains(number));
return freeRegisterSite(c, c->regFile->generalRegisters.mask);
@ -390,7 +390,7 @@ SiteMask RegisterSite::mask(Context* c UNUSED)
SiteMask RegisterSite::nextWordMask(Context* c, unsigned)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
if (registerSize(c) > c->targetInfo.pointerSize) {
return SiteMask(1 << (unsigned)lir::Operand::Type::RegisterPair, number, NoFrameIndex);
@ -403,7 +403,7 @@ SiteMask RegisterSite::nextWordMask(Context* c, unsigned)
unsigned RegisterSite::registerSize(Context* c)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
if (c->regFile->floatRegisters.mask.contains(number)) {
return c->arch->floatRegisterSize();
@ -414,14 +414,14 @@ unsigned RegisterSite::registerSize(Context* c)
RegisterMask RegisterSite::registerMask(Context* c UNUSED)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
return RegisterMask(number);
}
Site* registerSite(Context* c, Register number)
{
assertT(c, number != Register::None);
assertT(c, number != NoRegister);
assertT(c,
(c->regFile->generalRegisters.mask
| c->regFile->floatRegisters.mask).contains(number));
@ -431,7 +431,7 @@ Site* registerSite(Context* c, Register number)
Site* freeRegisterSite(Context* c, RegisterMask mask)
{
return new (c->zone) RegisterSite(mask, Register::None);
return new (c->zone) RegisterSite(mask, NoRegister);
}
MemorySite::MemorySite(Register base, int offset, Register index, unsigned scale)
@ -468,7 +468,7 @@ bool MemorySite::conflicts(const SiteMask& mask)
{
return (mask.typeMask & (1 << (unsigned)lir::Operand::Type::RegisterPair)) != 0
and (!mask.registerMask.contains(base)
or (index != Register::None
or (index != NoRegister
and !mask.registerMask.contains(index)));
}
@ -479,7 +479,7 @@ bool MemorySite::match(Context* c, const SiteMask& mask)
if (mask.typeMask & (1 << (unsigned)lir::Operand::Type::Memory)) {
if (mask.frameIndex >= 0) {
if (base == c->arch->stack()) {
assertT(c, index == Register::None);
assertT(c, index == NoRegister);
return static_cast<int>(frameIndexToOffset(c, mask.frameIndex))
== offset;
} else {
@ -499,7 +499,7 @@ bool MemorySite::loneMatch(Context* c, const SiteMask& mask)
if (mask.typeMask & (1 << (unsigned)lir::Operand::Type::Memory)) {
if (base == c->arch->stack()) {
assertT(c, index == Register::None);
assertT(c, index == NoRegister);
if (mask.frameIndex == AnyFrameIndex) {
return false;
@ -533,12 +533,12 @@ bool MemorySite::matchNextWord(Context* c, Site* s, unsigned index)
void MemorySite::acquire(Context* c, Value* v)
{
c->registerResources[(int8_t)base].increment(c);
if (index != Register::None) {
if (index != NoRegister) {
c->registerResources[(int8_t)index].increment(c);
}
if (base == c->arch->stack()) {
assertT(c, index == Register::None);
assertT(c, index == NoRegister);
assertT(c, not c->frameResources[offsetToFrameIndex(c, offset)].reserved);
compiler::acquire(
@ -551,7 +551,7 @@ void MemorySite::acquire(Context* c, Value* v)
void MemorySite::release(Context* c, Value* v)
{
if (base == c->arch->stack()) {
assertT(c, index == Register::None);
assertT(c, index == NoRegister);
assertT(c, not c->frameResources[offsetToFrameIndex(c, offset)].reserved);
compiler::release(
@ -559,7 +559,7 @@ void MemorySite::release(Context* c, Value* v)
}
c->registerResources[(int8_t)base].decrement(c);
if (index != Register::None) {
if (index != NoRegister) {
c->registerResources[(int8_t)index].decrement(c);
}
@ -572,7 +572,7 @@ void MemorySite::freeze(Context* c, Value* v)
c->frameResources[offsetToFrameIndex(c, offset)].freeze(c, v);
} else {
c->registerResources[(int8_t)base].increment(c);
if (index != Register::None) {
if (index != NoRegister) {
c->registerResources[(int8_t)index].increment(c);
}
}
@ -584,7 +584,7 @@ void MemorySite::thaw(Context* c, Value* v)
c->frameResources[offsetToFrameIndex(c, offset)].thaw(c, v);
} else {
c->registerResources[(int8_t)base].decrement(c);
if (index != Register::None) {
if (index != NoRegister) {
c->registerResources[(int8_t)index].decrement(c);
}
}
@ -668,7 +668,7 @@ SiteMask MemorySite::nextWordMask(Context* c, unsigned index)
{
int frameIndex;
if (base == c->arch->stack()) {
assertT(c, this->index == Register::None);
assertT(c, this->index == NoRegister);
frameIndex = static_cast<int>(offsetToFrameIndex(c, offset))
+ ((index == 1) xor c->arch->bigEndian() ? 1 : -1);
} else {
@ -697,7 +697,7 @@ MemorySite* frameSite(Context* c, int frameIndex)
return memorySite(c,
c->arch->stack(),
frameIndexToOffset(c, frameIndex),
Register::None,
NoRegister,
0);
}

View File

@ -360,7 +360,7 @@ class MemorySite : public Site {
MemorySite* memorySite(Context* c,
Register base,
int offset = 0,
Register index = Register::None,
Register index = NoRegister,
unsigned scale = 1);
MemorySite* frameSite(Context* c, int frameIndex);

View File

@ -13,12 +13,10 @@
namespace avian {
namespace codegen {
Register Register::None(-1);
unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
{
for (int i = 0; i <= 31; ++i) {
if (mask.contains(i))
if (mask.contains(Register(i)))
return i;
}
return 32;
@ -27,7 +25,7 @@ unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
unsigned BoundedRegisterMask::maskLimit(RegisterMask mask)
{
for (int i = 31; i >= 0; --i) {
if (mask.contains(i))
if (mask.contains(Register(i)))
return i + 1;
}
return 0;

View File

@ -792,7 +792,7 @@ class MyAssembler : public Assembler {
Register returnAddressSurrogate,
Register framePointerSurrogate UNUSED)
{
assertT(&con, framePointerSurrogate == Register::None);
assertT(&con, framePointerSurrogate == NoRegister);
if (TailCalls) {
if (offset) {
@ -813,7 +813,7 @@ class MyAssembler : public Assembler {
lir::Constant footprintConstant(&footprintPromise);
addC(&con, TargetBytesPerWord, &footprintConstant, &stack, &stack);
if (returnAddressSurrogate != Register::None) {
if (returnAddressSurrogate != NoRegister) {
assertT(&con, offset > 0);
lir::RegisterPair ras(returnAddressSurrogate);

View File

@ -737,7 +737,7 @@ void store(Context* con,
unsigned scale,
bool preserveIndex)
{
if (index != Register::None) {
if (index != NoRegister) {
bool release;
Register normalized
= normalize(con, offset, index, scale, &preserveIndex, &release);
@ -799,8 +799,8 @@ void store(Context* con,
case 8: { // split into 2 32-bit stores
lir::RegisterPair srcHigh(src->high);
store(con, 4, &srcHigh, base, offset, Register::None, 1, false);
store(con, 4, src, base, offset + 4, Register::None, 1, false);
store(con, 4, &srcHigh, base, offset, NoRegister, 1, false);
store(con, 4, src, base, offset + 4, NoRegister, 1, false);
} break;
default:
@ -853,7 +853,7 @@ void load(Context* con,
bool preserveIndex,
bool signExtend)
{
if (index != Register::None) {
if (index != NoRegister) {
bool release;
Register normalized
= normalize(con, offset, index, scale, &preserveIndex, &release);
@ -951,7 +951,7 @@ void load(Context* con,
4,
base,
offset,
Register::None,
NoRegister,
1,
4,
&dstHigh,
@ -961,7 +961,7 @@ void load(Context* con,
4,
base,
offset + 4,
Register::None,
NoRegister,
1,
4,
dst,

View File

@ -59,9 +59,9 @@ inline lir::RegisterPair makeTemp64(Context* con)
inline void freeTemp(Context* con, const lir::RegisterPair& tmp)
{
if (tmp.low != Register::None)
if (tmp.low != NoRegister)
freeTemp(con, tmp.low);
if (tmp.high != Register::None)
if (tmp.high != NoRegister)
freeTemp(con, tmp.high);
}

View File

@ -205,7 +205,7 @@ class MyArchitecture : public Architecture {
virtual Register returnHigh()
{
return (TargetBytesPerWord == 4 ? rdx : Register::None);
return (TargetBytesPerWord == 4 ? rdx : NoRegister);
}
virtual Register virtualCallTarget()
@ -1070,7 +1070,7 @@ class MyAssembler : public Assembler {
addCR(&c, TargetBytesPerWord, &footprint, TargetBytesPerWord, &stack);
if (returnAddressSurrogate != Register::None) {
if (returnAddressSurrogate != NoRegister) {
assertT(&c, offset > 0);
lir::RegisterPair ras(returnAddressSurrogate);
@ -1078,7 +1078,7 @@ class MyAssembler : public Assembler {
moveRM(&c, TargetBytesPerWord, &ras, TargetBytesPerWord, &dst);
}
if (framePointerSurrogate != Register::None) {
if (framePointerSurrogate != NoRegister) {
assertT(&c, offset > 0);
lir::RegisterPair fps(framePointerSurrogate);

View File

@ -65,11 +65,11 @@ void maybeRex(Context* c,
} else {
byte = REX_NONE;
}
if (a != Register::None and ((int8_t)a & 8))
if (a != NoRegister and ((int8_t)a & 8))
byte |= REX_R;
if (index != Register::None and ((int8_t)index & 8))
if (index != NoRegister and ((int8_t)index & 8))
byte |= REX_X;
if (base != Register::None and ((int8_t)base & 8))
if (base != NoRegister and ((int8_t)base & 8))
byte |= REX_B;
if (always or byte != REX_NONE)
c->code.append(byte);
@ -78,17 +78,17 @@ void maybeRex(Context* c,
void maybeRex(Context* c, unsigned size, lir::RegisterPair* a, lir::RegisterPair* b)
{
maybeRex(c, size, a->low, Register::None, b->low, false);
maybeRex(c, size, a->low, NoRegister, b->low, false);
}
void alwaysRex(Context* c, unsigned size, lir::RegisterPair* a, lir::RegisterPair* b)
{
maybeRex(c, size, a->low, Register::None, b->low, true);
maybeRex(c, size, a->low, NoRegister, b->low, true);
}
void maybeRex(Context* c, unsigned size, lir::RegisterPair* a)
{
maybeRex(c, size, Register::None, Register::None, a->low, false);
maybeRex(c, size, NoRegister, NoRegister, a->low, false);
}
void maybeRex(Context* c, unsigned size, lir::RegisterPair* a, lir::Memory* b)
@ -98,7 +98,7 @@ void maybeRex(Context* c, unsigned size, lir::RegisterPair* a, lir::Memory* b)
void maybeRex(Context* c, unsigned size, lir::Memory* a)
{
maybeRex(c, size, Register::None, a->index, a->base, false);
maybeRex(c, size, NoRegister, a->index, a->base, false);
}
void modrm(Context* c, uint8_t mod, Register a, Register b)
@ -119,7 +119,7 @@ void sib(Context* c, unsigned scale, Register index, Register base)
void modrmSib(Context* c, int width, Register a, int scale, Register index, Register base)
{
if (index == Register::None) {
if (index == NoRegister) {
modrm(c, width, base, a);
if (regCode(base) == rsp) {
sib(c, 0x00, rsp, rsp);