Skip to content

Commit

Permalink
[CodeGen][MachinePipeliner] Limit register pressure when scheduling (#…
Browse files Browse the repository at this point in the history
…74807)

In software pipelining, when searching for the Initiation Interval (II),
`MachinePipeliner` tries to reduce register pressure, but doesn't check
how many variables can actually be alive at the same time. As a result,
a lot of register spills/fills can be generated after register
allocation, which might cause performance degradation. To prevent such
cases, this patch adds a check phase that calculates the maximum
register pressure of the scheduled loop and reject it if the pressure is
too high. This can be enabled this by specifying
`pipeliner-register-pressure`. Additionally, an II search range is
currently fixed at 10, which is too small to find a schedule when the
above algorithm is applied. Therefore this patch also adds a new option
`pipeliner-ii-search-range` to specify the length of the range to
search. There is one more new option
`pipeliner-register-pressure-margin`, which can be used to estimate a
register pressure limit less than actual for conservative analysis.

Discourse thread:
https://discourse.llvm.org/t/considering-register-pressure-when-deciding-initiation-interval-in-machinepipeliner/74725
  • Loading branch information
kasuga-fj committed Jan 22, 2024
1 parent 5ab2d9c commit 7556626
Show file tree
Hide file tree
Showing 3 changed files with 801 additions and 27 deletions.
18 changes: 11 additions & 7 deletions llvm/include/llvm/CodeGen/MachinePipeliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ class SwingSchedulerDAG : public ScheduleDAGInstrs {

/// Return the new base register that was stored away for the changed
/// instruction.
unsigned getInstrBaseReg(SUnit *SU) {
DenseMap<SUnit *, std::pair<unsigned, int64_t>>::iterator It =
unsigned getInstrBaseReg(SUnit *SU) const {
DenseMap<SUnit *, std::pair<unsigned, int64_t>>::const_iterator It =
InstrChanges.find(SU);
if (It != InstrChanges.end())
return It->second.first;
Expand Down Expand Up @@ -639,16 +639,20 @@ class SMSchedule {
computeUnpipelineableNodes(SwingSchedulerDAG *SSD,
TargetInstrInfo::PipelinerLoopInfo *PLI);

std::deque<SUnit *>
reorderInstructions(const SwingSchedulerDAG *SSD,
const std::deque<SUnit *> &Instrs) const;

bool
normalizeNonPipelinedInstructions(SwingSchedulerDAG *SSD,
TargetInstrInfo::PipelinerLoopInfo *PLI);
bool isValidSchedule(SwingSchedulerDAG *SSD);
void finalizeSchedule(SwingSchedulerDAG *SSD);
void orderDependence(SwingSchedulerDAG *SSD, SUnit *SU,
std::deque<SUnit *> &Insts);
bool isLoopCarried(SwingSchedulerDAG *SSD, MachineInstr &Phi);
bool isLoopCarriedDefOfUse(SwingSchedulerDAG *SSD, MachineInstr *Def,
MachineOperand &MO);
void orderDependence(const SwingSchedulerDAG *SSD, SUnit *SU,
std::deque<SUnit *> &Insts) const;
bool isLoopCarried(const SwingSchedulerDAG *SSD, MachineInstr &Phi) const;
bool isLoopCarriedDefOfUse(const SwingSchedulerDAG *SSD, MachineInstr *Def,
MachineOperand &MO) const;
void print(raw_ostream &os) const;
void dump() const;
};
Expand Down

0 comments on commit 7556626

Please sign in to comment.