synchronizeICache removeed from TargetJITInfo.
[oota-llvm.git] / lib / Transforms / IPO / RaiseAllocations.cpp
index 42edb7e05de31fdf3d4ca4bad9e448afe4e0859d..2b487d009d7c2d1dd82e36ad66f0faa18dbfb3ba 100644 (file)
@@ -1,10 +1,10 @@
 //===- RaiseAllocations.cpp - Convert %malloc & %free calls to insts ------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // This file defines the RaiseAllocations pass which convert malloc and free
@@ -28,29 +28,29 @@ namespace {
   // RaiseAllocations - Turn %malloc and %free calls into the appropriate
   // instruction.
   //
-  class RaiseAllocations : public Pass {
+  class RaiseAllocations : public ModulePass {
     Function *MallocFunc;   // Functions in the module we are processing
     Function *FreeFunc;     // Initialized by doPassInitializationVirt
   public:
     RaiseAllocations() : MallocFunc(0), FreeFunc(0) {}
-    
+
     // doPassInitialization - For the raise allocations pass, this finds a
     // declaration for malloc and free if they exist.
     //
     void doInitialization(Module &M);
-    
+
     // run - This method does the actual work of converting instructions over.
     //
-    bool run(Module &M);
+    bool runOnModule(Module &M);
   };
-  
+
   RegisterOpt<RaiseAllocations>
   X("raiseallocs", "Raise allocations from calls to instructions");
 }  // end anonymous namespace
 
 
 // createRaiseAllocationsPass - The interface to this file...
-Pass *llvm::createRaiseAllocationsPass() {
+ModulePass *llvm::createRaiseAllocationsPass() {
   return new RaiseAllocations();
 }
 
@@ -114,7 +114,7 @@ void RaiseAllocations::doInitialization(Module &M) {
 
 // run - Transform calls into instructions...
 //
-bool RaiseAllocations::run(Module &M) {
+bool RaiseAllocations::runOnModule(Module &M) {
   // Find the malloc/free prototypes...
   doInitialization(M);
 
@@ -134,14 +134,14 @@ bool RaiseAllocations::run(Module &M) {
             (CS.getCalledFunction() == MallocFunc ||
              std::find(EqPointers.begin(), EqPointers.end(),
                        CS.getCalledValue()) != EqPointers.end())) {
-            
+
           Value *Source = *CS.arg_begin();
-          
+
           // If no prototype was provided for malloc, we may need to cast the
           // source size.
           if (Source->getType() != Type::UIntTy)
             Source = new CastInst(Source, Type::UIntTy, "MallocAmtCast", I);
-          
+
           std::string Name(I->getName()); I->setName("");
           MallocInst *MI = new MallocInst(Type::SByteTy, Source, Name, I);
           I->replaceAllUsesWith(MI);
@@ -183,10 +183,10 @@ bool RaiseAllocations::run(Module &M) {
             (CS.getCalledFunction() == FreeFunc ||
              std::find(EqPointers.begin(), EqPointers.end(),
                        CS.getCalledValue()) != EqPointers.end())) {
-          
+
           // If no prototype was provided for free, we may need to cast the
           // source pointer.  This should be really uncommon, but it's necessary
-          // just in case we are dealing with wierd code like this:
+          // just in case we are dealing with weird code like this:
           //   free((long)ptr);
           //
           Value *Source = *CS.arg_begin();
@@ -201,7 +201,9 @@ bool RaiseAllocations::run(Module &M) {
             new BranchInst(II->getNormalDest(), I);
 
           // Delete the old call site
-          I->getParent()->getInstList().erase(I);
+          if (I->getType() != Type::VoidTy)
+            I->replaceAllUsesWith(UndefValue::get(I->getType()));
+          I->eraseFromParent();
           Changed = true;
           ++NumRaised;
         }