move Compiler::Operand to ir::Value

This commit is contained in:
Joshua Warner
2014-05-01 12:44:42 -06:00
parent 865041b688
commit 479c056b2c
6 changed files with 351 additions and 328 deletions

View File

@ -40,15 +40,6 @@ class Compiler {
static const unsigned TailJump = 1 << 2; static const unsigned TailJump = 1 << 2;
static const unsigned LongJumpOrCall = 1 << 3; static const unsigned LongJumpOrCall = 1 << 3;
class Operand {
public:
ir::Type type;
Operand(ir::Type type) : type(type)
{
}
};
class State { }; class State { };
class Subroutine { }; class Subroutine { };
@ -56,8 +47,8 @@ class Compiler {
virtual void restoreState(State* state) = 0; virtual void restoreState(State* state) = 0;
virtual Subroutine* startSubroutine() = 0; virtual Subroutine* startSubroutine() = 0;
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address)
= 0; = 0;
virtual void linkSubroutine(Subroutine* subroutine) = 0; virtual void linkSubroutine(Subroutine* subroutine) = 0;
virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint, virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint,
@ -71,83 +62,84 @@ class Compiler {
virtual Promise* poolAppend(intptr_t value) = 0; virtual Promise* poolAppend(intptr_t value) = 0;
virtual Promise* poolAppendPromise(Promise* value) = 0; virtual Promise* poolAppendPromise(Promise* value) = 0;
virtual Operand* constant(int64_t value, ir::Type type) = 0; virtual ir::Value* constant(int64_t value, ir::Type type) = 0;
virtual Operand* promiseConstant(Promise* value, ir::Type type) = 0; virtual ir::Value* promiseConstant(Promise* value, ir::Type type) = 0;
virtual Operand* address(ir::Type type, Promise* address) = 0; virtual ir::Value* address(ir::Type type, Promise* address) = 0;
virtual Operand* memory(Operand* base, virtual ir::Value* memory(ir::Value* base,
ir::Type type, ir::Type type,
int displacement = 0, int displacement = 0,
Operand* index = 0) = 0; ir::Value* index = 0) = 0;
virtual Operand* threadRegister() = 0; virtual ir::Value* threadRegister() = 0;
virtual void push(ir::Type type, Operand* value) = 0; virtual void push(ir::Type type, ir::Value* value) = 0;
virtual void save(ir::Type type, Operand* value) = 0; virtual void save(ir::Type type, ir::Value* value) = 0;
virtual Operand* pop(ir::Type type) = 0; virtual ir::Value* pop(ir::Type type) = 0;
virtual void pushed() = 0; virtual void pushed() = 0;
virtual void popped(unsigned footprint) = 0; virtual void popped(unsigned footprint) = 0;
virtual unsigned topOfStack() = 0; virtual unsigned topOfStack() = 0;
virtual Operand* peek(unsigned footprint, unsigned index) = 0; virtual ir::Value* peek(unsigned footprint, unsigned index) = 0;
virtual Operand* call(Operand* address, virtual ir::Value* call(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentCount, unsigned argumentCount,
...) = 0; ...) = 0;
virtual Operand* stackCall(Operand* address, virtual ir::Value* stackCall(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentFootprint) = 0; unsigned argumentFootprint) = 0;
virtual void return_(ir::Type type, Operand* value) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0;
virtual void return_() = 0; virtual void return_() = 0;
virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0;
virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0;
virtual void storeLocal(unsigned footprint, Operand* src, virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index)
unsigned index) = 0; = 0;
virtual Operand* loadLocal(ir::Type type, unsigned index) = 0; virtual ir::Value* loadLocal(ir::Type type, unsigned index) = 0;
virtual void saveLocals() = 0; virtual void saveLocals() = 0;
virtual void checkBounds(Operand* object, unsigned lengthOffset, virtual void checkBounds(ir::Value* object,
Operand* index, intptr_t handler) = 0; unsigned lengthOffset,
ir::Value* index,
intptr_t handler) = 0;
virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend,
ir::Type extendType, ir::Type extendType,
ir::Type truncateType, ir::Type truncateType,
Operand* src) = 0; ir::Value* src) = 0;
virtual void store(ir::Type srcType, virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0;
Operand* src, virtual ir::Value* load(ir::SignExtendMode signExtend,
Operand* dst) = 0; ir::Type srcType,
virtual Operand* load(ir::SignExtendMode signExtend, ir::Value* src,
ir::Type srcType, ir::Type dstType) = 0;
Operand* src,
ir::Type dstType) = 0;
virtual void condJump(lir::TernaryOperation op, virtual void condJump(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b, ir::Value* b,
Operand* address) = 0; ir::Value* address) = 0;
virtual void jmp(Operand* address) = 0; virtual void jmp(ir::Value* address) = 0;
virtual void exit(Operand* address) = 0; virtual void exit(ir::Value* address) = 0;
virtual Operand* binaryOp(lir::TernaryOperation op, virtual ir::Value* binaryOp(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b) = 0; ir::Value* b) = 0;
virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) virtual ir::Value* unaryOp(lir::BinaryOperation op,
= 0; ir::Type type,
ir::Value* a) = 0;
virtual void nullaryOp(lir::Operation op) = 0; virtual void nullaryOp(lir::Operation op) = 0;
virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0;
virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) = 0;
virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0;
virtual void compile(uintptr_t stackOverflowHandler, virtual void compile(uintptr_t stackOverflowHandler,
unsigned stackLimitOffset) = 0; unsigned stackLimitOffset) = 0;

