Change LowerAllocations pass to 'require' TargetData instead of it being
authorChris Lattner <sabre@nondot.org>
Wed, 25 Sep 2002 23:47:47 +0000 (23:47 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 25 Sep 2002 23:47:47 +0000 (23:47 +0000)
passed in.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3929 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/LowerAllocations.cpp

index 001028eb21ae60918389219d301d4eac3126bcde..99eb2d044e4feeab8c189108cfd824686c340330 100644 (file)
@@ -20,40 +20,39 @@ using std::vector;
 
 namespace {
 
-// LowerAllocations - Turn malloc and free instructions into %malloc and %free
-// calls.
-//
-class LowerAllocations : public BasicBlockPass {
-  Function *MallocFunc;   // Functions in the module we are processing
-  Function *FreeFunc;     // Initialized by doInitialization
-
-  const TargetData &DataLayout;
-public:
-  LowerAllocations(const TargetData &TD) : DataLayout(TD) {
-    MallocFunc = FreeFunc = 0;
-  }
-
-  // doPassInitialization - For the lower allocations pass, this ensures that a
-  // module contains a declaration for a malloc and a free function.
-  //
-  bool doInitialization(Module &M);
+  /// LowerAllocations - Turn malloc and free instructions into %malloc and
+  /// %free calls.
+  ///
+  class LowerAllocations : public BasicBlockPass {
+    Function *MallocFunc;   // Functions in the module we are processing
+    Function *FreeFunc;     // Initialized by doInitialization
+  public:
+    LowerAllocations() : MallocFunc(0), FreeFunc(0) {}
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addRequired<TargetData>();
+    }
 
-  // runOnBasicBlock - This method does the actual work of converting
-  // instructions over, assuming that the pass has already been initialized.
-  //
-  bool runOnBasicBlock(BasicBlock &BB);
-};
+    /// doPassInitialization - For the lower allocations pass, this ensures that
+    /// a module contains a declaration for a malloc and a free function.
+    ///
+    bool doInitialization(Module &M);
+    
+    /// runOnBasicBlock - This method does the actual work of converting
+    /// instructions over, assuming that the pass has already been initialized.
+    ///
+    bool runOnBasicBlock(BasicBlock &BB);
+  };
+
+  RegisterOpt<LowerAllocations>
+  X("lowerallocs", "Lower allocations from instructions to calls");
 }
 
 // createLowerAllocationsPass - Interface to this file...
-Pass *createLowerAllocationsPass(const TargetData &TD) {
-  return new LowerAllocations(TD);
+Pass *createLowerAllocationsPass() {
+  return new LowerAllocations();
 }
 
-static RegisterOpt<LowerAllocations>
-X("lowerallocs", "Lower allocations from instructions to calls (TD)",
-  createLowerAllocationsPass);
-
 
 // doInitialization - For the lower allocations pass, this ensures that a
 // module contains a declaration for a malloc and a free function.
@@ -83,6 +82,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
   assert(MallocFunc && FreeFunc && "Pass not initialized!");
 
   BasicBlock::InstListType &BBIL = BB.getInstList();
+  TargetData &DataLayout = getAnalysis<TargetData>();
 
   // Loop over all of the instructions, looking for malloc or free instructions
   for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {