summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mca/Instruction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-mca/Instruction.cpp')
-rw-r--r--llvm/tools/llvm-mca/Instruction.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/llvm/tools/llvm-mca/Instruction.cpp b/llvm/tools/llvm-mca/Instruction.cpp
index e7f9916cae2..e3b26bd9609 100644
--- a/llvm/tools/llvm-mca/Instruction.cpp
+++ b/llvm/tools/llvm-mca/Instruction.cpp
@@ -92,17 +92,13 @@ void WriteState::dump() const {
}
#endif
-bool Instruction::isReady() {
- if (Stage == IS_READY)
- return true;
+void Instruction::dispatch() {
+ assert(Stage == IS_INVALID);
+ Stage = IS_AVAILABLE;
- assert(Stage == IS_AVAILABLE);
- for (const UniqueUse &Use : Uses)
- if (!Use.get()->isReady())
- return false;
-
- setReady();
- return true;
+ if (std::all_of(Uses.begin(), Uses.end(),
+ [](const UniqueUse &Use) { return Use->isReady(); }))
+ Stage = IS_READY;
}
void Instruction::execute() {
@@ -110,6 +106,8 @@ void Instruction::execute() {
Stage = IS_EXECUTING;
for (UniqueDef &Def : Defs)
Def->onInstructionIssued();
+ if (!CyclesLeft)
+ Stage = IS_EXECUTED;
}
bool Instruction::isZeroLatency() const {
@@ -117,18 +115,27 @@ bool Instruction::isZeroLatency() const {
}
void Instruction::cycleEvent() {
+ if (isReady())
+ return;
+
if (isDispatched()) {
- for (UniqueUse &Use : Uses)
+ bool IsReady = true;
+ for (UniqueUse &Use : Uses) {
Use->cycleEvent();
+ IsReady &= Use->isReady();
+ }
+
+ if (IsReady)
+ Stage = IS_READY;
return;
}
- if (isExecuting()) {
- for (UniqueDef &Def : Defs)
- Def->cycleEvent();
- CyclesLeft--;
- }
+
+ assert(isExecuting() && "Instruction not in-flight?");
+ assert(CyclesLeft && "Instruction already executed?");
+ for (UniqueDef &Def : Defs)
+ Def->cycleEvent();
+ CyclesLeft--;
if (!CyclesLeft)
Stage = IS_EXECUTED;
}
-
} // namespace mca
OpenPOWER on IntegriCloud