Remove FreeInst.
Remove LowerAllocations pass.
Update some more passes to treate free calls just like they were treating FreeInst.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85176 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Utils/CMakeLists.txt b/lib/Transforms/Utils/CMakeLists.txt
index f4394ea..fbc61d7 100644
--- a/lib/Transforms/Utils/CMakeLists.txt
+++ b/lib/Transforms/Utils/CMakeLists.txt
@@ -13,7 +13,6 @@
   LCSSA.cpp
   Local.cpp
   LoopSimplify.cpp
-  LowerAllocations.cpp
   LowerInvoke.cpp
   LowerSwitch.cpp
   Mem2Reg.cpp
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 940f5a9..6e18b66 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -60,9 +60,8 @@
 
     // If we see a free or a call which may write to memory (i.e. which might do
     // a free) the pointer could be marked invalid.
-    if (isa<FreeInst>(BBI) || isFreeCall(BBI) ||
-        (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
-         !isa<DbgInfoIntrinsic>(BBI)))
+    if (isFreeCall(BBI) || (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
+                            !isa<DbgInfoIntrinsic>(BBI)))
       return false;
 
     if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
deleted file mode 100644
index 5f7bf4c..0000000
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-//===- LowerAllocations.cpp - Reduce free insts to calls ------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// The LowerAllocations transformation is a target-dependent tranformation
-// because it depends on the size of data types and alignment constraints.
-//
-//===----------------------------------------------------------------------===//
-
-#define DEBUG_TYPE "lowerallocs"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
-#include "llvm/Module.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Instructions.h"
-#include "llvm/Constants.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Pass.h"
-#include "llvm/ADT/Statistic.h"
-#include "llvm/Target/TargetData.h"
-using namespace llvm;
-
-STATISTIC(NumLowered, "Number of allocations lowered");
-
-namespace {
-  /// LowerAllocations - Turn free instructions into @free calls.
-  ///
-  class LowerAllocations : public BasicBlockPass {
-    Constant *FreeFunc;   // Functions in the module we are processing
-                          // Initialized by doInitialization
-  public:
-    static char ID; // Pass ID, replacement for typeid
-    explicit LowerAllocations()
-      : BasicBlockPass(&ID), FreeFunc(0) {}
-
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<TargetData>();
-      AU.setPreservesCFG();
-
-      // This is a cluster of orthogonal Transforms:
-      AU.addPreserved<UnifyFunctionExitNodes>();
-      AU.addPreservedID(PromoteMemoryToRegisterID);
-      AU.addPreservedID(LowerSwitchID);
-      AU.addPreservedID(LowerInvokePassID);
-    }
-
-    /// doPassInitialization - For the lower allocations pass, this ensures that
-    /// a module contains a declaration for a free function.
-    ///
-    bool doInitialization(Module &M);
-
-    virtual bool doInitialization(Function &F) {
-      return doInitialization(*F.getParent());
-    }
-
-    /// runOnBasicBlock - This method does the actual work of converting
-    /// instructions over, assuming that the pass has already been initialized.
-    ///
-    bool runOnBasicBlock(BasicBlock &BB);
-  };
-}
-
-char LowerAllocations::ID = 0;
-static RegisterPass<LowerAllocations>
-X("lowerallocs", "Lower allocations from instructions to calls");
-
-// Publically exposed interface to pass...
-const PassInfo *const llvm::LowerAllocationsID = &X;
-// createLowerAllocationsPass - Interface to this file...
-Pass *llvm::createLowerAllocationsPass() {
-  return new LowerAllocations();
-}
-
-
-// doInitialization - For the lower allocations pass, this ensures that a
-// module contains a declaration for a free function.
-//
-// This function is always successful.
-//
-bool LowerAllocations::doInitialization(Module &M) {
-  const Type *BPTy = Type::getInt8PtrTy(M.getContext());
-  FreeFunc = M.getOrInsertFunction("free"  , Type::getVoidTy(M.getContext()),
-                                   BPTy, (Type *)0);
-  return true;
-}
-
-// runOnBasicBlock - This method does the actual work of converting
-// instructions over, assuming that the pass has already been initialized.
-//
-bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
-  bool Changed = false;
-  assert(FreeFunc && "Pass not initialized!");
-
-  BasicBlock::InstListType &BBIL = BB.getInstList();
-
-  // Loop over all of the instructions, looking for free instructions
-  for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
-    if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
-      // Insert a call to the free function...
-      CallInst::CreateFree(FI->getOperand(0), I);
-
-      // Delete the old free instruction
-      I = --BBIL.erase(I);
-      Changed = true;
-      ++NumLowered;
-    }
-  }
-
-  return Changed;
-}
-
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index abb7414..6e6e8d2 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -86,7 +86,6 @@
       // This is a cluster of orthogonal Transforms
       AU.addPreservedID(PromoteMemoryToRegisterID);
       AU.addPreservedID(LowerSwitchID);
-      AU.addPreservedID(LowerAllocationsID);
     }
 
   private:
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index bc1779f..8c18b59 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -43,7 +43,6 @@
       AU.addPreserved<UnifyFunctionExitNodes>();
       AU.addPreservedID(PromoteMemoryToRegisterID);
       AU.addPreservedID(LowerInvokePassID);
-      AU.addPreservedID(LowerAllocationsID);
     }
 
     struct CaseRange {
diff --git a/lib/Transforms/Utils/Mem2Reg.cpp b/lib/Transforms/Utils/Mem2Reg.cpp
index baa7d9e..9416604 100644
--- a/lib/Transforms/Utils/Mem2Reg.cpp
+++ b/lib/Transforms/Utils/Mem2Reg.cpp
@@ -44,7 +44,6 @@
       AU.addPreserved<UnifyFunctionExitNodes>();
       AU.addPreservedID(LowerSwitchID);
       AU.addPreservedID(LowerInvokePassID);
-      AU.addPreservedID(LowerAllocationsID);
     }
   };
 }  // end of anonymous namespace