From 165c77d7729fe12a8be241db5a094644741f1438 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 13 Feb 2013 19:43:19 -0700 Subject: [PATCH] move ReturnEvent out of compiler.cpp --- src/codegen/compiler.cpp | 91 ++-------------------------------- src/codegen/compiler/event.cpp | 52 +++++++++++++++++++ src/codegen/compiler/event.h | 43 +++++++++++++++- 3 files changed, 96 insertions(+), 90 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index ca6ee5ba23..5ab7eaea50 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -198,45 +198,6 @@ Cell* reverseDestroy(Cell* cell) { 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 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 maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst, @@ -2580,7 +2495,7 @@ class BranchEvent: public Event { ConstantSite* firstConstant = findConstantSite(c, first); ConstantSite* secondConstant = findConstantSite(c, second); - if (not unreachable(this)) { + if (not this->isUnreachable()) { if (firstConstant and secondConstant and firstConstant->value->resolved() @@ -2700,7 +2615,7 @@ class JumpEvent: public Event { } virtual void compile(Context* c) { - if (not unreachable(this)) { + if (not this->isUnreachable()) { apply(c, type, TargetBytesPerWord, address->source, address->source); } @@ -2719,7 +2634,7 @@ class JumpEvent: public Event { virtual bool isBranch() { return true; } virtual bool allExits() { - return exit or unreachable(this); + return exit or this->isUnreachable(); } lir::UnaryOperation type; diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index 9b4fee04e1..2ac259cf94 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -59,6 +59,8 @@ void clean(Context* c, Event* e, Stack* stack, Local* locals, Read* reads, Read* live(Context* c UNUSED, Value* v); +void popRead(Context* c, Event* e UNUSED, Value* v); + Event::Event(Context* c): next(0), stackBefore(c->stack), localsBefore(c->locals), 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); } +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 { public: @@ -441,6 +457,42 @@ appendCall(Context* c, Value* address, unsigned flags, 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 codegen } // namespace avian diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 3308ede12a..91b441353b 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -20,6 +20,7 @@ class CodePromise; class Snapshot; class Link; class Site; +class StubRead; const bool DebugReads = false; @@ -51,10 +52,10 @@ class Event { void addReads(Context* c, Value* v, unsigned size, const SiteMask& lowMask, const SiteMask& highMask); - - CodePromise* makeCodePromise(Context* c); + bool isUnreachable(); + Event* next; Stack* stackBefore; Local* localsBefore; @@ -72,12 +73,50 @@ class Event { 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 appendCall(Context* c, Value* address, unsigned flags, TraceHandler* traceHandler, Value* result, unsigned resultSize, Stack* argumentStack, unsigned argumentCount, unsigned stackArgumentFootprint); +void +appendReturn(Context* c, unsigned size, Value* value); + } // namespace compiler } // namespace codegen } // namespace avian