aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-02-19 19:23:27 +0000
committerDan Gohman <gohman@apple.com>2009-02-19 19:23:27 +0000
commit2f09f519542202b8af227c2a524f8fe82378a934 (patch)
tree47c294d70d50bf5106d51aa9346656c02bfcdedc /lib/Transforms
parent4dd82f6aaa483ef11bd74795c81cfc30b52821af (diff)
downloadexternal_llvm-2f09f519542202b8af227c2a524f8fe82378a934.zip
external_llvm-2f09f519542202b8af227c2a524f8fe82378a934.tar.gz
external_llvm-2f09f519542202b8af227c2a524f8fe82378a934.tar.bz2
Make the debug output of LSR less cryptic and more informative.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65057 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp75
1 files changed, 46 insertions, 29 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index a56bb67..d906ee7 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -696,11 +696,11 @@ Value *BasedUser::InsertCodeForBaseAtPosition(const SCEVHandle &NewBase,
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 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
}
// 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 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
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 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
// PHI node might have become a constant value after SplitCriticalEdge.
DeadInsts.push_back(Inst);
-
- DOUT << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst;
}
@@ -1494,20 +1501,13 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
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 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
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 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
// 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 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
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 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
// 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 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
// 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;