65#define DEBUG_TYPE "regalloc"
67STATISTIC(numJoins,
"Number of interval joins performed");
68STATISTIC(numCrossRCs,
"Number of cross class joins performed");
69STATISTIC(numCommutes,
"Number of instruction commuting performed");
71STATISTIC(NumReMats,
"Number of instructions re-materialized");
72STATISTIC(NumInflated,
"Number of register classes inflated");
73STATISTIC(NumLaneConflicts,
"Number of dead lane conflicts tested");
74STATISTIC(NumLaneResolves,
"Number of dead lane conflicts resolved");
75STATISTIC(NumShrinkToUses,
"Number of shrinkToUses called");
78 cl::desc(
"Coalesce copies (default=true)"),
93 cl::desc(
"Coalesce copies that span blocks (default=subtarget)"),
98 cl::desc(
"Verify machine instrs before and after register coalescing"),
103 cl::desc(
"During rematerialization for a copy, if the def instruction has "
104 "many other copy uses to be rematerialized, delay the multiple "
105 "separate live interval update work and do them all at once after "
106 "all those rematerialization are done. It will save a lot of "
112 cl::desc(
"If the valnos size of an interval is larger than the threshold, "
113 "it is regarded as a large interval. "),
118 cl::desc(
"For a large interval, if it is coalesced with other live "
119 "intervals many times more than the threshold, stop its "
120 "coalescing to control the compile time. "),
154 using DbgValueLoc = std::pair<SlotIndex, MachineInstr *>;
163 bool ShrinkMainRange =
false;
167 bool JoinGlobalCopies =
false;
171 bool JoinSplitEdges =
false;
203 void coalesceLocals();
206 void joinAllIntervals();
221 void lateLiveIntervalUpdate();
291 std::pair<bool, bool> removeCopyByCommutingDef(
const CoalescerPair &CP,
362 MI->eraseFromParent();
380 RegisterCoalescer() {}
381 RegisterCoalescer &operator=(RegisterCoalescer &&
Other) =
default;
410char RegisterCoalescerLegacy::ID = 0;
415 "Register Coalescer",
false,
false)
427 Dst =
MI->getOperand(0).getReg();
428 DstSub =
MI->getOperand(0).getSubReg();
429 Src =
MI->getOperand(1).getReg();
430 SrcSub =
MI->getOperand(1).getSubReg();
431 }
else if (
MI->isSubregToReg()) {
432 Dst =
MI->getOperand(0).getReg();
433 DstSub = tri.composeSubRegIndices(
MI->getOperand(0).getSubReg(),
434 MI->getOperand(3).getImm());
435 Src =
MI->getOperand(2).getReg();
436 SrcSub =
MI->getOperand(2).getSubReg();
451 for (
const auto &
MI : *
MBB) {
452 if (!
MI.isCopyLike() && !
MI.isUnconditionalBranch())
462 Flipped = CrossClass =
false;
465 unsigned SrcSub = 0, DstSub = 0;
468 Partial = SrcSub || DstSub;
471 if (Src.isPhysical()) {
472 if (Dst.isPhysical())
482 if (Dst.isPhysical()) {
485 Dst =
TRI.getSubReg(Dst, DstSub);
493 Dst =
TRI.getMatchingSuperReg(Dst, SrcSub, SrcRC);
504 if (SrcSub && DstSub) {
506 if (Src == Dst && SrcSub != DstSub)
509 NewRC =
TRI.getCommonSuperRegClass(SrcRC, SrcSub, DstRC, DstSub, SrcIdx,
516 NewRC =
TRI.getMatchingSuperRegClass(DstRC, SrcRC, DstSub);
520 NewRC =
TRI.getMatchingSuperRegClass(SrcRC, DstRC, SrcSub);
523 NewRC =
TRI.getCommonSubClass(DstRC, SrcRC);
532 if (DstIdx && !SrcIdx) {
538 CrossClass = NewRC != DstRC || NewRC != SrcRC;
541 assert(Src.isVirtual() &&
"Src must be virtual");
542 assert(!(Dst.isPhysical() && DstSub) &&
"Cannot have a physical SubIdx");
561 unsigned SrcSub = 0, DstSub = 0;
569 }
else if (Src != SrcReg) {
575 if (!Dst.isPhysical())
577 assert(!DstIdx && !SrcIdx &&
"Inconsistent CoalescerPair state.");
580 Dst =
TRI.getSubReg(Dst, DstSub);
583 return DstReg == Dst;
585 return Register(
TRI.getSubReg(DstReg, SrcSub)) == Dst;
591 return TRI.composeSubRegIndices(SrcIdx, SrcSub) ==
592 TRI.composeSubRegIndices(DstIdx, DstSub);
596void RegisterCoalescerLegacy::getAnalysisUsage(
AnalysisUsage &AU)
const {
608void RegisterCoalescer::eliminateDeadDefs(
LiveRangeEdit *Edit) {
618void RegisterCoalescer::LRE_WillEraseInstruction(
MachineInstr *
MI) {
623bool RegisterCoalescer::adjustCopiesBackFrom(
const CoalescerPair &CP,
625 assert(!
CP.isPartial() &&
"This doesn't work for partial copies.");
626 assert(!
CP.isPhys() &&
"This doesn't work for physreg copies.");
651 if (BS == IntB.
end())
653 VNInfo *BValNo = BS->valno;
658 if (BValNo->
def != CopyIdx)
665 if (AS == IntA.
end())
667 VNInfo *AValNo = AS->valno;
673 if (!
CP.isCoalescable(ACopyMI) || !ACopyMI->
isFullCopy())
679 if (ValS == IntB.
end())
697 SlotIndex FillerStart = ValS->end, FillerEnd = BS->start;
701 BValNo->
def = FillerStart;
709 if (BValNo != ValS->valno)
718 S.removeSegment(*SS,
true);
722 if (!S.getVNInfoAt(FillerStart)) {
725 S.extendInBlock(BBStart, FillerStart);
727 VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx);
730 if (SubBValNo != SubValSNo)
731 S.MergeValueNumberInto(SubBValNo, SubValSNo);
748 bool RecomputeLiveRange = AS->end == CopyIdx;
749 if (!RecomputeLiveRange) {
752 if (SS != S.end() &&
SS->end == CopyIdx) {
753 RecomputeLiveRange =
true;
758 if (RecomputeLiveRange)
765bool RegisterCoalescer::hasOtherReachingDefs(
LiveInterval &IntA,
774 if (ASeg.
valno != AValNo)
777 if (BI != IntB.
begin())
779 for (; BI != IntB.
end() && ASeg.
end >= BI->start; ++BI) {
780 if (BI->valno == BValNo)
782 if (BI->start <= ASeg.
start && BI->end > ASeg.
start)
784 if (BI->start > ASeg.
start && BI->start < ASeg.
end)
797 bool Changed =
false;
798 bool MergedWithDead =
false;
800 if (S.
valno != SrcValNo)
811 MergedWithDead =
true;
814 return std::make_pair(Changed, MergedWithDead);
818RegisterCoalescer::removeCopyByCommutingDef(
const CoalescerPair &CP,
851 assert(BValNo !=
nullptr && BValNo->
def == CopyIdx);
857 return {
false,
false};
860 return {
false,
false};
862 return {
false,
false};
869 return {
false,
false};
881 if (!
TII->findCommutedOpIndices(*
DefMI, UseOpIdx, NewDstIdx))
882 return {
false,
false};
887 return {
false,
false};
891 if (hasOtherReachingDefs(IntA, IntB, AValNo, BValNo))
892 return {
false,
false};
901 if (US == IntA.
end() || US->valno != AValNo)
905 return {
false,
false};
915 TII->commuteInstruction(*
DefMI,
false, UseOpIdx, NewDstIdx);
917 return {
false,
false};
919 !
MRI->constrainRegClass(IntB.
reg(),
MRI->getRegClass(IntA.
reg())))
920 return {
false,
false};
921 if (NewMI !=
DefMI) {
946 UseMO.setReg(NewReg);
951 assert(US != IntA.
end() &&
"Use must be live");
952 if (US->valno != AValNo)
955 UseMO.setIsKill(
false);
957 UseMO.substPhysReg(NewReg, *
TRI);
959 UseMO.setReg(NewReg);
978 VNInfo *SubDVNI = S.getVNInfoAt(DefIdx);
981 VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx);
983 S.MergeValueNumberInto(SubDVNI, SubBValNo);
991 bool ShrinkB =
false;
1005 VNInfo *ASubValNo = SA.getVNInfoAt(AIdx);
1014 MaskA |= SA.LaneMask;
1017 Allocator, SA.LaneMask,
1018 [&Allocator, &SA, CopyIdx, ASubValNo,
1020 VNInfo *BSubValNo = SR.empty() ? SR.getNextValue(CopyIdx, Allocator)
1021 : SR.getVNInfoAt(CopyIdx);
1022 assert(BSubValNo != nullptr);
1023 auto P = addSegmentsWithValNo(SR, BSubValNo, SA, ASubValNo);
1024 ShrinkB |= P.second;
1026 BSubValNo->def = ASubValNo->def;
1034 if ((SB.LaneMask & MaskA).any())
1038 SB.removeSegment(*S,
true);
1042 BValNo->
def = AValNo->
def;
1044 ShrinkB |=
P.second;
1051 return {
true, ShrinkB};
1101bool RegisterCoalescer::removePartialRedundancy(
const CoalescerPair &CP,
1134 bool FoundReverseCopy =
false;
1153 bool ValB_Changed =
false;
1154 for (
auto *VNI : IntB.
valnos) {
1155 if (VNI->isUnused())
1158 ValB_Changed =
true;
1166 FoundReverseCopy =
true;
1170 if (!FoundReverseCopy)
1180 if (CopyLeftBB && CopyLeftBB->
succ_size() > 1)
1191 if (InsPos != CopyLeftBB->
end()) {
1197 LLVM_DEBUG(
dbgs() <<
"\tremovePartialRedundancy: Move the copy to "
1202 TII->get(TargetOpcode::COPY), IntB.
reg())
1213 ErasedInstrs.
erase(NewCopyMI);
1215 LLVM_DEBUG(
dbgs() <<
"\tremovePartialRedundancy: Remove the copy from "
1226 deleteInstr(&CopyMI);
1242 if (!IntB.
liveAt(UseIdx))
1243 MO.setIsUndef(
true);
1253 VNInfo *BValNo = SR.Query(CopyIdx).valueOutOrDead();
1254 assert(BValNo &&
"All sublanes should be live");
1263 for (
unsigned I = 0;
I != EndPoints.
size();) {
1265 EndPoints[
I] = EndPoints.
back();
1287 assert(!Reg.isPhysical() &&
"This code cannot handle physreg aliasing");
1290 if (
Op.getReg() != Reg)
1294 if (
Op.getSubReg() == 0 ||
Op.isUndef())
1300bool RegisterCoalescer::reMaterializeTrivialDef(
const CoalescerPair &CP,
1304 Register SrcReg =
CP.isFlipped() ?
CP.getDstReg() :
CP.getSrcReg();
1305 unsigned SrcIdx =
CP.isFlipped() ?
CP.getDstIdx() :
CP.getSrcIdx();
1306 Register DstReg =
CP.isFlipped() ?
CP.getSrcReg() :
CP.getDstReg();
1307 unsigned DstIdx =
CP.isFlipped() ?
CP.getSrcIdx() :
CP.getDstIdx();
1329 LiveRangeEdit Edit(&SrcInt, NewRegs, *MF, *LIS,
nullptr,
this);
1335 bool SawStore =
false;
1347 if (SrcIdx && DstIdx)
1382 unsigned NewDstIdx =
TRI->composeSubRegIndices(
CP.getSrcIdx(), DefSubIdx);
1384 NewDstReg =
TRI->getSubReg(DstReg, NewDstIdx);
1394 "Only expect to deal with virtual or physical registers");
1420 assert(SrcIdx == 0 &&
CP.isFlipped() &&
1421 "Shouldn't have SrcIdx+DstIdx at this point");
1424 TRI->getCommonSubClass(DefRC, DstRC);
1425 if (CommonRC !=
nullptr) {
1433 if (MO.isReg() && MO.getReg() == DstReg && MO.getSubReg() == DstIdx) {
1455 "No explicit operands after implicit operands.");
1458 "unexpected implicit virtual register def");
1464 ErasedInstrs.
insert(CopyMI);
1478 bool NewMIDefinesFullReg =
false;
1488 if (MO.
getReg() == DstReg)
1489 NewMIDefinesFullReg =
true;
1494 ((
TRI->getSubReg(MO.
getReg(), DefSubIdx) ==
1507 assert(!
MRI->shouldTrackSubRegLiveness(DstReg) &&
1508 "subrange update for implicit-def of super register may not be "
1509 "properly handled");
1517 if (DefRC !=
nullptr) {
1519 NewRC =
TRI->getMatchingSuperRegClass(NewRC, DefRC, NewIdx);
1521 NewRC =
TRI->getCommonSubClass(NewRC, DefRC);
1522 assert(NewRC &&
"subreg chosen for remat incompatible with instruction");
1528 SR.LaneMask =
TRI->composeSubRegIndexLaneMask(DstIdx, SR.LaneMask);
1530 MRI->setRegClass(DstReg, NewRC);
1533 updateRegDefsUses(DstReg, DstReg, DstIdx);
1552 MRI->shouldTrackSubRegLiveness(DstReg)) {
1582 if (!SR.liveAt(DefIndex))
1583 SR.createDeadDef(DefIndex,
Alloc);
1584 MaxMask &= ~SR.LaneMask;
1586 if (MaxMask.
any()) {
1604 bool UpdatedSubRanges =
false;
1609 if ((SR.
LaneMask & DstMask).none()) {
1611 <<
"Removing undefined SubRange "
1624 UpdatedSubRanges =
true;
1631 if (!SR.
liveAt(DefIndex))
1635 if (UpdatedSubRanges)
1642 "Only expect virtual or physical registers in remat");
1645 if (!NewMIDefinesFullReg) {
1647 CopyDstReg,
true ,
true ,
false ));
1690 if (
MRI->use_nodbg_empty(SrcReg)) {
1696 UseMO.substPhysReg(DstReg, *
TRI);
1698 UseMO.setReg(DstReg);
1707 if (ToBeUpdated.
count(SrcReg))
1710 unsigned NumCopyUses = 0;
1712 if (UseMO.getParent()->isCopyLike())
1718 if (!DeadDefs.
empty())
1719 eliminateDeadDefs(&Edit);
1721 ToBeUpdated.
insert(SrcReg);
1739 unsigned SrcSubIdx = 0, DstSubIdx = 0;
1740 if (!
isMoveInstr(*
TRI, CopyMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx))
1749 if ((SR.
LaneMask & SrcMask).none())
1762 assert(Seg !=
nullptr &&
"No segment for defining instruction");
1767 if (((V &&
V->isPHIDef()) || (!V && !DstLI.
liveAt(
Idx)))) {
1775 CopyMI->
getOpcode() == TargetOpcode::SUBREG_TO_REG);
1780 CopyMI->
setDesc(
TII->get(TargetOpcode::IMPLICIT_DEF));
1797 if ((SR.
LaneMask & DstMask).none())
1819 if ((SR.
LaneMask & UseMask).none())
1827 isLive = DstLI.
liveAt(UseIdx);
1840 if (MO.
getReg() == DstReg)
1852 bool IsUndef =
true;
1854 if ((S.LaneMask & Mask).none())
1856 if (S.liveAt(UseIdx)) {
1869 ShrinkMainRange =
true;
1878 if (DstInt && DstInt->
hasSubRanges() && DstReg != SrcReg) {
1887 if (
MI.isDebugInstr())
1890 addUndefFlag(*DstInt, UseIdx, MO,
SubReg);
1896 E =
MRI->reg_instr_end();
1905 if (SrcReg == DstReg && !Visited.
insert(
UseMI).second)
1918 for (
unsigned Op : Ops) {
1924 if (SubIdx && MO.
isDef())
1930 unsigned SubUseIdx =
TRI->composeSubRegIndices(SubIdx, MO.
getSubReg());
1931 if (SubUseIdx != 0 &&
MRI->shouldTrackSubRegLiveness(DstReg)) {
1948 addUndefFlag(*DstInt, UseIdx, MO, SubUseIdx);
1959 dbgs() <<
"\t\tupdated: ";
1967bool RegisterCoalescer::canJoinPhys(
const CoalescerPair &CP) {
1971 if (!
MRI->isReserved(
CP.getDstReg())) {
1972 LLVM_DEBUG(
dbgs() <<
"\tCan only merge into reserved registers.\n");
1981 dbgs() <<
"\tCannot join complex intervals into reserved register.\n");
1985bool RegisterCoalescer::copyValueUndefInPredecessors(
1999void RegisterCoalescer::setUndefOnPrunedSubRegUses(
LiveInterval &LI,
2006 if (SubRegIdx == 0 || MO.
isUndef())
2012 if (!S.
liveAt(Pos) && (PrunedLanes & SubRegMask).any()) {
2028bool RegisterCoalescer::joinCopy(
2035 if (!
CP.setRegisters(CopyMI)) {
2040 if (
CP.getNewRC()) {
2041 auto SrcRC =
MRI->getRegClass(
CP.getSrcReg());
2042 auto DstRC =
MRI->getRegClass(
CP.getDstReg());
2043 unsigned SrcIdx =
CP.getSrcIdx();
2044 unsigned DstIdx =
CP.getDstIdx();
2045 if (
CP.isFlipped()) {
2049 if (!
TRI->shouldCoalesce(CopyMI, SrcRC, SrcIdx, DstRC, DstIdx,
2050 CP.getNewRC(), *LIS)) {
2062 eliminateDeadDefs();
2069 if (
MachineInstr *UndefMI = eliminateUndefCopy(CopyMI)) {
2070 if (UndefMI->isImplicitDef())
2072 deleteInstr(CopyMI);
2080 if (
CP.getSrcReg() ==
CP.getDstReg()) {
2082 LLVM_DEBUG(
dbgs() <<
"\tCopy already coalesced: " << LI <<
'\n');
2087 assert(ReadVNI &&
"No value before copy and no <undef> flag.");
2088 assert(ReadVNI != DefVNI &&
"Cannot read and define the same value.");
2103 if (copyValueUndefInPredecessors(S,
MBB, SLRQ)) {
2104 LLVM_DEBUG(
dbgs() <<
"Incoming sublane value is undef at copy\n");
2105 PrunedLanes |= S.LaneMask;
2112 if (PrunedLanes.
any()) {
2113 LLVM_DEBUG(
dbgs() <<
"Pruning undef incoming lanes: " << PrunedLanes
2115 setUndefOnPrunedSubRegUses(LI,
CP.getSrcReg(), PrunedLanes);
2120 deleteInstr(CopyMI);
2129 if (!canJoinPhys(CP)) {
2132 bool IsDefCopy =
false;
2133 if (reMaterializeTrivialDef(CP, CopyMI, IsDefCopy))
2146 dbgs() <<
"\tConsidering merging to "
2147 <<
TRI->getRegClassName(
CP.getNewRC()) <<
" with ";
2148 if (
CP.getDstIdx() &&
CP.getSrcIdx())
2150 <<
TRI->getSubRegIndexName(
CP.getDstIdx()) <<
" and "
2152 <<
TRI->getSubRegIndexName(
CP.getSrcIdx()) <<
'\n';
2160 ShrinkMainRange =
false;
2166 if (!joinIntervals(CP)) {
2171 bool IsDefCopy =
false;
2172 if (reMaterializeTrivialDef(CP, CopyMI, IsDefCopy))
2177 if (!
CP.isPartial() && !
CP.isPhys()) {
2178 bool Changed = adjustCopiesBackFrom(CP, CopyMI);
2179 bool Shrink =
false;
2181 std::tie(Changed, Shrink) = removeCopyByCommutingDef(CP, CopyMI);
2183 deleteInstr(CopyMI);
2185 Register DstReg =
CP.isFlipped() ?
CP.getSrcReg() :
CP.getDstReg();
2197 if (!
CP.isPartial() && !
CP.isPhys())
2198 if (removePartialRedundancy(CP, *CopyMI))
2209 if (
CP.isCrossClass()) {
2211 MRI->setRegClass(
CP.getDstReg(),
CP.getNewRC());
2222 if (ErasedInstrs.
erase(CopyMI))
2224 CurrentErasedInstrs.
insert(CopyMI);
2229 updateRegDefsUses(
CP.getDstReg(),
CP.getDstReg(),
CP.getDstIdx());
2230 updateRegDefsUses(
CP.getSrcReg(),
CP.getDstReg(),
CP.getSrcIdx());
2233 if (ShrinkMask.
any()) {
2236 if ((S.LaneMask & ShrinkMask).none())
2241 ShrinkMainRange =
true;
2249 if (ToBeUpdated.
count(
CP.getSrcReg()))
2250 ShrinkMainRange =
true;
2252 if (ShrinkMainRange) {
2262 TRI->updateRegAllocHint(
CP.getSrcReg(),
CP.getDstReg(), *MF);
2267 dbgs() <<
"\tResult = ";
2279bool RegisterCoalescer::joinReservedPhysReg(
CoalescerPair &CP) {
2282 assert(
CP.isPhys() &&
"Must be a physreg copy");
2283 assert(
MRI->isReserved(DstReg) &&
"Not a reserved register");
2287 assert(
RHS.containsOneValue() &&
"Invalid join with reserved register");
2296 if (!
MRI->isConstantPhysReg(DstReg)) {
2300 if (!
MRI->isReserved(*RI))
2313 !RegMaskUsable.
test(DstReg.
id())) {
2326 if (
CP.isFlipped()) {
2334 CopyMI =
MRI->getVRegDef(SrcReg);
2335 deleteInstr(CopyMI);
2344 if (!
MRI->hasOneNonDBGUse(SrcReg)) {
2355 CopyMI = &*
MRI->use_instr_nodbg_begin(SrcReg);
2359 if (!
MRI->isConstantPhysReg(DstReg)) {
2367 if (
MI->readsRegister(DstReg,
TRI)) {
2377 <<
printReg(DstReg,
TRI) <<
" at " << CopyRegIdx <<
"\n");
2380 deleteInstr(CopyMI);
2390 MRI->clearKillFlags(
CP.getSrcReg());
2475 const unsigned SubIdx;
2483 const bool SubRangeJoin;
2486 const bool TrackSubRegLiveness;
2502 enum ConflictResolution {
2534 ConflictResolution Resolution = CR_Keep;
2544 VNInfo *RedefVNI =
nullptr;
2547 VNInfo *OtherVNI =
nullptr;
2560 bool ErasableImplicitDef =
false;
2564 bool Pruned =
false;
2567 bool PrunedComputed =
false;
2574 bool Identical =
false;
2578 bool isAnalyzed()
const {
return WriteLanes.
any(); }
2585 ErasableImplicitDef =
false;
2599 std::pair<const VNInfo *, Register> followCopyChain(
const VNInfo *VNI)
const;
2602 const JoinVals &
Other)
const;
2611 ConflictResolution analyzeValue(
unsigned ValNo, JoinVals &
Other);
2616 void computeAssignment(
unsigned ValNo, JoinVals &
Other);
2647 bool isPrunedValue(
unsigned ValNo, JoinVals &
Other);
2653 bool TrackSubRegLiveness)
2654 : LR(LR),
Reg(
Reg), SubIdx(SubIdx), LaneMask(LaneMask),
2655 SubRangeJoin(SubRangeJoin), TrackSubRegLiveness(TrackSubRegLiveness),
2656 NewVNInfo(newVNInfo),
CP(cp), LIS(lis), Indexes(LIS->getSlotIndexes()),
2657 TRI(
TRI), Assignments(LR.getNumValNums(), -1),
2658 Vals(LR.getNumValNums()) {}
2662 bool mapValues(JoinVals &
Other);
2666 bool resolveConflicts(JoinVals &
Other);
2686 void pruneMainSegments(
LiveInterval &LI,
bool &ShrinkMainRange);
2697 void removeImplicitDefs();
2700 const int *getAssignments()
const {
return Assignments.
data(); }
2703 ConflictResolution getResolution(
unsigned Num)
const {
2704 return Vals[Num].Resolution;
2711 bool &Redef)
const {
2716 L |=
TRI->getSubRegIndexLaneMask(
2724std::pair<const VNInfo *, Register>
2725JoinVals::followCopyChain(
const VNInfo *VNI)
const {
2731 assert(
MI &&
"No defining instruction");
2732 if (!
MI->isFullCopy())
2733 return std::make_pair(VNI, TrackReg);
2734 Register SrcReg =
MI->getOperand(1).getReg();
2736 return std::make_pair(VNI, TrackReg);
2750 LaneBitmask SMask =
TRI->composeSubRegIndexLaneMask(SubIdx, S.LaneMask);
2751 if ((SMask & LaneMask).
none())
2759 return std::make_pair(VNI, TrackReg);
2762 if (ValueIn ==
nullptr) {
2769 return std::make_pair(
nullptr, SrcReg);
2774 return std::make_pair(VNI, TrackReg);
2777bool JoinVals::valuesIdentical(
VNInfo *Value0,
VNInfo *Value1,
2778 const JoinVals &
Other)
const {
2781 std::tie(Orig0, Reg0) = followCopyChain(Value0);
2782 if (Orig0 == Value1 && Reg0 ==
Other.Reg)
2787 std::tie(Orig1, Reg1) =
Other.followCopyChain(Value1);
2791 if (Orig0 ==
nullptr || Orig1 ==
nullptr)
2792 return Orig0 == Orig1 && Reg0 == Reg1;
2798 return Orig0->
def == Orig1->
def && Reg0 == Reg1;
2801JoinVals::ConflictResolution JoinVals::analyzeValue(
unsigned ValNo,
2803 Val &
V = Vals[ValNo];
2804 assert(!
V.isAnalyzed() &&
"Value has already been analyzed!");
2816 :
TRI->getSubRegIndexLaneMask(SubIdx);
2817 V.ValidLanes =
V.WriteLanes = Lanes;
2826 V.ErasableImplicitDef =
true;
2830 V.ValidLanes =
V.WriteLanes = computeWriteLanes(
DefMI, Redef);
2849 assert((TrackSubRegLiveness ||
V.RedefVNI) &&
2850 "Instruction is reading nonexistent value");
2851 if (
V.RedefVNI !=
nullptr) {
2852 computeAssignment(
V.RedefVNI->id,
Other);
2853 V.ValidLanes |= Vals[
V.RedefVNI->id].ValidLanes;
2865 V.ErasableImplicitDef =
true;
2882 if (OtherVNI->
def < VNI->
def)
2883 Other.computeAssignment(OtherVNI->
id, *
this);
2888 return CR_Impossible;
2890 V.OtherVNI = OtherVNI;
2891 Val &OtherV =
Other.Vals[OtherVNI->
id];
2895 if (!OtherV.isAnalyzed() ||
Other.Assignments[OtherVNI->
id] == -1)
2902 if ((
V.ValidLanes & OtherV.ValidLanes).any())
2904 return CR_Impossible;
2919 Other.computeAssignment(
V.OtherVNI->id, *
this);
2920 Val &OtherV =
Other.Vals[
V.OtherVNI->id];
2922 if (OtherV.ErasableImplicitDef) {
2942 <<
", keeping it.\n");
2943 OtherV.mustKeepImplicitDef(*
TRI, *OtherImpDef);
2950 dbgs() <<
"IMPLICIT_DEF defined at " <<
V.OtherVNI->def
2951 <<
" may be live into EH pad successors, keeping it.\n");
2952 OtherV.mustKeepImplicitDef(*
TRI, *OtherImpDef);
2955 OtherV.ValidLanes &= ~OtherV.WriteLanes;
2970 if (
CP.isCoalescable(
DefMI)) {
2973 V.ValidLanes &= ~V.WriteLanes | OtherV.ValidLanes;
2988 valuesIdentical(VNI,
V.OtherVNI,
Other)) {
3011 if ((
V.WriteLanes & OtherV.ValidLanes).none())
3024 "Only early clobber defs can overlap a kill");
3025 return CR_Impossible;
3032 if ((
TRI->getSubRegIndexLaneMask(
Other.SubIdx) & ~
V.WriteLanes).none())
3033 return CR_Impossible;
3035 if (TrackSubRegLiveness) {
3040 if (!OtherLI.hasSubRanges()) {
3042 return (OtherMask &
V.WriteLanes).none() ? CR_Replace : CR_Impossible;
3050 TRI->composeSubRegIndexLaneMask(
Other.SubIdx, OtherSR.LaneMask);
3051 if ((OtherMask &
V.WriteLanes).none())
3054 auto OtherSRQ = OtherSR.Query(VNI->
def);
3055 if (OtherSRQ.valueIn() && OtherSRQ.endPoint() > VNI->
def) {
3057 return CR_Impossible;
3070 return CR_Impossible;
3079 return CR_Unresolved;
3082void JoinVals::computeAssignment(
unsigned ValNo, JoinVals &
Other) {
3083 Val &
V = Vals[ValNo];
3084 if (
V.isAnalyzed()) {
3087 assert(Assignments[ValNo] != -1 &&
"Bad recursion?");
3090 switch ((
V.Resolution = analyzeValue(ValNo,
Other))) {
3094 assert(
V.OtherVNI &&
"OtherVNI not assigned, can't merge.");
3095 assert(
Other.Vals[
V.OtherVNI->id].isAnalyzed() &&
"Missing recursion");
3096 Assignments[ValNo] =
Other.Assignments[
V.OtherVNI->id];
3100 <<
V.OtherVNI->def <<
" --> @"
3101 << NewVNInfo[Assignments[ValNo]]->def <<
'\n');
3104 case CR_Unresolved: {
3106 assert(
V.OtherVNI &&
"OtherVNI not assigned, can't prune");
3107 Val &OtherV =
Other.Vals[
V.OtherVNI->id];
3108 OtherV.Pruned =
true;
3113 Assignments[ValNo] = NewVNInfo.
size();
3119bool JoinVals::mapValues(JoinVals &
Other) {
3121 computeAssignment(i,
Other);
3122 if (Vals[i].Resolution == CR_Impossible) {
3131bool JoinVals::taintExtent(
3140 assert(OtherI !=
Other.LR.end() &&
"No conflict?");
3145 if (
End >= MBBEnd) {
3147 << OtherI->valno->id <<
'@' << OtherI->start <<
'\n');
3151 << OtherI->valno->id <<
'@' << OtherI->start <<
" to "
3156 TaintExtent.push_back(std::make_pair(
End, TaintedLanes));
3159 if (++OtherI ==
Other.LR.end() || OtherI->start >= MBBEnd)
3163 const Val &OV =
Other.Vals[OtherI->valno->id];
3164 TaintedLanes &= ~OV.WriteLanes;
3167 }
while (TaintedLanes.
any());
3173 if (
MI.isDebugOrPseudoInstr())
3180 unsigned S =
TRI->composeSubRegIndices(SubIdx, MO.
getSubReg());
3181 if ((Lanes &
TRI->getSubRegIndexLaneMask(S)).any())
3187bool JoinVals::resolveConflicts(JoinVals &
Other) {
3190 assert(
V.Resolution != CR_Impossible &&
"Unresolvable conflict");
3191 if (
V.Resolution != CR_Unresolved)
3200 assert(
V.OtherVNI &&
"Inconsistent conflict resolution.");
3202 const Val &OtherV =
Other.Vals[
V.OtherVNI->id];
3207 LaneBitmask TaintedLanes =
V.WriteLanes & OtherV.ValidLanes;
3209 if (!taintExtent(i, TaintedLanes,
Other, TaintExtent))
3213 assert(!TaintExtent.
empty() &&
"There should be at least one conflict.");
3226 "Interference ends on VNI->def. Should have been handled earlier");
3229 assert(LastMI &&
"Range must end at a proper instruction");
3230 unsigned TaintNum = 0;
3233 if (usesLanes(*
MI,
Other.Reg,
Other.SubIdx, TaintedLanes)) {
3238 if (&*
MI == LastMI) {
3239 if (++TaintNum == TaintExtent.
size())
3242 assert(LastMI &&
"Range must end at a proper instruction");
3243 TaintedLanes = TaintExtent[TaintNum].second;
3249 V.Resolution = CR_Replace;
3255bool JoinVals::isPrunedValue(
unsigned ValNo, JoinVals &
Other) {
3256 Val &
V = Vals[ValNo];
3257 if (
V.Pruned ||
V.PrunedComputed)
3260 if (
V.Resolution != CR_Erase &&
V.Resolution != CR_Merge)
3265 V.PrunedComputed =
true;
3266 V.Pruned =
Other.isPrunedValue(
V.OtherVNI->id, *
this);
3270void JoinVals::pruneValues(JoinVals &
Other,
3272 bool changeInstrs) {
3275 switch (Vals[i].Resolution) {
3285 Val &OtherV =
Other.Vals[Vals[i].OtherVNI->id];
3287 OtherV.ErasableImplicitDef && OtherV.Resolution == CR_Keep;
3288 if (!
Def.isBlock()) {
3295 if (MO.
getReg() == Reg) {
3308 <<
": " <<
Other.LR <<
'\n');
3313 if (isPrunedValue(i,
Other)) {
3320 << Def <<
": " << LR <<
'\n');
3378 bool DidPrune =
false;
3383 if (
V.Resolution != CR_Erase &&
3384 (
V.Resolution != CR_Keep || !
V.ErasableImplicitDef || !
V.Pruned))
3391 OtherDef =
V.OtherVNI->def;
3394 LLVM_DEBUG(
dbgs() <<
"\t\tExpecting instruction removal at " << Def
3402 if (ValueOut !=
nullptr &&
3404 (
V.Identical &&
V.Resolution == CR_Erase && ValueOut->
def == Def))) {
3406 <<
" at " << Def <<
"\n");
3413 if (
V.Identical && S.Query(OtherDef).valueOutOrDead()) {
3423 ShrinkMask |= S.LaneMask;
3437 ShrinkMask |= S.LaneMask;
3449 if (VNI->
def == Def)
3455void JoinVals::pruneMainSegments(
LiveInterval &LI,
bool &ShrinkMainRange) {
3459 if (Vals[i].Resolution != CR_Keep)
3464 Vals[i].Pruned =
true;
3465 ShrinkMainRange =
true;
3469void JoinVals::removeImplicitDefs() {
3472 if (
V.Resolution != CR_Keep || !
V.ErasableImplicitDef || !
V.Pruned)
3488 switch (Vals[i].Resolution) {
3493 if (!Vals[i].ErasableImplicitDef || !Vals[i].Pruned)
3505 if (LI !=
nullptr) {
3530 ED = ED.
isValid() ? std::min(ED,
I->start) :
I->start;
3532 LE =
LE.isValid() ? std::max(LE,
I->end) :
I->
end;
3535 NewEnd = std::min(NewEnd, LE);
3537 NewEnd = std::min(NewEnd, ED);
3543 if (S != LR.
begin())
3544 std::prev(S)->end = NewEnd;
3548 dbgs() <<
"\t\tremoved " << i <<
'@' <<
Def <<
": " << LR <<
'\n';
3550 dbgs() <<
"\t\t LHS = " << *LI <<
'\n';
3557 assert(
MI &&
"No instruction to erase");
3560 if (
Reg.isVirtual() && Reg !=
CP.getSrcReg() && Reg !=
CP.getDstReg())
3566 MI->eraseFromParent();
3579 JoinVals RHSVals(RRange,
CP.getSrcReg(),
CP.getSrcIdx(), LaneMask, NewVNInfo,
3580 CP, LIS,
TRI,
true,
true);
3581 JoinVals LHSVals(LRange,
CP.getDstReg(),
CP.getDstIdx(), LaneMask, NewVNInfo,
3582 CP, LIS,
TRI,
true,
true);
3589 if (!LHSVals.mapValues(RHSVals) || !RHSVals.mapValues(LHSVals)) {
3594 if (!LHSVals.resolveConflicts(RHSVals) ||
3595 !RHSVals.resolveConflicts(LHSVals)) {
3606 LHSVals.pruneValues(RHSVals, EndPoints,
false);
3607 RHSVals.pruneValues(LHSVals, EndPoints,
false);
3609 LHSVals.removeImplicitDefs();
3610 RHSVals.removeImplicitDefs();
3615 LRange.
join(RRange, LHSVals.getAssignments(), RHSVals.getAssignments(),
3620 if (EndPoints.
empty())
3626 dbgs() <<
"\t\trestoring liveness to " << EndPoints.
size() <<
" points: ";
3627 for (
unsigned i = 0, n = EndPoints.
size(); i != n; ++i) {
3628 dbgs() << EndPoints[i];
3632 dbgs() <<
": " << LRange <<
'\n';
3637void RegisterCoalescer::mergeSubRangeInto(
LiveInterval &LI,
3641 unsigned ComposeSubRegIdx) {
3644 Allocator, LaneMask,
3647 SR.assign(ToMerge, Allocator);
3650 LiveRange RangeCopy(ToMerge, Allocator);
3651 joinSubRegRanges(SR, RangeCopy, SR.LaneMask, CP);
3657bool RegisterCoalescer::isHighCostLiveInterval(
LiveInterval &LI) {
3660 auto &Counter = LargeLIVisitCounter[LI.
reg()];
3672 bool TrackSubRegLiveness =
MRI->shouldTrackSubRegLiveness(*
CP.getNewRC());
3674 NewVNInfo, CP, LIS,
TRI,
false, TrackSubRegLiveness);
3676 NewVNInfo, CP, LIS,
TRI,
false, TrackSubRegLiveness);
3678 LLVM_DEBUG(
dbgs() <<
"\t\tRHS = " << RHS <<
"\n\t\tLHS = " << LHS <<
'\n');
3680 if (isHighCostLiveInterval(LHS) || isHighCostLiveInterval(RHS))
3685 if (!LHSVals.mapValues(RHSVals) || !RHSVals.mapValues(LHSVals))
3689 if (!LHSVals.resolveConflicts(RHSVals) || !RHSVals.resolveConflicts(LHSVals))
3693 if (
RHS.hasSubRanges() ||
LHS.hasSubRanges()) {
3698 unsigned DstIdx =
CP.getDstIdx();
3699 if (!
LHS.hasSubRanges()) {
3701 :
TRI->getSubRegIndexLaneMask(DstIdx);
3704 LHS.createSubRangeFrom(Allocator, Mask, LHS);
3705 }
else if (DstIdx != 0) {
3716 unsigned SrcIdx =
CP.getSrcIdx();
3717 if (!
RHS.hasSubRanges()) {
3719 :
TRI->getSubRegIndexLaneMask(SrcIdx);
3720 mergeSubRangeInto(LHS, RHS, Mask, CP, DstIdx);
3725 mergeSubRangeInto(LHS, R, Mask, CP, DstIdx);
3732 LHSVals.pruneMainSegments(LHS, ShrinkMainRange);
3734 LHSVals.pruneSubRegValues(LHS, ShrinkMask);
3735 RHSVals.pruneSubRegValues(LHS, ShrinkMask);
3736 }
else if (TrackSubRegLiveness && !
CP.getDstIdx() &&
CP.getSrcIdx()) {
3738 CP.getNewRC()->getLaneMask(), LHS);
3739 mergeSubRangeInto(LHS, RHS,
TRI->getSubRegIndexLaneMask(
CP.getSrcIdx()), CP,
3741 LHSVals.pruneMainSegments(LHS, ShrinkMainRange);
3742 LHSVals.pruneSubRegValues(LHS, ShrinkMask);
3750 LHSVals.pruneValues(RHSVals, EndPoints,
true);
3751 RHSVals.pruneValues(LHSVals, EndPoints,
true);
3756 LHSVals.eraseInstrs(ErasedInstrs, ShrinkRegs, &LHS);
3757 RHSVals.eraseInstrs(ErasedInstrs, ShrinkRegs);
3758 while (!ShrinkRegs.
empty())
3762 checkMergingChangesDbgValues(CP, LHS, LHSVals, RHS, RHSVals);
3766 auto RegIt = RegToPHIIdx.
find(
CP.getSrcReg());
3767 if (RegIt != RegToPHIIdx.
end()) {
3769 for (
unsigned InstID : RegIt->second) {
3770 auto PHIIt = PHIValToPos.
find(InstID);
3775 auto LII =
RHS.find(SI);
3776 if (LII ==
RHS.end() || LII->start > SI)
3791 if (
CP.getSrcIdx() != 0 ||
CP.getDstIdx() != 0)
3794 if (PHIIt->second.SubReg && PHIIt->second.SubReg !=
CP.getSrcIdx())
3798 PHIIt->second.Reg =
CP.getDstReg();
3802 if (
CP.getSrcIdx() != 0)
3803 PHIIt->second.SubReg =
CP.getSrcIdx();
3809 auto InstrNums = RegIt->second;
3810 RegToPHIIdx.
erase(RegIt);
3814 RegIt = RegToPHIIdx.
find(
CP.getDstReg());
3815 if (RegIt != RegToPHIIdx.
end())
3818 RegToPHIIdx.
insert({
CP.getDstReg(), InstrNums});
3822 LHS.join(RHS, LHSVals.getAssignments(), RHSVals.getAssignments(), NewVNInfo);
3827 MRI->clearKillFlags(
LHS.reg());
3828 MRI->clearKillFlags(
RHS.reg());
3830 if (!EndPoints.
empty()) {
3834 dbgs() <<
"\t\trestoring liveness to " << EndPoints.
size() <<
" points: ";
3835 for (
unsigned i = 0, n = EndPoints.
size(); i != n; ++i) {
3836 dbgs() << EndPoints[i];
3840 dbgs() <<
": " <<
LHS <<
'\n';
3849 return CP.isPhys() ? joinReservedPhysReg(CP) : joinVirtRegs(
CP);
3859 for (
auto *
X : ToInsert) {
3860 for (
const auto &
Op :
X->debug_operands()) {
3861 if (
Op.isReg() &&
Op.getReg().isVirtual())
3872 for (
auto &
MBB : MF) {
3875 for (
auto &
MI :
MBB) {
3876 if (
MI.isDebugValue()) {
3878 return MO.isReg() && MO.getReg().isVirtual();
3880 ToInsert.push_back(&
MI);
3881 }
else if (!
MI.isDebugOrPseudoInstr()) {
3883 CloseNewDVRange(CurrentSlot);
3892 for (
auto &Pair : DbgVRegToValues)
3896void RegisterCoalescer::checkMergingChangesDbgValues(
CoalescerPair &CP,
3900 JoinVals &RHSVals) {
3902 checkMergingChangesDbgValuesImpl(Reg, RHS, LHS, LHSVals);
3906 checkMergingChangesDbgValuesImpl(Reg, LHS, RHS, RHSVals);
3910 ScanForSrcReg(
CP.getSrcReg());
3911 ScanForDstReg(
CP.getDstReg());
3914void RegisterCoalescer::checkMergingChangesDbgValuesImpl(
Register Reg,
3917 JoinVals &RegVals) {
3919 auto VRegMapIt = DbgVRegToValues.
find(Reg);
3920 if (VRegMapIt == DbgVRegToValues.
end())
3923 auto &DbgValueSet = VRegMapIt->second;
3924 auto DbgValueSetIt = DbgValueSet.begin();
3925 auto SegmentIt = OtherLR.
begin();
3927 bool LastUndefResult =
false;
3932 auto ShouldUndef = [&RegVals, &
RegLR, &LastUndefResult,
3937 if (LastUndefIdx ==
Idx)
3938 return LastUndefResult;
3945 if (OtherIt ==
RegLR.end())
3954 auto Resolution = RegVals.getResolution(OtherIt->valno->id);
3956 Resolution != JoinVals::CR_Keep && Resolution != JoinVals::CR_Erase;
3958 return LastUndefResult;
3964 while (DbgValueSetIt != DbgValueSet.end() && SegmentIt != OtherLR.
end()) {
3965 if (DbgValueSetIt->first < SegmentIt->end) {
3968 if (DbgValueSetIt->first >= SegmentIt->start) {
3969 bool HasReg = DbgValueSetIt->second->hasDebugOperandForReg(Reg);
3970 bool ShouldUndefReg = ShouldUndef(DbgValueSetIt->first);
3971 if (HasReg && ShouldUndefReg) {
3973 DbgValueSetIt->second->setDebugValueUndef();
3987struct MBBPriorityInfo {
3993 :
MBB(mbb),
Depth(depth), IsSplit(issplit) {}
4003 const MBBPriorityInfo *RHS) {
4005 if (
LHS->Depth !=
RHS->Depth)
4006 return LHS->Depth >
RHS->Depth ? -1 : 1;
4009 if (
LHS->IsSplit !=
RHS->IsSplit)
4010 return LHS->IsSplit ? -1 : 1;
4014 unsigned cl =
LHS->MBB->pred_size() +
LHS->MBB->succ_size();
4015 unsigned cr =
RHS->MBB->pred_size() +
RHS->MBB->succ_size();
4017 return cl > cr ? -1 : 1;
4020 return LHS->MBB->getNumber() <
RHS->MBB->getNumber() ? -1 : 1;
4025 if (!Copy->isCopy())
4028 if (Copy->getOperand(1).isUndef())
4031 Register SrcReg = Copy->getOperand(1).getReg();
4032 Register DstReg = Copy->getOperand(0).getReg();
4040void RegisterCoalescer::lateLiveIntervalUpdate() {
4046 if (!DeadDefs.
empty())
4047 eliminateDeadDefs();
4049 ToBeUpdated.clear();
4052bool RegisterCoalescer::copyCoalesceWorkList(
4054 bool Progress =
false;
4066 bool Success = joinCopy(
MI, Again, CurrentErasedInstrs);
4072 if (!CurrentErasedInstrs.
empty()) {
4074 if (
MI && CurrentErasedInstrs.
count(
MI))
4078 if (
MI && CurrentErasedInstrs.
count(
MI))
4089 assert(Copy.isCopyLike());
4092 if (&
MI != &Copy &&
MI.isCopyLike())
4097bool RegisterCoalescer::applyTerminalRule(
const MachineInstr &Copy)
const {
4102 unsigned SrcSubReg = 0, DstSubReg = 0;
4103 if (!
isMoveInstr(*
TRI, &Copy, SrcReg, DstReg, SrcSubReg, DstSubReg))
4124 if (&
MI == &Copy || !
MI.isCopyLike() ||
MI.getParent() != OrigBB)
4127 unsigned OtherSrcSubReg = 0, OtherSubReg = 0;
4128 if (!
isMoveInstr(*
TRI, &Copy, OtherSrcReg, OtherReg, OtherSrcSubReg,
4131 if (OtherReg == SrcReg)
4132 OtherReg = OtherSrcReg;
4151 const unsigned PrevSize = WorkList.
size();
4152 if (JoinGlobalCopies) {
4158 if (!
MI.isCopyLike())
4160 bool ApplyTerminalRule = applyTerminalRule(
MI);
4162 if (ApplyTerminalRule)
4167 if (ApplyTerminalRule)
4174 LocalWorkList.
append(LocalTerminals.
begin(), LocalTerminals.
end());
4181 if (MII.isCopyLike()) {
4182 if (applyTerminalRule(MII))
4195 if (copyCoalesceWorkList(CurrList))
4197 std::remove(WorkList.
begin() + PrevSize, WorkList.
end(),
nullptr),
4201void RegisterCoalescer::coalesceLocals() {
4202 copyCoalesceWorkList(LocalWorkList);
4207 LocalWorkList.clear();
4210void RegisterCoalescer::joinAllIntervals() {
4211 LLVM_DEBUG(
dbgs() <<
"********** JOINING INTERVALS ***********\n");
4212 assert(WorkList.
empty() && LocalWorkList.empty() &&
"Old data still around.");
4214 std::vector<MBBPriorityInfo> MBBs;
4215 MBBs.reserve(MF->size());
4217 MBBs.push_back(MBBPriorityInfo(&
MBB,
Loops->getLoopDepth(&
MBB),
4223 unsigned CurrDepth = std::numeric_limits<unsigned>::max();
4224 for (MBBPriorityInfo &
MBB : MBBs) {
4226 if (JoinGlobalCopies &&
MBB.Depth < CurrDepth) {
4228 CurrDepth =
MBB.Depth;
4230 copyCoalesceInMBB(
MBB.MBB);
4232 lateLiveIntervalUpdate();
4237 while (copyCoalesceWorkList(WorkList))
4239 lateLiveIntervalUpdate();
4249 RegisterCoalescer Impl(&LIS, SI, &
Loops);
4261bool RegisterCoalescerLegacy::runOnMachineFunction(
MachineFunction &MF) {
4262 auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
4263 auto *
Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
4264 auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
4265 SlotIndexes *SI = SIWrapper ? &SIWrapper->getSI() :
nullptr;
4266 RegisterCoalescer Impl(LIS, SI,
Loops);
4267 return Impl.run(MF);
4271 LLVM_DEBUG(
dbgs() <<
"********** REGISTER COALESCER **********\n"
4272 <<
"********** Function: " << fn.
getName() <<
'\n');
4284 dbgs() <<
"* Skipped as it exposes functions that returns twice.\n");
4304 unsigned SubReg = DebugPHI.second.SubReg;
4307 PHIValToPos.
insert(std::make_pair(DebugPHI.first,
P));
4308 RegToPHIIdx[
Reg].push_back(DebugPHI.first);
4317 MF->
verify(LIS, SI,
"Before register coalescing", &
errs());
4319 DbgVRegToValues.
clear();
4336 if (
MRI->reg_nodbg_empty(Reg))
4338 if (
MRI->recomputeRegClass(Reg)) {
4340 <<
TRI->getRegClassName(
MRI->getRegClass(Reg)) <<
'\n');
4347 if (!
MRI->shouldTrackSubRegLiveness(Reg)) {
4355 assert((S.LaneMask & ~MaxMask).none());
4366 auto it = PHIValToPos.
find(
p.first);
4368 p.second.Reg = it->second.Reg;
4369 p.second.SubReg = it->second.SubReg;
4372 PHIValToPos.
clear();
4373 RegToPHIIdx.
clear();
4378 MF->
verify(LIS, SI,
"After register coalescing", &
errs());
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements the BitVector class.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseSet and SmallDenseSet classes.
std::optional< std::vector< StOtherPiece > > Other
SmallVector< uint32_t, 0 > Writes
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const HexagonInstrInfo * TII
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static cl::opt< cl::boolOrDefault > EnableGlobalCopies("join-globalcopies", cl::desc("Coalesce copies that span blocks (default=subtarget)"), cl::init(cl::BOU_UNSET), cl::Hidden)
Temporary flag to test global copy optimization.
static bool isLocalCopy(MachineInstr *Copy, const LiveIntervals *LIS)
static bool isSplitEdge(const MachineBasicBlock *MBB)
Return true if this block should be vacated by the coalescer to eliminate branches.
static int compareMBBPriority(const MBBPriorityInfo *LHS, const MBBPriorityInfo *RHS)
C-style comparator that sorts first based on the loop depth of the basic block (the unsigned),...
register Register Coalescer
static cl::opt< unsigned > LargeIntervalSizeThreshold("large-interval-size-threshold", cl::Hidden, cl::desc("If the valnos size of an interval is larger than the threshold, " "it is regarded as a large interval. "), cl::init(100))
static bool isDefInSubRange(LiveInterval &LI, SlotIndex Def)
Check if any of the subranges of LI contain a definition at Def.
static std::pair< bool, bool > addSegmentsWithValNo(LiveRange &Dst, VNInfo *DstValNo, const LiveRange &Src, const VNInfo *SrcValNo)
Copy segments with value number SrcValNo from liverange Src to live range @Dst and use value number D...
static bool isLiveThrough(const LiveQueryResult Q)
static bool isTerminalReg(Register DstReg, const MachineInstr &Copy, const MachineRegisterInfo *MRI)
Check if DstReg is a terminal node.
static cl::opt< bool > VerifyCoalescing("verify-coalescing", cl::desc("Verify machine instrs before and after register coalescing"), cl::Hidden)
register Register static false bool isMoveInstr(const TargetRegisterInfo &tri, const MachineInstr *MI, Register &Src, Register &Dst, unsigned &SrcSub, unsigned &DstSub)
static cl::opt< bool > EnableJoinSplits("join-splitedges", cl::desc("Coalesce copies on split edges (default=subtarget)"), cl::Hidden)
Temporary flag to test critical edge unsplitting.
static cl::opt< bool > EnableJoining("join-liveintervals", cl::desc("Coalesce copies (default=true)"), cl::init(true), cl::Hidden)
static cl::opt< unsigned > LargeIntervalFreqThreshold("large-interval-freq-threshold", cl::Hidden, cl::desc("For a large interval, if it is coalesced with other live " "intervals many times more than the threshold, stop its " "coalescing to control the compile time. "), cl::init(256))
static bool definesFullReg(const MachineInstr &MI, Register Reg)
Returns true if MI defines the full vreg Reg, as opposed to just defining a subregister.
static cl::opt< unsigned > LateRematUpdateThreshold("late-remat-update-threshold", cl::Hidden, cl::desc("During rematerialization for a copy, if the def instruction has " "many other copy uses to be rematerialized, delay the multiple " "separate live interval update work and do them all at once after " "all those rematerialization are done. It will save a lot of " "repeated work. "), cl::init(100))
static cl::opt< bool > UseTerminalRule("terminal-rule", cl::desc("Apply the terminal rule"), cl::init(false), cl::Hidden)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static DenseMap< Register, std::vector< std::pair< SlotIndex, MachineInstr * > > > buildVRegToDbgValueMap(MachineFunction &MF, const LiveIntervals *Liveness)
static void shrinkToUses(LiveInterval &LI, LiveIntervals &LIS)
A container for analyses that lazily runs them and caches their results.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addPreservedID(const void *ID)
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool test(unsigned Idx) const
Allocate memory in an ever growing pool, as if by bump-pointer.
Represents analyses that only rely on functions' control flow.
A helper class for register coalescers.
bool flip()
Swap SrcReg and DstReg.
bool isCoalescable(const MachineInstr *) const
Return true if MI is a copy instruction that will become an identity copy after coalescing.
bool setRegisters(const MachineInstr *)
Set registers to match the copy instruction MI.
This class represents an Operation in the Expression.
The location of a single variable, composed of an expression and 0 or more DbgValueLocEntries.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
bool isAsCheapAsAMove(const MachineInstr &MI) const override
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
LLVM_ABI void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
bool hasSubRanges() const
Returns true if subregister liveness information is available.
SubRange * createSubRangeFrom(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, const LiveRange &CopyFrom)
Like createSubRange() but the new range is filled with a copy of the liveness information in CopyFrom...
iterator_range< subrange_iterator > subranges()
LLVM_ABI void refineSubRanges(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, std::function< void(LiveInterval::SubRange &)> Apply, const SlotIndexes &Indexes, const TargetRegisterInfo &TRI, unsigned ComposeSubRegIdx=0)
Refines the subranges to support LaneMask.
LLVM_ABI void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
SubRange * createSubRange(BumpPtrAllocator &Allocator, LaneBitmask LaneMask)
Creates a new empty subregister live range.
LLVM_ABI void clearSubRanges()
Removes all subregister liveness information.
bool hasInterval(Register Reg) const
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
LLVM_ABI bool hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const
Returns true if VNI is killed by any PHI-def values in LI.
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
LLVM_ABI bool checkRegMaskInterference(const LiveInterval &LI, BitVector &UsableRegs)
Test if LI is live across any register mask instructions, and compute a bit mask of physical register...
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
VNInfo::Allocator & getVNInfoAllocator()
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
LiveRange & getRegUnit(unsigned Unit)
Return the live range for register unit Unit.
LiveRange * getCachedRegUnit(unsigned Unit)
Return the live range for register unit Unit if it has already been computed, or nullptr if it hasn't...
LiveInterval & getInterval(Register Reg)
LLVM_ABI void pruneValue(LiveRange &LR, SlotIndex Kill, SmallVectorImpl< SlotIndex > *EndPoints)
If LR has a live value at Kill, prune its live range by removing any liveness reachable from Kill.
void removeInterval(Register Reg)
Interval removal.
LLVM_ABI MachineBasicBlock * intervalIsInOneMBB(const LiveInterval &LI) const
If LI is confined to a single basic block, return a pointer to that block.
LLVM_ABI void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos.
LLVM_ABI bool shrinkToUses(LiveInterval *li, SmallVectorImpl< MachineInstr * > *dead=nullptr)
After removing some uses of a register, shrink its live range to just the remaining uses.
LLVM_ABI void extendToIndices(LiveRange &LR, ArrayRef< SlotIndex > Indices, ArrayRef< SlotIndex > Undefs)
Extend the live range LR to reach all points in Indices.
LLVM_ABI void dump() const
LLVM_ABI void removePhysRegDefAt(MCRegister Reg, SlotIndex Pos)
Remove value numbers and related live segments starting at position Pos that are part of any liverang...
LLVM_ABI void splitSeparateComponents(LiveInterval &LI, SmallVectorImpl< LiveInterval * > &SplitLIs)
Split separate components in LiveInterval LI into separate intervals.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
bool isLiveInToMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
SlotIndex ReplaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
Result of a LiveRange query.
VNInfo * valueOutOrDead() const
Returns the value alive at the end of the instruction, if any.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
VNInfo * valueOut() const
Return the value leaving the instruction, if any.
VNInfo * valueDefined() const
Return the value defined by this instruction, if any.
SlotIndex endPoint() const
Return the end point of the last live range segment to interact with the instruction,...
bool isKill() const
Return true if the live-in value is killed by this instruction.
Callback methods for LiveRangeEdit owners.
virtual void LRE_WillEraseInstruction(MachineInstr *MI)
Called immediately before erasing a dead machine instruction.
bool canRematerializeAt(Remat &RM, VNInfo *OrigVNI, SlotIndex UseIdx)
canRematerializeAt - Determine if ParentVNI can be rematerialized at UseIdx.
SlotIndex rematerializeAt(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, const Remat &RM, const TargetRegisterInfo &, bool Late=false, unsigned SubIdx=0, MachineInstr *ReplaceIndexMI=nullptr)
rematerializeAt - Rematerialize RM.ParentVNI into DestReg by inserting an instruction into MBB before...
void eliminateDeadDefs(SmallVectorImpl< MachineInstr * > &Dead, ArrayRef< Register > RegsBeingSpilled={})
eliminateDeadDefs - Try to delete machine instructions that are now dead (allDefsAreDead returns true...
bool checkRematerializable(VNInfo *VNI, const MachineInstr *DefMI)
checkRematerializable - Manually add VNI to the list of rematerializable values if DefMI may be remat...
This class represents the liveness of a register, stack slot, etc.
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
LLVM_ABI iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
LLVM_ABI void join(LiveRange &Other, const int *ValNoAssignments, const int *RHSValNoAssignments, SmallVectorImpl< VNInfo * > &NewVNInfo)
join - Join two live ranges (this, and other) together.
bool liveAt(SlotIndex index) const
LLVM_ABI VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
LLVM_ABI void removeValNo(VNInfo *ValNo)
removeValNo - Remove all the segments defined by the specified value#.
bool overlaps(const LiveRange &other) const
overlaps - Return true if the intersection of the two live ranges is not empty.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
bool verify() const
Walk the range and assert if any invariants fail to hold.
LLVM_ABI VNInfo * MergeValueNumberInto(VNInfo *V1, VNInfo *V2)
MergeValueNumberInto - This method is called when two value numbers are found to be equivalent.
unsigned getNumValNums() const
bool containsOneValue() const
iterator FindSegmentContaining(SlotIndex Idx)
Return an iterator to the segment that contains the specified index, or end() if there is none.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
LLVM_ABI iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
MCRegUnitRootIterator enumerates the root registers of a register unit.
bool isValid() const
Check if the iterator is at the end of the list.
Wrapper class representing physical registers. Should be passed by value.
An RAII based helper class to modify MachineFunctionProperties when running pass.
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
unsigned pred_size() const
LLVM_ABI bool hasEHPadSuccessor() const
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned succ_size() const
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
Analysis pass which computes a MachineDominatorTree.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual MachineFunctionProperties getClearedProperties() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
DenseMap< unsigned, DebugPHIRegallocPos > DebugPHIPositions
Map of debug instruction numbers to the position of their PHI instructions during register allocation...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI void setRegisterDefReadUndef(Register Reg, bool IsUndef=true)
Mark all subregister defs of register Reg with the undef flag.
bool isImplicitDef() const
const MachineBasicBlock * getParent() const
bool isCopyLike() const
Return true if the instruction behaves like a copy.
filtered_mop_range all_defs()
Returns an iterator range over all operands that are (explicit or implicit) register defs.
LLVM_ABI std::pair< bool, bool > readsWritesVirtualRegister(Register Reg, SmallVectorImpl< unsigned > *Ops=nullptr) const
Return a pair of bools (reads, writes) indicating if this instruction reads or writes Reg.
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
LLVM_ABI bool isSafeToMove(bool &SawStore) const
Return true if it is safe to move this instruction.
bool isDebugInstr() const
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx=nullptr) const
Given the index of a register def operand, check if the register def is tied to a source operand,...
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.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool isCommutable(QueryType Type=IgnoreBundle) const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z,...
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
LLVM_ABI void substituteRegister(Register FromReg, Register ToReg, unsigned SubIdx, const TargetRegisterInfo &RegInfo)
Replace all occurrences of FromReg with ToReg:SubIdx, properly composing subreg indices where necessa...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
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
LLVM_ABI int findRegisterDefOperandIdx(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false) const
Returns the operand index that is a def of the specified register or -1 if it is not found.
void setDebugLoc(DebugLoc DL)
Replace current source information with new such.
LLVM_ABI bool allDefsAreDead() const
Return true if all the defs of this instruction are dead.
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
LLVM_ABI void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
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.
void setIsDead(bool Val=true)
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(bool Val=true)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
LLVM_ABI void substPhysReg(MCRegister Reg, const TargetRegisterInfo &)
substPhysReg - Substitute the current register with the physical register Reg, taking any existing Su...
void setIsUndef(bool Val=true)
bool isEarlyClobber() const
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)
defusechain_iterator - This class provides iterator support for machine operands in the function that...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool isProperSubClass(const TargetRegisterClass *RC) const
isProperSubClass - Returns true if RC has a legal super-class with more allocatable registers.
LLVM_ABI void runOnMachineFunction(const MachineFunction &MF, bool Rev=false)
runOnFunction - Prepare to answer questions about MF.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr unsigned id() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SlotIndex - An opaque wrapper around machine indexes.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool isEarlyClobber() const
isEarlyClobber - Returns true if this is an early-clobber slot.
bool isValid() const
Returns true if this is a valid index.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
SlotIndex getIndexBefore(const MachineInstr &MI) const
getIndexBefore - Returns the index of the last indexed instruction before MI, or the start index of i...
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
static const unsigned CommuteAnyOperandIndex
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual bool enableJoinGlobalCopies() const
True if the subtarget should enable joining global copies.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
VNInfo - Value Number Information.
void markUnused()
Mark this value as unused.
bool isUnused() const
Returns true if this value is unused.
unsigned id
The ID number of this value.
SlotIndex def
The index of the defining instruction.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
NodeAddr< DefNode * > Def
LLVM_ABI const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI char & RegisterCoalescerID
RegisterCoalescer - This pass merges live ranges to eliminate copies.
LLVM_ABI char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LLVM_ABI Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
auto unique(Range &&R, Predicate P)
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
LLVM_ABI void initializeRegisterCoalescerLegacyPass(PassRegistry &)
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Success
The lock was released successfully.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void eraseInstrs(ArrayRef< MachineInstr * > DeadInstrs, MachineRegisterInfo &MRI, LostDebugLocObserver *LocObserver=nullptr)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static constexpr LaneBitmask getLane(unsigned Lane)
static constexpr LaneBitmask getAll()
constexpr bool any() const
static constexpr LaneBitmask getNone()
Remat - Information needed to rematerialize at a specific location.
This represents a simple continuous liveness interval for a value.