[llvm-commits] [llvm] r127974 - /llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp

Anders Carlsson andersca at mac.com
Sun Mar 20 12:51:13 PDT 2011


Author: andersca
Date: Sun Mar 20 14:51:13 2011
New Revision: 127974

URL: http://llvm.org/viewvc/llvm-project?rev=127974&view=rev
Log:
Address comments from Frits van Bommel.


Modified:
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=127974&r1=127973&r2=127974&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Sun Mar 20 14:51:13 2011
@@ -2706,9 +2706,10 @@
   
   const FunctionType *FTy = Fn->getFunctionType();
   
-  // Checking that the function has the right number of parameters and that they
-  // all have pointer types should be enough.
-  if (FTy->getNumParams() != 3 ||
+  // Checking that the function has the right return type, the right number of 
+  // parameters and that they all have pointer types should be enough.
+  if (!FTy->getReturnType()->isIntegerTy() ||
+      FTy->getNumParams() != 3 ||
       !FTy->getParamType(0)->isPointerTy() ||
       !FTy->getParamType(1)->isPointerTy() ||
       !FTy->getParamType(2)->isPointerTy())
@@ -2723,8 +2724,10 @@
 /// the code so we only look for a function with a single basic block, where
 /// the only allowed instructions are 'ret' or 'call' to empty C++ dtor.
 static bool cxxDtorIsEmpty(const Function& Fn) {
-  if (Fn.empty())
-    return true;
+  // FIXME: We could eliminate C++ destructors if they're readonly/readnone and
+  // unwind, but that doesn't seem worth doing.
+  if (Fn.isDeclaration())
+    return false;
 
   if (++Fn.begin() != Fn.end())
     return false;
@@ -2738,6 +2741,10 @@
       if (!CalledFn)
         return false;
 
+      // Don't treat recursive functions as empty.
+      if (CalledFn == &Fn)
+        return false;
+
       if (!cxxDtorIsEmpty(*CalledFn))
         return false;
     } else if (isa<ReturnInst>(*I))
@@ -2769,7 +2776,7 @@
   for (Function::use_iterator I = CXAAtExitFn->use_begin(), 
        E = CXAAtExitFn->use_end(); I != E;) {
     CallSite CS(*I++);
-    if (!CS.getInstruction())
+    if (!CS)
       continue;
 
     Function *DtorFn = 
@@ -2781,7 +2788,9 @@
       continue;
 
     // Just remove the call.
-    CS.getInstruction()->eraseFromParent();
+    CS->replaceAllUsesWith(Constant::getNullValue(CS.getType()));
+    CS->eraseFromParent();
+
     ++NumCXXDtorsRemoved;
 
     Changed |= true;





More information about the llvm-commits mailing list