diff options
author | John McCall <rjmccall@apple.com> | 2010-08-03 22:46:07 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-08-03 22:46:07 +0000 |
commit | 39dad53772c42eb36ebec1c81c56ba99d038fb94 (patch) | |
tree | f29b9495be994ad445917b5a18d8c1948e949c73 /lib/CodeGen/CodeGenFunction.cpp | |
parent | 863e7189dc437ef0f35ff94d74f62c775759d2ce (diff) |
Do a very simple pass over every function we emit to infer whether we can
mark it nounwind based on whether it contains any non-nounwind calls.
<rdar://problem/8087431>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110163 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 396ab4e6d2..35664af219 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -311,6 +311,19 @@ void CodeGenFunction::EmitFunctionBody(FunctionArgList &Args) { EmitStmt(FD->getBody()); } +/// Tries to mark the given function nounwind based on the +/// non-existence of any throwing calls within it. We believe this is +/// lightweight enough to do at -O0. +static void TryMarkNoThrow(llvm::Function *F) { + for (llvm::Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) + for (llvm::BasicBlock::iterator + BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) + if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(&*BI)) + if (!Call->doesNotThrow()) + return; + F->setDoesNotThrow(true); +} + void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) { const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl()); @@ -369,6 +382,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) { // Emit the standard function epilogue. FinishFunction(BodyRange.getEnd()); + + // If we haven't marked the function nothrow through other means, do + // a quick pass now to see if we can. + if (!CurFn->doesNotThrow()) + TryMarkNoThrow(CurFn); } /// ContainsLabel - Return true if the statement contains a label in it. If |