21 #include "llvm/Config/llvm-config.h" 32 #define DEBUG_TYPE "machine-scheduler" 34 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 39 dbgs() <<
"Live regs at " << SI <<
": " 47 if (LI.hasSubRanges()) {
48 bool firstTime =
true;
49 for (
const auto &S : LI.subranges()) {
50 if (!S.liveAt(SI))
continue;
56 dbgs() <<
" " << S <<
'\n';
59 }
else if (LI.liveAt(SI)) {
60 dbgs() <<
" " << LI <<
'\n';
64 if (!Num)
dbgs() <<
" <none>\n";
73 for (
const auto &
P : S1) {
75 if (
I == S2.
end() ||
I->second !=
P.second)
85 unsigned GCNRegPressure::getRegKind(
unsigned Reg,
101 if (NewMask == PrevMask)
105 if (NewMask < PrevMask) {
112 switch (
auto Kind = getRegKind(Reg, MRI)) {
116 assert(PrevMask.
none() && NewMask == MaxMask);
123 assert(NewMask < MaxMask || NewMask == MaxMask);
124 assert(PrevMask < NewMask);
127 Sign * (~PrevMask & NewMask).getNumLanes();
129 if (PrevMask.
none()) {
141 unsigned MaxOccupancy)
const {
142 const auto SGPROcc = std::min(MaxOccupancy,
144 const auto VGPROcc = std::min(MaxOccupancy,
146 const auto OtherSGPROcc = std::min(MaxOccupancy,
148 const auto OtherVGPROcc = std::min(MaxOccupancy,
151 const auto Occ = std::min(SGPROcc, VGPROcc);
152 const auto OtherOcc = std::min(OtherSGPROcc, OtherVGPROcc);
154 return Occ > OtherOcc;
156 bool SGPRImportant = SGPROcc < VGPROcc;
157 const bool OtherSGPRImportant = OtherSGPROcc < OtherVGPROcc;
160 if (SGPRImportant != OtherSGPRImportant) {
161 SGPRImportant =
false;
165 bool SGPRFirst = SGPRImportant;
166 for (
int I = 2;
I > 0; --
I, SGPRFirst = !SGPRFirst) {
183 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 187 OS <<
"AGPRs: " << Value[
AGPR32];
233 for (
const auto &MO : MI.
operands()) {
236 if (!MO.isUse() || !MO.readsReg())
241 auto Reg = MO.getReg();
243 return RM.RegUnit ==
Reg;
246 I->LaneMask |= UsedMask;
262 if (LI.hasSubRanges()) {
263 for (
const auto &S : LI.subranges())
265 LiveMask |= S.LaneMask;
269 }
else if (LI.liveAt(SI)) {
285 LiveRegs[Reg] = LiveMask;
296 if (&LiveRegs != LiveRegsCopy)
297 LiveRegs = *LiveRegsCopy;
312 assert(MRI &&
"call reset first");
322 auto AtMIPressure = CurPressure;
323 for (
const auto &U : RegUses) {
324 auto LiveMask = LiveRegs[U.RegUnit];
325 AtMIPressure.inc(U.RegUnit, LiveMask, LiveMask | U.LaneMask, *MRI);
328 MaxPressure =
max(AtMIPressure, MaxPressure);
330 for (
const auto &MO : MI.
defs()) {
334 auto Reg = MO.getReg();
335 auto I = LiveRegs.find(Reg);
336 if (
I == LiveRegs.end())
338 auto &LiveMask =
I->second;
339 auto PrevMask = LiveMask;
341 CurPressure.inc(Reg, PrevMask, LiveMask, *MRI);
345 for (
const auto &U : RegUses) {
346 auto &LiveMask = LiveRegs[U.RegUnit];
347 auto PrevMask = LiveMask;
348 LiveMask |= U.LaneMask;
349 CurPressure.inc(U.RegUnit, PrevMask, LiveMask, *MRI);
357 LastTrackedMI =
nullptr;
361 if (NextMI == MBBEnd)
368 assert(MRI &&
"call reset first");
371 if (NextMI == MBBEnd)
374 SlotIndex SI = LIS.getInstructionIndex(*NextMI).getBaseIndex();
378 for (
auto &It : LiveRegs) {
383 auto PrevMask = It.second;
384 It.second &= ~S.LaneMask;
385 CurPressure.inc(It.first, PrevMask, It.second, *MRI);
388 }
else if (!LI.
liveAt(SI)) {
389 auto PrevMask = It.second;
391 CurPressure.inc(It.first, PrevMask, It.second, *MRI);
393 if (It.second.none())
394 LiveRegs.erase(It.first);
397 MaxPressure =
max(MaxPressure, CurPressure);
403 LastTrackedMI = &*NextMI++;
406 for (
const auto &MO : LastTrackedMI->defs()) {
412 auto &LiveMask = LiveRegs[
Reg];
413 auto PrevMask = LiveMask;
415 CurPressure.inc(Reg, PrevMask, LiveMask, *MRI);
418 MaxPressure =
max(MaxPressure, CurPressure);
423 if ((NextMI == MBBEnd) || (LastTrackedMI && !advanceBeforeNext()))
430 while (NextMI != End)
431 if (!advance())
return false;
438 reset(*Begin, LiveRegsCopy);
442 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 447 for (
auto const &
P : TrackedLR) {
448 auto I = LISLR.
find(
P.first);
449 if (
I == LISLR.
end()) {
452 <<
" isn't found in LIS reported set\n";
454 else if (
I->second !=
P.second) {
456 <<
" masks doesn't match: LIS reported " 463 for (
auto const &
P : LISLR) {
464 auto I = TrackedLR.find(
P.first);
465 if (
I == TrackedLR.end()) {
468 <<
" isn't found in tracked set\n";
474 const auto &
SI = LIS.getInstructionIndex(*LastTrackedMI).getBaseIndex();
476 const auto &TrackedLR = LiveRegs;
478 if (!
isEqual(LISLR, TrackedLR)) {
479 dbgs() <<
"\nGCNUpwardRPTracker error: Tracked and" 480 " LIS reported livesets mismatch:\n";
487 if (LISPressure != CurPressure) {
488 dbgs() <<
"GCNUpwardRPTracker error: Pressure sets different\nTracked: ";
489 CurPressure.print(
dbgs());
490 dbgs() <<
"LIS rpt: ";
491 LISPressure.print(
dbgs());
502 auto It = LiveRegs.
find(Reg);
503 if (It != LiveRegs.
end() && It->second.any())
Interface definition for SIRegisterInfo.
A common definition of LaneBitmask for use in TableGen and CodeGen.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
AMDGPU specific subclass of TargetSubtarget.
static void printLiveRegs(raw_ostream &OS, const LiveRegSet &LiveRegs, const MachineRegisterInfo &MRI)
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
unsigned getSGPRTuplesWeight() const
void push_back(const T &Elt)
LiveInterval - This class represents the liveness of a register, or stack slot.
bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
unsigned getSubReg() const
friend GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isValid() const
Returns true if this is a valid index.
unsigned const TargetRegisterInfo * TRI
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
iterator_range< mop_iterator > operands()
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static LaneBitmask getDefRegMask(const MachineOperand &MO, const MachineRegisterInfo &MRI)
iterator_range< subrange_iterator > subranges()
bool hasSubRanges() const
Returns true if subregister liveness information is available.
unsigned getOccupancy(const GCNSubtarget &ST) const
bool isSGPRClass(const TargetRegisterClass *RC) const
static constexpr LaneBitmask getNone()
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
bool hasInterval(Register Reg) const
void inc(unsigned Reg, LaneBitmask PrevMask, LaneBitmask NewMask, const MachineRegisterInfo &MRI)
unsigned getVGPRTuplesWeight() const
GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)
bool less(const GCNSubtarget &ST, const GCNRegPressure &O, unsigned MaxOccupancy=std::numeric_limits< unsigned >::max()) const
static constexpr LaneBitmask getLane(unsigned Lane)
void reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
iterator find(const_arg_type_t< KeyT > Val)
const TargetRegisterInfo * getTargetRegisterInfo() const
unsigned const MachineRegisterInfo * MRI
bool liveAt(SlotIndex index) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
unsigned getSGPRNum() const
Printable printVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
constexpr bool none() const
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
LiveInterval & getInterval(Register Reg)
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
GCNRPTracker::LiveRegSet getLiveRegsAfter(const MachineInstr &MI, const LiveIntervals &LIS)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isDebugInstr() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static SmallVector< RegisterMaskPair, 8 > collectVirtualRegUses(const MachineInstr &MI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
static LLVM_DUMP_METHOD void reportMismatch(const GCNRPTracker::LiveRegSet &LISLR, const GCNRPTracker::LiveRegSet &TrackedLR, const TargetRegisterInfo *TRI)
void printLivesAt(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
static LaneBitmask getUsedRegMask(const MachineOperand &MO, const MachineRegisterInfo &MRI, const LiveIntervals &LIS)
MachineOperand class - Representation of each machine instruction operand.
unsigned getVGPRNum() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const
Return the maximum number of waves per SIMD for kernels using SGPRs SGPRs.
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
GCNRegPressure getRegPressure(const MachineRegisterInfo &MRI, Range &&LiveRegs)
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
PSetIterator getPressureSets(unsigned RegUnit) const
Get an iterator over the pressure sets affected by the given physical or virtual register.
constexpr bool any() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void print(raw_ostream &OS, const GCNSubtarget *ST=nullptr) const
LLVM Value Representation.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
This class implements an extremely fast bulk output stream that can only output to a stream...
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Register getReg() const
getReg - Returns the register number.
unsigned getWeight() const
unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const
Return the maximum number of waves per SIMD for kernels using VGPRs VGPRs.
SlotIndex - An opaque wrapper around machine indexes.
void recede(const MachineInstr &MI)
void reset(const MachineInstr &MI, const LiveRegSet *LiveRegsCopy, bool After)
Wrapper class representing virtual and physical registers.