Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 0093dbb

Browse files
committed
[llvm-mca] Avoid calling method update() on instructions that are already in the IS_READY state. NFCI
When promoting instructions from the wait queue to the ready queue, we should check if an instruction has already reached the IS_READY state before calling method update(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335722 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a62a0a3 commit 0093dbb

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

tools/llvm-mca/Instruction.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ void ReadState::writeStartEvent(unsigned Cycles) {
3232
--DependentWrites;
3333
TotalCycles = std::max(TotalCycles, Cycles);
3434

35-
if (!DependentWrites)
35+
if (!DependentWrites) {
3636
CyclesLeft = TotalCycles;
37+
IsReady = !CyclesLeft;
38+
}
3739
}
3840

3941
void WriteState::onInstructionIssued() {
@@ -83,8 +85,10 @@ void ReadState::cycleEvent() {
8385
if (CyclesLeft == UNKNOWN_CYCLES)
8486
return;
8587

86-
if (CyclesLeft)
88+
if (CyclesLeft) {
8789
--CyclesLeft;
90+
IsReady = !CyclesLeft;
91+
}
8892
}
8993

9094
#ifndef NDEBUG
@@ -119,9 +123,7 @@ void Instruction::execute() {
119123
}
120124

121125
void Instruction::update() {
122-
if (!isDispatched())
123-
return;
124-
126+
assert(isDispatched() && "Unexpected instruction stage found!");
125127
if (llvm::all_of(Uses, [](const UniqueUse &Use) { return Use->isReady(); }))
126128
Stage = IS_READY;
127129
}
@@ -131,9 +133,14 @@ void Instruction::cycleEvent() {
131133
return;
132134

133135
if (isDispatched()) {
134-
for (UniqueUse &Use : Uses)
136+
bool IsReady = true;
137+
for (UniqueUse &Use : Uses) {
135138
Use->cycleEvent();
136-
update();
139+
IsReady &= Use->isReady();
140+
}
141+
142+
if (IsReady)
143+
Stage = IS_READY;
137144
return;
138145
}
139146

tools/llvm-mca/Instruction.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,16 @@ class ReadState {
162162
// dependent writes (i.e. field DependentWrite) is zero, this value is
163163
// propagated to field CyclesLeft.
164164
unsigned TotalCycles;
165+
// This field is set to true only if there are no dependent writes, and
166+
// there are no `CyclesLeft' to wait.
167+
bool IsReady;
165168

166169
public:
167-
bool isReady() const {
168-
if (DependentWrites)
169-
return false;
170-
return (CyclesLeft == UNKNOWN_CYCLES || CyclesLeft == 0);
171-
}
170+
bool isReady() const { return IsReady; }
172171

173172
ReadState(const ReadDescriptor &Desc, unsigned RegID)
174173
: RD(Desc), RegisterID(RegID), DependentWrites(0),
175-
CyclesLeft(UNKNOWN_CYCLES), TotalCycles(0) {}
174+
CyclesLeft(UNKNOWN_CYCLES), TotalCycles(0), IsReady(true) {}
176175
ReadState(const ReadState &Other) = delete;
177176
ReadState &operator=(const ReadState &Other) = delete;
178177

@@ -182,7 +181,10 @@ class ReadState {
182181

183182
void cycleEvent();
184183
void writeStartEvent(unsigned Cycles);
185-
void setDependentWrites(unsigned Writes) { DependentWrites = Writes; }
184+
void setDependentWrites(unsigned Writes) {
185+
DependentWrites = Writes;
186+
IsReady = !Writes;
187+
}
186188
};
187189

188190
/// A sequence of cycles.

tools/llvm-mca/Scheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ void Scheduler::promoteToReadyQueue(SmallVectorImpl<InstRef> &Ready) {
293293

294294
// Check if this instruction is now ready. In case, force
295295
// a transition in state using method 'update()'.
296-
IS->update();
296+
if (!IS->isReady())
297+
IS->update();
297298

298299
const InstrDesc &Desc = IS->getDesc();
299300
bool IsMemOp = Desc.MayLoad || Desc.MayStore;

0 commit comments

Comments
 (0)