[llvm-mca] Simplify code that computes the latency of an instruction in
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 13 Mar 2018 15:59:59 +0000 (15:59 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 13 Mar 2018 15:59:59 +0000 (15:59 +0000)
InstrBuilder. NFCI

This was possible because of r327406, which added function`computeInstrLatency`
to MCSchedModel.

llvm-svn: 327415

llvm/tools/llvm-mca/InstrBuilder.cpp

index 9c69d54..35b3a35 100644 (file)
@@ -123,41 +123,16 @@ initializeUsedResources(InstrDesc &ID, const MCSchedClassDesc &SCDesc,
 static void computeMaxLatency(InstrDesc &ID, const MCInstrDesc &MCDesc,
                               const MCSchedClassDesc &SCDesc,
                               const MCSubtargetInfo &STI) {
-  unsigned MaxLatency = 0;
-  unsigned NumWriteLatencyEntries = SCDesc.NumWriteLatencyEntries;
-  for (unsigned I = 0, E = NumWriteLatencyEntries; I < E; ++I) {
-    int Cycles = STI.getWriteLatencyEntry(&SCDesc, I)->Cycles;
-    // Check if this is an unknown latency. Conservatively (pessimistically)
-    // assume a latency of 100cy if late.
-    if (Cycles == -1)
-      Cycles = 100;
-    MaxLatency = std::max(MaxLatency, static_cast<unsigned>(Cycles));
-  }
-
   if (MCDesc.isCall()) {
     // We cannot estimate how long this call will take.
     // Artificially set an arbitrarily high latency (100cy).
-    MaxLatency = std::max(100U, MaxLatency);
-  }
-
-  // Check if this instruction consumes any processor resources.
-  // If the latency is unknown, then conservatively set it equal to the maximum
-  // number of cycles for a resource consumed by this instruction.
-  if (!MaxLatency && ID.Resources.size()) {
-    // Check if this instruction consumes any processor resources.
-    // If so, then compute the max of the cycles spent for each resource, and
-    // use it as the MaxLatency.
-    for (const std::pair<uint64_t, ResourceUsage> &Resource : ID.Resources)
-      MaxLatency = std::max(MaxLatency, Resource.second.size());
-  }
-
-  if (SCDesc.isVariant() && MaxLatency == 0) {
-    errs() << "note: unknown latency for a variant opcode. Conservatively"
-           << " assume a default latency of 1cy.\n";
-    MaxLatency = 1;
+    ID.MaxLatency = 100U;
+    return;
   }
 
-  ID.MaxLatency = MaxLatency;
+  int Latency = MCSchedModel::computeInstrLatency(STI, SCDesc);
+  // If latency is unknown, then conservatively assume a MaxLatency of 100cy.
+  ID.MaxLatency = Latency < 0 ? 100U : static_cast<unsigned>(Latency);
 }
 
 static void populateWrites(InstrDesc &ID, const MCInst &MCI,