mirror of
https://github.com/corda/corda.git
synced 2025-06-18 07:08:15 +00:00
move ReturnEvent out of compiler.cpp
This commit is contained in:
@ -198,45 +198,6 @@ Cell<T>* reverseDestroy(Cell<T>* cell) {
|
|||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StubReadPair {
|
|
||||||
public:
|
|
||||||
Value* value;
|
|
||||||
StubRead* read;
|
|
||||||
};
|
|
||||||
|
|
||||||
class JunctionState {
|
|
||||||
public:
|
|
||||||
JunctionState(unsigned frameFootprint): frameFootprint(frameFootprint) { }
|
|
||||||
|
|
||||||
unsigned frameFootprint;
|
|
||||||
StubReadPair reads[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
class Link {
|
|
||||||
public:
|
|
||||||
Link(Event* predecessor, Link* nextPredecessor, Event* successor,
|
|
||||||
Link* nextSuccessor, ForkState* forkState):
|
|
||||||
predecessor(predecessor), nextPredecessor(nextPredecessor),
|
|
||||||
successor(successor), nextSuccessor(nextSuccessor), forkState(forkState),
|
|
||||||
junctionState(0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Event* predecessor;
|
|
||||||
Link* nextPredecessor;
|
|
||||||
Event* successor;
|
|
||||||
Link* nextSuccessor;
|
|
||||||
ForkState* forkState;
|
|
||||||
JunctionState* junctionState;
|
|
||||||
};
|
|
||||||
|
|
||||||
Link*
|
|
||||||
link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor,
|
|
||||||
Link* nextSuccessor, ForkState* forkState)
|
|
||||||
{
|
|
||||||
return new(c->zone) Link
|
|
||||||
(predecessor, nextPredecessor, successor, nextSuccessor, forkState);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
countPredecessors(Link* link)
|
countPredecessors(Link* link)
|
||||||
{
|
{
|
||||||
@ -1214,52 +1175,6 @@ saveLocals(Context* c, Event* e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
unreachable(Event* event)
|
|
||||||
{
|
|
||||||
for (Link* p = event->predecessors; p; p = p->nextPredecessor) {
|
|
||||||
if (not p->predecessor->allExits()) return false;
|
|
||||||
}
|
|
||||||
return event->predecessors != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ReturnEvent: public Event {
|
|
||||||
public:
|
|
||||||
ReturnEvent(Context* c, unsigned size, Value* value):
|
|
||||||
Event(c), value(value)
|
|
||||||
{
|
|
||||||
if (value) {
|
|
||||||
this->addReads(c, value, size,
|
|
||||||
SiteMask::fixedRegisterMask(c->arch->returnLow()),
|
|
||||||
SiteMask::fixedRegisterMask(c->arch->returnHigh()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char* name() {
|
|
||||||
return "ReturnEvent";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void compile(Context* c) {
|
|
||||||
for (Read* r = reads; r; r = r->eventNext) {
|
|
||||||
popRead(c, this, r->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not unreachable(this)) {
|
|
||||||
c->assembler->popFrameAndPopArgumentsAndReturn
|
|
||||||
(c->alignedFrameSize,
|
|
||||||
c->arch->argumentFootprint(c->parameterFootprint));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Value* value;
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
appendReturn(Context* c, unsigned size, Value* value)
|
|
||||||
{
|
|
||||||
append(c, new(c->zone) ReturnEvent(c, size, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize,
|
maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize,
|
||||||
unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst,
|
unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst,
|
||||||
@ -2580,7 +2495,7 @@ class BranchEvent: public Event {
|
|||||||
ConstantSite* firstConstant = findConstantSite(c, first);
|
ConstantSite* firstConstant = findConstantSite(c, first);
|
||||||
ConstantSite* secondConstant = findConstantSite(c, second);
|
ConstantSite* secondConstant = findConstantSite(c, second);
|
||||||
|
|
||||||
if (not unreachable(this)) {
|
if (not this->isUnreachable()) {
|
||||||
if (firstConstant
|
if (firstConstant
|
||||||
and secondConstant
|
and secondConstant
|
||||||
and firstConstant->value->resolved()
|
and firstConstant->value->resolved()
|
||||||
@ -2700,7 +2615,7 @@ class JumpEvent: public Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void compile(Context* c) {
|
virtual void compile(Context* c) {
|
||||||
if (not unreachable(this)) {
|
if (not this->isUnreachable()) {
|
||||||
apply(c, type, TargetBytesPerWord, address->source, address->source);
|
apply(c, type, TargetBytesPerWord, address->source, address->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2719,7 +2634,7 @@ class JumpEvent: public Event {
|
|||||||
virtual bool isBranch() { return true; }
|
virtual bool isBranch() { return true; }
|
||||||
|
|
||||||
virtual bool allExits() {
|
virtual bool allExits() {
|
||||||
return exit or unreachable(this);
|
return exit or this->isUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
lir::UnaryOperation type;
|
lir::UnaryOperation type;
|
||||||
|
@ -59,6 +59,8 @@ void clean(Context* c, Event* e, Stack* stack, Local* locals, Read* reads,
|
|||||||
|
|
||||||
Read* live(Context* c UNUSED, Value* v);
|
Read* live(Context* c UNUSED, Value* v);
|
||||||
|
|
||||||
|
void popRead(Context* c, Event* e UNUSED, Value* v);
|
||||||
|
|
||||||
Event::Event(Context* c):
|
Event::Event(Context* c):
|
||||||
next(0), stackBefore(c->stack), localsBefore(c->locals),
|
next(0), stackBefore(c->stack), localsBefore(c->locals),
|
||||||
stackAfter(0), localsAfter(0), promises(0), reads(0),
|
stackAfter(0), localsAfter(0), promises(0), reads(0),
|
||||||
@ -119,6 +121,20 @@ CodePromise* Event::makeCodePromise(Context* c) {
|
|||||||
return this->promises = new(c->zone) CodePromise(c, this->promises);
|
return this->promises = new(c->zone) CodePromise(c, this->promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Event::isUnreachable() {
|
||||||
|
for (Link* p = this->predecessors; p; p = p->nextPredecessor) {
|
||||||
|
if (not p->predecessor->allExits()) return false;
|
||||||
|
}
|
||||||
|
return this->predecessors != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor,
|
||||||
|
Link* nextSuccessor, ForkState* forkState)
|
||||||
|
{
|
||||||
|
return new(c->zone) Link
|
||||||
|
(predecessor, nextPredecessor, successor, nextSuccessor, forkState);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CallEvent: public Event {
|
class CallEvent: public Event {
|
||||||
public:
|
public:
|
||||||
@ -441,6 +457,42 @@ appendCall(Context* c, Value* address, unsigned flags,
|
|||||||
stackArgumentFootprint));
|
stackArgumentFootprint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ReturnEvent: public Event {
|
||||||
|
public:
|
||||||
|
ReturnEvent(Context* c, unsigned size, Value* value):
|
||||||
|
Event(c), value(value)
|
||||||
|
{
|
||||||
|
if (value) {
|
||||||
|
this->addReads(c, value, size,
|
||||||
|
SiteMask::fixedRegisterMask(c->arch->returnLow()),
|
||||||
|
SiteMask::fixedRegisterMask(c->arch->returnHigh()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const char* name() {
|
||||||
|
return "ReturnEvent";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void compile(Context* c) {
|
||||||
|
for (Read* r = reads; r; r = r->eventNext) {
|
||||||
|
popRead(c, this, r->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not this->isUnreachable()) {
|
||||||
|
c->assembler->popFrameAndPopArgumentsAndReturn
|
||||||
|
(c->alignedFrameSize,
|
||||||
|
c->arch->argumentFootprint(c->parameterFootprint));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Value* value;
|
||||||
|
};
|
||||||
|
|
||||||
|
void appendReturn(Context* c, unsigned size, Value* value) {
|
||||||
|
append(c, new(c->zone) ReturnEvent(c, size, value));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace compiler
|
} // namespace compiler
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
} // namespace avian
|
} // namespace avian
|
||||||
|
@ -20,6 +20,7 @@ class CodePromise;
|
|||||||
class Snapshot;
|
class Snapshot;
|
||||||
class Link;
|
class Link;
|
||||||
class Site;
|
class Site;
|
||||||
|
class StubRead;
|
||||||
|
|
||||||
const bool DebugReads = false;
|
const bool DebugReads = false;
|
||||||
|
|
||||||
@ -51,10 +52,10 @@ class Event {
|
|||||||
void addReads(Context* c, Value* v, unsigned size,
|
void addReads(Context* c, Value* v, unsigned size,
|
||||||
const SiteMask& lowMask, const SiteMask& highMask);
|
const SiteMask& lowMask, const SiteMask& highMask);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CodePromise* makeCodePromise(Context* c);
|
CodePromise* makeCodePromise(Context* c);
|
||||||
|
|
||||||
|
bool isUnreachable();
|
||||||
|
|
||||||
Event* next;
|
Event* next;
|
||||||
Stack* stackBefore;
|
Stack* stackBefore;
|
||||||
Local* localsBefore;
|
Local* localsBefore;
|
||||||
@ -72,12 +73,50 @@ class Event {
|
|||||||
unsigned readCount;
|
unsigned readCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class StubReadPair {
|
||||||
|
public:
|
||||||
|
Value* value;
|
||||||
|
StubRead* read;
|
||||||
|
};
|
||||||
|
|
||||||
|
class JunctionState {
|
||||||
|
public:
|
||||||
|
JunctionState(unsigned frameFootprint): frameFootprint(frameFootprint) { }
|
||||||
|
|
||||||
|
unsigned frameFootprint;
|
||||||
|
StubReadPair reads[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
class Link {
|
||||||
|
public:
|
||||||
|
Link(Event* predecessor, Link* nextPredecessor, Event* successor,
|
||||||
|
Link* nextSuccessor, ForkState* forkState):
|
||||||
|
predecessor(predecessor), nextPredecessor(nextPredecessor),
|
||||||
|
successor(successor), nextSuccessor(nextSuccessor), forkState(forkState),
|
||||||
|
junctionState(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
Event* predecessor;
|
||||||
|
Link* nextPredecessor;
|
||||||
|
Event* successor;
|
||||||
|
Link* nextSuccessor;
|
||||||
|
ForkState* forkState;
|
||||||
|
JunctionState* junctionState;
|
||||||
|
};
|
||||||
|
|
||||||
|
Link*
|
||||||
|
link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor,
|
||||||
|
Link* nextSuccessor, ForkState* forkState);
|
||||||
|
|
||||||
void
|
void
|
||||||
appendCall(Context* c, Value* address, unsigned flags,
|
appendCall(Context* c, Value* address, unsigned flags,
|
||||||
TraceHandler* traceHandler, Value* result, unsigned resultSize,
|
TraceHandler* traceHandler, Value* result, unsigned resultSize,
|
||||||
Stack* argumentStack, unsigned argumentCount,
|
Stack* argumentStack, unsigned argumentCount,
|
||||||
unsigned stackArgumentFootprint);
|
unsigned stackArgumentFootprint);
|
||||||
|
|
||||||
|
void
|
||||||
|
appendReturn(Context* c, unsigned size, Value* value);
|
||||||
|
|
||||||
} // namespace compiler
|
} // namespace compiler
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
} // namespace avian
|
} // namespace avian
|
||||||
|
Reference in New Issue
Block a user