diff options
author | Daniel Dunbar <daniel@zuster.org> | 2008-11-11 23:11:34 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2008-11-11 23:11:34 +0000 |
commit | a448fb2da03ece39978784793eea68760e8205a1 (patch) | |
tree | cb518bc50150fa941f164a2ae77193b77ca23259 /lib/CodeGen/CGStmt.cpp | |
parent | 5e08ad3cc62ab94649959ae227a9a411a729bf49 (diff) |
Rework IRgen invariant w.r.t. current insert point.
- EmitStmt is no longer required to finish with a current insertion
point defined (i.e. it does not need to make dummy
blocks). Instead, it can clear the insertion point in the builder
which indicates that the current insertion point is unreachable.
- CodeGenFunction provides HaveInsertPoint and EnsureInsertPoint
which respectively test if there is an insert point and ensure an
insertion point exists (by making a dummy block).
- Clearly mark functions in CodeGenFunction which can be called with
no insertion point defined. Currently this is a limited set, and
EmitStmt simply EnsureInsertPoint()s before emitting subsequent IR.
Remove EmitDummyBlock, which is no longer needed. Clients who haven't
already cleared the insertion point (typically via EmitBranch) can do
so by hand.
Remove isDummyBlock, which has effectively been renamed to
HaveInsertPoint.
The main thrust of this change is that we no longer have create dummy
blocks just to destroy them a short time later in EmitBlock in the
common case that there is no unreachable code following something like
a goto.
Additionally, this means that we are not using the hokey condition in
isDummyBlock that a block without a name is a dummy block. Guess how
well that works when we never emit block names!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59089 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGStmt.cpp')
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 97a7a05768..daad3f5e79 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -27,6 +27,13 @@ using namespace CodeGen; void CodeGenFunction::EmitStmt(const Stmt *S) { assert(S && "Null statement?"); + + // If we happen to be at an unreachable point just create a dummy + // basic block to hold the code. We could change parts of irgen to + // simply not generate this code, but this situation is rare and + // probably not worth the effort. + // FIXME: Verify previous performance/effort claim. + EnsureInsertPoint(); // Generate stoppoints if we are emitting debug info. // Beginning of a Compound Statement (e.g. an opening '{') does not produce @@ -128,6 +135,7 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, EmitStmt(*I); if (DI) { + EnsureInsertPoint(); DI->setLocation(S.getRBracLoc()); DI->EmitRegionEnd(CurFn, Builder); } @@ -145,6 +153,8 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, LastStmt = LS->getSubStmt(); } + EnsureInsertPoint(); + return EmitAnyExpr(cast<Expr>(LastStmt), AggLoc); } @@ -164,10 +174,6 @@ void CodeGenFunction::EmitBranch(llvm::BasicBlock *Target) { if (!CurBB || CurBB->getTerminator()) { // If there is no insert point or the previous block is already // terminated, don't touch it. - } else if (isDummyBlock(CurBB)) { - // If the last block was an empty placeholder, remove it now. - // TODO: cache and reuse these. - CurBB->eraseFromParent(); } else { // Otherwise, create a fall-through branch. Builder.CreateBr(Target); @@ -176,10 +182,6 @@ void CodeGenFunction::EmitBranch(llvm::BasicBlock *Target) { Builder.ClearInsertionPoint(); } -void CodeGenFunction::EmitDummyBlock() { - EmitBlock(createBasicBlock()); -} - void CodeGenFunction::EmitLabel(const LabelStmt &S) { llvm::BasicBlock *NextBB = getBasicBlockForLabel(&S); EmitBlock(NextBB); @@ -199,10 +201,6 @@ void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) { } EmitBranch(getBasicBlockForLabel(S.getLabel())); - - // Emit a block after the branch so that dead code after a goto has some place - // to go. - EmitDummyBlock(); } void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) { @@ -221,9 +219,8 @@ void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) { llvm::SwitchInst *I = Builder.CreateSwitch(V, Builder.GetInsertBlock()); IndirectSwitches.push_back(I); - // Emit a block after the branch so that dead code after a goto has some place - // to go. - EmitDummyBlock(); + // Clear the insertion point to indicate we are in unreachable code. + Builder.ClearInsertionPoint(); } void CodeGenFunction::EmitIfStmt(const IfStmt &S) { @@ -445,10 +442,6 @@ void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) { StoreComplexToAddr(RV.getComplexVal(), ReturnValue, false); } EmitBranch(ReturnBlock); - - // Emit a block after the branch so that dead code after a return has some - // place to go. - EmitDummyBlock(); } /// EmitReturnStmt - Note that due to GCC extensions, this can have an operand @@ -485,10 +478,6 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { } EmitBranch(ReturnBlock); - - // Emit a block after the branch so that dead code after a return has some - // place to go. - EmitDummyBlock(); } void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) { @@ -502,7 +491,6 @@ void CodeGenFunction::EmitBreakStmt() { llvm::BasicBlock *Block = BreakContinueStack.back().BreakBlock; EmitBranch(Block); - EmitDummyBlock(); } void CodeGenFunction::EmitContinueStmt() { @@ -510,7 +498,6 @@ void CodeGenFunction::EmitContinueStmt() { llvm::BasicBlock *Block = BreakContinueStack.back().ContinueBlock; EmitBranch(Block); - EmitDummyBlock(); } /// EmitCaseStmtRange - If case statement range is not too big then @@ -566,7 +553,10 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) { Builder.CreateCondBr(Cond, CaseDest, FalseDest); // Restore the appropriate insertion point. - Builder.SetInsertPoint(RestoreBB); + if (RestoreBB) + Builder.SetInsertPoint(RestoreBB); + else + Builder.ClearInsertionPoint(); } void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) { |