diff --git a/llvm/include/llvm/CodeGen/MachineTraceMetrics.h b/llvm/include/llvm/CodeGen/MachineTraceMetrics.h --- a/llvm/include/llvm/CodeGen/MachineTraceMetrics.h +++ b/llvm/include/llvm/CodeGen/MachineTraceMetrics.h @@ -86,6 +86,10 @@ 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 --- a/llvm/lib/CodeGen/MachineTraceMetrics.cpp +++ b/llvm/lib/CodeGen/MachineTraceMetrics.cpp @@ -318,6 +318,21 @@ : 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 @@ 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"); } }