Index: src/IceTargetLowering.cpp |
diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp |
index 2a9b8c431ac6fbd42cabba5f8bfb9384017829bb..0034de5f7ca3e2340eb15e52f23530dfafc8ca56 100644 |
--- a/src/IceTargetLowering.cpp |
+++ b/src/IceTargetLowering.cpp |
@@ -26,11 +26,12 @@ namespace Ice { |
void LoweringContext::init(CfgNode *N) { |
Node = N; |
- Cur = getNode()->getInsts().begin(); |
+ Begin = getNode()->getInsts().begin(); |
+ Cur = Begin; |
End = getNode()->getInsts().end(); |
skipDeleted(Cur); |
Next = Cur; |
- advance(Next); |
+ advanceForward(Next); |
} |
void LoweringContext::insert(Inst *Inst) { |
@@ -43,13 +44,26 @@ void LoweringContext::skipDeleted(InstList::iterator &I) const { |
++I; |
} |
-void LoweringContext::advance(InstList::iterator &I) const { |
+void LoweringContext::advanceForward(InstList::iterator &I) const { |
if (I != End) { |
++I; |
skipDeleted(I); |
} |
} |
+void LoweringContext::advanceBackward(InstList::iterator &I) const { |
+ assert(I != Begin); |
+ do { |
+ --I; |
+ } while (I != Begin && (*I)->isDeleted()); |
+} |
+ |
+Inst *LoweringContext::getLastInserted() const { |
+ InstList::iterator Cursor = Next; |
+ advanceBackward(Cursor); |
+ return *Cursor; |
+} |
+ |
TargetLowering *TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
// These statements can be #ifdef'd to specialize the code generator |
// to a subset of the available targets. TODO: use CRTP. |