remove redundant size parameter to appendBranch, rename type -> op

This commit is contained in:
Joshua Warner 2014-05-03 21:45:59 -06:00 committed by Joshua Warner
parent 0eda1d7d11
commit e7837c243e
3 changed files with 244 additions and 149 deletions

View File

@ -2638,7 +2638,6 @@ class MyCompiler: public Compiler {
appendBranch(&c, appendBranch(&c,
op, op,
a->type.size(),
static_cast<Value*>(a), static_cast<Value*>(a),
static_cast<Value*>(b), static_cast<Value*>(b),
static_cast<Value*>(address)); static_cast<Value*>(address));

View File

@ -60,9 +60,13 @@ Read* live(Context* c UNUSED, Value* v);
void popRead(Context* c, Event* e UNUSED, Value* v); void popRead(Context* c, Event* e UNUSED, Value* v);
void void maybeMove(Context* c,
maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, lir::BinaryOperation op,
unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst, unsigned srcSize,
unsigned srcSelectSize,
Value* src,
unsigned dstSize,
Value* dst,
const SiteMask& dstMask); const SiteMask& dstMask);
Site* Site*
@ -654,11 +658,22 @@ void appendReturn(Context* c, Value* value)
class MoveEvent: public Event { class MoveEvent: public Event {
public: public:
MoveEvent(Context* c, lir::BinaryOperation type, unsigned srcSize, MoveEvent(Context* c,
unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue, lir::BinaryOperation op,
const SiteMask& srcLowMask, const SiteMask& srcHighMask): unsigned srcSize,
Event(c), type(type), srcSize(srcSize), srcSelectSize(srcSelectSize), unsigned srcSelectSize,
srcValue(srcValue), dstSize(dstSize), dstValue(dstValue) Value* srcValue,
unsigned dstSize,
Value* dstValue,
const SiteMask& srcLowMask,
const SiteMask& srcHighMask)
: Event(c),
op(op),
srcSize(srcSize),
srcSelectSize(srcSelectSize),
srcValue(srcValue),
dstSize(dstSize),
dstValue(dstValue)
{ {
assert(c, srcSelectSize <= srcSize); assert(c, srcSelectSize <= srcSize);
@ -684,14 +699,15 @@ class MoveEvent: public Event {
virtual void compile(Context* c) { virtual void compile(Context* c) {
OperandMask dst; OperandMask dst;
c->arch->planDestination c->arch->planDestination(
(type, op,
srcSelectSize, srcSelectSize,
OperandMask( OperandMask(
1 << srcValue->source->type(c), 1 << srcValue->source->type(c),
(static_cast<uint64_t>(srcValue->nextWord->source->registerMask(c)) << 32) (static_cast<uint64_t>(srcValue->nextWord->source->registerMask(c))
| static_cast<uint64_t>(srcValue->source->registerMask(c))), << 32) | static_cast<uint64_t>(srcValue->source->registerMask(c))),
dstSize, dst); dstSize,
dst);
SiteMask dstLowMask = SiteMask::lowPart(dst); SiteMask dstLowMask = SiteMask::lowPart(dst);
SiteMask dstHighMask = SiteMask::highPart(dst); SiteMask dstHighMask = SiteMask::highPart(dst);
@ -737,7 +753,13 @@ class MoveEvent: public Event {
} else if (srcSelectSize <= vm::TargetBytesPerWord } else if (srcSelectSize <= vm::TargetBytesPerWord
and dstSize <= vm::TargetBytesPerWord) and dstSize <= vm::TargetBytesPerWord)
{ {
maybeMove(c, type, srcSize, srcSelectSize, srcValue, dstSize, dstValue, maybeMove(c,
op,
srcSize,
srcSelectSize,
srcValue,
dstSize,
dstValue,
dstLowMask); dstLowMask);
} else { } else {
assert(c, srcSize == vm::TargetBytesPerWord); assert(c, srcSize == vm::TargetBytesPerWord);
@ -800,7 +822,7 @@ class MoveEvent: public Event {
} }
} }
lir::BinaryOperation type; lir::BinaryOperation op;
unsigned srcSize; unsigned srcSize;
unsigned srcSelectSize; unsigned srcSelectSize;
Value* srcValue; Value* srcValue;
@ -808,21 +830,29 @@ class MoveEvent: public Event {
Value* dstValue; Value* dstValue;
}; };
void void appendMove(Context* c,
appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, lir::BinaryOperation op,
unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue) unsigned srcSize,
unsigned srcSelectSize,
Value* srcValue,
unsigned dstSize,
Value* dstValue)
{ {
bool thunk; bool thunk;
OperandMask src; OperandMask src;
c->arch->planSource c->arch->planSource(op, srcSelectSize, src, dstSize, &thunk);
(type, srcSelectSize, src, dstSize, &thunk);
assert(c, not thunk); assert(c, not thunk);
append(c, new(c->zone) append(c,
MoveEvent new (c->zone) MoveEvent(c,
(c, type, srcSize, srcSelectSize, srcValue, dstSize, dstValue, op,
srcSize,
srcSelectSize,
srcValue,
dstSize,
dstValue,
SiteMask::lowPart(src), SiteMask::lowPart(src),
SiteMask::highPart(src))); SiteMask::highPart(src)));
} }
@ -899,15 +929,18 @@ Site* getTarget(Context* c, Value* value, Value* result, const SiteMask& resultM
class CombineEvent: public Event { class CombineEvent: public Event {
public: public:
CombineEvent(Context* c, lir::TernaryOperation type, CombineEvent(Context* c,
lir::TernaryOperation op,
Value* firstValue, Value* firstValue,
Value* secondValue, Value* secondValue,
Value* resultValue, Value* resultValue,
const SiteMask& firstLowMask, const SiteMask& firstLowMask,
const SiteMask& firstHighMask, const SiteMask& firstHighMask,
const SiteMask& secondLowMask, const SiteMask& secondLowMask,
const SiteMask& secondHighMask): const SiteMask& secondHighMask)
Event(c), type(type), firstValue(firstValue), : Event(c),
op(op),
firstValue(firstValue),
secondValue(secondValue), secondValue(secondValue),
resultValue(resultValue) resultValue(resultValue)
{ {
@ -917,7 +950,7 @@ class CombineEvent: public Event {
resultValue->grow(c); resultValue->grow(c);
} }
bool condensed = c->arch->alwaysCondensed(type); bool condensed = c->arch->alwaysCondensed(op);
this->addReads(c, secondValue, secondValue->type.size(), this->addReads(c, secondValue, secondValue->type.size(),
secondLowMask, condensed ? resultValue : 0, secondLowMask, condensed ? resultValue : 0,
@ -944,17 +977,21 @@ class CombineEvent: public Event {
OperandMask cMask; OperandMask cMask;
c->arch->planDestination c->arch->planDestination(
(type, op,
firstValue->type.size(), firstValue->type.size(),
OperandMask( OperandMask(
1 << firstValue->source->type(c), 1 << firstValue->source->type(c),
(static_cast<uint64_t>(firstValue->nextWord->source->registerMask(c)) << 32) (static_cast<uint64_t>(
firstValue->nextWord->source->registerMask(c))
<< 32)
| static_cast<uint64_t>(firstValue->source->registerMask(c))), | static_cast<uint64_t>(firstValue->source->registerMask(c))),
secondValue->type.size(), secondValue->type.size(),
OperandMask( OperandMask(
1 << secondValue->source->type(c), 1 << secondValue->source->type(c),
(static_cast<uint64_t>(secondValue->nextWord->source->registerMask(c)) << 32) (static_cast<uint64_t>(
secondValue->nextWord->source->registerMask(c))
<< 32)
| static_cast<uint64_t>(secondValue->source->registerMask(c))), | static_cast<uint64_t>(secondValue->source->registerMask(c))),
resultValue->type.size(), resultValue->type.size(),
cMask); cMask);
@ -974,10 +1011,17 @@ class CombineEvent: public Event {
// secondValue, secondValue->nextWord, // secondValue, secondValue->nextWord,
// resultValue, resultValue->nextWord); // resultValue, resultValue->nextWord);
apply(c, type, apply(c,
firstValue->type.size(), firstValue->source, firstValue->nextWord->source, op,
secondValue->type.size(), secondValue->source, secondValue->nextWord->source, firstValue->type.size(),
resultValue->type.size(), low, high); firstValue->source,
firstValue->nextWord->source,
secondValue->type.size(),
secondValue->source,
secondValue->nextWord->source,
resultValue->type.size(),
low,
high);
thawSource(c, firstValue->type.size(), firstValue); thawSource(c, firstValue->type.size(), firstValue);
@ -998,7 +1042,7 @@ class CombineEvent: public Event {
} }
} }
lir::TernaryOperation type; lir::TernaryOperation op;
Value* firstValue; Value* firstValue;
Value* secondValue; Value* secondValue;
Value* resultValue; Value* resultValue;
@ -1076,14 +1120,15 @@ void appendCombine(Context* c,
class TranslateEvent: public Event { class TranslateEvent: public Event {
public: public:
TranslateEvent(Context* c, lir::BinaryOperation type, TranslateEvent(Context* c,
Value* firstValue, Value* resultValue, lir::BinaryOperation op,
Value* firstValue,
Value* resultValue,
const SiteMask& valueLowMask, const SiteMask& valueLowMask,
const SiteMask& valueHighMask): const SiteMask& valueHighMask)
Event(c), type(type), : Event(c), op(op), firstValue(firstValue), resultValue(resultValue)
firstValue(firstValue), resultValue(resultValue)
{ {
bool condensed = c->arch->alwaysCondensed(type); bool condensed = c->arch->alwaysCondensed(op);
if (resultValue->type.size() > vm::TargetBytesPerWord) { if (resultValue->type.size() > vm::TargetBytesPerWord) {
resultValue->grow(c); resultValue->grow(c);
@ -1102,12 +1147,14 @@ class TranslateEvent: public Event {
OperandMask bMask; OperandMask bMask;
c->arch->planDestination c->arch->planDestination(
(type, op,
firstValue->type.size(), firstValue->type.size(),
OperandMask( OperandMask(
1 << firstValue->source->type(c), 1 << firstValue->source->type(c),
(static_cast<uint64_t>(firstValue->nextWord->source->registerMask(c)) << 32) (static_cast<uint64_t>(
firstValue->nextWord->source->registerMask(c))
<< 32)
| static_cast<uint64_t>(firstValue->source->registerMask(c))), | static_cast<uint64_t>(firstValue->source->registerMask(c))),
resultValue->type.size(), resultValue->type.size(),
bMask); bMask);
@ -1122,8 +1169,14 @@ class TranslateEvent: public Event {
? getTarget(c, firstValue->nextWord, resultValue->nextWord, resultHighMask) ? getTarget(c, firstValue->nextWord, resultValue->nextWord, resultHighMask)
: low); : low);
apply(c, type, firstValue->type.size(), firstValue->source, firstValue->nextWord->source, apply(c,
resultValue->type.size(), low, high); op,
firstValue->type.size(),
firstValue->source,
firstValue->nextWord->source,
resultValue->type.size(),
low,
high);
for (Read* r = reads; r; r = r->eventNext) { for (Read* r = reads; r; r = r->eventNext) {
popRead(c, this, r->value); popRead(c, this, r->value);
@ -1142,7 +1195,7 @@ class TranslateEvent: public Event {
} }
} }
lir::BinaryOperation type; lir::BinaryOperation op;
Value* firstValue; Value* firstValue;
Value* resultValue; Value* resultValue;
Read* resultRead; Read* resultRead;
@ -1341,11 +1394,13 @@ unordered(double a, double b)
return not (a >= b or a < b); return not (a >= b or a < b);
} }
bool bool shouldJump(Context* c,
shouldJump(Context* c, lir::TernaryOperation type, unsigned size, int64_t b, lir::TernaryOperation op,
unsigned size,
int64_t b,
int64_t a) int64_t a)
{ {
switch (type) { switch (op) {
case lir::JumpIfEqual: case lir::JumpIfEqual:
return a == b; return a == b;
@ -1403,10 +1458,9 @@ shouldJump(Context* c, lir::TernaryOperation type, unsigned size, int64_t b,
} }
} }
lir::TernaryOperation lir::TernaryOperation thunkBranch(Context* c, lir::TernaryOperation op)
thunkBranch(Context* c, lir::TernaryOperation type)
{ {
switch (type) { switch (op) {
case lir::JumpIfFloatEqual: case lir::JumpIfFloatEqual:
return lir::JumpIfEqual; return lir::JumpIfEqual;
@ -1436,23 +1490,34 @@ thunkBranch(Context* c, lir::TernaryOperation type)
class BranchEvent: public Event { class BranchEvent: public Event {
public: public:
BranchEvent(Context* c, lir::TernaryOperation type, unsigned size, BranchEvent(Context* c,
Value* firstValue, Value* secondValue, Value* addressValue, lir::TernaryOperation op,
Value* firstValue,
Value* secondValue,
Value* addressValue,
const SiteMask& firstLowMask, const SiteMask& firstLowMask,
const SiteMask& firstHighMask, const SiteMask& firstHighMask,
const SiteMask& secondLowMask, const SiteMask& secondLowMask,
const SiteMask& secondHighMask): const SiteMask& secondHighMask)
Event(c), type(type), size(size), firstValue(firstValue), secondValue(secondValue), : Event(c),
op(op),
firstValue(firstValue),
secondValue(secondValue),
addressValue(addressValue) addressValue(addressValue)
{ {
this->addReads(c, firstValue, size, firstLowMask, firstHighMask); this->addReads(
this->addReads(c, secondValue, size, secondLowMask, secondHighMask); c, firstValue, firstValue->type.size(), firstLowMask, firstHighMask);
this->addReads(
c, secondValue, firstValue->type.size(), secondLowMask, secondHighMask);
OperandMask dstMask; OperandMask dstMask;
c->arch->planDestination(type, c->arch->planDestination(op,
size, OperandMask(0, 0), firstValue->type.size(),
size, OperandMask(0, 0), OperandMask(0, 0),
vm::TargetBytesPerWord, dstMask); firstValue->type.size(),
OperandMask(0, 0),
vm::TargetBytesPerWord,
dstMask);
this->addRead(c, addressValue, SiteMask::lowPart(dstMask)); this->addRead(c, addressValue, SiteMask::lowPart(dstMask));
} }
@ -1474,28 +1539,40 @@ class BranchEvent: public Event {
int64_t firstConstVal = firstConstant->value->value(); int64_t firstConstVal = firstConstant->value->value();
int64_t secondConstVal = secondConstant->value->value(); int64_t secondConstVal = secondConstant->value->value();
if (size > vm::TargetBytesPerWord) { if (firstValue->type.size() > vm::TargetBytesPerWord) {
firstConstVal |= findConstantSite firstConstVal |= findConstantSite
(c, firstValue->nextWord)->value->value() << 32; (c, firstValue->nextWord)->value->value() << 32;
secondConstVal |= findConstantSite secondConstVal |= findConstantSite
(c, secondValue->nextWord)->value->value() << 32; (c, secondValue->nextWord)->value->value() << 32;
} }
if (shouldJump(c, type, size, firstConstVal, secondConstVal)) { if (shouldJump(c,
op,
firstValue->type.size(),
firstConstVal,
secondConstVal)) {
apply(c, lir::Jump, vm::TargetBytesPerWord, addressValue->source, addressValue->source); apply(c, lir::Jump, vm::TargetBytesPerWord, addressValue->source, addressValue->source);
} }
} else { } else {
freezeSource(c, size, firstValue); freezeSource(c, firstValue->type.size(), firstValue);
freezeSource(c, size, secondValue); freezeSource(c, firstValue->type.size(), secondValue);
freezeSource(c, vm::TargetBytesPerWord, addressValue); freezeSource(c, vm::TargetBytesPerWord, addressValue);
apply(c, type, size, firstValue->source, firstValue->nextWord->source, apply(c,
size, secondValue->source, secondValue->nextWord->source, op,
vm::TargetBytesPerWord, addressValue->source, addressValue->source); firstValue->type.size(),
firstValue->source,
firstValue->nextWord->source,
firstValue->type.size(),
secondValue->source,
secondValue->nextWord->source,
vm::TargetBytesPerWord,
addressValue->source,
addressValue->source);
thawSource(c, vm::TargetBytesPerWord, addressValue); thawSource(c, vm::TargetBytesPerWord, addressValue);
thawSource(c, size, secondValue); thawSource(c, firstValue->type.size(), secondValue);
thawSource(c, size, firstValue); thawSource(c, firstValue->type.size(), firstValue);
} }
} }
@ -1506,45 +1583,47 @@ class BranchEvent: public Event {
virtual bool isBranch() { return true; } virtual bool isBranch() { return true; }
lir::TernaryOperation type; lir::TernaryOperation op;
unsigned size;
Value* firstValue; Value* firstValue;
Value* secondValue; Value* secondValue;
Value* addressValue; Value* addressValue;
}; };
void void appendBranch(Context* c,
appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* firstValue, lir::TernaryOperation op,
Value* secondValue, Value* addressValue) Value* firstValue,
Value* secondValue,
Value* addressValue)
{ {
assert(c, size == firstValue->type.size());
assert(c, size == secondValue->type.size());
bool thunk; bool thunk;
OperandMask firstMask; OperandMask firstMask;
OperandMask secondMask; OperandMask secondMask;
c->arch->planSource(type, c->arch->planSource(op,
size, firstMask, firstValue->type.size(),
size, secondMask, firstMask,
vm::TargetBytesPerWord, &thunk); firstValue->type.size(),
secondMask,
vm::TargetBytesPerWord,
&thunk);
if (thunk) { if (thunk) {
FixedSliceStack<ir::Value*, 4> slice; FixedSliceStack<ir::Value*, 4> slice;
size_t stackBase = c->stack ? c->stack->index + 1 : 0; size_t stackBase = c->stack ? c->stack->index + 1 : 0;
bool threadParameter; bool threadParameter;
intptr_t handler = c->client->getThunk intptr_t handler = c->client->getThunk(
(type, size, size, &threadParameter); op, firstValue->type.size(), firstValue->type.size(), &threadParameter);
assert(c, not threadParameter); assert(c, not threadParameter);
pushSlice(c, pushSlice(c,
ceilingDivide(size, vm::TargetBytesPerWord), ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord),
secondValue, secondValue,
stackBase, stackBase,
slice); slice);
pushSlice(c, pushSlice(c,
ceilingDivide(size, vm::TargetBytesPerWord), ceilingDivide(firstValue->type.size(), vm::TargetBytesPerWord),
firstValue, firstValue,
stackBase, stackBase,
slice); slice);
@ -1562,18 +1641,19 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first
slice); slice);
appendBranch(c, appendBranch(c,
thunkBranch(c, type), thunkBranch(c, op),
4,
value(c, value(c,
ir::Type(ir::Type::Address, vm::TargetBytesPerWord), ir::Type(ir::Type::Address, vm::TargetBytesPerWord),
constantSite(c, static_cast<int64_t>(0))), constantSite(c, static_cast<int64_t>(0))),
result, result,
addressValue); addressValue);
} else { } else {
append append(c,
(c, new(c->zone) new (c->zone) BranchEvent(c,
BranchEvent op,
(c, type, size, firstValue, secondValue, addressValue, firstValue,
secondValue,
addressValue,
SiteMask::lowPart(firstMask), SiteMask::lowPart(firstMask),
SiteMask::highPart(firstMask), SiteMask::highPart(firstMask),
SiteMask::lowPart(secondMask), SiteMask::lowPart(secondMask),
@ -1619,14 +1699,16 @@ clean(Context* c, Event* e, Stack* stack, Local* locals, Read* reads,
class JumpEvent: public Event { class JumpEvent: public Event {
public: public:
JumpEvent(Context* c, lir::UnaryOperation type, Value* address, bool exit, JumpEvent(Context* c,
bool cleanLocals): lir::UnaryOperation op,
Event(c), type(type), address(address), exit(exit), Value* address,
cleanLocals(cleanLocals) bool exit,
bool cleanLocals)
: Event(c), op(op), address(address), exit(exit), cleanLocals(cleanLocals)
{ {
bool thunk; bool thunk;
OperandMask mask; OperandMask mask;
c->arch->plan(type, vm::TargetBytesPerWord, mask, &thunk); c->arch->plan(op, vm::TargetBytesPerWord, mask, &thunk);
assert(c, not thunk); assert(c, not thunk);
@ -1639,7 +1721,7 @@ class JumpEvent: public Event {
virtual void compile(Context* c) { virtual void compile(Context* c) {
if (not this->isUnreachable()) { if (not this->isUnreachable()) {
apply(c, type, vm::TargetBytesPerWord, address->source, address->source); apply(c, op, vm::TargetBytesPerWord, address->source, address->source);
} }
for (Read* r = reads; r; r = r->eventNext) { for (Read* r = reads; r; r = r->eventNext) {
@ -1660,14 +1742,19 @@ class JumpEvent: public Event {
return exit or this->isUnreachable(); return exit or this->isUnreachable();
} }
lir::UnaryOperation type; lir::UnaryOperation op;
Value* address; Value* address;
bool exit; bool exit;
bool cleanLocals; bool cleanLocals;
}; };
void appendJump(Context* c, lir::UnaryOperation type, Value* address, bool exit, bool cleanLocals) { void appendJump(Context* c,
append(c, new(c->zone) JumpEvent(c, type, address, exit, cleanLocals)); lir::UnaryOperation op,
Value* address,
bool exit,
bool cleanLocals)
{
append(c, new (c->zone) JumpEvent(c, op, address, exit, cleanLocals));
} }
class BoundsCheckEvent: public Event { class BoundsCheckEvent: public Event {

View File

@ -123,19 +123,24 @@ void appendCall(Context* c,
void appendReturn(Context* c, Value* value); void appendReturn(Context* c, Value* value);
void void appendMove(Context* c,
appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, lir::BinaryOperation op,
unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst); unsigned srcSize,
unsigned srcSelectSize,
Value* src,
unsigned dstSize,
Value* dst);
void void appendCombine(Context* c,
appendCombine(Context* c, lir::TernaryOperation type, lir::TernaryOperation op,
Value* first, Value* first,
Value* second, Value* second,
Value* result); Value* result);
void void appendTranslate(Context* c,
appendTranslate(Context* c, lir::BinaryOperation type, lir::BinaryOperation op,
Value* first, Value* result); Value* first,
Value* result);
void void
appendOperation(Context* c, lir::Operation op); appendOperation(Context* c, lir::Operation op);
@ -144,12 +149,16 @@ void
appendMemory(Context* c, Value* base, int displacement, Value* index, appendMemory(Context* c, Value* base, int displacement, Value* index,
unsigned scale, Value* result); unsigned scale, Value* result);
void void appendBranch(Context* c,
appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first, lir::TernaryOperation op,
Value* second, Value* address); Value* first,
Value* second,
Value* address);
void void appendJump(Context* c,
appendJump(Context* c, lir::UnaryOperation type, Value* address, bool exit = false, lir::UnaryOperation op,
Value* address,
bool exit = false,
bool cleanLocals = false); bool cleanLocals = false);
void void