[Polly][OpTree] Better report applied changes.
Print to dbgs() any taken action.
Also, read-only scalars do not require any action unless
-polly-analyze-read-only-scalars=true is used. Better refect this by
using ForwardingAction::triviallyForwardable and thus not bumping the
statistics.
GitOrigin-RevId: c1cf51e77701719f3439eed148dfaf44e726c586
diff --git a/lib/Transform/ForwardOpTree.cpp b/lib/Transform/ForwardOpTree.cpp
index f2cb80d..d9b19ca 100644
--- a/lib/Transform/ForwardOpTree.cpp
+++ b/lib/Transform/ForwardOpTree.cpp
@@ -166,11 +166,14 @@
}
/// Named ctor: The value can just be used without any preparation.
- static ForwardingAction triviallyForwardable(bool IsProfitable) {
+ static ForwardingAction triviallyForwardable(bool IsProfitable, Value *Val) {
ForwardingAction Result;
Result.Decision =
IsProfitable ? FD_CanForwardProfitably : FD_CanForwardLeaf;
- Result.Execute = []() { return true; };
+ Result.Execute = [=]() {
+ LLVM_DEBUG(dbgs() << " trivially forwarded: " << *Val << "\n");
+ return true;
+ };
return Result;
}
@@ -637,6 +640,8 @@
Access = TargetStmt->ensureValueRead(Inst);
Access->setNewAccessRelation(SameVal);
+ LLVM_DEBUG(dbgs() << " forwarded known content of " << *Inst
+ << " which is " << SameVal << "\n");
TotalReloads++;
NumReloads++;
return false;
@@ -703,6 +708,9 @@
// operands. This ensures that its operands are inserted before the
// instruction using them.
TargetStmt->prependInstruction(UseInst);
+
+ LLVM_DEBUG(dbgs() << " forwarded speculable instruction: " << *UseInst
+ << "\n");
NumInstructionsCopied++;
TotalInstructionsCopied++;
return true;
@@ -736,7 +744,7 @@
case VirtualUse::Block:
case VirtualUse::Hoisted:
// These can be used anywhere without special considerations.
- return ForwardingAction::triviallyForwardable(false);
+ return ForwardingAction::triviallyForwardable(false, UseVal);
case VirtualUse::Synthesizable: {
// Check if the value is synthesizable at the new location as well. This
@@ -752,7 +760,7 @@
VirtualUse TargetUse = VirtualUse::create(
S, TargetStmt, TargetStmt->getSurroundingLoop(), UseVal, true);
if (TargetUse.getKind() == VirtualUse::Synthesizable)
- return ForwardingAction::triviallyForwardable(false);
+ return ForwardingAction::triviallyForwardable(false, UseVal);
LLVM_DEBUG(
dbgs() << " Synthesizable would not be synthesizable anymore: "
@@ -761,11 +769,15 @@
}
case VirtualUse::ReadOnly: {
+ if (!ModelReadOnlyScalars)
+ return ForwardingAction::triviallyForwardable(false, UseVal);
+
// If we model read-only scalars, we need to create a MemoryAccess for it.
auto ExecAction = [this, TargetStmt, UseVal]() {
- if (ModelReadOnlyScalars)
- TargetStmt->ensureValueRead(UseVal);
+ TargetStmt->ensureValueRead(UseVal);
+ LLVM_DEBUG(dbgs() << " forwarded read-only value " << *UseVal
+ << "\n");
NumReadOnlyCopied++;
TotalReadOnlyCopied++;
diff --git a/test/ForwardOpTree/forward_readonly.ll b/test/ForwardOpTree/forward_readonly.ll
index 215af70..f046b85 100644
--- a/test/ForwardOpTree/forward_readonly.ll
+++ b/test/ForwardOpTree/forward_readonly.ll
@@ -42,7 +42,8 @@
; STATS: Statistics {
; STATS: Instructions copied: 1
-; STATS: Read-only accesses copied: 1
+; MODEL: Read-only accesses copied: 1
+; NOMODEL: Read-only accesses copied: 0
; STATS: Operand trees forwarded: 1
; STATS: Statements with forwarded operand trees: 1
; STATS: }