[cfe-commits] r110163 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGen/unwind-attr.c test/CodeGenCXX/global-init.cpp

John McCall rjmccall at apple.com
Tue Aug 3 15:46:07 PDT 2010


Author: rjmccall
Date: Tue Aug  3 17:46:07 2010
New Revision: 110163

URL: http://llvm.org/viewvc/llvm-project?rev=110163&view=rev
Log:
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>


Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGen/unwind-attr.c
    cfe/trunk/test/CodeGenCXX/global-init.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=110163&r1=110162&r2=110163&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Aug  3 17:46:07 2010
@@ -311,6 +311,19 @@
   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 @@
 
   // 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

Modified: cfe/trunk/test/CodeGen/unwind-attr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/unwind-attr.c?rev=110163&r1=110162&r2=110163&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/unwind-attr.c (original)
+++ cfe/trunk/test/CodeGen/unwind-attr.c Tue Aug  3 17:46:07 2010
@@ -1,6 +1,16 @@
-// RUN: %clang_cc1 -fexceptions -emit-llvm -o - %s | grep "@foo()" | not grep nounwind
-// RUN: %clang_cc1 -emit-llvm -o - %s | grep "@foo()" | grep nounwind 
+// RUN: %clang_cc1 -fexceptions -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix NOEXC %s
 
-int foo(void) {
-  return 0;
+int opaque();
+
+// CHECK:       define [[INT:i.*]] @test0() {
+// CHECK-NOEXC: define [[INT:i.*]] @test0() nounwind {
+int test0(void) {
+  return opaque();
+}
+
+// <rdar://problem/8087431>: locally infer nounwind at -O0
+// CHECK:       define [[INT:i.*]] @test1() nounwind {
+// CHECK-NOEXC: define [[INT:i.*]] @test1() nounwind {
+int test1(void) {
 }

Modified: cfe/trunk/test/CodeGenCXX/global-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/global-init.cpp?rev=110163&r1=110162&r2=110163&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/global-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/global-init.cpp Tue Aug  3 17:46:07 2010
@@ -36,7 +36,7 @@
   const int y = x - 1; // This gets deferred.
   const int z = ~y;    // This also gets deferred, but gets "undeferred" before y.
   int test() { return z; }
-// CHECK:      define i32 @_ZN5test14testEv() {
+// CHECK:      define i32 @_ZN5test14testEv()
 
   // All of these initializers end up delayed, so we check them later.
 }





More information about the cfe-commits mailing list