aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorPhilip Reames <preames@rivosinc.com>2024-03-06 10:36:45 -0800
committerPhilip Reames <listmail@philipreames.com>2024-03-06 13:08:05 -0800
commit0d38f21e4ab7fe7cebe76a9d7c218ec54dba1e98 (patch)
tree03279306de563a628db89ee1385af09b379a7589 /llvm/lib/Analysis/ScalarEvolution.cpp
parent3b1512c477694c5ee4fb20fae416e834bf42518e (diff)
downloadllvm-0d38f21e4ab7fe7cebe76a9d7c218ec54dba1e98.zip
llvm-0d38f21e4ab7fe7cebe76a9d7c218ec54dba1e98.tar.gz
llvm-0d38f21e4ab7fe7cebe76a9d7c218ec54dba1e98.tar.bz2
[SCEV] Extend type hint in analysis output to all backedge kinds
This extends the work from 7755c26 to all of the different backend taken count kinds that we print for the scev analysis printer. As before, the goal is to cut down on confusion as i4 -1 is a very different (unsigned) value from i32 -1.
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp50
1 files changed, 33 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 57e3619..15c2965 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13469,6 +13469,14 @@ bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount(const Loop *L) {
return !isa<SCEVCouldNotCompute>(getBackedgeTakenCount(L));
}
+/// When printing a top-level SCEV for trip counts, it's helpful to include
+/// a type for constants which are otherwise hard to disambiguate.
+static void PrintSCEVWithTypeHint(raw_ostream &OS, const SCEV* S) {
+ if (isa<SCEVConstant>(S))
+ OS << *S->getType() << " ";
+ OS << *S;
+}
+
static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
const Loop *L) {
// Print all inner loops first
@@ -13485,15 +13493,18 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
OS << "<multiple exits> ";
auto *BTC = SE->getBackedgeTakenCount(L);
- if (!isa<SCEVCouldNotCompute>(BTC))
- OS << "backedge-taken count is " << *BTC << "\n";
- else
- OS << "Unpredictable backedge-taken count.\n";
+ if (!isa<SCEVCouldNotCompute>(BTC)) {
+ OS << "backedge-taken count is ";
+ PrintSCEVWithTypeHint(OS, BTC);
+ } else
+ OS << "Unpredictable backedge-taken count.";
+ OS << "\n";
if (ExitingBlocks.size() > 1)
for (BasicBlock *ExitingBlock : ExitingBlocks) {
- OS << " exit count for " << ExitingBlock->getName() << ": "
- << *SE->getExitCount(L, ExitingBlock) << "\n";
+ OS << " exit count for " << ExitingBlock->getName() << ": ";
+ PrintSCEVWithTypeHint(OS, SE->getExitCount(L, ExitingBlock));
+ OS << "\n";
}
OS << "Loop ";
@@ -13502,8 +13513,8 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
auto *ConstantBTC = SE->getConstantMaxBackedgeTakenCount(L);
if (!isa<SCEVCouldNotCompute>(ConstantBTC)) {
- OS << "constant max backedge-taken count is "
- << *ConstantBTC->getType() << " " << *ConstantBTC;
+ OS << "constant max backedge-taken count is ";
+ PrintSCEVWithTypeHint(OS, ConstantBTC);
if (SE->isBackedgeTakenCountMaxOrZero(L))
OS << ", actual taken count either this or zero.";
} else {
@@ -13517,19 +13528,22 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
auto *SymbolicBTC = SE->getSymbolicMaxBackedgeTakenCount(L);
if (!isa<SCEVCouldNotCompute>(SymbolicBTC)) {
- OS << "symbolic max backedge-taken count is " << *SymbolicBTC;
+ OS << "symbolic max backedge-taken count is ";
+ PrintSCEVWithTypeHint(OS, SymbolicBTC);
if (SE->isBackedgeTakenCountMaxOrZero(L))
OS << ", actual taken count either this or zero.";
} else {
OS << "Unpredictable symbolic max backedge-taken count. ";
}
-
OS << "\n";
+
if (ExitingBlocks.size() > 1)
for (BasicBlock *ExitingBlock : ExitingBlocks) {
- OS << " symbolic max exit count for " << ExitingBlock->getName() << ": "
- << *SE->getExitCount(L, ExitingBlock, ScalarEvolution::SymbolicMaximum)
- << "\n";
+ OS << " symbolic max exit count for " << ExitingBlock->getName() << ": ";
+ auto *ExitBTC = SE->getExitCount(L, ExitingBlock,
+ ScalarEvolution::SymbolicMaximum);
+ PrintSCEVWithTypeHint(OS, ExitBTC);
+ OS << "\n";
}
SmallVector<const SCEVPredicate *, 4> Preds;
@@ -13538,10 +13552,12 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
OS << "Loop ";
L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
OS << ": ";
- if (!isa<SCEVCouldNotCompute>(PBT))
- OS << "Predicated backedge-taken count is " << *PBT << "\n";
- else
- OS << "Unpredictable predicated backedge-taken count.\n";
+ if (!isa<SCEVCouldNotCompute>(PBT)) {
+ OS << "Predicated backedge-taken count is ";
+ PrintSCEVWithTypeHint(OS, PBT);
+ } else
+ OS << "Unpredictable predicated backedge-taken count.";
+ OS << "\n";
OS << " Predicates:\n";
for (const auto *P : Preds)
P->print(OS, 4);