19 #define DEBUG_TYPE "machine-scheduler"
21 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
26 dbgs() <<
"Live regs at " << SI <<
": "
34 if (LI.hasSubRanges()) {
35 bool firstTime =
true;
36 for (
const auto &S : LI.subranges()) {
37 if (!S.liveAt(SI))
continue;
43 dbgs() <<
" " << S <<
'\n';
46 }
else if (LI.liveAt(SI)) {
47 dbgs() <<
" " << LI <<
'\n';
51 if (!Num)
dbgs() <<
" <none>\n";
59 for (
const auto &
P : S1) {
61 if (
I == S2.
end() ||
I->second !=
P.second)
72 unsigned GCNRegPressure::getRegKind(
unsigned Reg,
86 if (NewMask == PrevMask)
90 if (NewMask < PrevMask) {
97 switch (
auto Kind = getRegKind(Reg, MRI)) {
100 assert(PrevMask.
none() && NewMask == MaxMask);
106 assert(NewMask < MaxMask || NewMask == MaxMask);
107 assert(PrevMask < NewMask);
112 if (PrevMask.
none()) {
124 unsigned MaxOccupancy)
const {
125 const auto SGPROcc =
std::min(MaxOccupancy,
127 const auto VGPROcc =
std::min(MaxOccupancy,
129 const auto OtherSGPROcc =
std::min(MaxOccupancy,
131 const auto OtherVGPROcc =
std::min(MaxOccupancy,
134 const auto Occ =
std::min(SGPROcc, VGPROcc);
135 const auto OtherOcc =
std::min(OtherSGPROcc, OtherVGPROcc);
137 return Occ > OtherOcc;
139 bool SGPRImportant = SGPROcc < VGPROcc;
140 const bool OtherSGPRImportant = OtherSGPROcc < OtherVGPROcc;
143 if (SGPRImportant != OtherSGPRImportant) {
144 SGPRImportant =
false;
148 bool SGPRFirst = SGPRImportant;
149 for (
int I = 2;
I > 0; --
I, SGPRFirst = !SGPRFirst) {
166 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
204 if (MaxMask.getAsInteger() == 1)
218 for (
const auto &MO : MI.
operands()) {
221 if (!MO.isUse() || !MO.readsReg())
226 auto Reg = MO.getReg();
228 return RM.RegUnit ==
Reg;
231 I->LaneMask |= UsedMask;
247 if (LI.hasSubRanges()) {
248 for (
const auto &S : LI.subranges())
250 LiveMask |= S.LaneMask;
254 }
else if (LI.liveAt(SI)) {
270 LiveRegs[Reg] = LiveMask;
288 assert(MRI &&
"call reset first");
299 for (
const auto &U : RegUses) {
300 auto LiveMask =
LiveRegs[U.RegUnit];
301 AtMIPressure.inc(U.RegUnit, LiveMask, LiveMask | U.LaneMask, *MRI);
306 for (
const auto &MO : MI.
defs()) {
311 auto Reg = MO.getReg();
315 auto &LiveMask =
I->second;
316 auto PrevMask = LiveMask;
322 for (
const auto &U : RegUses) {
323 auto &LiveMask =
LiveRegs[U.RegUnit];
324 auto PrevMask = LiveMask;
325 LiveMask |= U.LaneMask;
338 if (NextMI == MBBEnd)
351 assert(MRI &&
"call reset first");
354 if (NextMI == MBBEnd)
366 auto PrevMask = It.second;
367 It.second &= ~S.LaneMask;
371 }
else if (!LI.
liveAt(SI)) {
372 auto PrevMask = It.second;
376 if (It.second.none())
377 LiveRegs.erase(It.first);
392 unsigned Reg = MO.getReg();
396 auto PrevMask = LiveMask;
413 while (NextMI != End)
421 reset(*Begin, LiveRegsCopy);
425 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
430 for (
auto const &
P : TrackedLR) {
431 auto I = LISLR.
find(
P.first);
432 if (
I == LISLR.
end()) {
435 <<
" isn't found in LIS reported set\n";
437 else if (
I->second !=
P.second) {
439 <<
" masks doesn't match: LIS reported "
446 for (
auto const &
P : LISLR) {
447 auto I = TrackedLR.find(
P.first);
448 if (
I == TrackedLR.end()) {
451 <<
" isn't found in tracked set\n";
461 if (!
isEqual(LISLR, TrackedLR)) {
462 dbgs() <<
"\nGCNUpwardRPTracker error: Tracked and"
463 " LIS reported livesets mismatch:\n";
471 dbgs() <<
"GCNUpwardRPTracker error: Pressure sets different\nTracked: ";
473 dbgs() <<
"LIS rpt: ";
474 LISPressure.print(
dbgs());
485 auto It = LiveRegs.
find(Reg);
486 if (It != LiveRegs.
end() && It->second.any())
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static void printLiveRegs(raw_ostream &OS, const LiveRegSet &LiveRegs, const MachineRegisterInfo &MRI)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
const MachineInstr * LastTrackedMI
LiveInterval - This class represents the liveness of a register, or stack slot.
bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
bool isSGPRClass(const TargetRegisterClass *RC) const
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
iterator_range< mop_iterator > operands()
const LiveIntervals & LIS
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
static LaneBitmask getDefRegMask(const MachineOperand &MO, const MachineRegisterInfo &MRI)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const
Return the maximum number of waves per SIMD for kernels using SGPRs SGPRs.
const TargetRegisterInfo * getTargetRegisterInfo() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
iterator_range< subrange_iterator > subranges()
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
void inc(unsigned Reg, LaneBitmask PrevMask, LaneBitmask NewMask, const MachineRegisterInfo &MRI)
GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)
unsigned getSGPRTuplesWeight() const
GCNRegPressure CurPressure
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
void print(raw_ostream &OS, const SISubtarget *ST=nullptr) const
void reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
const MachineBasicBlock * getParent() const
iterator find(const_arg_type_t< KeyT > Val)
bool isDebugValue() const
static bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
bool erase(const KeyT &Val)
bool isValid() const
Returns true if this is a valid index.
unsigned const MachineRegisterInfo * MRI
constexpr bool none() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const
Return the maximum number of waves per SIMD for kernels using VGPRs VGPRs.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
static const unsigned End
unsigned getSubReg() const
GCNRPTracker::LiveRegSet getLiveRegsAfter(const MachineInstr &MI, const LiveIntervals &LIS)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool liveAt(SlotIndex index) const
unsigned getVGPRTuplesWeight() const
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)
unsigned countPopulation(T Value)
Count the number of set bits in a value.
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static LaneBitmask getNone()
unsigned getWeight() const
LiveInterval & getInterval(unsigned Reg)
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.
bool less(const SISubtarget &ST, const GCNRegPressure &O, unsigned MaxOccupancy=std::numeric_limits< unsigned >::max()) const
unsigned getOccupancy(const SISubtarget &ST) const
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
llvm_unreachable("Unknown RegBank!")
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
unsigned getSGPRNum() const
LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
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.
unsigned getVGPRNum() const
bool hasInterval(unsigned Reg) const
LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static LLVM_ATTRIBUTE_UNUSED Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
This class implements an extremely fast bulk output stream that can only output to a stream...
GCNRegPressure MaxPressure
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
bool hasSubRanges() const
Returns true if subregister liveness information is available.
SlotIndex - An opaque wrapper around machine indexes.
Printable PrintVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
void recede(const MachineInstr &MI)