From ee4f13a9046c380725cdeab62d57722db375c473 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 7 Jan 2007 01:14:12 +0000 Subject: [PATCH] add -debug output for -indvars. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32971 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 143a6828a22..c37132c8cd7 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -46,6 +46,7 @@ #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/CFG.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/CommandLine.h" @@ -113,6 +114,7 @@ DeleteTriviallyDeadInstructions(std::set &Insts) { if (Instruction *U = dyn_cast(I->getOperand(i))) Insts.insert(U); SE->deleteInstructionFromRecords(I); + DOUT << "INDVARS: Deleting: " << *I; I->eraseFromParent(); Changed = true; } @@ -133,7 +135,8 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN, dyn_cast(PN->getIncomingValue(BackedgeIdx))) if (GEPI->getOperand(0) == PN) { assert(GEPI->getNumOperands() == 2 && "GEP types must match!"); - + DOUT << "INDVARS: Eliminating pointer recurrence: " << *GEPI; + // Okay, we found a pointer recurrence. Transform this pointer // recurrence into an integer recurrence. Compute the value that gets // added to the pointer at every iteration. @@ -265,6 +268,9 @@ Instruction *IndVarSimplify::LinearFunctionTestReplace(Loop *L, // We have to use the preincremented value... IndVar = L->getCanonicalInductionVariable(); } + + DOUT << "INDVARS: LFTR: TripCount = " << *TripCount + << " IndVar = " << *IndVar << "\n"; // Expand the code for the iteration count into the preheader of the loop. BasicBlock *Preheader = L->getLoopPreheader(); @@ -359,6 +365,9 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) { Value *NewVal = Rewriter.expandCodeFor(ExitValue, InsertPt, I->getType()); + DOUT << "INDVARS: RLEV: AfterLoopVal = " << *NewVal + << " LoopVal = " << *I << "\n"; + // Rewrite any users of the computed value outside of the loop // with the newly computed value. for (unsigned i = 0, e = ExtraLoopUsers.size(); i != e; ++i) { @@ -502,6 +511,7 @@ void IndVarSimplify::runOnLoop(Loop *L) { Value *IndVar = Rewriter.getOrInsertCanonicalInductionVariable(L,LargestType); ++NumInserted; Changed = true; + DOUT << "INDVARS: New CanIV: " << *IndVar; if (!isa(IterationCount)) if (Instruction *DI = LinearFunctionTestReplace(L, IterationCount,Rewriter)) @@ -523,20 +533,23 @@ void IndVarSimplify::runOnLoop(Loop *L) { if (!InsertedSizes[IndVars[i].first->getType()->getPrimitiveSize()]) { PHINode *PN = IndVars[i].first; InsertedSizes[PN->getType()->getPrimitiveSize()] = true; - Instruction *New = CastInst::create(Instruction::Trunc, IndVar, - PN->getType(), "indvar", InsertPt); + Instruction *New = new TruncInst(IndVar, PN->getType(), "indvar", + InsertPt); Rewriter.addInsertedValue(New, SE->getSCEV(New)); + DOUT << "INDVARS: Made trunc IV for " << *PN + << " NewVal = " << *New << "\n"; } } - // If there were induction variables of other sizes, cast the primary - // induction variable to the right size for them, avoiding the need for the - // code evaluation methods to insert induction variables of different sizes. + // Rewrite all induction variables in terms of the canonical induction + // variable. std::map InsertedSizes; while (!IndVars.empty()) { PHINode *PN = IndVars.back().first; Value *NewVal = Rewriter.expandCodeFor(IndVars.back().second, InsertPt, PN->getType()); + DOUT << "INDVARS: Rewrote IV '" << *IndVars.back().second << "' " << *PN + << " into = " << *NewVal << "\n"; std::string Name = PN->getName(); PN->setName(""); NewVal->setName(Name); -- 2.34.1