Skip to content

Commit

Permalink
[MachineTraceMetrics] Add local strategy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
asi-sc committed Feb 15, 2023
1 parent b0e7ca7 commit 980aa8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/MachineTraceMetrics.h
Expand Up @@ -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
};

Expand Down
17 changes: 17 additions & 0 deletions llvm/lib/CodeGen/MachineTraceMetrics.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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");
}
}
Expand Down

0 comments on commit 980aa8d

Please sign in to comment.