Skip to content

Commit 4255e2a

Browse files
committed
Review comments
Change-Id: I3738cc0f14d7ab2db35109f3e02a2f7e4fa9f2e1
1 parent 5dddd84 commit 4255e2a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

llvm/lib/CodeGen/MachineSink.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -788,14 +788,15 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
788788
if (SinkInstsIntoCycle) {
789789
SmallVector<MachineCycle *, 8> Cycles(CI->toplevel_cycles());
790790
SchedModel.init(STI);
791-
enum CycleSinkStage { COPY, LOW_LATENCY, AGGRESSIVE, END };
792-
793-
CycleSinkStage Stage = CycleSinkStage::COPY;
794791
bool HasHighPressure;
795-
do {
792+
DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
793+
SunkInstrs;
794+
795+
enum CycleSinkStage { COPY, LOW_LATENCY, AGGRESSIVE, END };
796+
for (unsigned Stage = CycleSinkStage::COPY; Stage != CycleSinkStage::END;
797+
++Stage) {
796798
HasHighPressure = false;
797-
DenseMap<std::pair<MachineInstr *, MachineBasicBlock *>, MachineInstr *>
798-
SunkInstrs;
799+
SunkInstrs.clear();
799800
for (auto *Cycle : Cycles) {
800801
MachineBasicBlock *Preheader = Cycle->getCyclePreheader();
801802
if (!Preheader) {
@@ -816,7 +817,7 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
816817
if (i++ == SinkIntoCycleLimit) {
817818
LLVM_DEBUG(dbgs()
818819
<< "CycleSink: Limit reached of instructions to "
819-
"be analysed.");
820+
"be analyzed.");
820821
break;
821822
}
822823

@@ -840,8 +841,9 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
840841
if (!HasHighPressure)
841842
HasHighPressure = registerPressureExceedsLimit(*Preheader);
842843
}
843-
Stage = (CycleSinkStage)(Stage + 1);
844-
} while (HasHighPressure && Stage < CycleSinkStage::END);
844+
if (!HasHighPressure)
845+
break;
846+
}
845847
}
846848

847849
HasStoreCache.clear();
@@ -1726,12 +1728,14 @@ bool MachineSinking::aggressivelySinkIntoCycle(
17261728
MachineInstr *NewMI = nullptr;
17271729
std::pair<MachineInstr *, MachineBasicBlock *> MapEntry(&I, SinkBlock);
17281730

1731+
auto SI = SunkInstrs.find(MapEntry);
1732+
17291733
// Check for the case in which we have already sunk a copy of this
17301734
// instruction into the user block.
1731-
if (SunkInstrs.contains(MapEntry)) {
1735+
if (SI != SunkInstrs.end()) {
17321736
LLVM_DEBUG(dbgs() << "AggressiveCycleSink: Already sunk to block: "
17331737
<< printMBBReference(*SinkBlock) << "\n");
1734-
NewMI = SunkInstrs[MapEntry];
1738+
NewMI = SI->second;
17351739
}
17361740

17371741
// Create a copy of the instruction in the use block.
@@ -1748,12 +1752,12 @@ bool MachineSinking::aggressivelySinkIntoCycle(
17481752
}
17491753
SinkBlock->insert(SinkBlock->SkipPHIsAndLabels(SinkBlock->begin()),
17501754
NewMI);
1751-
SunkInstrs[MapEntry] = NewMI;
1755+
SunkInstrs.insert({MapEntry, NewMI});
17521756
}
17531757

17541758
// Conservatively clear any kill flags on uses of sunk instruction
1755-
for (MachineOperand &MO : NewMI->operands()) {
1756-
if (MO.isReg() && MO.readsReg())
1759+
for (MachineOperand &MO : NewMI->all_uses()) {
1760+
if (MO.isReg())
17571761
RegsToClearKillFlags.insert(MO.getReg());
17581762
}
17591763

0 commit comments

Comments
 (0)