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

View File

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

View File

@ -2151,7 +2151,8 @@ class MyCompiler: public Compiler {
return c.subroutine = new(c.zone) MySubroutine;
}
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) {
virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address)
{
appendSaveLocals(&c);
appendJump(&c, lir::Jump, static_cast<Value*>(address), false, true);
static_cast<MySubroutine*>(subroutine)->forkState = compiler::saveState(&c);
@ -2308,25 +2309,25 @@ class MyCompiler: public Compiler {
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);
}
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));
}
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));
}
virtual Operand* memory(Operand* base,
ir::Type type,
int displacement = 0,
Operand* index = 0)
virtual ir::Value* memory(ir::Value* base,
ir::Type type,
int displacement = 0,
ir::Value* index = 0)
{
Value* result = value(&c, type);
@ -2340,7 +2341,7 @@ class MyCompiler: public Compiler {
return result;
}
virtual Operand* threadRegister()
virtual ir::Value* threadRegister()
{
return compiler::threadRegister(&c);
}
@ -2349,7 +2350,7 @@ class MyCompiler: public Compiler {
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.
// 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));
}
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.
// 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.
// Some time later, we can remove the parameter.
// assert(&c, static_cast<Value*>(value)->type == type);
@ -2409,7 +2410,8 @@ class MyCompiler: public Compiler {
return c.stack->index;
}
virtual Operand* peek(unsigned footprint, unsigned index) {
virtual ir::Value* peek(unsigned footprint, unsigned index)
{
Stack* s = c.stack;
for (unsigned i = index; i > 0; --i) {
s = s->next;
@ -2445,12 +2447,12 @@ class MyCompiler: public Compiler {
return s->value;
}
virtual Operand* call(Operand* address,
unsigned flags,
TraceHandler* traceHandler,
ir::Type resultType,
unsigned argumentCount,
...)
virtual ir::Value* call(ir::Value* address,
unsigned flags,
TraceHandler* traceHandler,
ir::Type resultType,
unsigned argumentCount,
...)
{
va_list a; va_start(a, argumentCount);
@ -2500,11 +2502,11 @@ class MyCompiler: public Compiler {
return result;
}
virtual Operand* stackCall(Operand* address,
unsigned flags,
TraceHandler* traceHandler,
ir::Type resultType,
unsigned argumentFootprint)
virtual ir::Value* stackCall(ir::Value* address,
unsigned flags,
TraceHandler* traceHandler,
ir::Type resultType,
unsigned argumentFootprint)
{
Value* result = value(&c, resultType);
appendCall(&c,
@ -2519,7 +2521,7 @@ class MyCompiler: public Compiler {
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.
// Some time later, we can remove the parameter.
@ -2595,11 +2597,12 @@ class MyCompiler: public Compiler {
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);
}
virtual Operand* loadLocal(ir::Type type, unsigned index)
virtual ir::Value* loadLocal(ir::Type type, unsigned index)
{
return compiler::loadLocal(&c, type, index);
}
@ -2608,17 +2611,19 @@ class MyCompiler: public Compiler {
appendSaveLocals(&c);
}
virtual void checkBounds(Operand* object, unsigned lengthOffset,
Operand* index, intptr_t handler)
virtual void checkBounds(ir::Value* object,
unsigned lengthOffset,
ir::Value* index,
intptr_t handler)
{
appendBoundsCheck(&c, static_cast<Value*>(object), lengthOffset,
static_cast<Value*>(index), handler);
}
virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend,
ir::Type extendType,
ir::Type truncateType,
Operand* src)
virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend,
ir::Type extendType,
ir::Type truncateType,
ir::Value* src)
{
Value* dst = value(&c, extendType);
appendMove(&c,
@ -2631,9 +2636,7 @@ class MyCompiler: public Compiler {
return dst;
}
virtual void store(ir::Type srcType,
Operand* src,
Operand* dst)
virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst)
{
assert(&c, srcType.flavor() == static_cast<Value*>(src)->type.flavor());
assert(&c, srcType.flavor() == static_cast<Value*>(dst)->type.flavor());
@ -2649,10 +2652,10 @@ class MyCompiler: public Compiler {
static_cast<Value*>(dst));
}
virtual Operand* load(ir::SignExtendMode signExtend,
ir::Type srcType,
Operand* src,
ir::Type dstType)
virtual ir::Value* load(ir::SignExtendMode signExtend,
ir::Type srcType,
ir::Value* src,
ir::Type dstType)
{
assert(&c, dstType.size() >= TargetBytesPerWord);
assert(&c, srcType.flavor() == dstType.flavor());
@ -2670,9 +2673,9 @@ class MyCompiler: public Compiler {
virtual void condJump(lir::TernaryOperation op,
ir::Type type,
Operand* a,
Operand* b,
Operand* address)
ir::Value* a,
ir::Value* b,
ir::Value* address)
{
assert(&c,
(isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or(
@ -2692,18 +2695,20 @@ class MyCompiler: public Compiler {
static_cast<Value*>(address));
}
virtual void jmp(Operand* address) {
virtual void jmp(ir::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);
}
virtual Operand* binaryOp(lir::TernaryOperation op,
ir::Type type,
Operand* a,
Operand* b)
virtual ir::Value* binaryOp(lir::TernaryOperation op,
ir::Type type,
ir::Value* a,
ir::Value* b)
{
assert(&c,
(isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b))
@ -2722,7 +2727,9 @@ class MyCompiler: public Compiler {
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,
(isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op)
@ -2733,7 +2740,7 @@ class MyCompiler: public Compiler {
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, isFloatValue(a));
@ -2749,7 +2756,7 @@ class MyCompiler: public Compiler {
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
// assert(&c, aType == static_cast<Value*>(a)->type);
@ -2766,7 +2773,7 @@ class MyCompiler: public Compiler {
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
// assert(&c, aType == static_cast<Value*>(a)->type);

View File

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

View File

@ -26,7 +26,7 @@ const int NoFrameIndex = -1;
const bool DebugSites = false;
class Value: public Compiler::Operand {
class Value : public ir::Value {
public:
Read* reads;
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;
}
inline bool isGeneralValue(Compiler::Operand* a)
inline bool isGeneralValue(ir::Value* a)
{
return !isFloatValue(a);
}

File diff suppressed because it is too large Load Diff