[llvm-commits] [llvm] r65057 - /llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Dan Gohman
gohman at apple.com
Thu Feb 19 11:23:27 PST 2009
Author: djg
Date: Thu Feb 19 13:23:27 2009
New Revision: 65057
URL: http://llvm.org/viewvc/llvm-project?rev=65057&view=rev
Log:
Make the debug output of LSR less cryptic and more informative.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=65057&r1=65056&r2=65057&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Feb 19 13:23:27 2009
@@ -696,11 +696,11 @@
InsertLoop = InsertLoop->getParentLoop();
}
+ Value *Base = Rewriter.expandCodeFor(NewBase, BaseInsertPt);
+
// If there is no immediate value, skip the next part.
if (Imm->isZero())
- return Rewriter.expandCodeFor(NewBase, BaseInsertPt);
-
- Value *Base = Rewriter.expandCodeFor(NewBase, BaseInsertPt);
+ return Base;
// If we are inserting the base and imm values in the same block, make sure to
// adjust the IP position if insertion reused a result.
@@ -761,12 +761,15 @@
}
// Replace the use of the operand Value with the new Phi we just created.
Inst->replaceUsesOfWith(OperandValToReplace, NewVal);
- DOUT << " CHANGED: IMM =" << *Imm;
- DOUT << " \tNEWBASE =" << *NewBase;
- DOUT << " \tInst = " << *Inst;
+
+#ifndef NDEBUG
+ DOUT << " Replacing with ";
+ WriteAsOperand(*DOUT, NewVal, /*PrintType=*/false);
+ DOUT << ", which has value " << *NewBase << " plus IMM " << *Imm << "\n";
+#endif
return;
}
-
+
// PHI nodes are more complex. We have to insert one copy of the NewBase+Imm
// expression into each operand block that uses it. Note that PHI nodes can
// have multiple entries for the same predecessor. We use a map to make sure
@@ -826,8 +829,14 @@
Code,
PN->getType());
}
+
+#ifndef NDEBUG
+ DOUT << " Changing PHI use to ";
+ WriteAsOperand(*DOUT, Code, /*PrintType=*/false);
+ DOUT << ", which has value " << *NewBase << " plus IMM " << *Imm << "\n";
+#endif
}
-
+
// Replace the use of the operand Value with the new Phi we just created.
PN->setIncomingValue(i, Code);
Rewriter.clear();
@@ -836,8 +845,6 @@
// PHI node might have become a constant value after SplitCriticalEdge.
DeadInsts.push_back(Inst);
-
- DOUT << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst;
}
@@ -1494,20 +1501,13 @@
AllUsesAreOutsideLoop,
Stride, ReuseIV, CommonExprs->getType(),
UsersToProcess);
- if (!isa<SCEVConstant>(RewriteFactor) ||
- !cast<SCEVConstant>(RewriteFactor)->isZero()) {
- DOUT << "BASED ON IV of STRIDE " << *ReuseIV.Stride
- << " and BASE " << *ReuseIV.Base << " :\n";
- NewPHI = ReuseIV.PHI;
- IncV = ReuseIV.IncV;
- }
-
const Type *ReplacedTy = CommonExprs->getType();
// Now that we know what we need to do, insert the PHI node itself.
//
- DOUT << "INSERTING IV of TYPE " << *ReplacedTy << " of STRIDE "
- << *Stride << " and BASE " << *CommonExprs << ": ";
+ DOUT << "LSR: Examining IVs of TYPE " << *ReplacedTy << " of STRIDE "
+ << *Stride << ":\n"
+ << " Common base: " << *CommonExprs << "\n";
SCEVExpander Rewriter(*SE, *LI);
SCEVExpander PreheaderRewriter(*SE, *LI);
@@ -1515,10 +1515,8 @@
BasicBlock *Preheader = L->getLoopPreheader();
Instruction *PreInsertPt = Preheader->getTerminator();
Instruction *PhiInsertBefore = L->getHeader()->begin();
-
BasicBlock *LatchBlock = L->getLoopLatch();
-
// Emit the initial base value into the loop preheader.
Value *CommonBaseV
= PreheaderRewriter.expandCodeFor(CommonExprs, PreInsertPt);
@@ -1556,9 +1554,20 @@
// Remember this in case a later stride is multiple of this.
IVsByStride[Stride].addIV(Stride, CommonExprs, NewPHI, IncV);
-
- DOUT << " IV=%" << NewPHI->getNameStr() << " INC=%" << IncV->getNameStr();
+
+#ifndef NDEBUG
+ DOUT << " Inserted new PHI: IV=";
+ WriteAsOperand(*DOUT, NewPHI, /*PrintType=*/false);
+ DOUT << ", INC=";
+ WriteAsOperand(*DOUT, IncV, /*PrintType=*/false);
+ DOUT << "\n";
+#endif
} else {
+ DOUT << " Rewriting in terms of existing IV of STRIDE " << *ReuseIV.Stride
+ << " and BASE " << *ReuseIV.Base << "\n";
+ NewPHI = ReuseIV.PHI;
+ IncV = ReuseIV.IncV;
+
Constant *C = dyn_cast<Constant>(CommonBaseV);
if (!C ||
(!C->isNullValue() &&
@@ -1569,7 +1578,6 @@
CommonBaseV = new BitCastInst(CommonBaseV, CommonBaseV->getType(),
"commonbase", PreInsertPt);
}
- DOUT << "\n";
// We want to emit code for users inside the loop first. To do this, we
// rearrange BasedUser so that the entries at the end have
@@ -1605,14 +1613,16 @@
// loop handles all users of a particular base.
while (!UsersToProcess.empty()) {
SCEVHandle Base = UsersToProcess.back().Base;
+ Instruction *Inst = UsersToProcess.back().Inst;
// Emit the code for Base into the preheader.
Value *BaseV = PreheaderRewriter.expandCodeFor(Base, PreInsertPt);
- DOUT << " INSERTING code for BASE = " << *Base << ":";
- if (BaseV->hasName())
- DOUT << " Result value name = %" << BaseV->getNameStr();
- DOUT << "\n";
+#ifndef NDEBUG
+ DOUT << " Examining uses with BASE ";
+ WriteAsOperand(*DOUT, BaseV, /*PrintType=*/false);
+ DOUT << ":\n";
+#endif
// If BaseV is a constant other than 0, make sure that it gets inserted into
// the preheader, instead of being forward substituted into the uses. We do
@@ -1634,6 +1644,13 @@
// FIXME: Use emitted users to emit other users.
BasedUser &User = UsersToProcess.back();
+#ifndef NDEBUG
+ DOUT << " Examining use ";
+ WriteAsOperand(*DOUT, UsersToProcess.back().OperandValToReplace,
+ /*PrintType=*/false);
+ DOUT << " in Inst: " << *Inst;
+#endif
+
// If this instruction wants to use the post-incremented value, move it
// after the post-inc and use its value instead of the PHI.
Value *RewriteOp = NewPHI;
More information about the llvm-commits
mailing list