[llvm-mca] Simplify code. NFC

llvm-svn: 328187
diff --git a/llvm/tools/llvm-mca/Instruction.cpp b/llvm/tools/llvm-mca/Instruction.cpp
index e7f9916..e3b26bd 100644
--- a/llvm/tools/llvm-mca/Instruction.cpp
+++ b/llvm/tools/llvm-mca/Instruction.cpp
@@ -92,17 +92,13 @@
 }
 #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 @@
   Stage = IS_EXECUTING;
   for (UniqueDef &Def : Defs)
     Def->onInstructionIssued();
+  if (!CyclesLeft)
+    Stage = IS_EXECUTED;
 }
 
 bool Instruction::isZeroLatency() const {
@@ -117,18 +115,27 @@
 }
 
 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