[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.
This commit is contained in:
Michael Kruse 2020-11-11 16:00:42 -06:00
parent 4c55c3b66d
commit c1cf51e777
2 changed files with 20 additions and 7 deletions

View File

@ -166,11 +166,14 @@ struct ForwardingAction {
}
/// 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 @@ public:
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 @@ public:
// 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 @@ public:
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 @@ public:
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 @@ public:
}
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++;

View File

@ -42,7 +42,8 @@ return:
; 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: }