Generalize the MachineTraceMetrics public API.
authorAndrew Trick <atrick@apple.com>
Sat, 27 Apr 2013 03:54:20 +0000 (03:54 +0000)
committerAndrew Trick <atrick@apple.com>
Sat, 27 Apr 2013 03:54:20 +0000 (03:54 +0000)
Naturally, we should be able to pass in extra instructions, not just
extra blocks.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180667 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineTraceMetrics.h
lib/CodeGen/MachineTraceMetrics.cpp

index 2775a0485821998d009f5cd89be9df0e712be758..4e087fc62d875499e347ffc71a78bd76163afaa9 100644 (file)
@@ -260,9 +260,13 @@ public:
     /// independent, exposing the maximum instruction-level parallelism.
     ///
     /// Any blocks in Extrablocks are included as if they were part of the
-    /// trace.
+    /// trace. Likewise, extra resources required by the specified scheduling
+    /// classes are included. For the caller to account for extra machine
+    /// instructions, it must first resolve each instruction's scheduling class.
     unsigned getResourceLength(ArrayRef<const MachineBasicBlock*> Extrablocks =
-                               ArrayRef<const MachineBasicBlock*>()) const;
+                               ArrayRef<const MachineBasicBlock*>(),
+                               ArrayRef<const MCSchedClassDesc*> ExtraInstrs =
+                               ArrayRef<const MCSchedClassDesc*>()) const;
 
     /// Return the length of the (data dependency) critical path through the
     /// trace.
index 49d8c4e9470dce9c2841001a75070dba5e04441b..00f702c846c5d931ed68dada29ed46df2c8c985a 100644 (file)
@@ -1200,8 +1200,10 @@ unsigned MachineTraceMetrics::Trace::getResourceDepth(bool Bottom) const {
   return std::max(Instrs, PRMax);
 }
 
+
 unsigned MachineTraceMetrics::Trace::
-getResourceLength(ArrayRef<const MachineBasicBlock*> Extrablocks) const {
+getResourceLength(ArrayRef<const MachineBasicBlock*> Extrablocks,
+                  ArrayRef<const MCSchedClassDesc*> ExtraInstrs) const {
   // Add up resources above and below the center block.
   ArrayRef<unsigned> PRDepths = TE.getProcResourceDepths(getBlockNum());
   ArrayRef<unsigned> PRHeights = TE.getProcResourceHeights(getBlockNum());
@@ -1210,6 +1212,18 @@ getResourceLength(ArrayRef<const MachineBasicBlock*> Extrablocks) const {
     unsigned PRCycles = PRDepths[K] + PRHeights[K];
     for (unsigned I = 0; I != Extrablocks.size(); ++I)
       PRCycles += TE.MTM.getProcResourceCycles(Extrablocks[I]->getNumber())[K];
+    for (unsigned I = 0; I != ExtraInstrs.size(); ++I) {
+      const MCSchedClassDesc* SC = ExtraInstrs[I];
+      if (!SC->isValid())
+        continue;
+      for (TargetSchedModel::ProcResIter
+             PI = TE.MTM.SchedModel.getWriteProcResBegin(SC),
+             PE = TE.MTM.SchedModel.getWriteProcResEnd(SC); PI != PE; ++PI) {
+        if (PI->ProcResourceIdx != K)
+          continue;
+        PRCycles += (PI->Cycles * TE.MTM.SchedModel.getResourceFactor(K));
+      }
+    }
     PRMax = std::max(PRMax, PRCycles);
   }
   // Convert to cycle count.