[llvm-commits] [poolalloc] r129705 - /poolalloc/trunk/lib/AssistDS/StructReturnToPointer.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Mon Apr 18 11:21:20 PDT 2011


Author: aggarwa4
Date: Mon Apr 18 13:21:20 2011
New Revision: 129705

URL: http://llvm.org/viewvc/llvm-project?rev=129705&view=rev
Log:
Ensure that the uses we replace are all call insts.
Also, if the original function was varargs, this one
should be too.

Modified:
    poolalloc/trunk/lib/AssistDS/StructReturnToPointer.cpp

Modified: poolalloc/trunk/lib/AssistDS/StructReturnToPointer.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/StructReturnToPointer.cpp?rev=129705&r1=129704&r2=129705&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/StructReturnToPointer.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/StructReturnToPointer.cpp Mon Apr 18 13:21:20 2011
@@ -74,7 +74,7 @@
           TP.push_back(ii->getType());
         }
 
-        const FunctionType *NFTy = FunctionType::get(F->getReturnType(), TP, false);
+        const FunctionType *NFTy = FunctionType::get(F->getReturnType(), TP, F->isVarArg());
 
         // Create the new function body and insert it into the module.
         Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName(), &M);
@@ -111,6 +111,10 @@
         for(Value::use_iterator ui = F->use_begin(), ue = F->use_end();
             ui != ue; ) {
           CallInst *CI = dyn_cast<CallInst>(ui++);
+          if(!CI)
+            continue;
+          if(CI->getCalledFunction() != F)
+            continue;
           AllocaInst *AllocaNew = new AllocaInst(F->getReturnType(), 0, "", CI);
           SmallVector<Value*, 8> Args;
           
@@ -123,7 +127,8 @@
           CI->replaceAllUsesWith(LI);
           CI->eraseFromParent();
         }
-        F->eraseFromParent();
+        if(F->use_empty())
+          F->eraseFromParent();
       }
       return true;
     }





More information about the llvm-commits mailing list