42#include "llvm/Config/llvm-config.h"
62#define DEBUG_TYPE "machine-scheduler"
84 bool AllObjectsIdentified =
true;
88 if (MMO->isVolatile() || MMO->isAtomic()) {
89 AllObjectsIdentified =
false;
100 AllObjectsIdentified =
false;
101 }
else if (PSV->isAliased(&MFI)) {
105 AllObjectsIdentified =
false;
109 }
else if (
const Value *
V = MMO->getValue()) {
112 AllObjectsIdentified &= ObjectsIdentified;
119 AllObjectsIdentified =
false;
123 return AllObjectsIdentified;
138 unsigned regioninstrs) {
139 assert(bb ==
BB &&
"startBlock should set BB");
159 unsigned OpIdx = MO.getOperandNo();
161 if (Reg.isPhysical()) {
172 for (MCRegUnit Unit :
TRI->regunits(Reg))
174 }
else if (Reg.isVirtual() && MO.readsReg()) {
183 for (
const auto &LI : Succ->liveins()) {
185 auto [Unit, Mask] = *U;
186 if ((Mask & LI.LaneMask).any() && !
Uses.contains(Unit))
207 bool ImplicitPseudoDef = (OperIdx >= DefMIDesc.
getNumOperands() &&
211 for (MCRegUnit Unit :
TRI->regunits(Reg)) {
221 int UseOpIdx =
I->OpIdx;
222 bool ImplicitPseudoUse =
false;
223 bool IsInlineAsmUse =
false;
239 ImplicitPseudoUse = UseOpIdx >= ((int)UseMIDesc.
getNumOperands()) &&
245 if ((!ImplicitPseudoDef && !ImplicitPseudoUse) ||
246 (IsInlineAsmDef && IsInlineAsmUse)) {
248 UseInstr, UseOpIdx));
252 ST.adjustSchedDependency(SU, OperIdx, UseSU, UseOpIdx, Dep, &
SchedModel);
266 if (
MRI.isConstantPhysReg(Reg))
278 for (MCRegUnit Unit :
TRI->regunits(Reg)) {
291 SchedModel.computeOutputLatency(
MI, OperIdx, DefInstr));
293 ST.adjustSchedDependency(SU, OperIdx, DefSU,
I->OpIdx, Dep,
305 for (MCRegUnit Unit :
TRI->regunits(Reg))
313 for (MCRegUnit Unit :
TRI->regunits(Reg)) {
325 for (MCRegUnit Unit :
TRI->regunits(Reg)) {
329 for (
bool isBegin =
I ==
B; !isBegin; ) {
330 isBegin = (--
I) ==
B;
339 for (MCRegUnit Unit :
TRI->regunits(Reg))
355 return TRI->getSubRegIndexLaneMask(SubReg);
392 if (OtherMO.isReg() && OtherMO.isDef() && OtherMO.getReg() == Reg)
413 if ((LaneMask & KillLaneMask).
none()) {
418 if ((LaneMask & DefLaneMask).any()) {
424 ST.adjustSchedDependency(SU, OperIdx, UseSU,
I->OperandIndex, Dep,
429 LaneMask &= ~KillLaneMask;
431 if (LaneMask.
any()) {
432 I->LaneMask = LaneMask;
440 if (
MRI.hasOneDef(Reg))
454 if ((V2SU.LaneMask & LaneMask).none())
457 SUnit *DefSU = V2SU.SU;
473 LaneBitmask OverlapMask = V2SU.LaneMask & LaneMask;
474 LaneBitmask NonOverlapMask = V2SU.LaneMask & ~LaneMask;
476 V2SU.LaneMask = OverlapMask;
477 if (NonOverlapMask.
any())
493 assert(!
MI->isDebugOrPseudoInstr());
508 if ((PrevDefLaneMask & LaneMask).
none())
535 if (
MI.isDebugOrPseudoInstr())
560 switch (
SchedModel.getResourceBufferSize(PRE.ProcResourceIdx)) {
581using SUList = std::list<SUnit *>;
587 const CodeGenOptions &Opts;
620 struct MemopFrontier {
622 SUnit *SequencingStore =
nullptr;
624 SUList Stores, Loads;
627 unsigned size()
const;
661 struct UnanalyzableMemopFrontier {
663 MemopFrontier Frontier;
668 bool SeenSequencingLoad =
false;
681 UnanalyzableMemopFrontier UnanalyzableFrontier;
686 SUnit *BarrierChain =
nullptr;
688 unsigned MemOpsProcessed = 0;
692 unsigned MemopsInFlight = 0;
698 : Opts(DAG.Opts), DAG(DAG), AA(AA), RPTracker(RPTracker), PDiffs(PDiffs),
709 void addChainDependencies(
SUnit *SU, SUList &SUs,
unsigned Latency);
710 void addChainDependencies(
SUnit *SU, MemopFrontier &
F,
bool IsStore);
712 void addBarrierChain(SUList &SUs);
713 void addBarrierChain(MemopFrontier &
F);
717 void addBarrierMemoryDeps();
721 bool shouldUpdate(
const MemopFrontier &
F)
const;
726 bool shouldUpdate(
const UnanalyzableMemopFrontier &UF,
732 void updateSequencingStore(MemopFrontier &
F,
SUnit *SU,
733 bool PreserveNoAliasLoads =
false);
737 void updateSequencingStore(UnanalyzableMemopFrontier &UF,
SUnit *SU,
745unsigned ScheduleDAGDependencyBuilder::MemopFrontier::size()
const {
746 return Loads.size() + Stores.size();
749void ScheduleDAGDependencyBuilder::MemopFrontier::clear() {
750 SequencingStore =
nullptr;
755bool ScheduleDAGDependencyBuilder::shouldUpdate(
const MemopFrontier &
F)
const {
756 if (!Opts.store_sequencing)
758 return F.size() >= Opts.store_sequencing_max_frontier_size;
761bool ScheduleDAGDependencyBuilder::shouldUpdate(
762 const UnanalyzableMemopFrontier &UF,
764 if (!Opts.store_sequencing)
766 return shouldUpdate(
UF.Frontier) || !
UF.Frontier.SequencingStore ||
767 UF.SeenSequencingLoad ||
UF.escapesBaseObjects(Objs);
770bool ScheduleDAGDependencyBuilder::UnanalyzableMemopFrontier::
780void ScheduleDAGDependencyBuilder::UnanalyzableMemopFrontier::clear() {
782 SeenSequencingLoad =
false;
786bool ScheduleDAGDependencyBuilder::addChainDependency(SUnit *SUa, SUnit *SUb,
797void ScheduleDAGDependencyBuilder::addChainDependencies(SUnit *SU, SUList &SUs,
799 for (SUnit *Entry : SUs)
800 addChainDependency(SU, Entry,
Latency);
803void ScheduleDAGDependencyBuilder::addChainDependencies(SUnit *SU,
806 if (
F.SequencingStore)
807 F.SequencingStore->addPredBarrier(SU);
809 addChainDependencies(SU,
F.Stores, 0);
811 addChainDependencies(SU,
F.Loads, 1);
814void ScheduleDAGDependencyBuilder::addBarrierChain(SUList &SUs) {
815 assert(BarrierChain !=
nullptr);
823void ScheduleDAGDependencyBuilder::addBarrierChain(MemopFrontier &
F) {
824 assert(BarrierChain !=
nullptr);
826 addBarrierChain(
F.Stores);
827 addBarrierChain(
F.Loads);
829 if (
F.SequencingStore)
830 F.SequencingStore->addPredBarrier(BarrierChain);
835void ScheduleDAGDependencyBuilder::addBarrierMemoryDeps() {
836 assert(BarrierChain !=
nullptr);
838 addBarrierChain(UnanalyzableFrontier.Frontier);
839 UnanalyzableFrontier.clear();
841 for (
auto &[
_, AF] : AnalyzableFrontiers)
843 AnalyzableFrontiers.clear();
848void ScheduleDAGDependencyBuilder::updateSequencingStore(
849 MemopFrontier &
F, SUnit *SU,
bool PreserveNoAliasLoads) {
851 "Only store instructions should be used as sequencing stores");
852 LLVM_DEBUG(
dbgs() <<
"Promoting " << *SU <<
" to sequencing store\n");
855 MemopsInFlight -=
F.size();
857 if (
F.SequencingStore) {
858 F.SequencingStore->addPredBarrier(SU);
865 for (SUnit *S :
F.Stores)
870 if (PreserveNoAliasLoads) {
876 for (
auto It =
F.Loads.begin(); It !=
F.Loads.end();) {
877 if (addChainDependency(SU, *It, 1)) {
878 It =
F.Loads.erase(It);
885 MemopsInFlight +=
F.Loads.size();
888 for (SUnit *S :
F.Loads)
894 F.SequencingStore = SU;
897void ScheduleDAGDependencyBuilder::updateSequencingStore(
900 "Only store instructions should be used as sequencing stores");
903 bool ShouldPreserveNoAliasLoads = !shouldUpdate(
UF.Frontier);
904 updateSequencingStore(
UF.Frontier, SU,
905 ShouldPreserveNoAliasLoads);
906 UF.BaseObjects = std::move(Objs);
907 UF.SeenSequencingLoad =
false;
918 DAG.addSchedBarrierDeps();
926 DAG.DbgValues.emplace_back(DbgMI, &
MI);
930 if (
MI.isDebugValue() ||
MI.isDebugPHI()) {
935 if (
MI.isDebugLabel() ||
MI.isDebugRef() ||
MI.isPseudoProbe())
938 SUnit *SU = DAG.MISUnitMap[&
MI];
939 assert(SU &&
"No SUnit mapped to this MI");
943 RegOpers.
collect(
MI, *DAG.TRI, DAG.MRI, DAG.TrackLaneMasks,
false);
944 if (DAG.TrackLaneMasks) {
952 if (PDiffs !=
nullptr)
953 PDiffs->addInstruction(SU->
NodeNum, RegOpers, DAG.MRI);
955 if (RPTracker->getPos() == DAG.RegionEnd || &*RPTracker->getPos() != &
MI)
956 RPTracker->recedeSkipDebugValues();
957 assert(&*RPTracker->getPos() == &
MI &&
"RPTracker in sync");
958 RPTracker->recede(RegOpers);
961 assert((DAG.CanHandleTerminators ||
962 (!
MI.isTerminator() && !
MI.isPosition())) &&
963 "Cannot schedule terminators or labels!");
970 bool HasVRegDef =
false;
971 for (
unsigned j = 0, n =
MI.getNumOperands(); j != n; ++j) {
976 if (Reg.isPhysical()) {
977 DAG.addPhysRegDeps(SU, j);
978 }
else if (Reg.isVirtual()) {
980 DAG.addVRegDefDeps(SU, j);
984 for (
unsigned j = 0, n =
MI.getNumOperands(); j != n; ++j) {
993 if (Reg.isPhysical()) {
994 DAG.addPhysRegDeps(SU, j);
995 }
else if (Reg.isVirtual() && MO.
readsReg()) {
996 DAG.addVRegUseDeps(SU, j);
1009 DAG.ExitSU.addPred(Dep);
1018 if (
TII->isGlobalMemoryObject(&
MI)) {
1022 BarrierChain->addPredBarrier(SU);
1025 LLVM_DEBUG(
dbgs() <<
"Global memory object and new barrier chain: "
1026 << *BarrierChain <<
".\n");
1029 addBarrierChain(FPExceptions);
1030 addBarrierMemoryDeps();
1037 if (
MI.mayRaiseFPException()) {
1039 BarrierChain->addPredBarrier(SU);
1041 if (!Opts.store_sequencing &&
1042 FPExceptions.size() + 1 >= Opts.dag_maps_huge_region) {
1045 <<
"Creating barrier chain and clearing FPExceptions map.\n");
1047 addBarrierChain(FPExceptions);
1049 FPExceptions.push_back(SU);
1054 if (!
MI.mayStore() &&
1055 !(
MI.mayLoad() && !
MI.isDereferenceableInvariantLoad()))
1061 if (BarrierChain && BarrierChain != SU)
1062 BarrierChain->addPredBarrier(SU);
1065 if (!Opts.store_sequencing &&
1066 MemOpsProcessed >= Opts.dag_maps_huge_region) {
1067 LLVM_DEBUG(
dbgs() <<
"Creating barrier chain and clearing maps.\n");
1070 addBarrierMemoryDeps();
1072 MemOpsProcessed = 0;
1078 if (Opts.store_sequencing &&
1079 MemopsInFlight >= Opts.store_sequencing_max_memops_in_flight) {
1080 LLVM_DEBUG(
dbgs() <<
"Number of in-flight memory operations reached "
1081 << Opts.store_sequencing_max_memops_in_flight
1082 <<
", promoting " << *SU
1083 <<
" to barrier chain and clearing maps.\n");
1086 addBarrierMemoryDeps();
1095 DAG.MF.getDataLayout());
1096 bool IsStore =
MI.mayStore();
1098 if (!ObjsIdentified) {
1100 for (
auto &[
_, AF] : AnalyzableFrontiers)
1101 addChainDependencies(SU, AF, IsStore);
1103 if (IsStore && shouldUpdate(UnanalyzableFrontier, Objs)) {
1104 updateSequencingStore(UnanalyzableFrontier, SU, std::move(Objs));
1106 if (!IsStore && UnanalyzableFrontier.escapesBaseObjects(Objs))
1107 UnanalyzableFrontier.SeenSequencingLoad =
true;
1108 addChainDependencies(SU, UnanalyzableFrontier.Frontier, IsStore);
1109 (IsStore ? UnanalyzableFrontier.Frontier.Stores
1110 : UnanalyzableFrontier.Frontier.Loads)
1120 if (!SeenValues.
insert(V).second)
1123 MemopFrontier &Frontier = AnalyzableFrontiers[V];
1125 if (IsStore && shouldUpdate(Frontier)) {
1126 updateSequencingStore(Frontier, SU);
1128 addChainDependencies(SU, Frontier, IsStore);
1129 (IsStore ? Frontier.Stores : Frontier.Loads).push_back(SU);
1135 addChainDependencies(SU, UnanalyzableFrontier.Frontier, IsStore);
1140 DAG.FirstDbgValue = DbgMI;
1166 "Only BuildGraph should update Defs/Uses");
1167 Defs.setUniverse(
TRI->getNumRegs());
1168 Uses.setUniverse(
TRI->getNumRegs());
1172 unsigned NumVirtRegs =
MRI.getNumVirtRegs();
1176 std::optional<BatchAAResults> BatchAA;
1178 BatchAA.emplace(*
AA);
1181 *
this, BatchAA.has_value() ? &BatchAA.value() :
nullptr, RPTracker,
1194 PSV->printCustom(OS);
1201 if (!MO.isReg() || !MO.readsReg())
1211 MO.setIsKill(IsKill && !
MRI.isReserved(
Reg));
1225 if (
MI.isDebugOrPseudoInstr())
1246 if (!
MI.isBundled()) {
1257 while (
I->isBundledWithSucc())
1260 if (!
I->isDebugOrPseudoInstr())
1263 }
while (
I != Bundle);
1269#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1272 if (
Opts.sched_print_cycles)
1282#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1283 if (
EntrySU.getInstr() !=
nullptr)
1287 if (
ExitSU.getInstr() !=
nullptr)
1292#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
1293std::string ScheduleDAGInstrs::getGraphNodeLabel(
const SUnit *SU)
const {
1298 else if (SU == &ExitSU)
1309 return "dag." +
BB->getFullName();
1313 return SuccSU == &
ExitSU || !
Topo.IsReachable(PredSU, SuccSU);
1342 std::vector<std::pair<const SUnit *, const SUnit*>> ConnectionPairs;
1346 unsigned ParentNodeID;
1347 unsigned SubInstrCount = 0;
1350 RootData(
unsigned id): NodeID(
id),
1351 ParentNodeID(SchedDFSResult::InvalidSubtreeID) {}
1353 unsigned getSparseSetIndex()
const {
return NodeID; }
1360 RootSet.setUniverse(R.DFSNodeData.size());
1368 return R.DFSNodeData[SU->
NodeNum].SubtreeID
1369 != SchedDFSResult::InvalidSubtreeID;
1375 R.DFSNodeData[SU->
NodeNum].InstrCount =
1399 if ((
InstrCount - R.DFSNodeData[PredNum].InstrCount) < R.SubtreeLimit)
1403 if (R.DFSNodeData[PredNum].SubtreeID == PredNum) {
1406 if (RootSet[PredNum].ParentNodeID == SchedDFSResult::InvalidSubtreeID)
1407 RootSet[PredNum].ParentNodeID = SU->
NodeNum;
1409 else if (RootSet.count(PredNum)) {
1414 RData.SubInstrCount += RootSet[PredNum].SubInstrCount;
1415 RootSet.erase(PredNum);
1425 R.DFSNodeData[Succ->
NodeNum].InstrCount
1432 ConnectionPairs.emplace_back(PredDep.
getSUnit(), Succ);
1438 SubtreeClasses.compress();
1439 R.DFSTreeData.resize(SubtreeClasses.getNumClasses());
1440 assert(SubtreeClasses.getNumClasses() == RootSet.size()
1441 &&
"number of roots should match trees");
1442 for (
const RootData &Root : RootSet) {
1443 unsigned TreeID = SubtreeClasses[Root.NodeID];
1444 if (Root.ParentNodeID != SchedDFSResult::InvalidSubtreeID)
1445 R.DFSTreeData[TreeID].ParentTreeID = SubtreeClasses[Root.ParentNodeID];
1446 R.DFSTreeData[TreeID].SubInstrCount = Root.SubInstrCount;
1452 R.SubtreeConnections.resize(SubtreeClasses.getNumClasses());
1453 R.SubtreeConnectLevels.resize(SubtreeClasses.getNumClasses());
1455 for (
unsigned Idx = 0,
End = R.DFSNodeData.size(); Idx !=
End; ++Idx) {
1456 R.DFSNodeData[Idx].SubtreeID = SubtreeClasses[Idx];
1458 << R.DFSNodeData[Idx].SubtreeID <<
'\n');
1460 for (
const auto &[Pred, Succ] : ConnectionPairs) {
1461 unsigned PredTree = SubtreeClasses[Pred->NodeNum];
1462 unsigned SuccTree = SubtreeClasses[Succ->NodeNum];
1463 if (PredTree == SuccTree)
1465 unsigned Depth = Pred->getDepth();
1475 bool CheckLimit =
true) {
1480 unsigned PredNum = PredSU->
NodeNum;
1481 if (R.DFSNodeData[PredNum].SubtreeID != PredNum)
1486 unsigned NumDataSucs = 0;
1487 for (
const SDep &SuccDep : PredSU->
Succs) {
1489 if (++NumDataSucs >= 4)
1493 if (CheckLimit && R.DFSNodeData[PredNum].InstrCount > R.SubtreeLimit)
1495 R.DFSNodeData[PredNum].SubtreeID = Succ->
NodeNum;
1496 SubtreeClasses.join(Succ->
NodeNum, PredNum);
1507 R.SubtreeConnections[FromTree];
1508 for (SchedDFSResult::Connection &
C : Connections) {
1509 if (
C.TreeID == ToTree) {
1510 C.Level = std::max(
C.Level,
Depth);
1514 Connections.
push_back(SchedDFSResult::Connection(ToTree,
Depth));
1515 FromTree = R.DFSTreeData[FromTree].ParentTreeID;
1516 }
while (FromTree != SchedDFSResult::InvalidSubtreeID);
1525class SchedDAGReverseDFS {
1526 std::vector<std::pair<const SUnit *, SUnit::const_pred_iterator>> DFSStack;
1529 bool isComplete()
const {
return DFSStack.empty(); }
1531 void follow(
const SUnit *SU) {
1532 DFSStack.emplace_back(SU, SU->
Preds.begin());
1534 void advance() { ++DFSStack.back().second; }
1536 const SDep *backtrack() {
1537 DFSStack.pop_back();
1538 return DFSStack.empty() ? nullptr : std::prev(DFSStack.back().second);
1541 const SUnit *getCurr()
const {
return DFSStack.back().first; }
1546 return getCurr()->Preds.
end();
1568 for (
const SUnit &SU : SUnits) {
1572 SchedDAGReverseDFS DFS;
1573 Impl.visitPreorder(&SU);
1577 while (DFS.getPred() != DFS.getPredEnd()) {
1578 const SDep &PredDep = *DFS.getPred();
1586 if (Impl.isVisited(PredDep.
getSUnit())) {
1587 Impl.visitCrossEdge(PredDep, DFS.getCurr());
1590 Impl.visitPreorder(PredDep.
getSUnit());
1594 const SUnit *Child = DFS.getCurr();
1595 const SDep *PredDep = DFS.backtrack();
1596 Impl.visitPostorderNode(Child);
1598 Impl.visitPostorderEdge(*PredDep, DFS.getCurr());
1599 if (DFS.isComplete())
1603 Impl.finalize(SUnits);
1610 for (
const Connection &
C : SubtreeConnections[SubtreeID]) {
1611 SubtreeConnectLevels[
C.TreeID] =
1612 std::max(SubtreeConnectLevels[
C.TreeID],
C.Level);
1614 << SubtreeConnectLevels[
C.TreeID] <<
'\n');
1618#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1628 dbgs() << *
this <<
'\n';
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
static unsigned InstrCount
static Register UseReg(const MachineOperand &MO)
const HexagonInstrInfo * TII
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.
static cl::opt< bool > UseAA("loongarch-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
This file implements a map that provides insertion order iteration.
MachineRegisterInfo & MRI
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)
This file defines the SmallVector class.
This file defines the SparseSet class derived from the version described in Briggs,...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
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.
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.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
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
LLVM_ABI int findInlineAsmFlagIdx(unsigned OpIdx, unsigned *GroupNo=nullptr) const
Find the index of the flag word operand that corresponds to operand OpIdx on an inline asm instructio...
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,...
This class implements a map that also provides access to all stored values in a deterministic order.
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...
List of registers defined and used by a machine instruction.
LLVM_ABI void detectDeadDefs(const MachineInstr &MI, LiveIntervals &LIS, const MachineRegisterInfo &MRI)
Use liveness information to find dead defs at MI's dead slot not marked with a dead flag and move the...
LLVM_ABI void adjustLaneLiveness(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.
Kind getKind() const
Returns an enum value representing the kind of the dependence.
Kind
These are the different kinds of scheduling dependencies.
@ Output
A register output-dependence (aka WAW).
@ Anti
A register anti-dependence (aka WAR).
@ Data
Regular data dependence (aka true-dependence).
void setLatency(unsigned Lat)
Sets the latency for this edge.
@ Artificial
Arbitrary strong DAG edge (no real dependence).
@ MayAliasMem
Nonvolatile load/Store instructions that may alias.
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.
bool addPredBarrier(SUnit *SU)
Adds a barrier edge to SU by calling addPred(), with latency 0 generally or latency 1 for a store fol...
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 visitCrossEdge(const SDep &PredDep, const SUnit *Succ)
Adds a connection for cross edges.
void finalize(ArrayRef< SUnit > SUnits)
Sets each node's subtree ID to the representative ID and record connections between trees.
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.
friend class SchedDFSImpl
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.
ScheduleDAGDependencyBuilder(ScheduleDAGInstrs &DAG, BatchAAResults *AA, RegPressureTracker *RPTracker, PressureDiffs *PDiffs, LiveIntervals *LIS)
A ScheduleDAG for scheduling lists of MachineInstr.
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.
MachineInstr * FirstDbgValue
virtual void startBlock(MachineBasicBlock *BB)
Prepares to perform scheduling in the given block.
void addPhysRegDeps(SUnit *SU, unsigned OperIdx)
Adds register dependencies (data, anti, and output) from this SUnit to following instructions in the ...
const CodeGenOptions & Opts
friend class ScheduleDAGDependencyBuilder
MachineBasicBlock::iterator RegionEnd
The end of the range to be scheduled.
VReg2SUnitOperIdxMultiMap CurrentVRegUses
Tracks the last instructions in this region using each virtual register.
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.
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...
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).
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
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.
MachineRegisterInfo & MRI
Virtual/real register map.
void clearDAG()
Clears the DAG state (between regions).
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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.
std::pair< iterator, iterator > RangePair
iterator_base< SparseMultiSet * > iterator
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
TargetInstrInfo - Interface to description of machine instruction set.
TargetSubtargetInfo - Generic base class for all target subtargets.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
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 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.
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.
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.
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)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
constexpr bool valueOr(BoolOrDefault X, bool Default)
@ End
Run the machine verifier once, at the end of the pipeline.
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.
const CodeGenOptions & getCodeGenOptions(const LLVMContext &C)
MCRegisterClass TargetRegisterClass
Represent the ILP of the subDAG rooted at a DAG node.
unsigned Length
Length may either correspond to depth or height, depending on direction, and cycles or nodes dependin...
LLVM_ABI void dump() const
LLVM_ABI void print(raw_ostream &OS) const
static constexpr LaneBitmask getAll()
constexpr bool any() const
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...
Record a physical register access.
Mapping from virtual register to SUnit including an operand index.
An individual mapping from virtual register number to SUnit.