35#define DEBUG_TYPE "machine-scheduler"
37unsigned SystemZHazardRecognizer::
38getNumDecoderSlots(
SUnit *SU)
const {
44 "Only cracked instruction can have 2 uops.");
46 "Expanded instructions always group alone.");
48 "Expanded instructions fill the group(s).");
53unsigned SystemZHazardRecognizer::getCurrCycleIdx(
SUnit *SU)
const {
54 unsigned Idx = CurrGroupSize;
58 if (SU !=
nullptr && !fitsIntoCurrentGroup(SU)) {
59 if (Idx == 1 || Idx == 2)
61 else if (Idx == 4 || Idx == 5)
75 CurrGroupHas4RegOps =
false;
76 clearProcResCounters();
78 LastFPdOpCycleIdx = UINT_MAX;
79 LastEmittedMI =
nullptr;
84SystemZHazardRecognizer::fitsIntoCurrentGroup(
SUnit *SU)
const {
92 return (CurrGroupSize == 0);
95 assert ((CurrGroupSize < 2 || !CurrGroupHas4RegOps) &&
96 "Current decoder group is already full!");
97 if (CurrGroupSize == 2 && has4RegOps(SU->
getInstr()))
103 assert ((getNumDecoderSlots(SU) <= 1) && (CurrGroupSize < 3) &&
104 "Expected normal instruction to fit in non-full group!");
109bool SystemZHazardRecognizer::has4RegOps(
const MachineInstr *
MI)
const {
124void SystemZHazardRecognizer::nextGroup() {
125 if (CurrGroupSize == 0)
131 int NumGroups = ((CurrGroupSize > 3) ? (CurrGroupSize / 3) : 1);
132 assert((CurrGroupSize <= 3 || CurrGroupSize % 3 == 0) &&
133 "Current decoder group bad.");
137 CurrGroupHas4RegOps =
false;
139 GrpCount += ((unsigned) NumGroups);
142 for (
unsigned i = 0; i < SchedModel->getNumProcResourceKinds(); ++i)
143 ProcResourceCounters[i] = ((ProcResourceCounters[i] > NumGroups)
144 ? (ProcResourceCounters[i] - NumGroups)
148 if (CriticalResourceIdx != UINT_MAX &&
149 (ProcResourceCounters[CriticalResourceIdx] <= CLOpts.procres_cost_lim))
150 CriticalResourceIdx = UINT_MAX;
165 PI = SchedModel->getWriteProcResBegin(SC),
166 PE = SchedModel->getWriteProcResEnd(SC); PI != PE; ++PI) {
168 *SchedModel->getProcResource(PI->ProcResourceIdx);
169 std::string FU(PRD.
Name);
171 FU = FU.substr(FU.find(
'_') + 1);
172 size_t Pos = FU.find(
"Unit");
173 if (Pos != std::string::npos)
179 if (PI->ReleaseAtCycle> 1)
180 OS <<
"(" << PI->ReleaseAtCycle <<
"cyc)";
186 OS <<
"/GroupsAlone";
188 OS <<
"/BeginsGroup";
202 dbgs() <<
" <empty>\n";
205 dbgs() <<
" (" << CurrGroupSize <<
" decoder slot"
206 << (CurrGroupSize > 1 ?
"s":
"")
207 << (CurrGroupHas4RegOps ?
", 4RegOps" :
"")
215 for (
unsigned i = 0; i < SchedModel->getNumProcResourceKinds(); ++i)
216 if (ProcResourceCounters[i] > 0) {
224 dbgs() <<
"++ | Resource counters: ";
225 for (
unsigned i = 0; i < SchedModel->getNumProcResourceKinds(); ++i)
226 if (ProcResourceCounters[i] > 0)
227 dbgs() << SchedModel->getProcResource(i)->Name
228 <<
":" << ProcResourceCounters[i] <<
" ";
231 if (CriticalResourceIdx != UINT_MAX)
232 dbgs() <<
"++ | Critical resource: "
233 << SchedModel->getProcResource(CriticalResourceIdx)->Name
239 dbgs() <<
"++ | Current cycle index: "
240 << getCurrCycleIdx() <<
"\n";
242 if (LastFPdOpCycleIdx != UINT_MAX)
243 dbgs() <<
"++ | Last FPd cycle index: " << LastFPdOpCycleIdx <<
"\n";
248void SystemZHazardRecognizer::clearProcResCounters() {
250 CriticalResourceIdx = UINT_MAX;
254 return (
MI->isBranch() ||
MI->isReturn() ||
255 MI->getOpcode() == SystemZ::CondTrap);
268 if (!fitsIntoCurrentGroup(SU))
286 PI = SchedModel->getWriteProcResBegin(SC),
287 PE = SchedModel->getWriteProcResEnd(SC); PI != PE; ++PI) {
289 if (SchedModel->getProcResource(PI->ProcResourceIdx)->BufferSize == 1)
292 ProcResourceCounters[PI->ProcResourceIdx];
293 CurrCounter += PI->ReleaseAtCycle;
295 if ((CurrCounter > CLOpts.procres_cost_lim) &&
296 (CriticalResourceIdx == UINT_MAX ||
297 (PI->ProcResourceIdx != CriticalResourceIdx &&
298 CurrCounter > ProcResourceCounters[CriticalResourceIdx]))) {
300 dbgs() <<
"++ New critical resource: "
301 << SchedModel->getProcResource(PI->ProcResourceIdx)->Name
303 CriticalResourceIdx = PI->ProcResourceIdx;
309 LastFPdOpCycleIdx = getCurrCycleIdx(SU);
310 LLVM_DEBUG(
dbgs() <<
"++ Last FPd cycle index: " << LastFPdOpCycleIdx
316 CurrGroupSize += getNumDecoderSlots(SU);
317 CurrGroupHas4RegOps |= has4RegOps(SU->
getInstr());
318 unsigned GroupLim = (CurrGroupHas4RegOps ? 2 : 3);
319 assert((CurrGroupSize <= GroupLim || CurrGroupSize == getNumDecoderSlots(SU))
320 &&
"SU does not fit into decoder group!");
324 if (CurrGroupSize >= GroupLim || SC->
EndGroup)
337 return 3 - CurrGroupSize;
344 unsigned ResultingGroupSize = (CurrGroupSize + getNumDecoderSlots(SU));
345 if (ResultingGroupSize < 3)
346 return (3 - ResultingGroupSize);
351 if (CurrGroupSize == 2 && has4RegOps(SU->
getInstr()))
358bool SystemZHazardRecognizer::isFPdOpPreferred_distance(
SUnit *SU)
const {
361 if (LastFPdOpCycleIdx == UINT_MAX)
367 unsigned SUCycleIdx = getCurrCycleIdx(SU);
368 if (LastFPdOpCycleIdx > SUCycleIdx)
369 return ((LastFPdOpCycleIdx - SUCycleIdx) == 3);
370 return ((SUCycleIdx - LastFPdOpCycleIdx) == 3);
384 Cost = (isFPdOpPreferred_distance(SU) ? INT_MIN : INT_MAX);
386 else if (CriticalResourceIdx != UINT_MAX) {
388 PI = SchedModel->getWriteProcResBegin(SC),
389 PE = SchedModel->getWriteProcResEnd(SC); PI != PE; ++PI)
390 if (PI->ProcResourceIdx == CriticalResourceIdx)
391 Cost = PI->ReleaseAtCycle;
407 make_range(SchedModel->getWriteProcResBegin(SC),
408 SchedModel->getWriteProcResEnd(SC))) {
409 switch (SchedModel->getProcResource(PRE.ProcResourceIdx)->BufferSize) {
421 unsigned GroupSizeBeforeEmit = CurrGroupSize;
426 if (GroupSizeBeforeEmit == 1)
430 if (TakenBranch && CurrGroupSize > 0)
434 "Scheduler: unhandled terminator!");
440 CurrGroupSize = Incoming->CurrGroupSize;
444 ProcResourceCounters = Incoming->ProcResourceCounters;
445 CriticalResourceIdx = Incoming->CriticalResourceIdx;
448 LastFPdOpCycleIdx = Incoming->LastFPdOpCycleIdx;
449 GrpCount = Incoming->GrpCount;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
static bool isBranchRetTrap(MachineInstr *MI)
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Scheduling unit. This is a node in the scheduling DAG.
bool isCall
Is a function call.
bool isUnbuffered
Uses an unbuffered resource.
bool hasReservedResource
Uses a reserved resource.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
void assign(size_type NumElts, ValueParamT Elt)
int groupingCost(SUnit *SU) const
Return the cost of decoder grouping for SU.
void dumpProcResourceCounters() const
void emitInstruction(MachineInstr *MI, bool TakenBranch=false)
Wrap a non-scheduled instruction in an SU and emit it.
const MCSchedClassDesc * getSchedClass(SUnit *SU) const
Resolves and cache a resolved scheduling class for an SUnit.
void copyState(SystemZHazardRecognizer *Incoming)
Copy counters from end of single predecessor.
void Reset() override
Reset - This callback is invoked when a new block of instructions is about to be schedule.
void dumpSU(SUnit *SU, raw_ostream &OS) const
HazardType getHazardType(SUnit *SU, int Stalls=0) override
getHazardType - Return the hazard type of emitting this node.
void dumpCurrGroup(std::string Msg="") const
int resourcesCost(SUnit *SU)
Return the cost of SU in regards to processor resources usage.
SystemZHazardRecognizer(const SystemZInstrInfo *tii, const TargetSchedModel *SM, const SystemZOptions &CLOpts)
void EmitInstruction(SUnit *SU) override
EmitInstruction - This callback is invoked when an instruction is emitted, to advance the hazard stat...
const MCWriteProcResEntry * ProcResIter
unsigned getNumProcResourceKinds() const
Get the number of kinds of resources for this target.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
MCRegisterClass TargetRegisterClass
Define a kind of processor resource that will be modeled by the scheduler.
Summarize the scheduling resources required for an instruction of a particular scheduling class.
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...