View File

@ -115,6 +115,15 @@ class Types {
enum SignExtendMode { SignExtend, ZeroExtend }; enum SignExtendMode { SignExtend, ZeroExtend };
class Value {
public:
ir::Type type;
Value(ir::Type type) : type(type)
{
}
};
} // namespace ir } // namespace ir
} // namespace codegen } // namespace codegen
} // namespace avian } // namespace avian

View File

@ -2151,7 +2151,8 @@ class MyCompiler: public Compiler {
return c.subroutine = new(c.zone) MySubroutine; return c.subroutine = new(c.zone) MySubroutine;
} }
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) { virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address)
{
appendSaveLocals(&c); appendSaveLocals(&c);
appendJump(&c, lir::Jump, static_cast<Value*>(address), false, true); appendJump(&c, lir::Jump, static_cast<Value*>(address), false, true);
static_cast<MySubroutine*>(subroutine)->forkState = compiler::saveState(&c); static_cast<MySubroutine*>(subroutine)->forkState = compiler::saveState(&c);
@ -2308,25 +2309,25 @@ class MyCompiler: public Compiler {
return p; return p;
} }
virtual Operand* constant(int64_t value, ir::Type type) virtual ir::Value* constant(int64_t value, ir::Type type)
{ {
return promiseConstant(resolvedPromise(&c, value), type); return promiseConstant(resolvedPromise(&c, value), type);
} }
virtual Operand* promiseConstant(Promise* value, ir::Type type) virtual ir::Value* promiseConstant(Promise* value, ir::Type type)
{ {
return compiler::value(&c, type, compiler::constantSite(&c, value)); return compiler::value(&c, type, compiler::constantSite(&c, value));
} }
virtual Operand* address(ir::Type type, Promise* address) virtual ir::Value* address(ir::Type type, Promise* address)
{ {
return value(&c, type, compiler::addressSite(&c, address)); return value(&c, type, compiler::addressSite(&c, address));
} }
virtual Operand* memory(Operand* base, virtual ir::Value* memory(ir::Value* base,
ir::Type type, ir::Type type,
int displacement = 0, int displacement = 0,
Operand* index = 0) ir::Value* index = 0)
{ {
Value* result = value(&c, type); Value* result = value(&c, type);
@ -2340,7 +2341,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* threadRegister() virtual ir::Value* threadRegister()
{ {
return compiler::threadRegister(&c); return compiler::threadRegister(&c);
} }
@ -2349,7 +2350,7 @@ class MyCompiler: public Compiler {
return c.logicalCode[c.logicalIp]->lastEvent->makeCodePromise(&c); return c.logicalCode[c.logicalIp]->lastEvent->makeCodePromise(&c);
} }
virtual void push(ir::Type type, Operand* value) virtual void push(ir::Type type, ir::Value* value)
{ {
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
@ -2357,7 +2358,7 @@ class MyCompiler: public Compiler {
compiler::push(&c, typeFootprint(&c, type), static_cast<Value*>(value)); compiler::push(&c, typeFootprint(&c, type), static_cast<Value*>(value));
} }
virtual void save(ir::Type type, Operand* value) virtual void save(ir::Type type, ir::Value* value)
{ {
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
@ -2373,9 +2374,9 @@ class MyCompiler: public Compiler {
} }
} }
virtual Operand* pop(ir::Type type) virtual ir::Value* pop(ir::Type type)
{ {
Operand* value = compiler::pop(&c, typeFootprint(&c, type)); ir::Value* value = compiler::pop(&c, typeFootprint(&c, type));
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
// assert(&c, static_cast<Value*>(value)->type == type); // assert(&c, static_cast<Value*>(value)->type == type);
@ -2409,7 +2410,8 @@ class MyCompiler: public Compiler {
return c.stack->index; return c.stack->index;
} }
virtual Operand* peek(unsigned footprint, unsigned index) { virtual ir::Value* peek(unsigned footprint, unsigned index)
{
Stack* s = c.stack; Stack* s = c.stack;
for (unsigned i = index; i > 0; --i) { for (unsigned i = index; i > 0; --i) {
s = s->next; s = s->next;
@ -2445,12 +2447,12 @@ class MyCompiler: public Compiler {
return s->value; return s->value;
} }
virtual Operand* call(Operand* address, virtual ir::Value* call(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentCount, unsigned argumentCount,
...) ...)
{ {
va_list a; va_start(a, argumentCount); va_list a; va_start(a, argumentCount);
@ -2500,11 +2502,11 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* stackCall(Operand* address, virtual ir::Value* stackCall(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentFootprint) unsigned argumentFootprint)
{ {
Value* result = value(&c, resultType); Value* result = value(&c, resultType);
appendCall(&c, appendCall(&c,
@ -2519,7 +2521,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual void return_(ir::Type type, Operand* value) virtual void return_(ir::Type type, ir::Value* value)
{ {
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
@ -2595,11 +2597,12 @@ class MyCompiler: public Compiler {
linkLocals(&c, e->locals(), newLocals); linkLocals(&c, e->locals(), newLocals);
} }
virtual void storeLocal(unsigned footprint, Operand* src, unsigned index) { virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index)
{
compiler::storeLocal(&c, footprint, static_cast<Value*>(src), index, true); compiler::storeLocal(&c, footprint, static_cast<Value*>(src), index, true);
} }
virtual Operand* loadLocal(ir::Type type, unsigned index) virtual ir::Value* loadLocal(ir::Type type, unsigned index)
{ {
return compiler::loadLocal(&c, type, index); return compiler::loadLocal(&c, type, index);
} }
@ -2608,17 +2611,19 @@ class MyCompiler: public Compiler {
appendSaveLocals(&c); appendSaveLocals(&c);
} }
virtual void checkBounds(Operand* object, unsigned lengthOffset, virtual void checkBounds(ir::Value* object,
Operand* index, intptr_t handler) unsigned lengthOffset,
ir::Value* index,
intptr_t handler)
{ {
appendBoundsCheck(&c, static_cast<Value*>(object), lengthOffset, appendBoundsCheck(&c, static_cast<Value*>(object), lengthOffset,
static_cast<Value*>(index), handler); static_cast<Value*>(index), handler);
} }
virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend,
ir::Type extendType, ir::Type extendType,
ir::Type truncateType, ir::Type truncateType,
Operand* src) ir::Value* src)
{ {
Value* dst = value(&c, extendType); Value* dst = value(&c, extendType);
appendMove(&c, appendMove(&c,
@ -2631,9 +2636,7 @@ class MyCompiler: public Compiler {
return dst; return dst;
} }
virtual void store(ir::Type srcType, virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst)
Operand* src,
Operand* dst)
{ {
assert(&c, srcType.flavor() == static_cast<Value*>(src)->type.flavor()); assert(&c, srcType.flavor() == static_cast<Value*>(src)->type.flavor());
assert(&c, srcType.flavor() == static_cast<Value*>(dst)->type.flavor()); assert(&c, srcType.flavor() == static_cast<Value*>(dst)->type.flavor());
@ -2649,10 +2652,10 @@ class MyCompiler: public Compiler {
static_cast<Value*>(dst)); static_cast<Value*>(dst));
} }
virtual Operand* load(ir::SignExtendMode signExtend, virtual ir::Value* load(ir::SignExtendMode signExtend,
ir::Type srcType, ir::Type srcType,
Operand* src, ir::Value* src,
ir::Type dstType) ir::Type dstType)
{ {
assert(&c, dstType.size() >= TargetBytesPerWord); assert(&c, dstType.size() >= TargetBytesPerWord);
assert(&c, srcType.flavor() == dstType.flavor()); assert(&c, srcType.flavor() == dstType.flavor());
@ -2670,9 +2673,9 @@ class MyCompiler: public Compiler {
virtual void condJump(lir::TernaryOperation op, virtual void condJump(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b, ir::Value* b,
Operand* address) ir::Value* address)
{ {
assert(&c, assert(&c,
(isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or(
@ -2692,18 +2695,20 @@ class MyCompiler: public Compiler {
static_cast<Value*>(address)); static_cast<Value*>(address));
} }
virtual void jmp(Operand* address) { virtual void jmp(ir::Value* address)
{
appendJump(&c, lir::Jump, static_cast<Value*>(address)); appendJump(&c, lir::Jump, static_cast<Value*>(address));
} }
virtual void exit(Operand* address) { virtual void exit(ir::Value* address)
{
appendJump(&c, lir::Jump, static_cast<Value*>(address), true); appendJump(&c, lir::Jump, static_cast<Value*>(address), true);
} }
virtual Operand* binaryOp(lir::TernaryOperation op, virtual ir::Value* binaryOp(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b) ir::Value* b)
{ {
assert(&c, assert(&c,
(isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b))
@ -2722,7 +2727,9 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) virtual ir::Value* unaryOp(lir::BinaryOperation op,
ir::Type type,
ir::Value* a)
{ {
assert(&c, assert(&c,
(isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op)
@ -2733,7 +2740,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a)
{ {
assert(&c, aType == static_cast<Value*>(a)->type); assert(&c, aType == static_cast<Value*>(a)->type);
assert(&c, isFloatValue(a)); assert(&c, isFloatValue(a));
@ -2749,7 +2756,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a)
{ {
// TODO: enable when possible // TODO: enable when possible
// assert(&c, aType == static_cast<Value*>(a)->type); // assert(&c, aType == static_cast<Value*>(a)->type);
@ -2766,7 +2773,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a)
{ {
// TODO: enable when possible // TODO: enable when possible
// assert(&c, aType == static_cast<Value*>(a)->type); // assert(&c, aType == static_cast<Value*>(a)->type);

View File

@ -18,7 +18,7 @@ namespace codegen {
namespace compiler { namespace compiler {
Value::Value(Site* site, Site* target, ir::Type type) Value::Value(Site* site, Site* target, ir::Type type)
: Compiler::Operand(type), : ir::Value(type),
reads(0), reads(0),
lastRead(0), lastRead(0),
sites(site), sites(site),

View File

@ -26,7 +26,7 @@ const int NoFrameIndex = -1;
const bool DebugSites = false; const bool DebugSites = false;
class Value: public Compiler::Operand { class Value : public ir::Value {
public: public:
Read* reads; Read* reads;
Read* lastRead; Read* lastRead;
@ -66,12 +66,12 @@ class Value: public Compiler::Operand {
}; };
inline bool isFloatValue(Compiler::Operand* a) inline bool isFloatValue(ir::Value* a)
{ {
return static_cast<Value*>(a)->type.flavor() == ir::Type::Float; return static_cast<Value*>(a)->type.flavor() == ir::Type::Float;
} }
inline bool isGeneralValue(Compiler::Operand* a) inline bool isGeneralValue(ir::Value* a)
{ {
return !isFloatValue(a); return !isFloatValue(a);
} }

File diff suppressed because it is too large Load Diff