[llvm] 980aa8d - [MachineTraceMetrics] Add local strategy

Anton Sidorenko via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 04:54:04 PST 2023


Author: Anton Sidorenko
Date: 2023-02-15T15:53:14+03:00
New Revision: 980aa8d740dac77dfe722b04892457b731d1c58b

URL: https://github.com/llvm/llvm-project/commit/980aa8d740dac77dfe722b04892457b731d1c58b
DIFF: https://github.com/llvm/llvm-project/commit/980aa8d740dac77dfe722b04892457b731d1c58b.diff

LOG: [MachineTraceMetrics] Add local strategy

This strategy makes each trace local to the basic block. For in-order cores some
heuristics work better when we do local decisions. For example, MachineCombiner
may expect that instructions outside the current basic block do not lengthen
the critical path when we execute instructions in order or the core has a
small re-order buffer.

This patch only introduce the strategy, real use-case is added in the further
pathes.

Depends on D140539

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D140540

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/MachineTraceMetrics.h b/llvm/include/llvm/CodeGen/MachineTraceMetrics.h
index 66e37ab37ee2e..63e4210b2a860 100644
--- a/llvm/include/llvm/CodeGen/MachineTraceMetrics.h
+++ b/llvm/include/llvm/CodeGen/MachineTraceMetrics.h
@@ -86,6 +86,10 @@ struct LiveRegUnit {
 enum class MachineTraceStrategy {
   /// Select the trace through a block that has the fewest instructions.
   TS_MinInstrCount,
+  /// Select the trace that contains only the current basic block. For instance,
+  /// this strategy can be used by MachineCombiner to make better decisions when
+  /// we estimate critical path for in-order cores.
+  TS_Local,
   TS_NumStrategies
 };
 

diff  --git a/llvm/lib/CodeGen/MachineTraceMetrics.cpp b/llvm/lib/CodeGen/MachineTraceMetrics.cpp
index a3ea657c95317..62a114df7022f 100644
--- a/llvm/lib/CodeGen/MachineTraceMetrics.cpp
+++ b/llvm/lib/CodeGen/MachineTraceMetrics.cpp
@@ -318,6 +318,21 @@ class MinInstrCountEnsemble : public MachineTraceMetrics::Ensemble {
     : MachineTraceMetrics::Ensemble(mtm) {}
 };
 
+/// Pick only the current basic block for the trace and do not choose any
+/// predecessors/successors.
+class LocalEnsemble : public MachineTraceMetrics::Ensemble {
+  const char *getName() const override { return "Local"; }
+  const MachineBasicBlock *pickTracePred(const MachineBasicBlock *) override {
+    return nullptr;
+  };
+  const MachineBasicBlock *pickTraceSucc(const MachineBasicBlock *) override {
+    return nullptr;
+  };
+
+public:
+  LocalEnsemble(MachineTraceMetrics *MTM)
+      : MachineTraceMetrics::Ensemble(MTM) {}
+};
 } // end anonymous namespace
 
 // Select the preferred predecessor for MBB.
@@ -391,6 +406,8 @@ MachineTraceMetrics::getEnsemble(MachineTraceStrategy strategy) {
   switch (strategy) {
   case MachineTraceStrategy::TS_MinInstrCount:
     return (E = new MinInstrCountEnsemble(this));
+  case MachineTraceStrategy::TS_Local:
+    return (E = new LocalEnsemble(this));
   default: llvm_unreachable("Invalid trace strategy enum");
   }
 }


        


More information about the llvm-commits mailing list