From 40372ce62d181f9f563585274f790f9a1cf76f97 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 18 Oct 2001 05:27:33 +0000 Subject: [PATCH] Convert to new simpler pass itf llvm-svn: 880 --- lib/Transforms/HoistPHIConstants.cpp | 9 ++++++--- lib/Transforms/Scalar/InductionVars.cpp | 2 +- lib/Transforms/Scalar/LowerAllocations.cpp | 14 ++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Transforms/HoistPHIConstants.cpp b/lib/Transforms/HoistPHIConstants.cpp index de806fc4098..a47ab26c75f 100644 --- a/lib/Transforms/HoistPHIConstants.cpp +++ b/lib/Transforms/HoistPHIConstants.cpp @@ -40,8 +40,9 @@ static Value *NormalizePhiOperand(PHINode *PN, Value *CPV, // Entry point for normalizing constant args in PHIs //--------------------------------------------------------------------------- -bool HoistPHIConstants::doPerMethodWork(Method *M) { +bool HoistPHIConstants::doHoistPHIConstants(Method *M) { CachedCopyMap Cache; + bool Changed = false; for (Method::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI) for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) { @@ -51,11 +52,13 @@ bool HoistPHIConstants::doPerMethodWork(Method *M) { PHINode *PN = cast(Inst); for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { Value *Op = PN->getIncomingValue(i); - if (isa(Op)) + if (isa(Op)) { PN->setIncomingValue(i, NormalizePhiOperand(PN, Op, PN->getIncomingBlock(i), Cache)); + Changed = true; + } } } - return false; + return Changed; } diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index 9a8eb12c136..1cec66de71e 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -371,7 +371,7 @@ static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) { // This function loops over an interval partition of a program, reducing it // until the graph is gone. // -bool opt::DoInductionVariableCannonicalize(Method *M) { +bool opt::InductionVariableCannonicalize::doIt(Method *M) { // TODO: REMOVE if (0) { // Print basic blocks with their depth LoopDepthCalculator LDC(M); diff --git a/lib/Transforms/Scalar/LowerAllocations.cpp b/lib/Transforms/Scalar/LowerAllocations.cpp index ba78ce18fd5..945d941530c 100644 --- a/lib/Transforms/Scalar/LowerAllocations.cpp +++ b/lib/Transforms/Scalar/LowerAllocations.cpp @@ -19,7 +19,8 @@ // // This function is always successful. // -bool LowerAllocations::doPassInitializationVirt(Module *M) { +bool LowerAllocations::doPassInitialization(Module *M) { + bool Changed = false; const MethodType *MallocType = MethodType::get(PointerType::get(Type::UByteTy), vector(1, Type::UIntTy), false); @@ -31,6 +32,7 @@ bool LowerAllocations::doPassInitializationVirt(Module *M) { MallocMeth = cast(V); // Yup, got it } else { // Nope, add one M->getMethodList().push_back(MallocMeth = new Method(MallocType, "malloc")); + Changed = true; } const MethodType *FreeType = @@ -43,15 +45,17 @@ bool LowerAllocations::doPassInitializationVirt(Module *M) { FreeMeth = cast(V); // Yup, got it } else { // Nope, add one M->getMethodList().push_back(FreeMeth = new Method(FreeType, "free")); + Changed = true; } - return false; // Always successful + return Changed; // Always successful } // doPerMethodWork - This method does the actual work of converting // instructions over, assuming that the pass has already been initialized. // -bool LowerAllocations::doPerMethodWorkVirt(Method *M) { +bool LowerAllocations::doPerMethodWork(Method *M) { + bool Changed = false; assert(MallocMeth && FreeMeth && M && "Pass not initialized!"); // Loop over all of the instructions, looking for malloc or free instructions @@ -97,6 +101,7 @@ bool LowerAllocations::doPerMethodWorkVirt(Method *M) { // Replace all uses of the old malloc inst with the cast inst MI->replaceAllUsesWith(MCast); delete MI; // Delete the malloc inst + Changed = true; } else if (FreeInst *FI = dyn_cast(*(BBIL.begin()+i))) { BBIL.remove(BB->getInstList().begin()+i); @@ -112,10 +117,11 @@ bool LowerAllocations::doPerMethodWorkVirt(Method *M) { // Delete the old free instruction delete FI; + Changed = true; } } } - return false; // Always successful + return Changed; }