47 cl::desc(
"Disable hazard detection during preRA scheduling"));
51 cl::desc(
"Enable reassociation of accumulation chains"));
55 cl::desc(
"Minimum length of accumulator chains "
56 "required for the optimization to kick in"));
60 cl::desc(
"Maximum number of branches in the accumulator tree"));
65 unsigned OpNum)
const {
66 if (OpNum >=
MCID.getNumOperands())
77 return TRI.getRegClass(RegClass);
91 unsigned Quantity)
const {
92 for (
unsigned i = 0; i < Quantity; ++i)
117 unsigned MaxInstLength)
const {
119 bool AtInsnStart =
true;
121 if (MaxInstLength == 0)
123 for (; *Str; ++Str) {
133 if (AtInsnStart && !
isSpace(
static_cast<unsigned char>(*Str))) {
134 unsigned AddLength = MaxInstLength;
135 if (strncmp(Str,
".space", 6) == 0) {
138 SpaceSize = strtol(Str + 6, &EStr, 10);
139 SpaceSize = SpaceSize < 0 ? 0 : SpaceSize;
140 while (*EStr !=
'\n' &&
isSpace(
static_cast<unsigned char>(*EStr)))
142 if (*EStr ==
'\0' || *EStr ==
'\n' ||
144 AddLength = SpaceSize;
158 while (++
I != E &&
I->isInsideBundle()) {
159 assert(!
I->isBundle() &&
"No nested bundle!");
174 while (!
MBB->succ_empty())
175 MBB->removeSuccessor(
MBB->succ_begin());
182 while (Tail !=
MBB->end()) {
184 if (
MI->shouldUpdateAdditionalCallInfo())
185 MBB->getParent()->eraseAdditionalCallInfo(&*
MI);
192 MBB->addSuccessor(NewDest);
196 bool NewMI,
unsigned Idx1,
197 unsigned Idx2)
const {
199 bool HasDef =
MCID.getNumDefs();
200 if (HasDef && !
MI.getOperand(0).isReg())
204 unsigned CommutableOpIdx1 = Idx1; (void)CommutableOpIdx1;
205 unsigned CommutableOpIdx2 = Idx2; (void)CommutableOpIdx2;
207 CommutableOpIdx1 == Idx1 && CommutableOpIdx2 == Idx2 &&
208 "TargetInstrInfo::CommuteInstructionImpl(): not commutable operands.");
209 assert(
MI.getOperand(Idx1).isReg() &&
MI.getOperand(Idx2).isReg() &&
210 "This only knows how to commute register operands so far");
215 unsigned SubReg0 = HasDef ?
MI.getOperand(0).getSubReg() : 0;
216 unsigned SubReg1 =
MI.getOperand(Idx1).getSubReg();
217 unsigned SubReg2 =
MI.getOperand(Idx2).getSubReg();
218 bool Reg1IsKill =
MI.getOperand(Idx1).isKill();
219 bool Reg2IsKill =
MI.getOperand(Idx2).isKill();
220 bool Reg1IsUndef =
MI.getOperand(Idx1).isUndef();
221 bool Reg2IsUndef =
MI.getOperand(Idx2).isUndef();
222 bool Reg1IsInternal =
MI.getOperand(Idx1).isInternalRead();
223 bool Reg2IsInternal =
MI.getOperand(Idx2).isInternalRead();
226 bool Reg1IsRenamable =
227 Reg1.
isPhysical() ?
MI.getOperand(Idx1).isRenamable() :
false;
228 bool Reg2IsRenamable =
229 Reg2.
isPhysical() ?
MI.getOperand(Idx2).isRenamable() :
false;
236 if (HasDef &&
MI.hasImplicitDef()) {
241 if ((ImplReg.
isVirtual() && ImplReg == Reg0) ||
243 TRI.isSubRegisterEq(ImplReg, Reg0)))
244 UpdateImplicitDefIdx.
push_back(OpNo +
MI.getNumExplicitOperands());
250 if (HasDef && Reg0 == Reg1 &&
255 }
else if (HasDef && Reg0 == Reg2 &&
266 CommutedMI = MF.CloneMachineInstr(&
MI);
274 for (
unsigned Idx : UpdateImplicitDefIdx)
298 unsigned OpIdx2)
const {
305 "Precondition violation: MI must be commutable.");
312 unsigned &ResultIdx2,
313 unsigned CommutableOpIdx1,
314 unsigned CommutableOpIdx2) {
317 ResultIdx1 = CommutableOpIdx1;
318 ResultIdx2 = CommutableOpIdx2;
320 if (ResultIdx2 == CommutableOpIdx1)
321 ResultIdx1 = CommutableOpIdx2;
322 else if (ResultIdx2 == CommutableOpIdx2)
323 ResultIdx1 = CommutableOpIdx1;
327 if (ResultIdx1 == CommutableOpIdx1)
328 ResultIdx2 = CommutableOpIdx2;
329 else if (ResultIdx1 == CommutableOpIdx2)
330 ResultIdx2 = CommutableOpIdx1;
336 return (ResultIdx1 == CommutableOpIdx1 && ResultIdx2 == CommutableOpIdx2) ||
337 (ResultIdx1 == CommutableOpIdx2 && ResultIdx2 == CommutableOpIdx1);
344 unsigned &SrcOpIdx2)
const {
346 "TargetInstrInfo::findCommutedOpIndices() can't handle bundles");
349 if (!
MCID.isCommutable())
354 unsigned CommutableOpIdx1 =
MCID.getNumDefs();
355 unsigned CommutableOpIdx2 = CommutableOpIdx1 + 1;
357 CommutableOpIdx1, CommutableOpIdx2))
360 if (!
MI.getOperand(SrcOpIdx1).isReg() || !
MI.getOperand(SrcOpIdx2).isReg())
367 if (!
MI.isTerminator())
return false;
370 if (
MI.isBranch() && !
MI.isBarrier())
372 if (!
MI.isPredicable())
379 bool MadeChange =
false;
382 "TargetInstrInfo::PredicateInstruction() can't handle bundles");
385 if (!
MI.isPredicable())
388 for (
unsigned j = 0, i = 0, e =
MI.getNumOperands(); i != e; ++i) {
389 if (
MCID.operands()[i].isPredicate()) {
394 }
else if (MO.
isImm()) {
397 }
else if (MO.
isMBB()) {
398 MO.
setMBB(Pred[j].getMBB());
412 oe =
MI.memoperands_end();
414 if ((*o)->isLoad() &&
418 return Accesses.size() != StartSize;
426 oe =
MI.memoperands_end();
428 if ((*o)->isStore() &&
432 return Accesses.size() != StartSize;
436 unsigned SubIdx,
unsigned &
Size,
444 unsigned BitSize =
TRI.getSubRegIdxSize(SubIdx);
449 int BitOffset =
TRI.getSubRegIdxOffset(SubIdx);
450 if (BitOffset < 0 || BitOffset % 8)
470 MI->substituteRegister(
MI->getOperand(0).getReg(), DestReg, SubIdx,
TRI);
490 "Instruction cannot be duplicated");
492 return MF.cloneMachineInstrBundle(
MBB, InsertBefore, Orig);
500 assert(
TII.isCopyInstr(
MI) &&
"MI must be a COPY instruction");
501 if (
MI.getNumOperands() != 2)
503 assert(FoldIdx<2 &&
"FoldIdx refers no nonexistent operand");
541 DefMI =
MRI->getVRegDef(FoldAsLoadDefReg);
543 bool SawStore =
false;
544 if (!
DefMI->isSafeToMove(SawStore))
549 for (
unsigned i = 0, e =
MI.getNumOperands(); i != e; ++i) {
554 if (Reg != FoldAsLoadDefReg)
561 if (SrcOperandIds.
empty())
567 FoldAsLoadDefReg = 0;
574std::pair<unsigned, unsigned>
576 switch (
MI.getOpcode()) {
577 case TargetOpcode::STACKMAP:
580 case TargetOpcode::PATCHPOINT:
584 case TargetOpcode::STATEPOINT:
595 unsigned StartIdx = 0;
596 unsigned NumDefs = 0;
598 std::tie(NumDefs, StartIdx) =
TII.getPatchpointUnfoldableRange(
MI);
600 unsigned DefToFoldIdx =
MI.getNumOperands();
604 for (
unsigned Op :
Ops) {
606 assert(DefToFoldIdx ==
MI.getNumOperands() &&
"Folding multiple defs");
608 }
else if (
Op < StartIdx) {
611 if (
MI.getOperand(
Op).isTied())
616 MF.CreateMachineInstr(
TII.get(
MI.getOpcode()),
MI.getDebugLoc(),
true);
620 for (
unsigned i = 0; i < StartIdx; ++i)
621 if (i != DefToFoldIdx)
622 MIB.
add(
MI.getOperand(i));
624 for (
unsigned i = StartIdx, e =
MI.getNumOperands(); i < e; ++i) {
627 (void)
MI.isRegTiedToDefOperand(i, &TiedTo);
630 assert(TiedTo == e &&
"Cannot fold tied operands");
632 unsigned SpillOffset;
637 TII.getStackSlotRange(RC, MO.
getSubReg(), SpillSize, SpillOffset, MF);
640 MIB.
addImm(StackMaps::IndirectMemRefOp);
647 assert(TiedTo < NumDefs &&
"Bad tied operand");
648 if (TiedTo > DefToFoldIdx)
660 if (
MI->getOperand(OpNo).isTied()) {
661 unsigned TiedTo =
MI->findTiedOperandIdx(OpNo);
662 MI->untieRegOperand(OpNo);
668 TII.getFrameIndexOperands(NewOps, FI);
669 assert(!NewOps.
empty() &&
"getFrameIndexOperands didn't create any operands");
670 MI->removeOperand(OpNo);
671 MI->insert(
MI->operands_begin() + OpNo, NewOps);
686 assert(
MI.isInlineAsm() &&
"wrong opcode");
689 unsigned Op =
Ops[0];
690 assert(
Op &&
"should never be first operand");
691 assert(
MI.getOperand(
Op).isReg() &&
"shouldn't be folding non-reg operands");
693 if (!
MI.mayFoldInlineAsmRegOp(
Op))
729 for (
unsigned OpIdx :
Ops)
734 assert(
MBB &&
"foldMemoryOperand needs an inserted instruction");
746 for (
unsigned OpIdx :
Ops) {
749 if (
auto SubReg =
MI.getOperand(OpIdx).getSubReg()) {
750 unsigned SubRegSize =
TRI.getSubRegIdxSize(SubReg);
751 if (SubRegSize > 0 && !(SubRegSize % 8))
752 OpSize = SubRegSize / 8;
755 MemSize = std::max(MemSize, OpSize);
759 assert(MemSize &&
"Did not expect a zero-sized stack slot");
763 if (
MI.getOpcode() == TargetOpcode::STACKMAP ||
764 MI.getOpcode() == TargetOpcode::PATCHPOINT ||
765 MI.getOpcode() == TargetOpcode::STATEPOINT) {
769 MBB->insert(
MI, NewMI);
770 }
else if (
MI.isInlineAsm()) {
782 "Folded a def to a non-store!");
785 "Folded a use to a non-load!");
830 for (
unsigned OpIdx :
Ops)
831 assert(
MI.getOperand(OpIdx).isUse() &&
"Folding load into def!");
841 if ((
MI.getOpcode() == TargetOpcode::STACKMAP ||
842 MI.getOpcode() == TargetOpcode::PATCHPOINT ||
843 MI.getOpcode() == TargetOpcode::STATEPOINT) &&
848 NewMI = &*
MBB.insert(
MI, NewMI);
860 if (
MI.memoperands_empty()) {
884 CopyMI->addOperand(MO);
890 if (MO.isKill() &&
TRI->regsOverlap(DstReg, MO.getReg()))
891 CopyMI->getOperand(CopyMI->getNumOperands() - 1).setIsKill(
false);
896 if (
MI->allDefsAreDead()) {
897 MI->setDesc(
get(TargetOpcode::KILL));
905 if (IdentityCopy || SrcMO.
isUndef()) {
908 if (SrcMO.
isUndef() ||
MI->getNumOperands() > 2) {
911 MI->setDesc(
get(TargetOpcode::KILL));
915 MI->eraseFromParent();
924 if (
MI->getNumOperands() > 2)
926 MI->eraseFromParent();
940 MI1 =
MRI.getUniqueVRegDef(Op1.
getReg());
942 MI2 =
MRI.getUniqueVRegDef(Op2.
getReg());
949 unsigned Opcode2)
const {
954 bool &Commuted)
const {
989 bool &Commuted)
const {
1001 unsigned CombineOpc = 0) {
1008 if (!
MI ||
MI->getParent() != &
MBB ||
1009 (
MI->getOpcode() != CombineOpc && CombineOpc != 0))
1031 unsigned AccumulatorOpcode = CurrentInstr->
getOpcode();
1032 std::optional<unsigned> ChainStartOpCode =
1035 if (!ChainStartOpCode.has_value())
1042 while (CurrentInstr &&
1049 if (CurrentInstr->
getOpcode() == AccumulatorOpcode &&
1086 for (
const auto &
I :
MBB) {
1087 if (
I.getOpcode() ==
Opc &&
1088 !ReductionChain.
contains(
I.getOperand(0).getReg()))
1110 for (
unsigned int i = 1; i <= (RegistersToReduce.
size() / 2); i += 2) {
1111 auto RHS = RegistersToReduce[i - 1];
1112 auto LHS = RegistersToReduce[i];
1115 if (RegistersToReduce.
size() == 2)
1119 auto NewVR =
MRI.createVirtualRegister(
1123 InstrIdxForVirtReg.
insert(std::make_pair(Dest, InsInstrs.
size()));
1138 if (RegistersToReduce.
size() % 2 != 0)
1139 NewRegs.
push_back(RegistersToReduce[RegistersToReduce.
size() - 1]);
1141 RegistersToReduce = std::move(NewRegs);
1153 return Info.AccOpIdx;
1168 -> std::optional<TargetInstrInfo::FMAChainLinkInfo> {
1171 return std::nullopt;
1172 return TII.getFMAChainLinkInfo(
MI);
1175 std::optional<TargetInstrInfo::FMAChainLinkInfo> RootInfo = GetInfo(Root);
1180 if (
MRI.use_nodbg_empty(RootReg))
1185 -> std::optional<TargetInstrInfo::FMAChainLinkInfo> {
1186 std::optional<TargetInstrInfo::FMAChainLinkInfo> Info = GetInfo(
MI);
1187 if (Info && Info->AddOpc != RootInfo->AddOpc)
1188 return std::nullopt;
1196 if (!Def || Def->getParent() != &
MBB || !GetLinkInfo(*Def) ||
1198 Def->getOperand(0).getReg() != MO.getReg())
1206 std::optional<TargetInstrInfo::FMAChainLinkInfo> Info = GetLinkInfo(
MI);
1209 if (Info->isFused())
1210 return GetLinkDef(
MI.getOperand(Info->AccOpIdx));
1216 return GetLinkDef(
MI.getOperand(2));
1222 if (
User.getParent() == &
MBB && GetPrevLink(
User) == &Root)
1227 for (
MachineInstr *Link = GetPrevLink(Root); Link; Link = GetPrevLink(*Link))
1229 std::reverse(Chain.
begin(), Chain.
end());
1231 if (Chain.
size() < 4)
1236 unsigned SplitIdx = Chain.
size() / 2;
1239 bool MovesLoad =
false;
1240 auto NextMoved = Chain.
begin() + SplitIdx;
1243 if (&
MI == *NextMoved) {
1245 if (
MI.isBundled() ||
MI.mayStore() ||
MI.isNotDuplicable() ||
1246 TII.isGlobalMemoryObject(&
MI))
1255 if (!MO.getReg().isPhysical())
1257 if (!MO.isImplicit())
1260 ImplicitPhysRegs.
insert(MO.getReg());
1262 if (!MovesLoad &&
MI.mayLoad() && !
MI.isDereferenceableInvariantLoad())
1264 if (NextMoved == Chain.
end())
1270 if (
MI.isDebugInstr())
1272 if (MovesLoad && (
MI.mayStore() ||
MI.isLifetimeMarker() ||
1273 TII.isGlobalMemoryObject(&
MI)))
1276 return MI.modifiesRegister(
Reg,
TRI);
1280 if (NextMoved != Chain.
end())
1289 TII.get(
TII.getFMAChainLinkInfo(Root)->AddOpc),
1309 unsigned SplitIdx = Chain.
size() / 2;
1310 unsigned UpperAccLat = 0;
1311 bool PrevFused =
TII.getFMAChainLinkInfo(Leaf)->isFused();
1312 for (
auto [
I, Prev, Link] :
1317 if (Info.isFused() && PrevFused &&
1318 Lat >= SchedModel.computeInstrLatency(Prev))
1320 if (
I >= SplitIdx - 1)
1322 PrevFused = Info.isFused();
1342 Register LowerReg = Chain[SplitIdx - 1]->getOperand(0).getReg();
1344 Chain[SplitIdx]->getOperand(0).
getReg());
1348 MF.deleteMachineInstr(
Add);
1349 unsigned BackedgeLat =
1351 return AddLat < UpperAccLat + BackedgeLat;
1358 bool DoRegPressureReduce) {
1387 assert(!Chain.
empty() &&
"expected an FMA chain");
1388 unsigned SplitIdx = Chain.
size() / 2;
1392 Flags &= Link->getFlags();
1404 *
TII.getFMAChainLinkInfo(*Chain[
I]);
1408 UpperAcc = Chain[
I]->getOperand(AccIdx == 1 ? 2 : 1).getReg();
1415 if (Link == Unfused)
1438 TII, Root, Chain[SplitIdx - 1]->getOperand(0).
getReg(), UpperAcc);
1439 Add->setFlags(Flags);
1441 Add->setDebugInstrNum(OldRootNum);
1468 bool DoRegPressureReduce)
const {
1471 bool FoundFMAChain =
1491 return FoundFMAChain;
1510std::pair<unsigned, unsigned>
1520 if (AssocCommutRoot && AssocCommutPrev) {
1530 "Incorrectly matched pattern");
1531 unsigned AssocCommutOpcode = Root.
getOpcode();
1533 if (!AssocCommutRoot)
1534 std::swap(AssocCommutOpcode, InverseOpcode);
1562 if (!AssocCommutRoot && AssocCommutPrev)
1563 return {AssocCommutOpcode, InverseOpcode};
1564 if (AssocCommutRoot && !AssocCommutPrev)
1565 return {InverseOpcode, InverseOpcode};
1566 if (!AssocCommutRoot && !AssocCommutPrev)
1567 return {InverseOpcode, AssocCommutOpcode};
1570 if (!AssocCommutRoot && AssocCommutPrev)
1571 return {AssocCommutOpcode, InverseOpcode};
1572 if (AssocCommutRoot && !AssocCommutPrev)
1573 return {InverseOpcode, AssocCommutOpcode};
1574 if (!AssocCommutRoot && !AssocCommutPrev)
1575 return {InverseOpcode, InverseOpcode};
1578 if (!AssocCommutRoot && AssocCommutPrev)
1579 return {InverseOpcode, InverseOpcode};
1580 if (AssocCommutRoot && !AssocCommutPrev)
1581 return {AssocCommutOpcode, InverseOpcode};
1582 if (!AssocCommutRoot && !AssocCommutPrev)
1583 return {InverseOpcode, AssocCommutOpcode};
1586 if (!AssocCommutRoot && AssocCommutPrev)
1587 return {InverseOpcode, InverseOpcode};
1588 if (AssocCommutRoot && !AssocCommutPrev)
1589 return {InverseOpcode, AssocCommutOpcode};
1590 if (!AssocCommutRoot && !AssocCommutPrev)
1591 return {AssocCommutOpcode, InverseOpcode};
1605 return {
false,
false};
1607 return {
true,
false};
1609 return {
true,
true};
1611 return {
true,
true};
1665 MRI.constrainRegClass(RegA, RC);
1667 MRI.constrainRegClass(RegB, RC);
1669 MRI.constrainRegClass(RegX, RC);
1671 MRI.constrainRegClass(RegY, RC);
1673 MRI.constrainRegClass(RegC, RC);
1679 unsigned SubRegNewVR = 0;
1680 InstrIdxForVirtReg.
insert(std::make_pair(NewVR, 0));
1686 if (SwapPrevOperands) {
1691 unsigned PrevFirstOpIdx, PrevSecondOpIdx;
1692 unsigned RootFirstOpIdx, RootSecondOpIdx;
1726 MF, MF.CreateMachineInstr(
MCID, MIMD.getDL(),
true))
1733 buildMINoImplicit(*MF,
MIMetadata(Prev),
TII->get(NewPrevOpc), NewVR);
1735 unsigned Idx = MO.getOperandNo();
1739 if (Idx == PrevFirstOpIdx)
1740 MIB1.
addReg(RegX, {}, SubRegX);
1741 else if (Idx == PrevSecondOpIdx)
1742 MIB1.
addReg(RegY, {}, SubRegY);
1748 if (SwapRootOperands) {
1754 buildMINoImplicit(*MF,
MIMetadata(Root),
TII->get(NewRootOpc), RegC);
1756 unsigned Idx = MO.getOperandNo();
1760 if (Idx == RootFirstOpIdx)
1761 MIB2 = MIB2.
addReg(RegA, {}, SubRegA);
1762 else if (Idx == RootSecondOpIdx)
1763 MIB2 = MIB2.
addReg(NewVR, {}, SubRegNewVR);
1765 MIB2 = MIB2.
add(MO);
1840 "Max accumulator width set to illegal value");
1848 if (IndexedReg.index() == 0)
1855 if (IndexedReg.index() < MaxWidth) {
1857 AccReg = Instr->getOperand(0).getReg();
1861 .
addReg(Instr->getOperand(2).getReg())
1862 .
addReg(Instr->getOperand(3).getReg());
1867 ?
MRI.createVirtualRegister(
1869 : Instr->getOperand(0).getReg();
1870 assert(IndexedReg.index() >= MaxWidth);
1871 auto AccumulatorInput =
1872 ChainRegs[
Depth - (IndexedReg.index() - MaxWidth) - 1];
1875 .
addReg(AccumulatorInput)
1876 .
addReg(Instr->getOperand(2).getReg())
1877 .
addReg(Instr->getOperand(3).getReg());
1881 InstIdxForVirtReg.
insert(std::make_pair(AccReg, InsInstrs.
size()));
1887 for (
unsigned i = (InsInstrs.
size() - MaxWidth); i < InsInstrs.
size();
1889 auto Reg = InsInstrs[i]->getOperand(0).getReg();
1893 while (RegistersToReduce.
size() > 1)
1915 if (!
MI.getNumOperands() || !
MI.getOperand(0).isReg())
1923 if (DefReg.
isVirtual() &&
MI.getOperand(0).getSubReg() &&
1924 MI.readsVirtualRegister(DefReg))
1936 if (
MI.isNotDuplicable() ||
MI.mayStore() ||
MI.mayRaiseFPException() ||
1937 MI.hasUnmodeledSideEffects())
1942 if (
MI.isInlineAsm())
1946 if (
MI.mayLoad() && !
MI.isDereferenceableInvariantLoad())
1952 if (!MO.isReg())
continue;
1958 if (Reg.isPhysical()) {
1963 if (!
MRI.isConstantPhysReg(Reg))
1974 if (MO.isDef() && Reg != DefReg)
1985 bool StackGrowsDown =
1996 if ((!StackGrowsDown &&
MI.getOpcode() == FrameSetupOpcode) ||
1997 (StackGrowsDown &&
MI.getOpcode() == FrameDestroyOpcode))
2010 if (
MI.isTerminator() ||
MI.isPosition())
2014 if (
MI.getOpcode() == TargetOpcode::INLINEASM_BR)
2023 return MI.modifiesRegister(
TLI.getStackPointerRegisterToSaveRestore(), &
TRI);
2057 bool &OffsetIsScalable)
const {
2062 BaseOps.
size() != 1)
2064 BaseOp = BaseOps.
front();
2072std::optional<unsigned>
2074 SDNode *DefNode,
unsigned DefIdx,
2075 SDNode *UseNode,
unsigned UseIdx)
const {
2076 if (!ItinData || ItinData->
isEmpty())
2077 return std::nullopt;
2080 return std::nullopt;
2091 if (!ItinData || ItinData->
isEmpty())
2094 if (!
N->isMachineOpcode())
2106 if (!ItinData || ItinData->
isEmpty())
2109 unsigned Class =
MI.getDesc().getSchedClass();
2123 if (
DefMI.isTransient())
2125 if (
DefMI.mayLoad())
2138 unsigned *PredCost)
const {
2142 return MI.mayLoad() ? 2 : 1;
2149 unsigned DefIdx)
const {
2151 if (!ItinData || ItinData->
isEmpty())
2154 unsigned DefClass =
DefMI.getDesc().getSchedClass();
2155 std::optional<unsigned> DefCycle =
2157 return DefCycle && DefCycle <= 1U;
2165 if (!OutlineFromLinkOnceODRs &&
F.hasLinkOnceODRLinkage())
2188 if (SectionPrefix &&
2189 (*SectionPrefix ==
"unlikely" || *SectionPrefix ==
"unknown")) {
2196std::optional<ParamLoadedValue>
2202 bool OffsetIsScalable;
2209 Register DestReg = DestSrc->Destination->getReg();
2220 return std::nullopt;
2226 }
else if (
MI.hasOneMemOperand()) {
2237 return std::nullopt;
2241 return std::nullopt;
2244 if (OffsetIsScalable)
2245 return std::nullopt;
2253 if (
MI.getNumExplicitDefs() != 1)
2254 return std::nullopt;
2262 return std::nullopt;
2268 Ops.push_back(dwarf::DW_OP_deref_size);
2274 return std::nullopt;
2290 return MBB->getCallFrameSize();
2298 unsigned DefClass =
DefMI.getDesc().getSchedClass();
2299 unsigned UseClass =
UseMI.getDesc().getSchedClass();
2307 MI.isRegSequenceLike()) &&
"Instruction do not have the proper type");
2309 if (!
MI.isRegSequence())
2314 assert(DefIdx == 0 &&
"REG_SEQUENCE only has one def");
2315 for (
unsigned OpIdx = 1, EndOpIdx =
MI.getNumOperands(); OpIdx != EndOpIdx;
2322 "One of the subindex of the reg_sequence is not an immediate");
2325 (
unsigned)MOSubIdx.
getImm()));
2334 MI.isExtractSubregLike()) &&
"Instruction do not have the proper type");
2336 if (!
MI.isExtractSubreg())
2341 assert(DefIdx == 0 &&
"EXTRACT_SUBREG only has one def");
2347 "The subindex of the extract_subreg is not an immediate");
2359 MI.isInsertSubregLike()) &&
"Instruction do not have the proper type");
2361 if (!
MI.isInsertSubreg())
2366 assert(DefIdx == 0 &&
"INSERT_SUBREG only has one def");
2373 "One of the subindex of the reg_sequence is not an immediate");
2374 BaseReg.Reg = MOBaseReg.
getReg();
2377 InsertedReg.
Reg = MOInsertedReg.
getReg();
2386 unsigned OpIdx)
const {
2388 if (!
MI.isInlineAsm())
2396 unsigned ExtraInfo =
Op.getImm();
2401 int FlagIdx =
MI.findInlineAsmFlagIdx(OpIdx);
2402 if (FlagIdx < 0 || (
unsigned)FlagIdx != OpIdx)
2405 assert(
Op.isImm() &&
"Expected flag operand to be an immediate");
2407 unsigned Flag =
Op.getImm();
2409 OS <<
F.getKindName();
2412 if (!
F.isImmKind() && !
F.isMemKind() && !
F.isFuncKind() &&
2413 F.hasRegClassConstraint(RCID))
2414 OS <<
':' <<
TRI.getRegClassName(
TRI.getRegClass(RCID));
2416 if (
F.isMemKind() ||
F.isFuncKind()) {
2422 if (
F.isUseOperandTiedToDef(TiedTo))
2423 OS <<
" tiedto:$" << TiedTo;
2425 if ((
F.isRegDefKind() ||
F.isRegDefEarlyClobberKind() ||
F.isRegUseKind()) &&
2426 F.getRegMayBeFolded())
2435 Function &
F, std::vector<outliner::Candidate> &Candidates)
const {
2449 return C.getMF()->getFunction().hasFnAttribute(Attribute::NoUnwind);
2451 F.addFnAttr(Attribute::NoUnwind);
2457 unsigned Flags)
const {
2462 if (
MI.isCFIInstruction())
2467 if (
MI.isInlineAsm())
2478 if (
MI.isDebugInstr())
2482 switch (
MI.getOpcode()) {
2483 case TargetOpcode::IMPLICIT_DEF:
2484 case TargetOpcode::KILL:
2485 case TargetOpcode::LIFETIME_START:
2486 case TargetOpcode::LIFETIME_END:
2493 if (
MI.isTerminator()) {
2495 if (!
MI.getParent()->succ_empty())
2520 assert(!MOP.isTargetIndex() &&
"This isn't used quite yet!");
2523 assert(!MOP.isCFIIndex() &&
"CFI instructions handled elsewhere!");
2526 assert(!MOP.isFI() &&
"FrameIndex instructions should be gone by now!");
2528 if (MOP.isMBB() || MOP.isBlockAddress() || MOP.isCPI() || MOP.isJTI())
2537 unsigned &Flags)
const {
2540 auto First =
MBB.getFirstNonDebugInstr();
2544 if (
First->getOpcode() == TargetOpcode::FENTRY_CALL ||
2545 First->getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_ENTER)
2550 auto Last =
MBB.getLastNonDebugInstr();
2551 if (
Last->getOpcode() == TargetOpcode::PATCHABLE_RET ||
2552 Last->getOpcode() == TargetOpcode::PATCHABLE_TAIL_CALL)
2557 if (
Last->getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_EXIT ||
2558 Last->getOpcode() == TargetOpcode::PATCHABLE_TAIL_CALL)
2565 return MI->isCall() ||
MI->hasUnmodeledSideEffects() ||
2566 (
MI->hasOrderedMemoryRef() && !
MI->isDereferenceableInvariantLoad());
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
SmallVector< int16_t, MAX_SRC_OPERANDS_NUM > OperandIndices
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
bpf unwind BPF Unwind Lower
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
DXIL Forward Handle Accesses
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
uint64_t IntrinsicInst * II
TargetInstrInfo::RegSubRegPairAndIdx RegSubRegPairAndIdx
MachineRegisterInfo & MRI
Provides some synthesis utilities to produce sequences of values.
This file defines the SmallSet class.
static bool isAsmComment(const char *Str, const MCAsmInfo &MAI)
static void transferImplicitOperands(MachineInstr *MI, const TargetRegisterInfo *TRI)
transferImplicitOperands - MI is a pseudo-instruction, and the lowered replacement instructions immed...
static bool isFMASplitProfitable(const TargetInstrInfo &TII, ArrayRef< MachineInstr * > Chain)
static cl::opt< bool > EnableAccReassociation("acc-reassoc", cl::Hidden, cl::init(true), cl::desc("Enable reassociation of accumulation chains"))
static int getFMAChainAccOpIdx(const TargetInstrInfo::FMAChainLinkInfo &Info, const MachineInstr &Link, const MachineInstr &Prev)
static bool isPlainVirtRegOperand(const MachineOperand &MO)
static SmallVector< MachineInstr * > collectFMAChain(const TargetInstrInfo &TII, MachineInstr &Root)
static std::pair< bool, bool > mustSwapOperands(unsigned Pattern)
static const TargetRegisterClass * canFoldCopy(const MachineInstr &MI, const TargetInstrInfo &TII, unsigned FoldIdx)
static cl::opt< unsigned int > MinAccumulatorDepth("acc-min-depth", cl::Hidden, cl::init(8), cl::desc("Minimum length of accumulator chains " "required for the optimization to kick in"))
static void foldInlineAsmMemOperand(MachineInstr *MI, unsigned OpNo, int FI, const TargetInstrInfo &TII)
static void reassociateFMAChain(const TargetInstrInfo &TII, MachineInstr &Root, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< Register, unsigned > &InstrIdxForVirtReg)
static cl::opt< unsigned int > MaxAccumulatorWidth("acc-max-width", cl::Hidden, cl::init(3), cl::desc("Maximum number of branches in the accumulator tree"))
static bool getFMAChainPatterns(const TargetInstrInfo &TII, MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce)
static bool canCombine(MachineBasicBlock &MBB, MachineOperand &MO, unsigned CombineOpc=0)
static MachineInstr * buildFMAChainAdd(const TargetInstrInfo &TII, MachineInstr &Root, Register Lower, Register Upper)
static cl::opt< bool > DisableHazardRecognizer("disable-sched-hazard", cl::Hidden, cl::init(false), cl::desc("Disable hazard detection during preRA scheduling"))
static MachineInstr * foldPatchpoint(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, int FrameIndex, const TargetInstrInfo &TII)
This file describes how to lower LLVM code to machine code.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
Get the last element.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
const T & front() const
Get the first element.
size_t size() const
Get the array size.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static LLVM_ABI DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
static LLVM_ABI DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
bool isLittleEndian() const
Layout endianness...
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
LLVM_ABI std::optional< StringRef > getSectionPrefix() const
Get the section prefix for this global object.
bool hasSection() const
Check if this global has a custom object file section.
Module * getParent()
Get the module that this global value is contained inside of...
static std::vector< StringRef > getExtraInfoNames(unsigned ExtraInfo)
static StringRef getMemConstraintName(ConstraintCode C)
Itinerary data supplied by a subtarget to be used by a target.
std::optional< unsigned > getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const
Return the cycle for the given class and operand.
unsigned getStageLatency(unsigned ItinClassIndx) const
Return the total stage latency of the given class.
std::optional< unsigned > getOperandLatency(unsigned DefClass, unsigned DefIdx, unsigned UseClass, unsigned UseIdx) const
Compute and return the use operand latency of a given itinerary class and operand index if the value ...
const InstrItinerary * Itineraries
Array of itineraries selected.
bool isEmpty() const
Returns true if there are no itineraries.
static LocationSize precise(uint64_t Value)
TypeSize getValue() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
unsigned getMaxInstLength() const
Returns the maximum possible encoded instruction size in bytes.
StringRef getCommentString() const
const char * getSeparatorString() const
Instances of this class represent a single low-level machine instruction.
Describe properties that are true of each instruction in the target description file.
unsigned getSchedClass() const
Return the scheduling class for this instruction.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
This holds information about one operand of a machine instruction, indicating the register class for ...
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
bool hasSubClassEq(const MCRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Instructions::const_iterator const_instr_iterator
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
const MachineFunctionProperties & getProperties() const
Get the function properties.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
const MachineInstrBuilder & copyMIMetadata(const MIMetadata &MIMD) const
Representation of each machine instruction.
ArrayRef< MachineMemOperand * >::iterator mmo_iterator
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
void setFlags(unsigned flags)
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
unsigned getNumOperands() const
Retuns the total number of operands.
void setDebugInstrNum(unsigned Num)
Set instruction number of this MachineInstr.
mmo_iterator memoperands_end() const
Access to memory operands of the instruction.
unsigned peekDebugInstrNum() const
Examine the instruction number of this MachineInstr.
LLVM_ABI void setMemRefs(MachineFunction &MF, ArrayRef< MachineMemOperand * > MemRefs)
Assign this MachineInstr's memory reference descriptor list.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
LLVM_ABI int findRegisterUseOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isKill=false) const
Returns the operand index that is a use of the specific register or -1 if it is not found.
bool isCFIInstruction() const
bool isNotDuplicable(QueryType Type=AnyInBundle) const
Return true if this instruction cannot be safely duplicated.
void clearFlag(MIFlag Flag)
clearFlag - Clear a MI flag.
void untieRegOperand(unsigned OpIdx)
Break any tie involving OpIdx.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
mop_range explicit_operands()
LLVM_ABI void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
LLVM_ABI void cloneInstrSymbols(MachineFunction &MF, const MachineInstr &MI)
Clone another MachineInstr's pre- and post- instruction symbols and replace ours with it.
LLVM_ABI bool isIdenticalTo(const MachineInstr &Other, MICheckType Check=CheckDefs) const
Return true if this instruction is identical to Other.
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
LLVM_ABI void removeOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with.
const MachineOperand & getOperand(unsigned i) const
uint32_t getFlags() const
Return the MI flags bitvector.
LLVM_ABI void clearKillInfo()
Clears kill flags on all operands.
bool canFoldAsLoad(QueryType Type=IgnoreBundle) const
Return true for instructions that can be folded as memory operands in other instructions.
LLVM_ABI const TargetRegisterClass * getRegClassConstraint(unsigned OpIdx, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
Compute the static register class constraint for operand OpIdx.
LLVM_ABI void addMemOperand(MachineFunction &MF, MachineMemOperand *MO)
Add a MachineMemOperand to the machine instruction.
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
const PseudoSourceValue * getPseudoValue() const
Flags
Flags values. These may be or'd together.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
This class contains meta information specific to a module.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
void setIsInternalRead(bool Val=true)
void setImm(int64_t immVal)
LLVM_ABI void setIsRenamable(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(bool Val=true)
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
void setMBB(MachineBasicBlock *MBB)
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
MI-level patchpoint operands.
Special value supplied for machine level alias analysis.
virtual bool mayAlias(const MachineFrameInfo *) const
Return true if the memory pointed to by this PseudoSourceValue can ever alias an LLVM IR Value.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Represents one node in the SelectionDAG.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool contains(const T &V) const
Check if the SmallSet contains the given element.
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 append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level stackmap operands.
MI-level Statepoint operands.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Information about stack frame layout on the target.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
int alignSPAdjust(int SPAdj) const
alignSPAdjust - This method aligns the stack adjustment to the correct alignment.
virtual ~PipelinerLoopInfo()
TargetInstrInfo - Interface to description of machine instruction set.
virtual ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *, const ScheduleDAG *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
virtual bool hasLowDefLatency(const TargetSchedModel &SchedModel, const MachineInstr &DefMI, unsigned DefIdx) const
Compute operand latency of a def of 'Reg'.
virtual unsigned getInlineAsmLength(const char *Str, const MCAsmInfo &MAI, unsigned MaxInstLength=0) const
Measure the specified inline asm to determine an approximation of its length.
virtual void setSpecialOperandAttr(MachineInstr &OldMI1, MachineInstr &OldMI2, MachineInstr &NewMI1, MachineInstr &NewMI2) const
This is an architecture-specific helper function of reassociateOps.
const TargetRegisterInfo & TRI
virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, const MachineInstr &MI) const
Return the number of u-operations the given machine instruction will be decoded to on the target cpu.
virtual const TargetRegisterClass * getRegClass(const MCInstrDesc &MCID, unsigned OpNum) const
Given a machine instruction descriptor, returns the register class constraint for OpNum,...
virtual int getSPAdjust(const MachineInstr &MI) const
Returns the actual stack pointer adjustment made by an instruction as part of a call sequence.
virtual void ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail, MachineBasicBlock *NewDest) const
Delete the instruction OldInst and everything after it, replacing it with an unconditional branch to ...
virtual bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Pred) const
Convert the instruction into a predicated instruction.
int16_t getOpRegClassID(const MCOperandInfo &OpInfo) const
bool areOpcodesEqualOrInverse(unsigned Opcode1, unsigned Opcode2) const
Return true when \P Opcode1 or its inversion is equal to \P Opcode2.
virtual outliner::InstrType getOutliningTypeImpl(const MachineModuleInfo &MMI, MachineBasicBlock::iterator &MIT, unsigned Flags) const
Target-dependent implementation for getOutliningTypeImpl.
virtual bool getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx, RegSubRegPair &BaseReg, RegSubRegPairAndIdx &InsertedReg) const
Target-dependent implementation of getInsertSubregInputs.
outliner::InstrType getOutliningType(const MachineModuleInfo &MMI, MachineBasicBlock::iterator &MIT, unsigned Flags) const
Returns how or if MIT should be outlined.
virtual bool isThroughputPattern(unsigned Pattern) const
Return true when a code sequence can improve throughput.
bool getAccumulatorReassociationPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns) const
Find chains of accumulations that can be rewritten as a tree for increased ILP.
virtual std::pair< unsigned, unsigned > getPatchpointUnfoldableRange(const MachineInstr &MI) const
For a patchpoint, stackmap, or statepoint intrinsic, return the range of operands which can't be fold...
virtual bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const
Returns true iff the routine could find two commutable operands in the given machine instruction.
virtual void mergeOutliningCandidateAttributes(Function &F, std::vector< outliner::Candidate > &Candidates) const
Optional target hook to create the LLVM IR attributes for the outlined function.
bool isUnpredicatedTerminator(const MachineInstr &MI) const
Returns true if the instruction is a terminator instruction that has not been predicated.
virtual void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
Insert a noop into the instruction stream at the specified point.
void getAccumulatorChain(MachineInstr *CurrentInstr, SmallVectorImpl< Register > &Chain) const
Find the chain of accumulator instructions in \P MBB and return them in \P Chain.
bool isFrameInstr(const MachineInstr &I) const
Returns true if the argument is a frame pseudo instruction.
virtual bool getRegSequenceLikeInputs(const MachineInstr &MI, unsigned DefIdx, SmallVectorImpl< RegSubRegPairAndIdx > &InputRegs) const
Target-dependent implementation of getRegSequenceInputs.
unsigned defaultDefLatency(const TargetSubtargetInfo &STI, const MCSchedModel &SchedModel, const MachineInstr &DefMI) const
Return the default expected latency for a def based on its opcode.
virtual bool getStackSlotRange(const TargetRegisterClass *RC, unsigned SubIdx, unsigned &Size, unsigned &Offset, const MachineFunction &MF) const
Compute the size in bytes and offset within a stack slot of a spilled register or subregister.
virtual ScheduleHazardRecognizer * CreateTargetMIHazardRecognizer(const InstrItineraryData *, const ScheduleDAGMI *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
virtual bool hasStoreToStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const
If the specified machine instruction has a store to a stack slot, return true along with the FrameInd...
virtual bool hasReassociableOperands(const MachineInstr &Inst, const MachineBasicBlock *MBB) const
Return true when \P Inst has reassociable operands in the same \P MBB.
virtual void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const
Store the specified register of the given register class to the specified stack frame index.
virtual void genAlternativeCodeSequence(MachineInstr &Root, unsigned Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< Register, unsigned > &InstIdxForVirtReg) const
When getMachineCombinerPatterns() finds patterns, this function generates the instructions that could...
virtual std::optional< ParamLoadedValue > describeLoadedValue(const MachineInstr &MI, Register Reg) const
Produce the expression describing the MI loading a value into the physical register Reg.
virtual unsigned getReduceOpcodeForAccumulator(unsigned int AccumulatorOpCode) const
Returns the opcode that should be use to reduce accumulation registers.
virtual Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const
If the specified machine instruction is a direct load from a stack slot, return the virtual or physic...
virtual ScheduleHazardRecognizer * CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, const ScheduleDAG *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
virtual MachineInstr * optimizeLoadInstr(MachineInstr &MI, const MachineRegisterInfo *MRI, Register &FoldAsLoadDefReg, MachineInstr *&DefMI, MachineInstr *&CopyMI) const
Try to remove the load by folding it to a register operand at the use.
TargetInstrInfo(const TargetRegisterInfo &TRI, unsigned CFSetupOpcode=~0u, unsigned CFDestroyOpcode=~0u, unsigned CatchRetOpcode=~0u, unsigned ReturnOpcode=~0u, const int16_t *const RegClassByHwModeTable=nullptr)
virtual unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const
Insert branch code into the end of the specified MachineBasicBlock.
virtual void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const
Emit instructions to copy a pair of physical registers.
virtual unsigned getAccumulationStartOpcode(unsigned Opcode) const
Returns an opcode which defines the accumulator used by \P Opcode.
unsigned getCallFrameSetupOpcode() const
These methods return the opcode of the frame setup/destroy instructions if they exist (-1 otherwise).
virtual bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce) const
Return true when there is potentially a faster code sequence for an instruction chain ending in Root.
virtual bool isReMaterializableImpl(const MachineInstr &MI) const
For instructions with opcodes for which the M_REMATERIALIZABLE flag is set, this hook lets the target...
virtual MCInst getNop() const
Return the noop instruction to use for a noop.
unsigned getCallFrameSizeAt(MachineInstr &MI) const
virtual MachineInstr & duplicate(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) const
Clones instruction or the whole instruction bundle Orig and insert into MBB before InsertBefore.
virtual std::string createMIROperandComment(const MachineInstr &MI, const MachineOperand &Op, unsigned OpIdx) const
std::pair< unsigned, unsigned > getReassociationOpcodes(unsigned Pattern, const MachineInstr &Root, const MachineInstr &Prev) const
Reassociation of some instructions requires inverse operations (e.g.
virtual bool isFunctionSafeToOutlineFrom(MachineFunction &MF, bool OutlineFromLinkOnceODRs) const
Return true if the function can safely be outlined from.
unsigned getInstBundleSize(const MachineInstr &MI) const
Sum the sizes of instructions inside of a BUNDLE, by calling getInstSizeInBytes on each.
virtual bool isMBBSafeToOutlineFrom(MachineBasicBlock &MBB, unsigned &Flags) const
Optional target hook that returns true if MBB is safe to outline from, and returns any target-specifi...
virtual void getReassociateOperandIndices(const MachineInstr &Root, unsigned Pattern, std::array< unsigned, 5 > &OperandIndices) const
The returned array encodes the operand index for each parameter because the operands may be commuted;...
virtual bool supportsSectionAwareOutlining() const
Return true if the target supports outlining candidates from multiple input sections in one pass.
virtual bool getMemOperandsWithOffsetWidth(const MachineInstr &MI, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const
Get zero or more base operands and the byte offset of an instruction that reads/writes memory.
int64_t getFrameTotalSize(const MachineInstr &I) const
Returns the total frame size, which is made up of the space set up inside the pair of frame start-sto...
MachineInstr * commuteInstruction(MachineInstr &MI, bool NewMI=false, unsigned OpIdx1=CommuteAnyOperandIndex, unsigned OpIdx2=CommuteAnyOperandIndex) const
This method commutes the operands of the given machine instruction MI.
virtual std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, SDNode *DefNode, unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const
virtual bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert=false) const
Return true when \P Inst is both associative and commutative.
virtual void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, unsigned SubIdx, const MachineInstr &Orig, LaneBitmask UsedLanes=LaneBitmask::getAll()) const
Re-issue the specified 'original' instruction at the specific location targeting a new destination re...
void reassociateOps(MachineInstr &Root, MachineInstr &Prev, unsigned Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, ArrayRef< unsigned > OperandIndices, DenseMap< Register, unsigned > &InstrIdxForVirtReg) const
Attempt to reassociate \P Root and \P Prev according to \P Pattern to reduce critical path length.
virtual std::optional< unsigned > getInverseOpcode(unsigned Opcode) const
Return the inverse operation opcode if it exists for \P Opcode (e.g.
virtual void insertNoops(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned Quantity) const
Insert noops into the instruction stream at the specified point.
unsigned getCallFrameDestroyOpcode() const
int64_t getFrameSize(const MachineInstr &I) const
Returns size of the frame associated with the given frame instruction.
virtual bool isPredicated(const MachineInstr &MI) const
Returns true if the instruction is already predicated.
bool getInsertSubregInputs(const MachineInstr &MI, unsigned DefIdx, RegSubRegPair &BaseReg, RegSubRegPairAndIdx &InsertedReg) const
Build the equivalent inputs of a INSERT_SUBREG for the given MI and DefIdx.
virtual ~TargetInstrInfo()
virtual unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const
Compute the instruction latency of a given instruction.
virtual bool produceSameValue(const MachineInstr &MI0, const MachineInstr &MI1, const MachineRegisterInfo *MRI=nullptr) const
Return true if two machine instructions would produce identical values.
virtual bool isAccumulationOpcode(unsigned Opcode) const
Return true when \P OpCode is an instruction which performs accumulation into one of its operand regi...
std::optional< DestSourcePair > isCopyInstr(const MachineInstr &MI) const
If the specific machine instruction is a instruction that moves/copies value from one register to ano...
bool isReassociationCandidate(const MachineInstr &Inst, bool &Commuted) const
Return true if the input \P Inst is part of a chain of dependent ops that are suitable for reassociat...
virtual MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, int FrameIndex, MachineInstr *&CopyMI, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const
Target-dependent implementation for foldMemoryOperand.
void reduceAccumulatorTree(SmallVectorImpl< Register > &RegistersToReduce, SmallVectorImpl< MachineInstr * > &InsInstrs, MachineFunction &MF, MachineInstr &Root, MachineRegisterInfo &MRI, DenseMap< Register, unsigned > &InstrIdxForVirtReg, Register ResultReg) const
Reduces branches of the accumulator tree into a single register.
virtual bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const
Test if the given instruction should be considered a scheduling boundary.
virtual unsigned getInstSizeInBytes(const MachineInstr &MI) const
Returns the size in bytes of the specified MachineInstr, or ~0U when this function is not implemented...
virtual unsigned getPredicationCost(const MachineInstr &MI) const
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const
Load the specified register of the given register class from the specified stack frame index.
MachineInstr * foldMemoryOperand(MachineInstr &MI, ArrayRef< unsigned > Ops, int FI, MachineInstr *&CopyMI, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const
Attempt to fold a load or store of the specified stack slot into the specified machine instruction fo...
bool getMemOperandWithOffset(const MachineInstr &MI, const MachineOperand *&BaseOp, int64_t &Offset, bool &OffsetIsScalable) const
Get the base operand and byte offset of an instruction that reads/writes memory.
virtual CombinerObjective getCombinerObjective(unsigned Pattern) const
Return the objective of a combiner pattern.
virtual MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const
This method commutes the operands of the given machine instruction MI.
virtual bool isFunctionSafeToSplit(const MachineFunction &MF) const
Return true if the function is a viable candidate for machine function splitting.
void lowerCopy(MachineInstr *MI) const
This function defines the logic to lower COPY instruction to target specific instruction(s).
virtual MachineTraceStrategy getMachineCombinerTraceStrategy() const
Return a strategy that MachineCombiner must use when creating traces.
bool getRegSequenceInputs(const MachineInstr &MI, unsigned DefIdx, SmallVectorImpl< RegSubRegPairAndIdx > &InputRegs) const
Build the equivalent inputs of a REG_SEQUENCE for the given MI and DefIdx.
virtual bool hasLoadFromStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const
If the specified machine instruction has a load from a stack slot, return true along with the FrameIn...
virtual bool isGlobalMemoryObject(const MachineInstr *MI) const
Returns true if MI is an instruction we are unable to reason about (like a call or something with unm...
virtual std::optional< RegImmPair > isAddImmediate(const MachineInstr &MI, Register Reg) const
If the specific machine instruction is an instruction that adds an immediate value and a register,...
static const unsigned CommuteAnyOperandIndex
virtual bool hasReassociableSibling(const MachineInstr &Inst, bool &Commuted) const
Return true when \P Inst has reassociable sibling.
virtual bool isHighLatencyDef(int opc) const
Return true if this opcode has high latency to its result.
static bool fixCommutedOpIndices(unsigned &ResultIdx1, unsigned &ResultIdx2, unsigned CommutableOpIdx1, unsigned CommutableOpIdx2)
Assigns the (CommutableOpIdx1, CommutableOpIdx2) pair of commutable operand indices to (ResultIdx1,...
bool getExtractSubregInputs(const MachineInstr &MI, unsigned DefIdx, RegSubRegPairAndIdx &InputReg) const
Build the equivalent inputs of a EXTRACT_SUBREG for the given MI and DefIdx.
virtual bool getExtractSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx, RegSubRegPairAndIdx &InputReg) const
Target-dependent implementation of getExtractSubregInputs.
bool usePreRAHazardRecognizer() const
Provide a global flag for disabling the PreRA hazard recognizer that targets may choose to honor.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Provide an instruction scheduling machine model to CodeGen passes.
LLVM_ABI void init(const TargetSubtargetInfo *TSInfo, bool EnableSModel=true, bool EnableSItins=true)
Initialize the machine model for instruction scheduling.
LLVM_ABI unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *UseMI, unsigned UseOperIdx) const
Compute operand latency based on the available machine model.
bool hasInstrSchedModelOrItineraries() const
Return true if this machine model includes an instruction-level scheduling model or cycle-to-cycle it...
const InstrItineraryData * getInstrItineraries() const
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual unsigned getLoadLatency() const
Return the expected latency of load instructions.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetLowering * getTargetLowering() const
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, DriverKit, XROS, or bridgeOS).
A Use represents the edge between a Value definition and its users.
constexpr ScalarTy getFixedValue() const
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
InstrType
Represents how an instruction should be mapped by the outliner.
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.
MachineTraceStrategy
Strategies for selecting traces.
@ TS_MinInstrCount
Select the trace through a block that has the fewest instructions.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Define
Register definition.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
constexpr from_range_t from_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool isa_and_nonnull(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
CombinerObjective
The combiner's goal may differ based on which pattern it is attempting to optimize.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
LLVM_ABI VirtRegInfo AnalyzeVirtRegInBundle(MachineInstr &MI, Register Reg, SmallVectorImpl< std::pair< MachineInstr *, unsigned > > *Ops=nullptr)
AnalyzeVirtRegInBundle - Analyze how the current instruction or bundle uses a virtual register.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
DWARFExpression::Operation Op
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
std::pair< MachineOperand, DIExpression * > ParamLoadedValue
IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It, then continue decrementing it while it points to a debug instruction.
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Machine model for scheduling, bundling, and heuristics.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Link of an FP accumulation chain, see MachineCombinerPattern::FMA_CHAIN.
A pair composed of a pair of a register and a sub-register index, and another sub-register index.
A pair composed of a register and a sub-register index.
VirtRegInfo - Information about a virtual register used by a set of operands.
bool Reads
Reads - One of the operands read the virtual register.
bool Writes
Writes - One of the operands writes the virtual register.
An individual sequence of instructions to be replaced with a call to an outlined function.
MachineFunction * getMF() const