LowerAllocations is really a BasicBlock pass. Make it so.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1521 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-01-21 23:34:02 +00:00
parent 59b6b8e0b3
commit 8445372636
2 changed files with 57 additions and 62 deletions

View File

@ -13,7 +13,7 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
class TargetData; class TargetData;
class LowerAllocations : public MethodPass { class LowerAllocations : public BasicBlockPass {
Method *MallocMeth; // Methods in the module we are processing Method *MallocMeth; // Methods in the module we are processing
Method *FreeMeth; // Initialized by doPassInitializationVirt Method *FreeMeth; // Initialized by doPassInitializationVirt
@ -26,14 +26,12 @@ public:
// doPassInitialization - For the lower allocations pass, this ensures that a // doPassInitialization - For the lower allocations pass, this ensures that a
// module contains a declaration for a malloc and a free function. // module contains a declaration for a malloc and a free function.
// //
// This function is always successful.
//
bool doInitialization(Module *M); bool doInitialization(Module *M);
// doPerMethodWork - This method does the actual work of converting // runOnBasicBlock - This method does the actual work of converting
// instructions over, assuming that the pass has already been initialized. // instructions over, assuming that the pass has already been initialized.
// //
bool runOnMethod(Method *M); bool runOnBasicBlock(BasicBlock *BB);
}; };
#endif #endif

View File

@ -1,4 +1,4 @@
//===- llvm/Transforms/LowerAllocations.h - Remove Malloc & Free Insts ------=// //===- LowerAllocations.cpp - Remove Malloc & Free Instructions -------------=//
// //
// This file implements a pass that lowers malloc and free instructions to // This file implements a pass that lowers malloc and free instructions to
// calls to %malloc & %free functions. This transformation is a target // calls to %malloc & %free functions. This transformation is a target
@ -52,19 +52,17 @@ bool LowerAllocations::doInitialization(Module *M) {
Changed = true; Changed = true;
} }
return Changed; // Always successful return Changed;
} }
// runOnMethod - This method does the actual work of converting // runOnBasicBlock - This method does the actual work of converting
// instructions over, assuming that the pass has already been initialized. // instructions over, assuming that the pass has already been initialized.
// //
bool LowerAllocations::runOnMethod(Method *M) { bool LowerAllocations::runOnBasicBlock(BasicBlock *BB) {
bool Changed = false; bool Changed = false;
assert(MallocMeth && FreeMeth && M && "Pass not initialized!"); assert(MallocMeth && FreeMeth && BB && "Pass not initialized!");
// Loop over all of the instructions, looking for malloc or free instructions // Loop over all of the instructions, looking for malloc or free instructions
for (Method::iterator BBI = M->begin(), BBE = M->end(); BBI != BBE; ++BBI) {
BasicBlock *BB = *BBI;
for (unsigned i = 0; i < BB->size(); ++i) { for (unsigned i = 0; i < BB->size(); ++i) {
BasicBlock::InstListType &BBIL = BB->getInstList(); BasicBlock::InstListType &BBIL = BB->getInstList();
if (MallocInst *MI = dyn_cast<MallocInst>(*(BBIL.begin()+i))) { if (MallocInst *MI = dyn_cast<MallocInst>(*(BBIL.begin()+i))) {
@ -118,7 +116,6 @@ bool LowerAllocations::runOnMethod(Method *M) {
Changed = true; Changed = true;
} }
} }
}
return Changed; return Changed;
} }