+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<TargetData>();
+ }
+
+ /// 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() {
+ return new LowerAllocations();
+}
+