Skip to content

Commit c1cf51e

Browse files
committed
[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.
1 parent 4c55c3b commit c1cf51e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

polly/lib/Transform/ForwardOpTree.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ struct ForwardingAction {
166166
}
167167

168168
/// Named ctor: The value can just be used without any preparation.
169-
static ForwardingAction triviallyForwardable(bool IsProfitable) {
169+
static ForwardingAction triviallyForwardable(bool IsProfitable, Value *Val) {
170170
ForwardingAction Result;
171171
Result.Decision =
172172
IsProfitable ? FD_CanForwardProfitably : FD_CanForwardLeaf;
173-
Result.Execute = []() { return true; };
173+
Result.Execute = [=]() {
174+
LLVM_DEBUG(dbgs() << " trivially forwarded: " << *Val << "\n");
175+
return true;
176+
};
174177
return Result;
175178
}
176179

@@ -637,6 +640,8 @@ class ForwardOpTreeImpl : ZoneAlgorithm {
637640
Access = TargetStmt->ensureValueRead(Inst);
638641
Access->setNewAccessRelation(SameVal);
639642

643+
LLVM_DEBUG(dbgs() << " forwarded known content of " << *Inst
644+
<< " which is " << SameVal << "\n");
640645
TotalReloads++;
641646
NumReloads++;
642647
return false;
@@ -703,6 +708,9 @@ class ForwardOpTreeImpl : ZoneAlgorithm {
703708
// operands. This ensures that its operands are inserted before the
704709
// instruction using them.
705710
TargetStmt->prependInstruction(UseInst);
711+
712+
LLVM_DEBUG(dbgs() << " forwarded speculable instruction: " << *UseInst
713+
<< "\n");
706714
NumInstructionsCopied++;
707715
TotalInstructionsCopied++;
708716
return true;
@@ -736,7 +744,7 @@ class ForwardOpTreeImpl : ZoneAlgorithm {
736744
case VirtualUse::Block:
737745
case VirtualUse::Hoisted:
738746
// These can be used anywhere without special considerations.
739-
return ForwardingAction::triviallyForwardable(false);
747+
return ForwardingAction::triviallyForwardable(false, UseVal);
740748

741749
case VirtualUse::Synthesizable: {
742750
// Check if the value is synthesizable at the new location as well. This
@@ -752,7 +760,7 @@ class ForwardOpTreeImpl : ZoneAlgorithm {
752760
VirtualUse TargetUse = VirtualUse::create(
753761
S, TargetStmt, TargetStmt->getSurroundingLoop(), UseVal, true);
754762
if (TargetUse.getKind() == VirtualUse::Synthesizable)
755-
return ForwardingAction::triviallyForwardable(false);
763+
return ForwardingAction::triviallyForwardable(false, UseVal);
756764

757765
LLVM_DEBUG(
758766
dbgs() << " Synthesizable would not be synthesizable anymore: "
@@ -761,11 +769,15 @@ class ForwardOpTreeImpl : ZoneAlgorithm {
761769
}
762770

763771
case VirtualUse::ReadOnly: {
772+
if (!ModelReadOnlyScalars)
773+
return ForwardingAction::triviallyForwardable(false, UseVal);
774+
764775
// If we model read-only scalars, we need to create a MemoryAccess for it.
765776
auto ExecAction = [this, TargetStmt, UseVal]() {
766-
if (ModelReadOnlyScalars)
767-
TargetStmt->ensureValueRead(UseVal);
777+
TargetStmt->ensureValueRead(UseVal);
768778

779+
LLVM_DEBUG(dbgs() << " forwarded read-only value " << *UseVal
780+
<< "\n");
769781
NumReadOnlyCopied++;
770782
TotalReadOnlyCopied++;
771783

polly/test/ForwardOpTree/forward_readonly.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ return:
4242

4343
; STATS: Statistics {
4444
; STATS: Instructions copied: 1
45-
; STATS: Read-only accesses copied: 1
45+
; MODEL: Read-only accesses copied: 1
46+
; NOMODEL: Read-only accesses copied: 0
4647
; STATS: Operand trees forwarded: 1
4748
; STATS: Statements with forwarded operand trees: 1
4849
; STATS: }

0 commit comments

Comments
 (0)