diff options
author | Chris Lattner <sabre@nondot.org> | 2002-02-26 21:46:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-02-26 21:46:54 +0000 |
commit | bd0ef77cde9c9e82f2b4ad33e4982c46274d6540 (patch) | |
tree | 0903b61112c9e6d336c8b623e235ede2f937f13c /lib/Transforms/Utils/LowerAllocations.cpp | |
parent | 3b2541424f771ae11c30675ce06da7b380780028 (diff) |
Change over to use new style pass mechanism, now passes only expose small
creation functions in their public header file, unless they can help it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1816 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LowerAllocations.cpp')
-rw-r--r-- | lib/Transforms/Utils/LowerAllocations.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index ff7a3674ec..dc5137e1ff 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -15,9 +15,57 @@ #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(); +} + + |