LLVM 24.0.0git
ScheduleDAGInstrs.cpp
Go to the documentation of this file.
1//===---- ScheduleDAGInstrs.cpp - MachineInstr Rescheduling ---------------===//
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 This implements the ScheduleDAGInstrs class, which implements
10/// re-scheduling of MachineInstrs.
11//
12//===----------------------------------------------------------------------===//
13
15
17#include "llvm/ADT/MapVector.h"
19#include "llvm/ADT/SparseSet.h"
41#include "llvm/Config/llvm-config.h"
42#include "llvm/IR/Constants.h"
43#include "llvm/IR/Function.h"
44#include "llvm/IR/Type.h"
45#include "llvm/IR/Value.h"
46#include "llvm/MC/LaneBitmask.h"
51#include "llvm/Support/Debug.h"
53#include "llvm/Support/Format.h"
55#include <algorithm>
56#include <cassert>
57#include <iterator>
58#include <utility>
59#include <vector>
60
61using namespace llvm;
62
63#define DEBUG_TYPE "machine-scheduler"
64
65static cl::opt<bool>
66 EnableAASchedMI("enable-aa-sched-mi", cl::Hidden,
67 cl::desc("Enable use of AA during MI DAG construction"));
68
69static cl::opt<bool> UseTBAA("use-tbaa-in-sched-mi", cl::Hidden,
70 cl::init(true), cl::desc("Enable use of TBAA during MI DAG construction"));
71
72static cl::opt<bool>
73 EnableSchedModel("schedmodel", cl::Hidden, cl::init(true),
74 cl::desc("Use TargetSchedModel for latency lookup"));
75
76static cl::opt<bool>
77 EnableSchedItins("scheditins", cl::Hidden, cl::init(true),
78 cl::desc("Use InstrItineraryData for latency lookup"));
79
80// Note: the two options below might be used in tuning compile time vs
81// output quality. Setting HugeRegion so large that it will never be
82// reached means best-effort, but may be slow.
83
84// When Stores and Loads maps together hold this many SUs, a reduction of maps
85// will be done.
87 HugeRegion("dag-maps-huge-region", cl::Hidden, cl::init(500),
88 cl::desc("The limit to use while constructing the DAG "
89 "prior to scheduling, at which point a trade-off "
90 "is made to avoid excessive compile time."));
91
92#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
94 "sched-print-cycles", cl::Hidden, cl::init(false),
95 cl::desc("Report top/bottom cycles when dumping SUnit instances"));
96#endif
97
99#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
100 dbgs() << "{ ";
101 for (const SUnit *SU : L) {
102 dbgs() << "SU(" << SU->NodeNum << ")";
103 if (SU != L.back())
104 dbgs() << ", ";
105 }
106 dbgs() << "}\n";
107#endif
108}
109
111 const MachineLoopInfo *mli,
112 bool RemoveKillFlags)
113 : ScheduleDAG(mf), MLI(mli), MFI(mf.getFrameInfo()),
116 Type::getVoidTy(mf.getFunction().getContext()))), Topo(SUnits, &ExitSU) {
117 DbgValues.clear();
118
119 const TargetSubtargetInfo &ST = mf.getSubtarget();
121}
122
123/// If this machine instruction has memory reference information, collect the
124/// list of underlying objects in \p Objects. If any of these objects are
125/// unknown or may alias anything, return false. Atomic and volatile memory
126/// operands are skipped.
128 const MachineFrameInfo &MFI,
130 const DataLayout &DL) {
131 bool AllObjectsIdentified = true;
132
133 for (const MachineMemOperand *MMO : MI->memoperands()) {
134 // TODO: Figure out whether isAtomic is really necessary (see D57601).
135 if (MMO->isVolatile() || MMO->isAtomic()) {
136 AllObjectsIdentified = false;
137 continue;
138 }
139
140 if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
141 if (MFI.hasTailCall()) {
142 // Function that contain tail calls don't have unique PseudoSourceValue
143 // objects. Two PseudoSourceValues might refer to the same or
144 // overlapping locations. The client code calling this function assumes
145 // this is not the case. So return a conservative answer of no known
146 // object.
147 AllObjectsIdentified = false;
148 } else if (PSV->isAliased(&MFI)) {
149 // For now, ignore PseudoSourceValues which may alias LLVM IR values
150 // because the code that uses this function has no way to cope with such
151 // aliases.
152 AllObjectsIdentified = false;
153 }
154
155 Objects.push_back(PSV);
156 } else if (const Value *V = MMO->getValue()) {
158 bool ObjectsIdentified = getUnderlyingObjectsForCodeGen(V, Objs);
159 AllObjectsIdentified &= ObjectsIdentified;
160
161 for (Value *V : Objs) {
162 assert(!ObjectsIdentified || isIdentifiedObject(V));
163 Objects.push_back(V);
164 }
165 } else {
166 AllObjectsIdentified = false;
167 }
168 }
169
170 return AllObjectsIdentified;
171}
172
176
178 // Subclasses should no longer refer to the old block.
179 BB = nullptr;
180}
181
185 unsigned regioninstrs) {
186 assert(bb == BB && "startBlock should set BB");
188 RegionEnd = end;
189 NumRegionInstrs = regioninstrs;
190}
191
193 // Nothing to do.
194}
195
197 MachineInstr *ExitMI =
198 RegionEnd != BB->end()
200 : nullptr;
201 ExitSU.setInstr(ExitMI);
202 // Add dependencies on the defs and uses of the instruction.
203 if (ExitMI) {
204 const MCInstrDesc &MIDesc = ExitMI->getDesc();
205 for (const MachineOperand &MO : ExitMI->all_uses()) {
206 unsigned OpIdx = MO.getOperandNo();
207 Register Reg = MO.getReg();
208 if (Reg.isPhysical()) {
209 // addPhysRegDataDeps uses the provided operand index to retrieve
210 // the operand use cycle from the scheduling model. If the operand
211 // is "fake" (e.g., an operand of a call instruction used to pass
212 // an argument to the called function.), the scheduling model may not
213 // have an entry for it. If this is the case, pass -1 as operand index,
214 // which will cause addPhysRegDataDeps to add an artificial dependency.
215 // FIXME: Using hasImplicitUseOfPhysReg here is inaccurate as it misses
216 // aliases. When fixing, make sure to update addPhysRegDataDeps, too.
217 bool IsRealUse = OpIdx < MIDesc.getNumOperands() ||
218 MIDesc.hasImplicitUseOfPhysReg(Reg);
219 for (MCRegUnit Unit : TRI->regunits(Reg))
220 Uses.insert(PhysRegSUOper(&ExitSU, IsRealUse ? OpIdx : -1, Unit));
221 } else if (Reg.isVirtual() && MO.readsReg()) {
222 addVRegUseDeps(&ExitSU, OpIdx);
223 }
224 }
225 }
226 if (!ExitMI || (!ExitMI->isCall() && !ExitMI->isBarrier())) {
227 // For others, e.g. fallthrough, conditional branch, assume the exit
228 // uses all the registers that are livein to the successor blocks.
229 for (const MachineBasicBlock *Succ : BB->successors()) {
230 for (const auto &LI : Succ->liveins()) {
231 for (MCRegUnitMaskIterator U(LI.PhysReg, TRI); U.isValid(); ++U) {
232 auto [Unit, Mask] = *U;
233 if ((Mask & LI.LaneMask).any() && !Uses.contains(Unit))
234 Uses.insert(PhysRegSUOper(&ExitSU, -1, Unit));
235 }
236 }
237 }
238 }
239}
240
241/// MO is an operand of SU's instruction that defines a physical register. Adds
242/// data dependencies from SU to any uses of the physical register.
243void ScheduleDAGInstrs::addPhysRegDataDeps(SUnit *SU, unsigned OperIdx) {
244 const MachineOperand &MO = SU->getInstr()->getOperand(OperIdx);
245 assert(MO.isDef() && "expect physreg def");
246 Register Reg = MO.getReg();
247
248 // Ask the target if address-backscheduling is desirable, and if so how much.
249 const TargetSubtargetInfo &ST = MF.getSubtarget();
250
251 // Only use any non-zero latency for real defs/uses, in contrast to
252 // "fake" operands added by regalloc.
253 const MCInstrDesc &DefMIDesc = SU->getInstr()->getDesc();
254 bool ImplicitPseudoDef = (OperIdx >= DefMIDesc.getNumOperands() &&
255 !DefMIDesc.hasImplicitDefOfPhysReg(Reg));
256 for (MCRegUnit Unit : TRI->regunits(Reg)) {
257 for (RegUnit2SUnitsMap::iterator I = Uses.find(Unit); I != Uses.end();
258 ++I) {
259 SUnit *UseSU = I->SU;
260 if (UseSU == SU)
261 continue;
262
263 // Adjust the dependence latency using operand def/use information,
264 // then allow the target to perform its own adjustments.
265 MachineInstr *UseInstr = nullptr;
266 int UseOpIdx = I->OpIdx;
267 bool ImplicitPseudoUse = false;
268 SDep Dep;
269 if (UseOpIdx < 0) {
270 Dep = SDep(SU, SDep::Artificial);
271 } else {
272 // Set the hasPhysRegDefs only for physreg defs that have a use within
273 // the scheduling region.
274 SU->hasPhysRegDefs = true;
275
276 UseInstr = UseSU->getInstr();
277 Register UseReg = UseInstr->getOperand(UseOpIdx).getReg();
278 const MCInstrDesc &UseMIDesc = UseInstr->getDesc();
279 ImplicitPseudoUse = UseOpIdx >= ((int)UseMIDesc.getNumOperands()) &&
281
282 Dep = SDep(SU, SDep::Data, UseReg);
283 }
284 if (!ImplicitPseudoDef && !ImplicitPseudoUse) {
285 Dep.setLatency(SchedModel.computeOperandLatency(SU->getInstr(), OperIdx,
286 UseInstr, UseOpIdx));
287 } else {
288 Dep.setLatency(0);
289 }
290 ST.adjustSchedDependency(SU, OperIdx, UseSU, UseOpIdx, Dep, &SchedModel);
291 UseSU->addPred(Dep);
292 }
293 }
294}
295
296/// Adds register dependencies (data, anti, and output) from this SUnit
297/// to following instructions in the same scheduling region that depend the
298/// physical register referenced at OperIdx.
299void ScheduleDAGInstrs::addPhysRegDeps(SUnit *SU, unsigned OperIdx) {
300 MachineInstr *MI = SU->getInstr();
301 MachineOperand &MO = MI->getOperand(OperIdx);
302 Register Reg = MO.getReg();
303 // We do not need to track any dependencies for constant registers.
304 if (MRI.isConstantPhysReg(Reg))
305 return;
306
307 const TargetSubtargetInfo &ST = MF.getSubtarget();
308
309 // Optionally add output and anti dependencies. For anti
310 // dependencies we use a latency of 0 because for a multi-issue
311 // target we want to allow the defining instruction to issue
312 // in the same cycle as the using instruction.
313 // TODO: Using a latency of 1 here for output dependencies assumes
314 // there's no cost for reusing registers.
315 SDep::Kind Kind = MO.isUse() ? SDep::Anti : SDep::Output;
316 for (MCRegUnit Unit : TRI->regunits(Reg)) {
317 for (RegUnit2SUnitsMap::iterator I = Defs.find(Unit); I != Defs.end();
318 ++I) {
319 SUnit *DefSU = I->SU;
320 if (DefSU == &ExitSU)
321 continue;
322 MachineInstr *DefInstr = DefSU->getInstr();
323 MachineOperand &DefMO = DefInstr->getOperand(I->OpIdx);
324 if (DefSU != SU &&
325 (Kind != SDep::Output || !MO.isDead() || !DefMO.isDead())) {
326 SDep Dep(SU, Kind, DefMO.getReg());
327 if (Kind != SDep::Anti) {
328 Dep.setLatency(
329 SchedModel.computeOutputLatency(MI, OperIdx, DefInstr));
330 }
331 ST.adjustSchedDependency(SU, OperIdx, DefSU, I->OpIdx, Dep,
332 &SchedModel);
333 DefSU->addPred(Dep);
334 }
335 }
336 }
337
338 if (MO.isUse()) {
339 SU->hasPhysRegUses = true;
340 // Either insert a new Reg2SUnits entry with an empty SUnits list, or
341 // retrieve the existing SUnits list for this register's uses.
342 // Push this SUnit on the use list.
343 for (MCRegUnit Unit : TRI->regunits(Reg))
344 Uses.insert(PhysRegSUOper(SU, OperIdx, Unit));
345 if (RemoveKillFlags)
346 MO.setIsKill(false);
347 } else {
348 addPhysRegDataDeps(SU, OperIdx);
349
350 // Clear previous uses and defs of this register and its subregisters.
351 for (MCRegUnit Unit : TRI->regunits(Reg)) {
352 Uses.eraseAll(Unit);
353 if (!MO.isDead())
354 Defs.eraseAll(Unit);
355 }
356
357 if (MO.isDead() && SU->isCall) {
358 // Calls will not be reordered because of chain dependencies (see
359 // below). Since call operands are dead, calls may continue to be added
360 // to the DefList making dependence checking quadratic in the size of
361 // the block. Instead, we leave only one call at the back of the
362 // DefList.
363 for (MCRegUnit Unit : TRI->regunits(Reg)) {
364 RegUnit2SUnitsMap::RangePair P = Defs.equal_range(Unit);
367 for (bool isBegin = I == B; !isBegin; /* empty */) {
368 isBegin = (--I) == B;
369 if (!I->SU->isCall)
370 break;
371 I = Defs.erase(I);
372 }
373 }
374 }
375
376 // Defs are pushed in the order they are visited and never reordered.
377 for (MCRegUnit Unit : TRI->regunits(Reg))
378 Defs.insert(PhysRegSUOper(SU, OperIdx, Unit));
379 }
380}
381
383{
384 Register Reg = MO.getReg();
385 // No point in tracking lanemasks if we don't have interesting subregisters.
386 const TargetRegisterClass &RC = *MRI.getRegClass(Reg);
387 if (!RC.HasDisjunctSubRegs)
388 return LaneBitmask::getAll();
389
390 unsigned SubReg = MO.getSubReg();
391 if (SubReg == 0)
392 return RC.getLaneMask();
393 return TRI->getSubRegIndexLaneMask(SubReg);
394}
395
397 auto RegUse = CurrentVRegUses.find(MO.getReg());
398 if (RegUse == CurrentVRegUses.end())
399 return true;
400 return (RegUse->LaneMask & getLaneMaskForMO(MO)).none();
401}
402
403/// Adds register output and data dependencies from this SUnit to instructions
404/// that occur later in the same scheduling region if they read from or write to
405/// the virtual register defined at OperIdx.
406///
407/// TODO: Hoist loop induction variable increments. This has to be
408/// reevaluated. Generally, IV scheduling should be done before coalescing.
409void ScheduleDAGInstrs::addVRegDefDeps(SUnit *SU, unsigned OperIdx) {
410 MachineInstr *MI = SU->getInstr();
411 MachineOperand &MO = MI->getOperand(OperIdx);
412 Register Reg = MO.getReg();
413
414 LaneBitmask DefLaneMask;
415 LaneBitmask KillLaneMask;
416 if (TrackLaneMasks) {
417 bool IsKill = MO.getSubReg() == 0 || MO.isUndef();
418 DefLaneMask = getLaneMaskForMO(MO);
419 // If we have a <read-undef> flag, none of the lane values comes from an
420 // earlier instruction.
421 KillLaneMask = IsKill ? LaneBitmask::getAll() : DefLaneMask;
422
423 if (MO.getSubReg() != 0 && MO.isUndef()) {
424 // There may be other subregister defs on the same instruction of the same
425 // register in later operands. The lanes of other defs will now be live
426 // after this instruction, so these should not be treated as killed by the
427 // instruction even though they appear to be killed in this one operand.
428 for (const MachineOperand &OtherMO :
429 llvm::drop_begin(MI->operands(), OperIdx + 1))
430 if (OtherMO.isReg() && OtherMO.isDef() && OtherMO.getReg() == Reg)
431 KillLaneMask &= ~getLaneMaskForMO(OtherMO);
432 }
433
434 // Clear undef flag, we'll re-add it later once we know which subregister
435 // Def is first.
436 MO.setIsUndef(false);
437 } else {
438 DefLaneMask = LaneBitmask::getAll();
439 KillLaneMask = LaneBitmask::getAll();
440 }
441
442 if (MO.isDead()) {
443 assert(deadDefHasNoUse(MO) && "Dead defs should have no uses");
444 } else {
445 // Add data dependence to all uses we found so far.
446 const TargetSubtargetInfo &ST = MF.getSubtarget();
448 E = CurrentVRegUses.end(); I != E; /*empty*/) {
449 LaneBitmask LaneMask = I->LaneMask;
450 // Ignore uses of other lanes.
451 if ((LaneMask & KillLaneMask).none()) {
452 ++I;
453 continue;
454 }
455
456 if ((LaneMask & DefLaneMask).any()) {
457 SUnit *UseSU = I->SU;
458 MachineInstr *Use = UseSU->getInstr();
459 SDep Dep(SU, SDep::Data, Reg);
460 Dep.setLatency(SchedModel.computeOperandLatency(MI, OperIdx, Use,
461 I->OperandIndex));
462 ST.adjustSchedDependency(SU, OperIdx, UseSU, I->OperandIndex, Dep,
463 &SchedModel);
464 UseSU->addPred(Dep);
465 }
466
467 LaneMask &= ~KillLaneMask;
468 // If we found a Def for all lanes of this use, remove it from the list.
469 if (LaneMask.any()) {
470 I->LaneMask = LaneMask;
471 ++I;
472 } else
473 I = CurrentVRegUses.erase(I);
474 }
475 }
476
477 // Shortcut: Singly defined vregs do not have output/anti dependencies.
478 if (MRI.hasOneDef(Reg))
479 return;
480
481 // Add output dependence to the next nearest defs of this vreg.
482 //
483 // Unless this definition is dead, the output dependence should be
484 // transitively redundant with antidependencies from this definition's
485 // uses. We're conservative for now until we have a way to guarantee the uses
486 // are not eliminated sometime during scheduling. The output dependence edge
487 // is also useful if output latency exceeds def-use latency.
488 LaneBitmask LaneMask = DefLaneMask;
489 for (VReg2SUnit &V2SU : make_range(CurrentVRegDefs.find(Reg),
490 CurrentVRegDefs.end())) {
491 // Ignore defs for other lanes.
492 if ((V2SU.LaneMask & LaneMask).none())
493 continue;
494 // Add an output dependence.
495 SUnit *DefSU = V2SU.SU;
496 // Ignore additional defs of the same lanes in one instruction. This can
497 // happen because lanemasks are shared for targets with too many
498 // subregisters. We also use some representration tricks/hacks where we
499 // add super-register defs/uses, to imply that although we only access parts
500 // of the reg we care about the full one.
501 if (DefSU == SU)
502 continue;
503 SDep Dep(SU, SDep::Output, Reg);
504 Dep.setLatency(
505 SchedModel.computeOutputLatency(MI, OperIdx, DefSU->getInstr()));
506 DefSU->addPred(Dep);
507
508 // Update current definition. This can get tricky if the def was about a
509 // bigger lanemask before. We then have to shrink it and create a new
510 // VReg2SUnit for the non-overlapping part.
511 LaneBitmask OverlapMask = V2SU.LaneMask & LaneMask;
512 LaneBitmask NonOverlapMask = V2SU.LaneMask & ~LaneMask;
513 V2SU.SU = SU;
514 V2SU.LaneMask = OverlapMask;
515 if (NonOverlapMask.any())
516 CurrentVRegDefs.insert(VReg2SUnit(Reg, NonOverlapMask, DefSU));
517 }
518 // If there was no CurrentVRegDefs entry for some lanes yet, create one.
519 if (LaneMask.any())
520 CurrentVRegDefs.insert(VReg2SUnit(Reg, LaneMask, SU));
521}
522
523/// Adds a register data dependency if the instruction that defines the
524/// virtual register used at OperIdx is mapped to an SUnit. Add a register
525/// antidependency from this SUnit to instructions that occur later in the same
526/// scheduling region if they write the virtual register.
527///
528/// TODO: Handle ExitSU "uses" properly.
529void ScheduleDAGInstrs::addVRegUseDeps(SUnit *SU, unsigned OperIdx) {
530 const MachineInstr *MI = SU->getInstr();
531 assert(!MI->isDebugOrPseudoInstr());
532
533 const MachineOperand &MO = MI->getOperand(OperIdx);
534 Register Reg = MO.getReg();
535
536 // Remember the use. Data dependencies will be added when we find the def.
539 CurrentVRegUses.insert(VReg2SUnitOperIdx(Reg, LaneMask, OperIdx, SU));
540
541 // Add antidependences to the following defs of the vreg.
542 for (VReg2SUnit &V2SU : make_range(CurrentVRegDefs.find(Reg),
543 CurrentVRegDefs.end())) {
544 // Ignore defs for unrelated lanes.
545 LaneBitmask PrevDefLaneMask = V2SU.LaneMask;
546 if ((PrevDefLaneMask & LaneMask).none())
547 continue;
548 if (V2SU.SU == SU)
549 continue;
550
551 V2SU.SU->addPred(SDep(SU, SDep::Anti, Reg));
552 }
553}
554
555
557 unsigned Latency) {
558 if (SUa->getInstr()->mayAlias(getAAForDep(), *SUb->getInstr(), UseTBAA)) {
559 SDep Dep(SUa, SDep::MayAliasMem);
560 Dep.setLatency(Latency);
561 SUb->addPred(Dep);
562 }
563}
564
565/// Creates an SUnit for each real instruction, numbered in top-down
566/// topological order. The instruction order A < B, implies that no edge exists
567/// from B to A.
568///
569/// Map each real instruction to its SUnit.
570///
571/// After initSUnits, the SUnits vector cannot be resized and the scheduler may
572/// hang onto SUnit pointers. We may relax this in the future by using SUnit IDs
573/// instead of pointers.
574///
575/// MachineScheduler relies on initSUnits numbering the nodes by their order in
576/// the original instruction list.
578 // We'll be allocating one SUnit for each real instruction in the region,
579 // which is contained within a basic block.
580 SUnits.reserve(NumRegionInstrs);
581
583 if (MI.isDebugOrPseudoInstr())
584 continue;
585
586 SUnit *SU = newSUnit(&MI);
587 MISUnitMap[&MI] = SU;
588
589 SU->isCall = MI.isCall();
590 SU->isCommutable = MI.isCommutable();
591
592 // Assign the Latency field of SU using target-provided information.
593 SU->Latency = SchedModel.computeInstrLatency(SU->getInstr());
594
595 // If this SUnit uses a reserved or unbuffered resource, mark it as such.
596 //
597 // Reserved resources block an instruction from issuing and stall the
598 // entire pipeline. These are identified by BufferSize=0.
599 //
600 // Unbuffered resources prevent execution of subsequent instructions that
601 // require the same resources. This is used for in-order execution pipelines
602 // within an out-of-order core. These are identified by BufferSize=1.
603 if (SchedModel.hasInstrSchedModel()) {
604 const MCSchedClassDesc *SC = getSchedClass(SU);
605 for (const MCWriteProcResEntry &PRE :
606 make_range(SchedModel.getWriteProcResBegin(SC),
607 SchedModel.getWriteProcResEnd(SC))) {
608 switch (SchedModel.getResourceBufferSize(PRE.ProcResourceIdx)) {
609 case 0:
610 SU->hasReservedResource = true;
611 break;
612 case 1:
613 SU->isUnbuffered = true;
614 break;
615 default:
616 break;
617 }
618 }
619 }
620 }
621}
622
624 : public SmallMapVector<ValueType, SUList, 4> {
625 /// Current total number of SUs in map.
626 unsigned NumNodes = 0;
627
628 /// 1 for loads, 0 for stores. (see comment in SUList)
629 unsigned TrueMemOrderLatency;
630
631public:
632 Value2SUsMap(unsigned lat = 0) : TrueMemOrderLatency(lat) {}
633
634 /// To keep NumNodes up to date, insert() is used instead of
635 /// this operator w/ push_back().
637 llvm_unreachable("Don't use. Use insert() instead."); };
638
639 /// Adds SU to the SUList of V. If Map grows huge, reduce its size by calling
640 /// reduce().
641 void inline insert(SUnit *SU, ValueType V) {
642 MapVector::operator[](V).push_back(SU);
643 NumNodes++;
644 }
645
646 /// Clears the list of SUs mapped to V.
647 void inline clearList(ValueType V) {
648 iterator Itr = find(V);
649 if (Itr != end()) {
650 assert(NumNodes >= Itr->second.size());
651 NumNodes -= Itr->second.size();
652
653 Itr->second.clear();
654 }
655 }
656
657 /// Clears map from all contents.
658 void clear() {
660 NumNodes = 0;
661 }
662
663 unsigned inline size() const { return NumNodes; }
664
665 /// Counts the number of SUs in this map after a reduction.
667 NumNodes = 0;
668 for (auto &I : *this)
669 NumNodes += I.second.size();
670 }
671
672 unsigned inline getTrueMemOrderLatency() const {
673 return TrueMemOrderLatency;
674 }
675
676 void dump();
677};
678
680 Value2SUsMap &Val2SUsMap) {
681 for (auto &I : Val2SUsMap)
682 addChainDependencies(SU, I.second,
683 Val2SUsMap.getTrueMemOrderLatency());
684}
685
687 Value2SUsMap &Val2SUsMap,
688 ValueType V) {
689 Value2SUsMap::iterator Itr = Val2SUsMap.find(V);
690 if (Itr != Val2SUsMap.end())
691 addChainDependencies(SU, Itr->second,
692 Val2SUsMap.getTrueMemOrderLatency());
693}
694
696 assert(BarrierChain != nullptr);
697
698 for (auto &[V, SUs] : map) {
699 (void)V;
700 for (auto *SU : SUs)
701 SU->addPredBarrier(BarrierChain);
702 }
703 map.clear();
704}
705
707 RegPressureTracker *RPTracker,
708 PressureDiffs *PDiffs,
709 LiveIntervals *LIS,
710 bool TrackLaneMasks) {
711 const TargetSubtargetInfo &ST = MF.getSubtarget();
712 bool UseAA = EnableAASchedMI.getNumOccurrences() > 0 ? EnableAASchedMI
713 : ST.useAA();
714 if (UseAA && AA)
715 AAForDep.emplace(*AA);
716
717 BarrierChain = nullptr;
718 MemOpsProcessed = 0;
719
720 this->TrackLaneMasks = TrackLaneMasks;
721 MISUnitMap.clear();
723
724 // Create an SUnit for each real instruction.
725 initSUnits();
726
727 if (PDiffs)
728 PDiffs->init(SUnits.size());
729
730 // We build scheduling units by walking a block's instruction list
731 // from bottom to top.
732
733 // Each MIs' memory operand(s) is analyzed to a list of underlying
734 // objects. The SU is then inserted in the SUList(s) mapped from the
735 // Value(s). Each Value thus gets mapped to lists of SUs depending
736 // on it, stores and loads kept separately. Two SUs are trivially
737 // non-aliasing if they both depend on only identified Values and do
738 // not share any common Value.
739 Value2SUsMap Stores, Loads(1 /*TrueMemOrderLatency*/);
740
741 // Track all instructions that may raise floating-point exceptions.
742 // These do not depend on one other (or normal loads or stores), but
743 // must not be rescheduled across global barriers. Note that we don't
744 // really need a "map" here since we don't track those MIs by value;
745 // using the same Value2SUsMap data type here is simply a matter of
746 // convenience.
747 Value2SUsMap FPExceptions;
748
749 // Remove any stale debug info; sometimes BuildSchedGraph is called again
750 // without emitting the info from the previous call.
751 DbgValues.clear();
752 FirstDbgValue = nullptr;
753
754 assert(Defs.empty() && Uses.empty() &&
755 "Only BuildGraph should update Defs/Uses");
756 Defs.setUniverse(TRI->getNumRegs());
757 Uses.setUniverse(TRI->getNumRegs());
758
759 assert(CurrentVRegDefs.empty() && "nobody else should use CurrentVRegDefs");
760 assert(CurrentVRegUses.empty() && "nobody else should use CurrentVRegUses");
761 unsigned NumVirtRegs = MRI.getNumVirtRegs();
762 CurrentVRegDefs.setUniverse(NumVirtRegs);
763 CurrentVRegUses.setUniverse(NumVirtRegs);
764
765 // Model data dependencies between instructions being scheduled and the
766 // ExitSU.
768
769 // Walk the list of instructions, from bottom moving up.
770 MachineInstr *DbgMI = nullptr;
772 MII != MIE; --MII) {
773 MachineInstr &MI = *std::prev(MII);
774 if (DbgMI) {
775 DbgValues.emplace_back(DbgMI, &MI);
776 DbgMI = nullptr;
777 }
778
779 if (MI.isDebugValue() || MI.isDebugPHI()) {
780 DbgMI = &MI;
781 continue;
782 }
783
784 if (MI.isDebugLabel() || MI.isDebugRef() || MI.isPseudoProbe())
785 continue;
786
787 SUnit *SU = MISUnitMap[&MI];
788 assert(SU && "No SUnit mapped to this MI");
789
790 if (RPTracker) {
791 RegisterOperands RegOpers;
792 RegOpers.collect(MI, *TRI, MRI, TrackLaneMasks, false);
793 if (TrackLaneMasks) {
794 SlotIndex SlotIdx = LIS->getInstructionIndex(MI);
795 RegOpers.adjustLaneLiveness(*LIS, MRI, SlotIdx);
796 }
797 if (PDiffs != nullptr)
798 PDiffs->addInstruction(SU->NodeNum, RegOpers, MRI);
799
800 if (RPTracker->getPos() == RegionEnd || &*RPTracker->getPos() != &MI)
801 RPTracker->recedeSkipDebugValues();
802 assert(&*RPTracker->getPos() == &MI && "RPTracker in sync");
803 RPTracker->recede(RegOpers);
804 }
805
806 assert(
807 (CanHandleTerminators || (!MI.isTerminator() && !MI.isPosition())) &&
808 "Cannot schedule terminators or labels!");
809
810 // Add register-based dependencies (data, anti, and output).
811 // For some instructions (calls, returns, inline-asm, etc.) there can
812 // be explicit uses and implicit defs, in which case the use will appear
813 // on the operand list before the def. Do two passes over the operand
814 // list to make sure that defs are processed before any uses.
815 bool HasVRegDef = false;
816 for (unsigned j = 0, n = MI.getNumOperands(); j != n; ++j) {
817 const MachineOperand &MO = MI.getOperand(j);
818 if (!MO.isReg() || !MO.isDef())
819 continue;
820 Register Reg = MO.getReg();
821 if (Reg.isPhysical()) {
822 addPhysRegDeps(SU, j);
823 } else if (Reg.isVirtual()) {
824 HasVRegDef = true;
825 addVRegDefDeps(SU, j);
826 }
827 }
828 // Now process all uses.
829 for (unsigned j = 0, n = MI.getNumOperands(); j != n; ++j) {
830 const MachineOperand &MO = MI.getOperand(j);
831 // Only look at use operands.
832 // We do not need to check for MO.readsReg() here because subsequent
833 // subregister defs will get output dependence edges and need no
834 // additional use dependencies.
835 if (!MO.isReg() || !MO.isUse())
836 continue;
837 Register Reg = MO.getReg();
838 if (Reg.isPhysical()) {
839 addPhysRegDeps(SU, j);
840 } else if (Reg.isVirtual() && MO.readsReg()) {
841 addVRegUseDeps(SU, j);
842 }
843 }
844
845 // If we haven't seen any uses in this scheduling region, create a
846 // dependence edge to ExitSU to model the live-out latency. This is required
847 // for vreg defs with no in-region use, and prefetches with no vreg def.
848 //
849 // FIXME: NumDataSuccs would be more precise than NumSuccs here. This
850 // check currently relies on being called before adding chain deps.
851 if (SU->NumSuccs == 0 && SU->Latency > 1 && (HasVRegDef || MI.mayLoad())) {
852 SDep Dep(SU, SDep::Artificial);
853 Dep.setLatency(SU->Latency - 1);
854 ExitSU.addPred(Dep);
855 }
856
857 // Add memory dependencies (Note: isStoreToStackSlot and
858 // isLoadFromStackSLot are not usable after stack slots are lowered to
859 // actual addresses).
860
861 const TargetInstrInfo *TII = ST.getInstrInfo();
862 // This is a barrier event that acts as a pivotal node in the DAG.
863 if (TII->isGlobalMemoryObject(&MI)) {
864
865 // Become the barrier chain.
866 if (BarrierChain)
867 BarrierChain->addPredBarrier(SU);
868 BarrierChain = SU;
869
870 LLVM_DEBUG(dbgs() << "Global memory object and new barrier chain: SU("
871 << BarrierChain->NodeNum << ").\n");
872
873 // Add dependencies against everything below it and clear maps.
874 addBarrierChain(Stores);
875 addBarrierChain(Loads);
876 addBarrierChain(FPExceptions);
877
878 continue;
879 }
880
881 // Instructions that may raise FP exceptions may not be moved
882 // across any global barriers.
883 if (MI.mayRaiseFPException()) {
884 if (BarrierChain)
885 BarrierChain->addPredBarrier(SU);
886
887 if (FPExceptions.size() + 1 >= HugeRegion) {
889 dbgs()
890 << "Creating barrier chain and clearing FPExceptions map.\n");
891 BarrierChain = SU;
892 addBarrierChain(FPExceptions);
893 } else {
894 FPExceptions.insert(SU, UnknownValue);
895 }
896 }
897
898 // If it's not a store or a variant load, we're done.
899 if (!MI.mayStore() &&
900 !(MI.mayLoad() && !MI.isDereferenceableInvariantLoad()))
901 continue;
902
904
905 // Always add dependecy edge to BarrierChain if present.
906 if (BarrierChain && BarrierChain != SU)
907 BarrierChain->addPredBarrier(SU);
908
909 // Reduce maps if they grow huge.
911 LLVM_DEBUG(dbgs() << "Creating barrier chain and clearing maps.\n");
912
913 BarrierChain = SU;
914
915 addBarrierChain(Stores);
916 addBarrierChain(Loads);
917
918 MemOpsProcessed = 0;
919 continue;
920 }
921
922 // Find the underlying objects for MI. The Objs vector is either
923 // empty, or filled with the Values of memory locations which this
924 // SU depends on.
926 bool ObjsIdentified =
927 getUnderlyingObjectsForInstr(&MI, MFI, Objs, MF.getDataLayout());
928
929 if (MI.mayStore()) {
930 if (!ObjsIdentified) {
931 // An unknown store depends on all stores and loads.
932 addChainDependencies(SU, Stores);
933 addChainDependencies(SU, Loads);
934
935 // Map this store to 'UnknownValue'.
936 Stores.insert(SU, UnknownValue);
937 } else {
938 // Add precise dependencies against all previously seen memory
939 // accesses mapped to the same Value(s).
940 for (const ValueType V : Objs) {
941 // Add dependencies to previous stores and loads mapped to V.
942 addChainDependencies(SU, Stores, V);
943 addChainDependencies(SU, Loads, V);
944 }
945 // Update the store map after all chains have been added to avoid adding
946 // self-loop edge if multiple underlying objects are present.
947 for (const ValueType V : Objs)
948 Stores.insert(SU, V);
949
950 // The store may have dependencies to unanalyzable loads and
951 // stores.
954 }
955 } else { // SU is a load.
956 if (!ObjsIdentified) {
957 // An unknown load depends on all stores.
958 addChainDependencies(SU, Stores);
959
960 // Map this load to 'UnknownValue'.
961 Loads.insert(SU, UnknownValue);
962 } else {
963 for (const ValueType V : Objs) {
964 // Add precise dependencies against all previously seen stores
965 // mapping to the same Value(s).
966 addChainDependencies(SU, Stores, V);
967
968 // Map this load to V.
969 Loads.insert(SU, V);
970 }
971 // The load may have dependencies to unanalyzable stores.
973 }
974 }
975 }
976
977 if (DbgMI)
978 FirstDbgValue = DbgMI;
979
980 Defs.clear();
981 Uses.clear();
982 CurrentVRegDefs.clear();
983 CurrentVRegUses.clear();
984
985 Topo.MarkDirty();
986}
987
989 PSV->printCustom(OS);
990 return OS;
991}
992
994 for (const auto &[ValType, SUs] : *this) {
995 if (isa<const Value *>(ValType)) {
996 const Value *V = cast<const Value *>(ValType);
997 if (isa<UndefValue>(V))
998 dbgs() << "Unknown";
999 else
1000 V->printAsOperand(dbgs());
1001 } else if (isa<const PseudoSourceValue *>(ValType))
1003 else
1004 llvm_unreachable("Unknown Value type.");
1005
1006 dbgs() << " : ";
1007 dumpSUList(SUs);
1008 }
1009}
1010
1012 MachineInstr &MI, bool addToLiveRegs) {
1013 for (MachineOperand &MO : MI.operands()) {
1014 if (!MO.isReg() || !MO.readsReg())
1015 continue;
1016 Register Reg = MO.getReg();
1017 if (!Reg)
1018 continue;
1019
1020 // Things that are available after the instruction are killed by it.
1021 bool IsKill = LiveRegs.available(Reg);
1022
1023 // Exception: Do not kill reserved registers
1024 MO.setIsKill(IsKill && !MRI.isReserved(Reg));
1025 if (addToLiveRegs)
1026 LiveRegs.addReg(Reg);
1027 }
1028}
1029
1031 LLVM_DEBUG(dbgs() << "Fixup kills for " << printMBBReference(MBB) << '\n');
1032
1033 LiveRegs.init(*TRI);
1034 LiveRegs.addLiveOuts(MBB);
1035
1036 // Examine block from end to start...
1037 for (MachineInstr &MI : llvm::reverse(MBB)) {
1038 if (MI.isDebugOrPseudoInstr())
1039 continue;
1040
1041 // Update liveness. Registers that are defed but not used in this
1042 // instruction are now dead. Mark register and all subregs as they
1043 // are completely defined.
1044 for (ConstMIBundleOperands O(MI); O.isValid(); ++O) {
1045 const MachineOperand &MO = *O;
1046 if (MO.isReg()) {
1047 if (!MO.isDef())
1048 continue;
1049 Register Reg = MO.getReg();
1050 if (!Reg)
1051 continue;
1052 LiveRegs.removeReg(Reg);
1053 } else if (MO.isRegMask()) {
1054 LiveRegs.removeRegsNotPreserved(MO.getRegMask());
1055 }
1056 }
1057
1058 // If there is a bundle header fix it up first.
1059 if (!MI.isBundled()) {
1060 toggleKills(MRI, LiveRegs, MI, true);
1061 } else {
1062 MachineBasicBlock::instr_iterator Bundle = MI.getIterator();
1063 if (MI.isBundle())
1064 toggleKills(MRI, LiveRegs, MI, false);
1065
1066 // Some targets make the (questionable) assumtion that the instructions
1067 // inside the bundle are ordered and consequently only the last use of
1068 // a register inside the bundle can kill it.
1069 MachineBasicBlock::instr_iterator I = std::next(Bundle);
1070 while (I->isBundledWithSucc())
1071 ++I;
1072 do {
1073 if (!I->isDebugOrPseudoInstr())
1074 toggleKills(MRI, LiveRegs, *I, true);
1075 --I;
1076 } while (I != Bundle);
1077 }
1078 }
1079}
1080
1081void ScheduleDAGInstrs::dumpNode(const SUnit &SU) const {
1082#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1083 dumpNodeName(SU);
1084 if (SchedPrintCycles)
1085 dbgs() << " [TopReadyCycle = " << SU.TopReadyCycle
1086 << ", BottomReadyCycle = " << SU.BotReadyCycle << "]";
1087 dbgs() << ": ";
1088 SU.getInstr()->dump();
1089#endif
1090}
1091
1093#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1094 if (EntrySU.getInstr() != nullptr)
1096 for (const SUnit &SU : SUnits)
1097 dumpNodeAll(SU);
1098 if (ExitSU.getInstr() != nullptr)
1100#endif
1101}
1102
1103std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
1104 std::string s;
1105 raw_string_ostream oss(s);
1106 if (SU == &EntrySU)
1107 oss << "<entry>";
1108 else if (SU == &ExitSU)
1109 oss << "<exit>";
1110 else
1111 SU->getInstr()->print(oss, /*IsStandalone=*/true);
1112 return s;
1113}
1114
1115/// Return the basic block label. It is not necessarily unique because a block
1116/// contains multiple scheduling regions. But it is fine for visualization.
1118 return "dag." + BB->getFullName();
1119}
1120
1122 return SuccSU == &ExitSU || !Topo.IsReachable(PredSU, SuccSU);
1123}
1124
1125bool ScheduleDAGInstrs::addEdge(SUnit *SuccSU, const SDep &PredDep) {
1126 if (SuccSU != &ExitSU) {
1127 // Do not use WillCreateCycle, it assumes SD scheduling.
1128 // If Pred is reachable from Succ, then the edge creates a cycle.
1129 if (Topo.IsReachable(PredDep.getSUnit(), SuccSU))
1130 return false;
1131 Topo.AddPredQueued(SuccSU, PredDep.getSUnit());
1132 }
1133 SuccSU->addPred(PredDep, /*Required=*/!PredDep.isArtificial());
1134 // Return true regardless of whether a new edge needed to be inserted.
1135 return true;
1136}
1137
1138//===----------------------------------------------------------------------===//
1139// SchedDFSResult Implementation
1140//===----------------------------------------------------------------------===//
1141
1142namespace llvm {
1143
1144/// Internal state used to compute SchedDFSResult.
1146 SchedDFSResult &R;
1147
1148 /// Join DAG nodes into equivalence classes by their subtree.
1149 IntEqClasses SubtreeClasses;
1150 /// List PredSU, SuccSU pairs that represent data edges between subtrees.
1151 std::vector<std::pair<const SUnit *, const SUnit*>> ConnectionPairs;
1152
1153 struct RootData {
1154 unsigned NodeID;
1155 unsigned ParentNodeID; ///< Parent node (member of the parent subtree).
1156 unsigned SubInstrCount = 0; ///< Instr count in this tree only, not
1157 /// children.
1158
1159 RootData(unsigned id): NodeID(id),
1160 ParentNodeID(SchedDFSResult::InvalidSubtreeID) {}
1161
1162 unsigned getSparseSetIndex() const { return NodeID; }
1163 };
1164
1165 SparseSet<RootData> RootSet;
1166
1167public:
1168 SchedDFSImpl(SchedDFSResult &r): R(r), SubtreeClasses(R.DFSNodeData.size()) {
1169 RootSet.setUniverse(R.DFSNodeData.size());
1170 }
1171
1172 /// Returns true if this node been visited by the DFS traversal.
1173 ///
1174 /// During visitPostorderNode the Node's SubtreeID is assigned to the Node
1175 /// ID. Later, SubtreeID is updated but remains valid.
1176 bool isVisited(const SUnit *SU) const {
1177 return R.DFSNodeData[SU->NodeNum].SubtreeID
1178 != SchedDFSResult::InvalidSubtreeID;
1179 }
1180
1181 /// Initializes this node's instruction count. We don't need to flag the node
1182 /// visited until visitPostorder because the DAG cannot have cycles.
1183 void visitPreorder(const SUnit *SU) {
1184 R.DFSNodeData[SU->NodeNum].InstrCount =
1185 SU->getInstr()->isTransient() ? 0 : 1;
1186 }
1187
1188 /// Called once for each node after all predecessors are visited. Revisit this
1189 /// node's predecessors and potentially join them now that we know the ILP of
1190 /// the other predecessors.
1191 void visitPostorderNode(const SUnit *SU) {
1192 // Mark this node as the root of a subtree. It may be joined with its
1193 // successors later.
1194 R.DFSNodeData[SU->NodeNum].SubtreeID = SU->NodeNum;
1195 RootData RData(SU->NodeNum);
1196 RData.SubInstrCount = SU->getInstr()->isTransient() ? 0 : 1;
1197
1198 // If any predecessors are still in their own subtree, they either cannot be
1199 // joined or are large enough to remain separate. If this parent node's
1200 // total instruction count is not greater than a child subtree by at least
1201 // the subtree limit, then try to join it now since splitting subtrees is
1202 // only useful if multiple high-pressure paths are possible.
1203 unsigned InstrCount = R.DFSNodeData[SU->NodeNum].InstrCount;
1204 for (const SDep &PredDep : SU->Preds) {
1205 if (PredDep.getKind() != SDep::Data)
1206 continue;
1207 unsigned PredNum = PredDep.getSUnit()->NodeNum;
1208 if ((InstrCount - R.DFSNodeData[PredNum].InstrCount) < R.SubtreeLimit)
1209 joinPredSubtree(PredDep, SU, /*CheckLimit=*/false);
1210
1211 // Either link or merge the TreeData entry from the child to the parent.
1212 if (R.DFSNodeData[PredNum].SubtreeID == PredNum) {
1213 // If the predecessor's parent is invalid, this is a tree edge and the
1214 // current node is the parent.
1215 if (RootSet[PredNum].ParentNodeID == SchedDFSResult::InvalidSubtreeID)
1216 RootSet[PredNum].ParentNodeID = SU->NodeNum;
1217 }
1218 else if (RootSet.count(PredNum)) {
1219 // The predecessor is not a root, but is still in the root set. This
1220 // must be the new parent that it was just joined to. Note that
1221 // RootSet[PredNum].ParentNodeID may either be invalid or may still be
1222 // set to the original parent.
1223 RData.SubInstrCount += RootSet[PredNum].SubInstrCount;
1224 RootSet.erase(PredNum);
1225 }
1226 }
1227 RootSet[SU->NodeNum] = RData;
1228 }
1229
1230 /// Called once for each tree edge after calling visitPostOrderNode on
1231 /// the predecessor. Increment the parent node's instruction count and
1232 /// preemptively join this subtree to its parent's if it is small enough.
1233 void visitPostorderEdge(const SDep &PredDep, const SUnit *Succ) {
1234 R.DFSNodeData[Succ->NodeNum].InstrCount
1235 += R.DFSNodeData[PredDep.getSUnit()->NodeNum].InstrCount;
1236 joinPredSubtree(PredDep, Succ);
1237 }
1238
1239 /// Adds a connection for cross edges.
1240 void visitCrossEdge(const SDep &PredDep, const SUnit *Succ) {
1241 ConnectionPairs.emplace_back(PredDep.getSUnit(), Succ);
1242 }
1243
1244 /// Sets each node's subtree ID to the representative ID and record
1245 /// connections between trees.
1246 void finalize() {
1247 SubtreeClasses.compress();
1248 R.DFSTreeData.resize(SubtreeClasses.getNumClasses());
1249 assert(SubtreeClasses.getNumClasses() == RootSet.size()
1250 && "number of roots should match trees");
1251 for (const RootData &Root : RootSet) {
1252 unsigned TreeID = SubtreeClasses[Root.NodeID];
1253 if (Root.ParentNodeID != SchedDFSResult::InvalidSubtreeID)
1254 R.DFSTreeData[TreeID].ParentTreeID = SubtreeClasses[Root.ParentNodeID];
1255 R.DFSTreeData[TreeID].SubInstrCount = Root.SubInstrCount;
1256 // Note that SubInstrCount may be greater than InstrCount if we joined
1257 // subtrees across a cross edge. InstrCount will be attributed to the
1258 // original parent, while SubInstrCount will be attributed to the joined
1259 // parent.
1260 }
1261 R.SubtreeConnections.resize(SubtreeClasses.getNumClasses());
1262 R.SubtreeConnectLevels.resize(SubtreeClasses.getNumClasses());
1263 LLVM_DEBUG(dbgs() << R.getNumSubtrees() << " subtrees:\n");
1264 for (unsigned Idx = 0, End = R.DFSNodeData.size(); Idx != End; ++Idx) {
1265 R.DFSNodeData[Idx].SubtreeID = SubtreeClasses[Idx];
1266 LLVM_DEBUG(dbgs() << " SU(" << Idx << ") in tree "
1267 << R.DFSNodeData[Idx].SubtreeID << '\n');
1268 }
1269 for (const auto &[Pred, Succ] : ConnectionPairs) {
1270 unsigned PredTree = SubtreeClasses[Pred->NodeNum];
1271 unsigned SuccTree = SubtreeClasses[Succ->NodeNum];
1272 if (PredTree == SuccTree)
1273 continue;
1274 unsigned Depth = Pred->getDepth();
1275 addConnection(PredTree, SuccTree, Depth);
1276 addConnection(SuccTree, PredTree, Depth);
1277 }
1278 }
1279
1280protected:
1281 /// Joins the predecessor subtree with the successor that is its DFS parent.
1282 /// Applies some heuristics before joining.
1283 bool joinPredSubtree(const SDep &PredDep, const SUnit *Succ,
1284 bool CheckLimit = true) {
1285 assert(PredDep.getKind() == SDep::Data && "Subtrees are for data edges");
1286
1287 // Check if the predecessor is already joined.
1288 const SUnit *PredSU = PredDep.getSUnit();
1289 unsigned PredNum = PredSU->NodeNum;
1290 if (R.DFSNodeData[PredNum].SubtreeID != PredNum)
1291 return false;
1292
1293 // Four is the magic number of successors before a node is considered a
1294 // pinch point.
1295 unsigned NumDataSucs = 0;
1296 for (const SDep &SuccDep : PredSU->Succs) {
1297 if (SuccDep.getKind() == SDep::Data) {
1298 if (++NumDataSucs >= 4)
1299 return false;
1300 }
1301 }
1302 if (CheckLimit && R.DFSNodeData[PredNum].InstrCount > R.SubtreeLimit)
1303 return false;
1304 R.DFSNodeData[PredNum].SubtreeID = Succ->NodeNum;
1305 SubtreeClasses.join(Succ->NodeNum, PredNum);
1306 return true;
1307 }
1308
1309 /// Called by finalize() to record a connection between trees.
1310 void addConnection(unsigned FromTree, unsigned ToTree, unsigned Depth) {
1311 if (!Depth)
1312 return;
1313
1314 do {
1316 R.SubtreeConnections[FromTree];
1317 for (SchedDFSResult::Connection &C : Connections) {
1318 if (C.TreeID == ToTree) {
1319 C.Level = std::max(C.Level, Depth);
1320 return;
1321 }
1322 }
1323 Connections.push_back(SchedDFSResult::Connection(ToTree, Depth));
1324 FromTree = R.DFSTreeData[FromTree].ParentTreeID;
1325 } while (FromTree != SchedDFSResult::InvalidSubtreeID);
1326 }
1327};
1328
1329} // end namespace llvm
1330
1331namespace {
1332
1333/// Manage the stack used by a reverse depth-first search over the DAG.
1334class SchedDAGReverseDFS {
1335 std::vector<std::pair<const SUnit *, SUnit::const_pred_iterator>> DFSStack;
1336
1337public:
1338 bool isComplete() const { return DFSStack.empty(); }
1339
1340 void follow(const SUnit *SU) {
1341 DFSStack.emplace_back(SU, SU->Preds.begin());
1342 }
1343 void advance() { ++DFSStack.back().second; }
1344
1345 const SDep *backtrack() {
1346 DFSStack.pop_back();
1347 return DFSStack.empty() ? nullptr : std::prev(DFSStack.back().second);
1348 }
1349
1350 const SUnit *getCurr() const { return DFSStack.back().first; }
1351
1352 SUnit::const_pred_iterator getPred() const { return DFSStack.back().second; }
1353
1354 SUnit::const_pred_iterator getPredEnd() const {
1355 return getCurr()->Preds.end();
1356 }
1357};
1358
1359} // end anonymous namespace
1360
1361static bool hasDataSucc(const SUnit *SU) {
1362 for (const SDep &SuccDep : SU->Succs) {
1363 if (SuccDep.getKind() == SDep::Data &&
1364 !SuccDep.getSUnit()->isBoundaryNode())
1365 return true;
1366 }
1367 return false;
1368}
1369
1370/// Computes an ILP metric for all nodes in the subDAG reachable via depth-first
1371/// search from this root.
1373 if (!IsBottomUp)
1374 llvm_unreachable("Top-down ILP metric is unimplemented");
1375
1376 SchedDFSImpl Impl(*this);
1377 for (const SUnit &SU : SUnits) {
1378 if (Impl.isVisited(&SU) || hasDataSucc(&SU))
1379 continue;
1380
1381 SchedDAGReverseDFS DFS;
1382 Impl.visitPreorder(&SU);
1383 DFS.follow(&SU);
1384 while (true) {
1385 // Traverse the leftmost path as far as possible.
1386 while (DFS.getPred() != DFS.getPredEnd()) {
1387 const SDep &PredDep = *DFS.getPred();
1388 DFS.advance();
1389 // Ignore non-data edges.
1390 if (PredDep.getKind() != SDep::Data
1391 || PredDep.getSUnit()->isBoundaryNode()) {
1392 continue;
1393 }
1394 // An already visited edge is a cross edge, assuming an acyclic DAG.
1395 if (Impl.isVisited(PredDep.getSUnit())) {
1396 Impl.visitCrossEdge(PredDep, DFS.getCurr());
1397 continue;
1398 }
1399 Impl.visitPreorder(PredDep.getSUnit());
1400 DFS.follow(PredDep.getSUnit());
1401 }
1402 // Visit the top of the stack in postorder and backtrack.
1403 const SUnit *Child = DFS.getCurr();
1404 const SDep *PredDep = DFS.backtrack();
1405 Impl.visitPostorderNode(Child);
1406 if (PredDep)
1407 Impl.visitPostorderEdge(*PredDep, DFS.getCurr());
1408 if (DFS.isComplete())
1409 break;
1410 }
1411 }
1412 Impl.finalize();
1413}
1414
1415/// The root of the given SubtreeID was just scheduled. For all subtrees
1416/// connected to this tree, record the depth of the connection so that the
1417/// nearest connected subtrees can be prioritized.
1418void SchedDFSResult::scheduleTree(unsigned SubtreeID) {
1419 for (const Connection &C : SubtreeConnections[SubtreeID]) {
1420 SubtreeConnectLevels[C.TreeID] =
1421 std::max(SubtreeConnectLevels[C.TreeID], C.Level);
1422 LLVM_DEBUG(dbgs() << " Tree: " << C.TreeID << " @"
1423 << SubtreeConnectLevels[C.TreeID] << '\n');
1424 }
1425}
1426
1427#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1429 OS << InstrCount << " / " << Length << " = ";
1430 if (!Length)
1431 OS << "BADILP";
1432 else
1433 OS << format("%g", ((double)InstrCount / Length));
1434}
1435
1437 dbgs() << *this << '\n';
1438}
1439
1440[[maybe_unused]]
1442 Val.print(OS);
1443 return OS;
1444}
1445
1446#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > UseAA("aarch64-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:678
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static unsigned InstrCount
static Register UseReg(const MachineOperand &MO)
IRTranslator LLVM IR MI
Equivalence classes for small integers.
A common definition of LaneBitmask for use in TableGen and CodeGen.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
This file implements a map that provides insertion order iteration.
#define P(N)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static void toggleKills(const MachineRegisterInfo &MRI, LiveRegUnits &LiveRegs, MachineInstr &MI, bool addToLiveRegs)
static bool getUnderlyingObjectsForInstr(const MachineInstr *MI, const MachineFrameInfo &MFI, UnderlyingObjectsVector &Objects, const DataLayout &DL)
If this machine instruction has memory reference information, collect the list of underlying objects ...
static bool hasDataSucc(const SUnit *SU)
static cl::opt< bool > EnableSchedModel("schedmodel", cl::Hidden, cl::init(true), cl::desc("Use TargetSchedModel for latency lookup"))
static cl::opt< bool > EnableAASchedMI("enable-aa-sched-mi", cl::Hidden, cl::desc("Enable use of AA during MI DAG construction"))
static void dumpSUList(const ScheduleDAGInstrs::SUList &L)
static cl::opt< bool > UseTBAA("use-tbaa-in-sched-mi", cl::Hidden, cl::init(true), cl::desc("Enable use of TBAA during MI DAG construction"))
static cl::opt< unsigned > HugeRegion("dag-maps-huge-region", cl::Hidden, cl::init(500), cl::desc("The limit to use while constructing the DAG " "prior to scheduling, at which point a trade-off " "is made to avoid excessive compile time."))
static cl::opt< bool > EnableSchedItins("scheditins", cl::Hidden, cl::init(true), cl::desc("Use InstrItineraryData for latency lookup"))
static cl::opt< bool > SchedPrintCycles("sched-print-cycles", cl::Hidden, cl::init(false), cl::desc("Report top/bottom cycles when dumping SUnit instances"))
This file defines the SmallVector class.
This file defines the SparseSet class derived from the version described in Briggs,...
#define LLVM_DEBUG(...)
Definition Debug.h:119
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
void reComputeSize()
Counts the number of SUs in this map after a reduction.
void insert(SUnit *SU, ValueType V)
Adds SU to the SUList of V.
void clear()
Clears map from all contents.
void clearList(ValueType V)
Clears the list of SUs mapped to V.
ValueType & operator[](const SUList &Key)
To keep NumNodes up to date, insert() is used instead of this operator w/ push_back().
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
A set of register units used to track register liveness.
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.
bool hasImplicitUseOfPhysReg(MCRegister Reg) const
Return true if this instruction implicitly uses the specified physical register.
LLVM_ABI bool hasImplicitDefOfPhysReg(MCRegister Reg, const MCRegisterInfo *MRI=nullptr) const
Return true if this instruction implicitly defines the specified physical register.
MCRegUnitMaskIterator enumerates a list of register units and their associated lane masks for Reg.
bool isValid() const
Returns true if this iterator is not yet at the end.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
Instructions::iterator instr_iterator
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasTailCall() const
Returns true if the function contains a tail call.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ABI bool mayAlias(BatchAAResults *AA, const MachineInstr &Other, bool UseTBAA) const
Returns true if this instruction's memory access aliases the memory access of Other.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
LLVM_ABI void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
filtered_mop_range all_uses()
Returns an iterator range over all operands that are (explicit or implicit) register uses.
bool isTransient() const
Return true if this is a transient instruction that is either very likely to be eliminated during reg...
LLVM_ABI void dump() const
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
void setIsKill(bool Val=true)
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
iterator end()
Definition MapVector.h:69
ValueT & operator[](const KeyT &Key)
Definition MapVector.h:100
Array of PressureDiffs.
LLVM_ABI void addInstruction(unsigned Idx, const RegisterOperands &RegOpers, const MachineRegisterInfo &MRI)
Record pressure difference induced by the given operand list to node with index Idx.
LLVM_ABI void init(unsigned N)
Initialize an array of N PressureDiffs.
Special value supplied for machine level alias analysis.
Track the current register pressure at some position in the instruction stream, and remember the high...
LLVM_ABI void recede(SmallVectorImpl< VRegMaskOrUnit > *LiveUses=nullptr)
Recede across the previous instruction.
LLVM_ABI void recedeSkipDebugValues()
Recede until we find an instruction which is not a DebugValue.
MachineBasicBlock::const_iterator getPos() const
Get the MI position corresponding to this register pressure.
List of registers defined and used by a machine instruction.
LLVM_ABI void adjustLaneLiveness(const LiveIntervals &LIS, const MachineRegisterInfo &MRI, SlotIndex Pos)
Use liveness information to find out which uses/defs are partially undefined/dead at Pos and adjust t...
LLVM_ABI void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, bool TrackLaneMasks, bool IgnoreDead)
Analyze the given instruction MI and fill in the Uses, Defs and DeadDefs list based on the MachineOpe...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Scheduling dependency.
Definition ScheduleDAG.h:52
SUnit * getSUnit() const
Kind getKind() const
Returns an enum value representing the kind of the dependence.
Kind
These are the different kinds of scheduling dependencies.
Definition ScheduleDAG.h:55
@ Output
A register output-dependence (aka WAW).
Definition ScheduleDAG.h:58
@ Anti
A register anti-dependence (aka WAR).
Definition ScheduleDAG.h:57
@ Data
Regular data dependence (aka true-dependence).
Definition ScheduleDAG.h:56
void setLatency(unsigned Lat)
Sets the latency for this edge.
@ Artificial
Arbitrary strong DAG edge (no real dependence).
Definition ScheduleDAG.h:75
@ MayAliasMem
Nonvolatile load/Store instructions that may alias.
Definition ScheduleDAG.h:73
bool isArtificial() const
Tests if this is an Order dependence that is marked as "artificial", meaning it isn't necessary for c...
Scheduling unit. This is a node in the scheduling DAG.
bool isCall
Is a function call.
unsigned NumSuccs
unsigned TopReadyCycle
Cycle relative to start when node is ready.
unsigned NodeNum
Entry # of node in the node vector.
bool isUnbuffered
Uses an unbuffered resource.
SmallVectorImpl< SDep >::const_iterator const_pred_iterator
unsigned short Latency
Node latency.
bool isBoundaryNode() const
Boundary nodes are placeholders for the boundary of the scheduling region.
bool hasPhysRegDefs
Has physreg defs that are being used.
unsigned BotReadyCycle
Cycle relative to end when node is ready.
SmallVector< SDep, 4 > Succs
All sunit successors.
bool hasReservedResource
Uses a reserved resource.
bool isCommutable
Is a commutable instruction.
bool hasPhysRegUses
Has physreg uses.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
LLVM_ABI bool addPred(const SDep &D, bool Required=true)
Adds the specified edge as a pred of the current node if not already.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
void visitPostorderNode(const SUnit *SU)
Called once for each node after all predecessors are visited.
bool joinPredSubtree(const SDep &PredDep, const SUnit *Succ, bool CheckLimit=true)
Joins the predecessor subtree with the successor that is its DFS parent.
void addConnection(unsigned FromTree, unsigned ToTree, unsigned Depth)
Called by finalize() to record a connection between trees.
void finalize()
Sets each node's subtree ID to the representative ID and record connections between trees.
void visitCrossEdge(const SDep &PredDep, const SUnit *Succ)
Adds a connection for cross edges.
void visitPostorderEdge(const SDep &PredDep, const SUnit *Succ)
Called once for each tree edge after calling visitPostOrderNode on the predecessor.
void visitPreorder(const SUnit *SU)
Initializes this node's instruction count.
bool isVisited(const SUnit *SU) const
Returns true if this node been visited by the DFS traversal.
SchedDFSImpl(SchedDFSResult &r)
Compute the values of each DAG node for various metrics during DFS.
Definition ScheduleDFS.h:65
friend class SchedDFSImpl
Definition ScheduleDFS.h:66
LLVM_ABI void compute(ArrayRef< SUnit > SUnits)
Compute various metrics for the DAG with given roots.
LLVM_ABI void scheduleTree(unsigned SubtreeID)
Scheduler callback to update SubtreeConnectLevels when a tree is initially scheduled.
LiveRegUnits LiveRegs
Set of live physical registers for updating kill flags.
DenseMap< MachineInstr *, SUnit * > MISUnitMap
After calling BuildSchedGraph, each machine instruction in the current scheduling region is mapped to...
void addVRegUseDeps(SUnit *SU, unsigned OperIdx)
Adds a register data dependency if the instruction that defines the virtual register used at OperIdx ...
void addVRegDefDeps(SUnit *SU, unsigned OperIdx)
Adds register output and data dependencies from this SUnit to instructions that occur later in the sa...
virtual void finishBlock()
Cleans up after scheduling in the given block.
MachineBasicBlock::iterator end() const
Returns an iterator to the bottom of the current scheduling region.
std::string getDAGName() const override
Returns a label for the region of code covered by the DAG.
MachineBasicBlock * BB
The block in which to insert instructions.
virtual void startBlock(MachineBasicBlock *BB)
Prepares to perform scheduling in the given block.
bool CanHandleTerminators
The standard DAG builder does not normally include terminators as DAG nodes because it does not creat...
void addBarrierChain(Value2SUsMap &map)
Adds barrier chain edges from all SUs in map, and then clear the map.
void addPhysRegDeps(SUnit *SU, unsigned OperIdx)
Adds register dependencies (data, anti, and output) from this SUnit to following instructions in the ...
MachineBasicBlock::iterator RegionEnd
The end of the range to be scheduled.
VReg2SUnitOperIdxMultiMap CurrentVRegUses
Tracks the last instructions in this region using each virtual register.
void addChainDependencies(SUnit *SU, SUList &SUs, unsigned Latency)
Adds dependencies as needed from all SUs in list to SU.
const MCSchedClassDesc * getSchedClass(SUnit *SU) const
Resolves and cache a resolved scheduling class for an SUnit.
void fixupKills(MachineBasicBlock &MBB)
Fixes register kill flags that scheduling has made invalid.
void addPhysRegDataDeps(SUnit *SU, unsigned OperIdx)
MO is an operand of SU's instruction that defines a physical register.
ScheduleDAGInstrs(MachineFunction &mf, const MachineLoopInfo *mli, bool RemoveKillFlags=false)
LaneBitmask getLaneMaskForMO(const MachineOperand &MO) const
Returns a mask for which lanes get read/written by the given (register) machine operand.
DbgValueVector DbgValues
Remember instruction that precedes DBG_VALUE.
SUnit * newSUnit(MachineInstr *MI)
Creates a new SUnit and return a ptr to it.
void initSUnits()
Creates an SUnit for each real instruction, numbered in top-down topological order.
bool addEdge(SUnit *SuccSU, const SDep &PredDep)
Add a DAG edge to the given SU with the given predecessor dependence data.
ScheduleDAGTopologicalSort Topo
Topo - A topological ordering for SUnits which permits fast IsReachable and similar queries.
std::list< SUnit * > SUList
A list of SUnits, used in Value2SUsMap, during DAG construction.
SUnit * BarrierChain
Remember a generic side-effecting instruction as we proceed.
BatchAAResults * getAAForDep() const
Returns a (possibly null) pointer to the current BatchAAResults.
bool TrackLaneMasks
Whether lane masks should get tracked.
void dumpNode(const SUnit &SU) const override
RegUnit2SUnitsMap Defs
Defs, Uses - Remember where defs and uses of each register are as we iterate upward through the instr...
UndefValue * UnknownValue
For an unanalyzable memory access, this Value is used in maps.
VReg2SUnitMultiMap CurrentVRegDefs
Tracks the last instruction(s) in this region defining each virtual register.
MachineBasicBlock::iterator begin() const
Returns an iterator to the top of the current scheduling region.
void buildSchedGraph(AAResults *AA, RegPressureTracker *RPTracker=nullptr, PressureDiffs *PDiffs=nullptr, LiveIntervals *LIS=nullptr, bool TrackLaneMasks=false)
Builds SUnits for the current region.
TargetSchedModel SchedModel
TargetSchedModel provides an interface to the machine model.
virtual void exitRegion()
Called when the scheduler has finished scheduling the current region.
bool canAddEdge(SUnit *SuccSU, SUnit *PredSU)
True if an edge can be added from PredSU to SuccSU without creating a cycle.
const MachineLoopInfo * MLI
bool RemoveKillFlags
True if the DAG builder should remove kill flags (in preparation for rescheduling).
std::optional< BatchAAResults > AAForDep
MachineBasicBlock::iterator RegionBegin
The beginning of the range to be scheduled.
void addSchedBarrierDeps()
Adds dependencies from instructions in the current list of instructions being scheduled to scheduling...
virtual void enterRegion(MachineBasicBlock *bb, MachineBasicBlock::iterator begin, MachineBasicBlock::iterator end, unsigned regioninstrs)
Initialize the DAG and common scheduler state for a new scheduling region.
void dump() const override
void addChainDependency(SUnit *SUa, SUnit *SUb, unsigned Latency=0)
Adds a chain edge between SUa and SUb, but only if both AAResults and Target fail to deny the depende...
unsigned NumRegionInstrs
Instructions in this region (distance(RegionBegin, RegionEnd)).
const MachineFrameInfo & MFI
bool deadDefHasNoUse(const MachineOperand &MO)
Returns true if the def register in MO has no uses.
std::string getGraphNodeLabel(const SUnit *SU) const override
Returns a label for a DAG node that points to an instruction.
MachineRegisterInfo & MRI
Virtual/real register map.
void clearDAG()
Clears the DAG state (between regions).
const TargetInstrInfo * TII
Target instruction information.
std::vector< SUnit > SUnits
The scheduling units.
const TargetRegisterInfo * TRI
Target processor register info.
SUnit EntrySU
Special node for the region entry.
MachineFunction & MF
Machine function.
ScheduleDAG(const ScheduleDAG &)=delete
void dumpNodeAll(const SUnit &SU) const
void dumpNodeName(const SUnit &SU) const
SUnit ExitSU
Special node for the region exit.
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:66
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
Definition SparseSet.h:117
TargetInstrInfo - Interface to description of machine instruction set.
TargetSubtargetInfo - Generic base class for all target subtargets.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
'undef' values are things that do not have specified contents.
Definition Constants.h:1647
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
Definition Attributor.h:165
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
SmallVector< ValueType, 4 > UnderlyingObjectsVector
LLVM_ABI bool getUnderlyingObjectsForCodeGen(const Value *V, SmallVectorImpl< Value * > &Objects)
This is a wrapper around getUnderlyingObjects and adds support for basic ptrtoint+arithmetic+inttoptr...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Represent the ILP of the subDAG rooted at a DAG node.
Definition ScheduleDFS.h:34
unsigned Length
Length may either correspond to depth or height, depending on direction, and cycles or nodes dependin...
Definition ScheduleDFS.h:38
LLVM_ABI void dump() const
LLVM_ABI void print(raw_ostream &OS) const
unsigned InstrCount
Definition ScheduleDFS.h:35
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
constexpr bool any() const
Definition LaneBitmask.h:53
Summarize the scheduling resources required for an instruction of a particular scheduling class.
Definition MCSchedule.h:129
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...
Definition MCSchedule.h:74
Record a physical register access.
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:342
Mapping from virtual register to SUnit including an operand index.
An individual mapping from virtual register number to SUnit.