Remove MallocInst from LLVM Instructions.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84299 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index f26d7c1..9c9113d 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -1,4 +1,4 @@
-//===- LowerAllocations.cpp - Reduce malloc & free insts to calls ---------===//
+//===- LowerAllocations.cpp - Reduce free insts to calls ------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -29,18 +29,15 @@
 STATISTIC(NumLowered, "Number of allocations lowered");
 
 namespace {
-  /// LowerAllocations - Turn malloc and free instructions into @malloc and
-  /// @free calls.
+  /// LowerAllocations - Turn free instructions into @free calls.
   ///
   class VISIBILITY_HIDDEN LowerAllocations : public BasicBlockPass {
     Constant *FreeFunc;   // Functions in the module we are processing
                           // Initialized by doInitialization
-    bool LowerMallocArgToInteger;
   public:
     static char ID; // Pass ID, replacement for typeid
-    explicit LowerAllocations(bool LowerToInt = false)
-      : BasicBlockPass(&ID), FreeFunc(0), 
-        LowerMallocArgToInteger(LowerToInt) {}
+    explicit LowerAllocations()
+      : BasicBlockPass(&ID), FreeFunc(0) {}
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequired<TargetData>();
@@ -54,7 +51,7 @@
     }
 
     /// doPassInitialization - For the lower allocations pass, this ensures that
-    /// a module contains a declaration for a malloc and a free function.
+    /// a module contains a declaration for a free function.
     ///
     bool doInitialization(Module &M);
 
@@ -76,13 +73,13 @@
 // Publically exposed interface to pass...
 const PassInfo *const llvm::LowerAllocationsID = &X;
 // createLowerAllocationsPass - Interface to this file...
-Pass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) {
-  return new LowerAllocations(LowerMallocArgToInteger);
+Pass *llvm::createLowerAllocationsPass() {
+  return new LowerAllocations();
 }
 
 
 // doInitialization - For the lower allocations pass, this ensures that a
-// module contains a declaration for a malloc and a free function.
+// module contains a declaration for a free function.
 //
 // This function is always successful.
 //
@@ -102,25 +99,9 @@
 
   BasicBlock::InstListType &BBIL = BB.getInstList();
 
-  const TargetData &TD = getAnalysis<TargetData>();
-  const Type *IntPtrTy = TD.getIntPtrType(BB.getContext());
-
-  // Loop over all of the instructions, looking for malloc or free instructions
+  // Loop over all of the instructions, looking for free instructions
   for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
-    if (MallocInst *MI = dyn_cast<MallocInst>(I)) {
-      Value *ArraySize = MI->getOperand(0);
-      if (ArraySize->getType() != IntPtrTy)
-        ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy,
-                                                false /*ZExt*/, "", I);
-      Value *MCast = CallInst::CreateMalloc(I, IntPtrTy,
-                                            MI->getAllocatedType(), ArraySize);
-
-      // Replace all uses of the old malloc inst with the cast inst
-      MI->replaceAllUsesWith(MCast);
-      I = --BBIL.erase(I);         // remove and delete the malloc instr...
-      Changed = true;
-      ++NumLowered;
-    } else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
+    if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
       Value *PtrCast = 
         new BitCastInst(FI->getOperand(0),
                Type::getInt8PtrTy(BB.getContext()), "", I);