diff options
author | Justin Bogner <mail@justinbogner.com> | 2014-01-21 00:35:11 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2014-01-21 00:35:11 +0000 |
commit | e25ffdf8a18a4b20c6bab43b25687c0143473853 (patch) | |
tree | 4ca73f6c2e47cb6a0544a600bb4939348231c913 /clang/lib/CodeGen/CGStmt.cpp | |
parent | b3fd5cfa81b830adbadc96f706e364ac1753f5c6 (diff) | |
download | bcm5719-llvm-e25ffdf8a18a4b20c6bab43b25687c0143473853.tar.gz bcm5719-llvm-e25ffdf8a18a4b20c6bab43b25687c0143473853.zip |
Revert "CodeGen: Simplify CodeGenFunction::EmitCaseStmt"
I misunderstood the discussion on this. The complexity here is
justified by the malloc overhead it saves.
This reverts commit r199302.
llvm-svn: 199700
Diffstat (limited to 'clang/lib/CodeGen/CGStmt.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 3c059c2b52d..880e801189a 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -1075,6 +1075,30 @@ void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) { llvm::ConstantInt *CaseVal = Builder.getInt(S.getLHS()->EvaluateKnownConstInt(getContext())); + // If the body of the case is just a 'break', try to not emit an empty block. + // If we're profiling or we're not optimizing, leave the block in for better + // debug and coverage analysis. + if (!CGM.getCodeGenOpts().ProfileInstrGenerate && + CGM.getCodeGenOpts().OptimizationLevel > 0 && + isa<BreakStmt>(S.getSubStmt())) { + JumpDest Block = BreakContinueStack.back().BreakBlock; + + // Only do this optimization if there are no cleanups that need emitting. + if (isObviouslyBranchWithoutCleanups(Block)) { + if (SwitchWeights) + SwitchWeights->push_back(CaseCnt.getCount() - CaseCnt.getParentCount()); + SwitchInsn->addCase(CaseVal, Block.getBlock()); + + // If there was a fallthrough into this case, make sure to redirect it to + // the end of the switch as well. + if (Builder.GetInsertBlock()) { + Builder.CreateBr(Block.getBlock()); + Builder.ClearInsertionPoint(); + } + return; + } + } + EmitBlock(createBasicBlock("sw.bb")); llvm::BasicBlock *CaseDest = Builder.GetInsertBlock(); if (SwitchWeights) |