LLVM 24.0.0git
GCNIterativeScheduler.h
Go to the documentation of this file.
1//===- GCNIterativeScheduler.h - GCN Scheduler ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the class GCNIterativeScheduler, which uses an iterative
11/// approach to find a best schedule for GCN architecture. It basically makes
12/// use of various lightweight schedules, scores them, chooses best one based on
13/// their scores, and finally implements the chosen one.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
18#define LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
19
20#include "GCNRegPressure.h"
22
23namespace llvm {
24
25class MachineInstr;
26class SUnit;
27class raw_ostream;
28
30 using BaseClass = ScheduleDAGMILive;
31
32public:
39
41 StrategyKind S);
42
43 void schedule() override;
44
48 unsigned RegionInstrs) override;
49
50 void finalizeSchedule() override;
51
52protected:
54
56 std::vector<MachineInstr *> Schedule;
58 };
59
60 struct Region {
61 // Fields except for BestSchedule are supposed to reflect current IR state
62 // `const` fields are to emphasize they shouldn't change for any schedule.
64 // End is either a boundary instruction or end of basic block
66 const unsigned NumRegionInstrs;
68
69 // best schedule for the region so far (not scheduled yet)
70 std::unique_ptr<TentativeSchedule> BestSchedule;
71 };
72
74 std::vector<Region*> Regions;
75
79
80 std::vector<std::unique_ptr<ScheduleDAGMutation>> SavedMutations;
81
82 class BuildDAG;
84
85 template <typename Range>
87 Range &&Schedule) const;
88
91
93 return getRegionPressure(R.Begin, R.End);
94 }
95
96 void swapIGLPMutations(const Region &R, bool IsReentry);
97 void setBestSchedule(Region &R,
98 ScheduleRef Schedule,
99 const GCNRegPressure &MaxRP = GCNRegPressure());
100
101 void scheduleBest(Region &R);
102 // Restore the instruction's dead and read-undef liveness flags.
104 // Restore dead and read-undef liveness flags for all instructions in the
105 // region.
106 void restoreRegionLivenessFlags(const Region &R);
107
108 std::vector<MachineInstr*> detachSchedule(ScheduleRef Schedule) const;
109
110 void sortRegionsByPressure(unsigned TargetOcc);
111
112 template <typename Range>
113 void scheduleRegion(Region &R, Range &&Schedule,
114 const GCNRegPressure &MaxRP = GCNRegPressure());
115
116 unsigned tryMaximizeOccupancy(unsigned TargetOcc =
117 std::numeric_limits<unsigned>::max());
118
119 void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy = true);
120 void scheduleMinReg(bool force = false);
121 void scheduleILP(bool TryMaximizeOccupancy = true);
122
123 void printRegions(raw_ostream &OS) const;
125 const Region *R,
126 const GCNRegPressure &RP) const;
127 void printSchedRP(raw_ostream &OS,
128 const GCNRegPressure &Before,
129 const GCNRegPressure &After) const;
130};
131
132} // end namespace llvm
133
134#endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the GCNRegPressure class, which tracks registry pressure by bookkeeping number of S...
IRTranslator LLVM IR MI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
SpecificBumpPtrAllocator< Region > Alloc
void printSchedRP(raw_ostream &OS, const GCNRegPressure &Before, const GCNRegPressure &After) const
void enterRegion(MachineBasicBlock *BB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned RegionInstrs) override
Initialize the DAG and common scheduler state for a new scheduling region.
void sortRegionsByPressure(unsigned TargetOcc)
std::vector< Region * > Regions
void restoreLivenessFlags(MachineInstr &MI)
void scheduleILP(bool TryMaximizeOccupancy=true)
void swapIGLPMutations(const Region &R, bool IsReentry)
GCNIterativeScheduler(MachineSchedContext *C, StrategyKind S)
void printSchedResult(raw_ostream &OS, const Region *R, const GCNRegPressure &RP) const
unsigned tryMaximizeOccupancy(unsigned TargetOcc=std::numeric_limits< unsigned >::max())
void printRegions(raw_ostream &OS) const
void setBestSchedule(Region &R, ScheduleRef Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy=true)
std::vector< std::unique_ptr< ScheduleDAGMutation > > SavedMutations
void restoreRegionLivenessFlags(const Region &R)
void schedule() override
Orders nodes according to selected style.
GCNRegPressure getSchedulePressure(const Region &R, Range &&Schedule) const
void scheduleMinReg(bool force=false)
GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End) const
ArrayRef< const SUnit * > ScheduleRef
void scheduleRegion(Region &R, Range &&Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
GCNRegPressure getRegionPressure(const Region &R) const
std::vector< MachineInstr * > detachSchedule(ScheduleRef Schedule) const
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
Scheduling unit. This is a node in the scheduling DAG.
MachineBasicBlock * BB
The block in which to insert instructions.
ScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition Allocator.h:397
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
const MachineBasicBlock::iterator End
std::unique_ptr< TentativeSchedule > BestSchedule
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...