Change over to use new style pass mechanism, now passes only expose small
[oota-llvm.git] / lib / Transforms / Utils / LowerAllocations.cpp
index ff7a3674ec1d2fa1cb237f4260b822e54aa08cb7..dc5137e1ff8b61d6ab1f8529514bd6ee9d25c856 100644 (file)
 #include "llvm/iOther.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/ConstantVals.h"
+#include "llvm/Pass.h"
 #include "TransformInternals.h"
 using std::vector;
 
+namespace {
+
+// LowerAllocations - Turn malloc and free instructions into %malloc and %free
+// calls.
+//
+class LowerAllocations : public BasicBlockPass {
+  Method *MallocMeth;   // Methods in the module we are processing
+  Method *FreeMeth;     // Initialized by doInitialization
+
+  const TargetData &DataLayout;
+public:
+  inline LowerAllocations(const TargetData &TD) : DataLayout(TD) {
+    MallocMeth = FreeMeth = 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);
+
+  // runOnBasicBlock - This method does the actual work of converting
+  // instructions over, assuming that the pass has already been initialized.
+  //
+  bool runOnBasicBlock(BasicBlock *BB);
+};
+
+// RaiseAllocations - Turn %malloc and %free calls into the appropriate
+// instruction.
+//
+class RaiseAllocations : public BasicBlockPass {
+  Method *MallocMeth;   // Methods in the module we are processing
+  Method *FreeMeth;     // Initialized by doPassInitializationVirt
+public:
+  inline RaiseAllocations() : MallocMeth(0), FreeMeth(0) {}
+
+  // doPassInitialization - For the raise allocations pass, this finds a
+  // declaration for malloc and free if they exist.
+  //
+  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);
+};
+
+}  // end anonymous namespace
 
 // doInitialization - For the lower allocations pass, this ensures that a
 // module contains a declaration for a malloc and a free function.
@@ -181,3 +229,12 @@ bool RaiseAllocations::runOnBasicBlock(BasicBlock *BB) {
 
   return Changed;
 }
+
+Pass *createLowerAllocationsPass(const TargetData &TD) {
+  return new LowerAllocations(TD);
+}
+Pass *createRaiseAllocationsPass() {
+  return new RaiseAllocations();
+}
+
+