summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-08-03 22:46:07 +0000
committerJohn McCall <rjmccall@apple.com>2010-08-03 22:46:07 +0000
commit8601a7511869e0f91f16c60a45e07bca9b5b8593 (patch)
treec8cead7cc686b4f95ea8a5e7e32cddbe38226d91 /clang/lib/CodeGen/CodeGenFunction.cpp
parent38321174e09cde27318cf58f6b08e5bd7c92144c (diff)
downloadbcm5719-llvm-8601a7511869e0f91f16c60a45e07bca9b5b8593.tar.gz
bcm5719-llvm-8601a7511869e0f91f16c60a45e07bca9b5b8593.zip
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> llvm-svn: 110163
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 396ab4e6d2b..35664af219b 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud