X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FUtils%2FLowerAllocations.cpp;h=8c6550003dd72b0dbe78a4c0ca89148bc83349a2;hb=dee430d26e14a3d7c8d86688d49ac8b116aa044f;hp=001028eb21ae60918389219d301d4eac3126bcde;hpb=1d608abbc07bbc7c78c20da6b305ef14c6c30e8e;p=oota-llvm.git diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index 001028eb21a..8c6550003dd 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -13,47 +13,46 @@ #include "llvm/Constants.h" #include "llvm/Pass.h" #include "llvm/Target/TargetData.h" -#include "Support/StatisticReporter.h" +#include "Support/Statistic.h" -static Statistic<> NumLowered("lowerallocs\t- Number of allocations lowered"); using std::vector; namespace { + Statistic<> NumLowered("lowerallocs", "Number of allocations lowered"); + + /// 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(); + } -// 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); - - // 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 + 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 -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(); // Loop over all of the instructions, looking for malloc or free instructions for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {