62#define DEBUG_TYPE "regalloc"
66STATISTIC(NumCoalesced,
"Number of copies coalesced");
75class InstrPosIndexes {
77 void unsetInitialized() { IsInitialized =
false; }
79 void init(
const MachineBasicBlock &
MBB) {
81 Instr2PosIndex.
clear();
83 for (
const MachineInstr &
MI :
MBB) {
84 LastIndex += InstrDist;
85 Instr2PosIndex[&
MI] = LastIndex;
92 bool getIndex(
const MachineInstr &
MI,
uint64_t &Index) {
100 assert(
MI.getParent() == CurMBB &&
"MI is not in CurMBB");
101 auto It = Instr2PosIndex.find(&
MI);
102 if (It != Instr2PosIndex.end()) {
116 unsigned Distance = 1;
118 End = std::next(Start);
119 while (Start != CurMBB->begin() &&
120 !Instr2PosIndex.count(&*std::prev(Start))) {
124 while (
End != CurMBB->end() && !Instr2PosIndex.count(&*(
End))) {
132 Start == CurMBB->begin() ? 0 : Instr2PosIndex.at(&*std::prev(Start));
134 if (
End == CurMBB->end())
135 Step =
static_cast<uint64_t>(InstrDist);
139 assert(EndIndex > LastIndex &&
"Index must be ascending order");
140 unsigned NumAvailableIndexes = EndIndex - LastIndex - 1;
159 Step = (NumAvailableIndexes + 1) / (Distance + 1);
164 if (
LLVM_UNLIKELY(!Step || (!LastIndex && Step == InstrDist))) {
166 Index = Instr2PosIndex.at(&
MI);
170 for (
auto I = Start;
I !=
End; ++
I) {
172 Instr2PosIndex[&*
I] = LastIndex;
174 Index = Instr2PosIndex.at(&
MI);
179 bool IsInitialized =
false;
180 enum { InstrDist = 1024 };
181 const MachineBasicBlock *CurMBB =
nullptr;
182 DenseMap<const MachineInstr *, uint64_t> Instr2PosIndex;
185class RegAllocFastImpl {
188 bool ClearVirtRegs_ =
true)
189 : ShouldAllocateRegisterImpl(
F), StackSlotForVirtReg(-1),
190 ClearVirtRegs(ClearVirtRegs_) {}
193 MachineFrameInfo *MFI =
nullptr;
194 MachineRegisterInfo *MRI =
nullptr;
195 const TargetRegisterInfo *TRI =
nullptr;
196 const TargetInstrInfo *TII =
nullptr;
197 RegisterClassInfo *RegClassInfo =
nullptr;
202 bool LowerTiedOps =
false;
205 MachineBasicBlock *MBB =
nullptr;
208 IndexedMap<int, VirtReg2IndexFunctor> StackSlotForVirtReg;
213 MachineInstr *LastUse =
nullptr;
216 bool LiveOut =
false;
217 bool Reloaded =
false;
220 explicit LiveReg(
Register VirtReg) : VirtReg(VirtReg) {}
221 explicit LiveReg() =
default;
223 unsigned getSparseSetIndex()
const {
return VirtReg.virtRegIndex(); }
226 using LiveRegMap = SparseSet<LiveReg, unsigned, identity, uint16_t>;
229 LiveRegMap LiveVirtRegs;
232 DenseMap<Register, LiveReg> BundleVirtRegsMap;
234 DenseMap<Register, SmallVector<MachineOperand *, 2>> LiveDbgValueMap;
237 DenseMap<Register, SmallVector<MachineInstr *, 1>> DanglingDbgValues;
241 BitVector MayLiveAcrossBlocks;
262 std::vector<unsigned> RegUnitStates;
280 SmallVector<unsigned, 0> UsedInInstr;
285 SmallVector<unsigned, 8> DefOperandIndexes;
288 bool HasErrorDef =
false;
294 InstrPosIndexes PosIndexes;
296 void setRegUnitState(MCRegUnit Unit,
unsigned NewState);
297 unsigned getRegUnitState(MCRegUnit Unit)
const;
299 void setPhysRegState(MCRegister PhysReg,
unsigned NewState);
300 bool isPhysRegFree(MCRegister PhysReg)
const;
303 void markRegUsedInInstr(MCRegister PhysReg) {
304 for (MCRegUnit Unit : TRI->regunits(PhysReg))
305 UsedInInstr[
static_cast<unsigned>(
Unit)] = InstrGen | 1;
309 bool isClobberedByRegMasks(MCRegister PhysReg)
const {
310 return llvm::any_of(RegMasks, [PhysReg](
const uint32_t *Mask) {
316 bool isRegUsedInInstr(MCRegister PhysReg,
bool LookAtPhysRegUses)
const {
317 if (LookAtPhysRegUses && isClobberedByRegMasks(PhysReg))
319 for (MCRegUnit Unit : TRI->regunits(PhysReg))
320 if (UsedInInstr[
static_cast<unsigned>(Unit)] >=
321 (InstrGen | !LookAtPhysRegUses))
328 void markPhysRegUsedInInstr(MCRegister PhysReg) {
329 for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
330 assert(UsedInInstr[
static_cast<unsigned>(Unit)] <= InstrGen &&
331 "non-phys use before phys use?");
332 UsedInInstr[
static_cast<unsigned>(
Unit)] = InstrGen;
337 void unmarkRegUsedInInstr(MCRegister PhysReg) {
338 for (MCRegUnit Unit : TRI->regunits(PhysReg))
339 UsedInInstr[
static_cast<unsigned>(
Unit)] = 0;
344 bool hasLiveDefOfSuperReg(MCRegister PhysReg)
const {
345 return any_of(LiveDefRegs, [&](MCRegister LiveReg) {
346 return TRI->isSuperRegisterEq(PhysReg, LiveReg);
354 spillImpossible = ~0
u
360 bool runOnMachineFunction(
MachineFunction &MF, RegisterClassInfo &RCI);
363 void allocateBasicBlock(MachineBasicBlock &MBB);
364 void expandSubregPseudo(MachineInstr &
MI);
369 void findAndSortDefOperandIndexes(
const MachineInstr &
MI);
371 void allocateInstruction(MachineInstr &
MI);
372 void handleDebugValue(MachineInstr &
MI);
373 void handleBundle(MachineInstr &
MI);
375 bool usePhysReg(MachineInstr &
MI, MCRegister PhysReg);
376 bool definePhysReg(MachineInstr &
MI, MCRegister PhysReg);
377 bool displacePhysReg(MachineInstr &
MI, MCRegister PhysReg);
378 void freePhysReg(MCRegister PhysReg);
380 unsigned calcSpillCost(
MCPhysReg PhysReg)
const;
390 void assignVirtToPhysReg(MachineInstr &
MI, LiveReg &, MCRegister PhysReg);
391 void allocVirtReg(MachineInstr &
MI, LiveReg &LR,
Register Hint,
392 bool LookAtPhysRegUses =
false);
393 void allocVirtRegUndef(MachineOperand &MO);
394 void assignDanglingDebugValues(MachineInstr &Def,
Register VirtReg,
396 bool defineLiveThroughVirtReg(MachineInstr &
MI,
unsigned OpNum,
398 bool defineVirtReg(MachineInstr &
MI,
unsigned OpNum,
Register VirtReg,
399 bool LookAtPhysRegUses =
false);
400 bool useVirtReg(MachineInstr &
MI, MachineOperand &MO,
Register VirtReg);
401 bool lowerTiedUse(MachineInstr &
MI, MachineOperand &MO, LiveReg &LR);
403 MCPhysReg getErrorAssignment(
const LiveReg &LR, MachineInstr &
MI,
407 getMBBBeginInsertionPoint(MachineBasicBlock &MBB,
408 SmallSet<Register, 2> &PrologLiveIns)
const;
410 void reloadAtBegin(MachineBasicBlock &MBB);
411 bool setPhysReg(MachineInstr &
MI, MachineOperand &MO,
412 const LiveReg &Assignment);
417 bool shouldAllocateRegister(
const Register Reg)
const;
418 int getStackSpaceFor(
Register VirtReg);
420 MCRegister AssignedReg,
bool Kill,
bool LiveOut);
427 bool mayBeSpillFromInlineAsmBr(
const MachineInstr &
MI)
const;
429 void dumpState()
const;
433 RegAllocFastImpl Impl;
439 : MachineFunctionPass(ID), Impl(
F, ClearVirtRegs_) {}
442 return Impl.runOnMachineFunction(
443 MF, getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI());
446 StringRef getPassName()
const override {
return "Fast Register Allocator"; }
448 void getAnalysisUsage(AnalysisUsage &AU)
const override {
449 AU.
addRequired<MachineRegisterClassInfoWrapperPass>();
454 MachineFunctionProperties getRequiredProperties()
const override {
455 return MachineFunctionProperties().setNoPHIs();
458 MachineFunctionProperties getSetProperties()
const override {
459 MachineFunctionProperties
P;
460 if (Impl.ClearVirtRegs)
461 P.setNoVRegs().setTiedOpsRewritten();
465 MachineFunctionProperties getClearedProperties()
const override {
466 return MachineFunctionProperties().setIsSSA();
472char RegAllocFast::ID = 0;
482 if (!ShouldAllocateRegisterImpl)
485 return ShouldAllocateRegisterImpl(*
TRI, *
MRI,
Reg);
488void RegAllocFastImpl::setRegUnitState(MCRegUnit Unit,
unsigned NewState) {
489 RegUnitStates[
static_cast<unsigned>(
Unit)] = NewState;
492unsigned RegAllocFastImpl::getRegUnitState(MCRegUnit Unit)
const {
493 return RegUnitStates[
static_cast<unsigned>(
Unit)];
496void RegAllocFastImpl::setPhysRegState(MCRegister PhysReg,
unsigned NewState) {
497 for (MCRegUnit Unit :
TRI->regunits(PhysReg))
498 setRegUnitState(Unit, NewState);
501bool RegAllocFastImpl::isPhysRegFree(MCRegister PhysReg)
const {
502 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
503 if (getRegUnitState(Unit) != regFree)
511int RegAllocFastImpl::getStackSpaceFor(
Register VirtReg) {
513 int SS = StackSlotForVirtReg[VirtReg];
520 unsigned Size =
TRI->getSpillSize(RC);
525 Align CurrentAlign =
ST.getFrameLowering()->getStackAlign();
526 if (Alignment > CurrentAlign && !
TRI->canRealignStack(MF))
533 StackSlotForVirtReg[VirtReg] = FrameIdx;
540 PosIndexes.getIndex(
A, IndexA);
543 PosIndexes.getIndex(
A, IndexA);
544 return IndexA < IndexB;
551bool RegAllocFastImpl::mayBeSpillFromInlineAsmBr(
const MachineInstr &
MI)
const {
556 for (
const auto &
Op :
MI.operands())
563bool RegAllocFastImpl::mayLiveOut(
Register VirtReg) {
569 const MachineInstr *SelfLoopDef =
nullptr;
576 if (DefInst.getParent() !=
MBB) {
580 if (!SelfLoopDef ||
dominates(PosIndexes, DefInst, *SelfLoopDef))
581 SelfLoopDef = &DefInst;
592 static const unsigned Limit = 8;
595 if (UseInst.getParent() !=
MBB || ++
C >= Limit) {
604 if (SelfLoopDef == &UseInst ||
605 !
dominates(PosIndexes, *SelfLoopDef, UseInst)) {
616bool RegAllocFastImpl::mayLiveIn(
Register VirtReg) {
621 static const unsigned Limit = 8;
624 if (DefInst.getParent() !=
MBB || ++
C >= Limit) {
636 Register VirtReg, MCRegister AssignedReg,
637 bool Kill,
bool LiveOut) {
640 int FI = getStackSpaceFor(VirtReg);
652 SmallVectorImpl<MachineOperand *> &LRIDbgOperands = LiveDbgValueMap[VirtReg];
653 SmallMapVector<MachineInstr *, SmallVector<const MachineOperand *>, 2>
655 for (MachineOperand *MO : LRIDbgOperands)
656 SpilledOperandsMap[MO->getParent()].push_back(MO);
657 for (
const auto &MISpilledOperands : SpilledOperandsMap) {
658 MachineInstr &
DBG = *MISpilledOperands.first;
660 if (
DBG.isDebugValueList())
663 *
MBB, Before, *MISpilledOperands.first, FI, MISpilledOperands.second);
666 LLVM_DEBUG(
dbgs() <<
"Inserting debug info due to spill:\n" << *NewDV);
673 MachineInstr *ClonedDV =
MBB->
getParent()->CloneMachineInstr(NewDV);
675 LLVM_DEBUG(
dbgs() <<
"Cloning debug info due to live out spill\n");
681 if (
DBG.isNonListDebugValue()) {
682 MachineOperand &MO =
DBG.getDebugOperand(0);
691 LRIDbgOperands.
clear();
696 Register VirtReg, MCRegister PhysReg) {
699 int FI = getStackSpaceFor(VirtReg);
710 MachineBasicBlock &
MBB, SmallSet<Register, 2> &PrologLiveIns)
const {
719 if (!
TII->isBasicBlockPrologue(*
I) && !mayBeSpillFromInlineAsmBr(*
I))
724 for (MachineOperand &MO :
I->operands()) {
736void RegAllocFastImpl::reloadAtBegin(MachineBasicBlock &
MBB) {
737 if (LiveVirtRegs.empty())
742 for (MachineBasicBlock::RegisterMaskPair
P :
MBB.
liveins())
743 setPhysRegState(
P.PhysReg, regLiveIn);
745 SmallSet<Register, 2> PrologLiveIns;
750 getMBBBeginInsertionPoint(
MBB, PrologLiveIns);
751 for (
const LiveReg &LR : LiveVirtRegs) {
752 MCRegister PhysReg = LR.PhysReg;
753 if (!PhysReg || LR.Error)
756 MCRegUnit FirstUnit = *
TRI->regunits(PhysReg).begin();
757 if (getRegUnitState(FirstUnit) == regLiveIn)
761 "no reload in start block. Missing vreg def?");
763 if (PrologLiveIns.
count(PhysReg)) {
767 reload(
MBB.
begin(), LR.VirtReg, PhysReg);
769 reload(InsertBefore, LR.VirtReg, PhysReg);
771 LiveVirtRegs.clear();
778bool RegAllocFastImpl::usePhysReg(MachineInstr &
MI, MCRegister
Reg) {
780 bool displacedAny = displacePhysReg(
MI,
Reg);
781 setPhysRegState(
Reg, regPreAssigned);
782 markRegUsedInInstr(
Reg);
791bool RegAllocFastImpl::definePhysReg(MachineInstr &
MI, MCRegister
Reg) {
792 bool displacedAny = displacePhysReg(
MI,
Reg);
793 setPhysRegState(
Reg, regPreAssigned);
800bool RegAllocFastImpl::displacePhysReg(MachineInstr &
MI, MCRegister PhysReg) {
801 bool displacedAny =
false;
803 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
804 switch (
unsigned VirtReg = getRegUnitState(Unit)) {
806 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
807 assert(LRI != LiveVirtRegs.end() &&
"datastructures in sync");
810 while (mayBeSpillFromInlineAsmBr(*ReloadBefore))
812 reload(ReloadBefore, VirtReg, LRI->PhysReg);
814 setPhysRegState(LRI->PhysReg, regFree);
815 LRI->PhysReg = MCRegister();
816 LRI->Reloaded =
true;
821 setRegUnitState(Unit, regFree);
831void RegAllocFastImpl::freePhysReg(MCRegister PhysReg) {
834 MCRegUnit FirstUnit = *
TRI->regunits(PhysReg).begin();
835 switch (
unsigned VirtReg = getRegUnitState(FirstUnit)) {
841 setPhysRegState(PhysReg, regFree);
844 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
845 assert(LRI != LiveVirtRegs.end());
847 setPhysRegState(LRI->PhysReg, regFree);
848 LRI->PhysReg = MCRegister();
858unsigned RegAllocFastImpl::calcSpillCost(
MCPhysReg PhysReg)
const {
859 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
860 switch (
unsigned VirtReg = getRegUnitState(Unit)) {
866 return spillImpossible;
868 bool SureSpill = StackSlotForVirtReg[VirtReg] != -1 ||
869 findLiveVirtReg(VirtReg)->LiveOut;
870 return SureSpill ? spillClean : spillDirty;
877void RegAllocFastImpl::assignDanglingDebugValues(MachineInstr &Definition,
880 auto UDBGValIter = DanglingDbgValues.
find(VirtReg);
881 if (UDBGValIter == DanglingDbgValues.
end())
884 SmallVectorImpl<MachineInstr *> &Dangling = UDBGValIter->second;
885 for (MachineInstr *DbgValue : Dangling) {
886 assert(DbgValue->isDebugValue());
887 if (!DbgValue->hasDebugOperandForReg(VirtReg))
893 MCRegister SetToReg =
Reg;
896 if (!Definition.definesRegister(
Reg,
TRI))
899 if (
I->modifiesRegister(
Reg,
TRI) || --Limit == 0) {
902 SetToReg = MCRegister();
906 for (MachineOperand &MO : DbgValue->getDebugOperandsForReg(VirtReg)) {
918void RegAllocFastImpl::assignVirtToPhysReg(MachineInstr &AtMI, LiveReg &LR,
919 MCRegister PhysReg) {
923 assert(!LR.PhysReg &&
"Already assigned a physreg");
924 assert(PhysReg &&
"Trying to assign no register");
925 LR.PhysReg = PhysReg;
926 setPhysRegState(PhysReg, VirtReg.
id());
928 assignDanglingDebugValues(AtMI, VirtReg, PhysReg);
936 return MI.getOperand(
MI.findTiedOperandIdx(
MI.getOperandNo(&MO)));
950 static const unsigned ChainLengthLimit = 3;
951 for (
unsigned C = 0;
C <= ChainLengthLimit; ++
C) {
961 Reg =
Def->getOperand(1).getReg();
977 static const unsigned DefLimit = 3;
983 Reg =
MI.getOperand(1).getReg();
984 else if (LowerTiedOps)
987 Reg = traceCopyChain(
Reg);
999void RegAllocFastImpl::allocVirtReg(MachineInstr &
MI, LiveReg &LR,
1000 Register Hint0,
bool LookAtPhysRegUses) {
1001 const Register VirtReg = LR.VirtReg;
1006 <<
" in class " <<
TRI->getRegClassName(&RC)
1007 <<
" with hint " <<
printReg(Hint0,
TRI) <<
'\n');
1011 !isRegUsedInInstr(Hint0, LookAtPhysRegUses)) {
1013 if (isPhysRegFree(Hint0)) {
1016 assignVirtToPhysReg(
MI, LR, Hint0);
1027 Register Hint1 = traceCopies(VirtReg);
1029 !isRegUsedInInstr(Hint1, LookAtPhysRegUses)) {
1031 if (isPhysRegFree(Hint1)) {
1034 assignVirtToPhysReg(
MI, LR, Hint1);
1045 unsigned BestCost = spillImpossible;
1047 for (
MCPhysReg PhysReg : AllocationOrder) {
1049 if (isRegUsedInInstr(PhysReg, LookAtPhysRegUses)) {
1054 unsigned Cost = calcSpillCost(PhysReg);
1058 assignVirtToPhysReg(
MI, LR, PhysReg);
1062 if (PhysReg == Hint0 || PhysReg == Hint1)
1063 Cost -= spillPrefBonus;
1065 if (
Cost < BestCost) {
1074 LR.PhysReg = getErrorAssignment(LR,
MI, RC);
1079 displacePhysReg(
MI, BestReg);
1080 assignVirtToPhysReg(
MI, LR, BestReg);
1083void RegAllocFastImpl::allocVirtRegUndef(MachineOperand &MO) {
1087 if (!shouldAllocateRegister(VirtReg))
1093 for (
const MachineOperand &Tied :
MI.all_uses()) {
1094 if (!Tied.isTied() || Tied.getReg() != VirtReg)
1097 for (MachineOperand &O :
MI.all_uses()) {
1098 if (
O.getReg() != VirtReg)
1101 unsigned SubIdx =
O.isTied() ? 0 :
O.getSubReg();
1102 O.setReg(SubIdx ?
TRI->getSubReg(DefReg, SubIdx) : DefReg);
1109 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
1111 bool IsRenamable =
true;
1112 if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
1113 PhysReg = LRI->PhysReg;
1117 if (AllocationOrder.
empty()) {
1123 PhysReg = getErrorAssignment(*LRI, *MO.
getParent(), RC);
1125 IsRenamable =
false;
1127 PhysReg = AllocationOrder.
front();
1131 if (SubRegIdx != 0) {
1132 PhysReg =
TRI->getSubReg(PhysReg, SubRegIdx);
1142bool RegAllocFastImpl::defineLiveThroughVirtReg(MachineInstr &
MI,
1145 if (!shouldAllocateRegister(VirtReg))
1147 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
1148 if (LRI != LiveVirtRegs.end()) {
1149 MCRegister PrevReg = LRI->PhysReg;
1150 if (PrevReg && isRegUsedInInstr(PrevReg,
true)) {
1152 <<
" (tied/earlyclobber resolution)\n");
1153 freePhysReg(PrevReg);
1154 LRI->PhysReg = MCRegister();
1161 TII->get(TargetOpcode::COPY), PrevReg)
1164 MachineOperand &MO =
MI.getOperand(OpNum);
1169 return defineVirtReg(
MI, OpNum, VirtReg,
true);
1179bool RegAllocFastImpl::defineVirtReg(MachineInstr &
MI,
unsigned OpNum,
1180 Register VirtReg,
bool LookAtPhysRegUses) {
1182 if (!shouldAllocateRegister(VirtReg))
1184 MachineOperand &MO =
MI.getOperand(OpNum);
1185 LiveRegMap::iterator LRI;
1187 std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg));
1190 if (mayLiveOut(VirtReg)) {
1191 LRI->LiveOut =
true;
1198 if (!LRI->PhysReg) {
1199 allocVirtReg(
MI, *LRI,
Register(), LookAtPhysRegUses);
1201 assert((!isRegUsedInInstr(LRI->PhysReg, LookAtPhysRegUses) || LRI->Error) &&
1202 "TODO: preassign mismatch");
1204 <<
" use existing assignment to "
1208 MCRegister PhysReg = LRI->PhysReg;
1210 if (LRI->Reloaded || LRI->LiveOut) {
1211 if (!
MI.isImplicitDef()) {
1215 <<
" RL: " << LRI->Reloaded <<
'\n');
1216 bool Kill = LRI->LastUse ==
nullptr;
1217 spill(SpillBefore, VirtReg, PhysReg,
Kill, LRI->LiveOut);
1221 if (
MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
1222 int FI = StackSlotForVirtReg[VirtReg];
1224 for (MachineOperand &MO :
MI.operands()) {
1226 MachineBasicBlock *Succ = MO.
getMBB();
1235 LRI->LastUse =
nullptr;
1236 }
else if (!LRI->LastUse) {
1241 LRI->LiveOut =
false;
1242 LRI->Reloaded =
false;
1244 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
1245 BundleVirtRegsMap[VirtReg] = *LRI;
1247 markRegUsedInInstr(PhysReg);
1248 return setPhysReg(
MI, MO, *LRI);
1253bool RegAllocFastImpl::lowerTiedUse(MachineInstr &
MI, MachineOperand &MO,
1266 any_of(
MI.all_uses(), [&](
const MachineOperand &O) {
1267 return &O != &MO && O.getReg() == LR.VirtReg;
1271 freePhysReg(DefReg);
1272 assignVirtToPhysReg(
MI, LR, DefReg);
1277 assert((LR.Error || !
TRI->regsOverlap(LR.PhysReg, DefReg)) &&
1278 "copy source overlaps the tied def");
1281 MCRegister SrcReg = SubReg ?
TRI->getSubReg(LR.PhysReg, SubReg) : LR.PhysReg;
1283 if (SrcReg == DefReg)
1290 markRegUsedInInstr(LR.PhysReg);
1293 auto ReadDefReg = [&](MachineOperand &
O) {
1303 for (MachineOperand &O :
MI.all_uses()) {
1304 if (
O.isTied() ||
O.getReg() != LR.VirtReg ||
O.getSubReg() != SubReg)
1312 freePhysReg(DefReg);
1318bool RegAllocFastImpl::useVirtReg(MachineInstr &
MI, MachineOperand &MO,
1321 if (!shouldAllocateRegister(VirtReg))
1323 LiveRegMap::iterator LRI;
1325 std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg));
1328 if (mayLiveOut(VirtReg)) {
1329 LRI->LiveOut =
true;
1336 assert((!MO.
isKill() || LRI->LastUse == &
MI) &&
"Invalid kill flag");
1339 if (LowerTiedOps && MO.
isTied() && lowerTiedUse(
MI, MO, *LRI))
1343 if (!LRI->PhysReg) {
1346 if (
MI.isCopy() &&
MI.getOperand(1).getSubReg() == 0) {
1347 Hint =
MI.getOperand(0).getReg();
1348 if (
Hint.isVirtual()) {
1349 assert(!shouldAllocateRegister(Hint));
1353 "Copy destination should already be assigned");
1356 allocVirtReg(
MI, *LRI, Hint,
false);
1361 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
1362 BundleVirtRegsMap[VirtReg] = *LRI;
1364 markRegUsedInInstr(LRI->PhysReg);
1365 return setPhysReg(
MI, MO, *LRI);
1372 MI.clearRegisterDeads(MO.
getReg());
1379MCPhysReg RegAllocFastImpl::getErrorAssignment(
const LiveReg &LR,
1393 if (AllocationOrder.
empty()) {
1397 "no registers from class available to allocate", Fn,
1402 assert(!RawRegs.
empty() &&
"register classes cannot have no registers");
1403 return RawRegs.
front();
1406 if (!LR.Error && EmitError) {
1409 if (
MI.isInlineAsm()) {
1410 MI.emitInlineAsmError(
1411 "inline assembly requires more registers than available");
1415 "ran out of registers during register allocation", Fn,
1420 return AllocationOrder.
front();
1425bool RegAllocFastImpl::setPhysReg(MachineInstr &
MI, MachineOperand &MO,
1426 const LiveReg &Assignment) {
1427 MCRegister PhysReg = Assignment.PhysReg;
1428 assert(PhysReg &&
"assignments should always be to a valid physreg");
1458 MI.addRegisterKilled(PhysReg,
TRI,
true);
1467 MI.addRegisterDead(PhysReg,
TRI,
true);
1469 MI.addRegisterDefined(PhysReg,
TRI);
1478void RegAllocFastImpl::dumpState()
const {
1479 for (MCRegUnit Unit :
TRI->regunits()) {
1480 switch (
unsigned VirtReg = getRegUnitState(Unit)) {
1483 case regPreAssigned:
1490 LiveRegMap::const_iterator
I = findLiveVirtReg(VirtReg);
1491 assert(
I != LiveVirtRegs.end() &&
"have LiveVirtRegs entry");
1492 if (
I->LiveOut ||
I->Reloaded) {
1500 assert(
TRI->hasRegUnit(
I->PhysReg, Unit) &&
"inverse mapping present");
1507 for (
const LiveReg &LR : LiveVirtRegs) {
1510 MCRegister PhysReg = LR.PhysReg;
1513 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
1514 assert(getRegUnitState(Unit) == VirtReg &&
"inverse map valid");
1522void RegAllocFastImpl::addRegClassDefCounts(
1524 assert(RegClassDefCounts.
size() ==
TRI->getNumRegClasses());
1527 if (!shouldAllocateRegister(
Reg))
1530 for (
unsigned RCIdx = 0, RCIdxEnd =
TRI->getNumRegClasses();
1531 RCIdx != RCIdxEnd; ++RCIdx) {
1535 ++RegClassDefCounts[RCIdx];
1541 for (
unsigned RCIdx = 0, RCIdxEnd =
TRI->getNumRegClasses();
1542 RCIdx != RCIdxEnd; ++RCIdx) {
1544 for (MCRegAliasIterator Alias(
Reg,
TRI,
true); Alias.isValid(); ++Alias) {
1546 ++RegClassDefCounts[RCIdx];
1560 !
MI.getOperand(
MI.findTiedOperandIdx(
MI.getOperandNo(&MO))).isUndef();
1566void RegAllocFastImpl::findAndSortDefOperandIndexes(
const MachineInstr &
MI) {
1567 DefOperandIndexes.
clear();
1570 for (
unsigned I = 0,
E =
MI.getNumOperands();
I <
E; ++
I) {
1571 const MachineOperand &MO =
MI.getOperand(
I);
1578 markPhysRegUsedInInstr(
Reg);
1588 if (DefOperandIndexes.
size() <= 1)
1596 SmallVector<unsigned> RegClassDefCounts(
TRI->getNumRegClasses(), 0);
1598 for (
const MachineOperand &MO :
MI.all_defs())
1599 addRegClassDefCounts(RegClassDefCounts, MO.
getReg());
1601 llvm::sort(DefOperandIndexes, [&](
unsigned I0,
unsigned I1) {
1602 const MachineOperand &MO0 =
MI.getOperand(I0);
1603 const MachineOperand &MO1 =
MI.getOperand(I1);
1611 unsigned ClassSize0 = RegClassInfo->
getOrder(&RC0).size();
1612 unsigned ClassSize1 = RegClassInfo->
getOrder(&RC1).size();
1614 bool SmallClass0 = ClassSize0 < RegClassDefCounts[RC0.
getID()];
1615 bool SmallClass1 = ClassSize1 < RegClassDefCounts[RC1.
getID()];
1616 if (SmallClass0 > SmallClass1)
1618 if (SmallClass0 < SmallClass1)
1624 if (Livethrough0 > Livethrough1)
1626 if (Livethrough0 < Livethrough1)
1634void RegAllocFastImpl::allocateInstruction(MachineInstr &
MI) {
1657 LiveDefRegs.
clear();
1658 BundleVirtRegsMap.
clear();
1661 bool HasPhysRegUse =
false;
1662 bool HasRegMask =
false;
1663 bool HasVRegDef =
false;
1664 bool HasDef =
false;
1665 bool HasEarlyClobber =
false;
1666 bool HasTiedDef =
false;
1667 bool NeedToAssignLiveThroughs =
false;
1668 for (MachineOperand &MO :
MI.operands()) {
1672 if (!shouldAllocateRegister(
Reg))
1678 HasEarlyClobber =
true;
1679 if (LowerTiedOps && MO.
isTied())
1682 NeedToAssignLiveThroughs =
true;
1688 bool displacedAny = definePhysReg(
MI,
Reg);
1690 HasEarlyClobber =
true;
1697 HasPhysRegUse =
true;
1711 bool ReArrangedImplicitOps =
true;
1719 if (NeedToAssignLiveThroughs) {
1720 while (ReArrangedImplicitOps) {
1721 ReArrangedImplicitOps =
false;
1722 findAndSortDefOperandIndexes(
MI);
1723 for (
unsigned OpIdx : DefOperandIndexes) {
1724 MachineOperand &MO =
MI.getOperand(OpIdx);
1728 ReArrangedImplicitOps = defineLiveThroughVirtReg(
MI, OpIdx,
Reg);
1730 ReArrangedImplicitOps = defineVirtReg(
MI, OpIdx,
Reg);
1734 if (ReArrangedImplicitOps)
1740 while (ReArrangedImplicitOps) {
1741 ReArrangedImplicitOps =
false;
1742 for (MachineOperand &MO :
MI.all_defs()) {
1745 ReArrangedImplicitOps =
1746 defineVirtReg(
MI,
MI.getOperandNo(&MO),
Reg);
1747 if (ReArrangedImplicitOps)
1758 for (MachineOperand &MO :
reverse(
MI.all_defs())) {
1775 "tied def assigned to clobbered register");
1790 unmarkRegUsedInInstr(
Reg);
1799 for (
const auto *RM : RegMasks)
1802 for (
const LiveReg &LR : LiveVirtRegs) {
1803 MCRegister PhysReg = LR.PhysReg;
1804 if (PhysReg && isClobberedByRegMasks(PhysReg))
1805 displacePhysReg(
MI, PhysReg);
1810 if (HasPhysRegUse) {
1811 for (MachineOperand &MO :
MI.operands()) {
1819 if (!usePhysReg(
MI,
Reg))
1827 bool HasUndefUse =
false;
1828 bool TiedOnly = HasTiedDef;
1829 bool ReArrangedImplicitMOs =
true;
1830 while (ReArrangedImplicitMOs) {
1831 ReArrangedImplicitMOs =
false;
1832 for (MachineOperand &MO :
MI.operands()) {
1837 (TiedOnly && !MO.
isTied()))
1851 ReArrangedImplicitMOs = useVirtReg(
MI, MO,
Reg);
1852 if (ReArrangedImplicitMOs)
1858 if (TiedOnly && !ReArrangedImplicitMOs) {
1860 ReArrangedImplicitMOs =
true;
1868 for (MachineOperand &MO :
MI.all_uses()) {
1873 assert(MO.
isUndef() &&
"Should only have undef virtreg uses left");
1874 allocVirtRegUndef(MO);
1880 if (HasEarlyClobber) {
1881 for (MachineOperand &MO :
reverse(
MI.all_defs())) {
1884 assert(!MO.
getSubReg() &&
"should be already handled in def processing");
1910 (
MI.getOperand(0).getReg() ==
MI.getOperand(1).getReg() ||
1911 MI.getOperand(0).isDead()) &&
1912 MI.getNumOperands() == 2) {
1918void RegAllocFastImpl::handleDebugValue(MachineInstr &
MI) {
1921 assert(
MI.isDebugValue() &&
"not a DBG_VALUE*");
1922 for (
const auto &MO :
MI.debug_operands()) {
1928 if (!shouldAllocateRegister(
Reg))
1932 int SS = StackSlotForVirtReg[
Reg];
1942 LiveRegMap::iterator LRI = findLiveVirtReg(
Reg);
1946 if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
1948 for (
auto &RegMO : DbgOps)
1949 setPhysReg(
MI, *RegMO, *LRI);
1951 DanglingDbgValues[
Reg].push_back(&
MI);
1956 LiveDbgValueMap[
Reg].append(DbgOps.begin(), DbgOps.end());
1960void RegAllocFastImpl::handleBundle(MachineInstr &
MI) {
1963 while (BundledMI->isBundledWithPred()) {
1964 for (MachineOperand &MO : BundledMI->operands()) {
1972 auto DI = BundleVirtRegsMap.
find(
Reg);
1973 assert(DI != BundleVirtRegsMap.
end() &&
"Unassigned virtual register");
1975 setPhysReg(
MI, MO, DI->second);
1982void RegAllocFastImpl::allocateBasicBlock(MachineBasicBlock &
MBB) {
1986 PosIndexes.unsetInitialized();
1987 RegUnitStates.assign(
TRI->getNumRegUnits(), regFree);
1988 assert(LiveVirtRegs.empty() &&
"Mapping not cleared from last block?");
1991 setPhysRegState(LiveReg.PhysReg, regPreAssigned);
2003 if (
MI.isDebugValue()) {
2004 handleDebugValue(
MI);
2008 allocateInstruction(
MI);
2013 HasErrorDef =
false;
2018 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
2026 LLVM_DEBUG(
dbgs() <<
"Loading live registers at begin of block.\n");
2031 for (MachineInstr *
MI : Coalesced)
2033 NumCoalesced += Coalesced.size();
2035 for (
auto &UDBGPair : DanglingDbgValues) {
2036 for (MachineInstr *DbgValue : UDBGPair.second) {
2041 LLVM_DEBUG(
dbgs() <<
"Register did not survive for " << *DbgValue
2046 DanglingDbgValues.clear();
2054void RegAllocFastImpl::expandSubregPseudo(MachineInstr &
MI) {
2057 if (
MI.isInsertSubreg()) {
2060 const MachineOperand &BaseMO =
MI.getOperand(1);
2063 MI.getOperand(0).getReg())
2065 unsigned SubIdx =
MI.getOperand(3).getImm();
2066 MI.removeOperand(3);
2067 assert(
MI.getOperand(0).getSubReg() == 0 &&
"Unexpected subreg idx");
2068 MI.getOperand(0).setSubReg(SubIdx);
2069 MI.getOperand(0).setIsUndef(
MI.getOperand(1).isUndef());
2070 MI.removeOperand(1);
2071 MI.setDesc(
TII->get(TargetOpcode::COPY));
2084 if (
unsigned UseSubIdx =
Use.getSubReg())
2085 ReadLanes |=
TRI->getSubRegIndexLaneMask(UseSubIdx);
2087 bool DefEmitted =
false;
2088 for (
unsigned I = 1,
E =
MI.getNumOperands();
I + 1 <
E;
I += 2) {
2089 const MachineOperand &SrcMO =
MI.getOperand(
I);
2090 unsigned SubIdx =
MI.getOperand(
I + 1).getImm();
2092 (ReadLanes &
TRI->getSubRegIndexLaneMask(SubIdx)).none())
2102 MI.setDesc(
TII->get(TargetOpcode::IMPLICIT_DEF));
2103 while (
MI.getNumOperands() > 1)
2104 MI.removeOperand(
MI.getNumOperands() - 1);
2107 MI.eraseFromParent();
2111 RegisterClassInfo &RCI) {
2112 LLVM_DEBUG(
dbgs() <<
"********** FAST REGISTER ALLOCATION **********\n"
2113 <<
"********** Function: " << MF.
getName() <<
'\n');
2119 RegClassInfo = &RCI;
2123 unsigned NumRegUnits =
TRI->getNumRegUnits();
2125 UsedInInstr.
assign(NumRegUnits, 0);
2132 for (MachineBasicBlock &
MBB : MF)
2134 if (
MI.isRegSequence() ||
MI.isInsertSubreg())
2135 expandSubregPseudo(
MI);
2141 StackSlotForVirtReg.
resize(NumVirtRegs);
2142 LiveVirtRegs.setUniverse(NumVirtRegs);
2143 MayLiveAcrossBlocks.
clear();
2144 MayLiveAcrossBlocks.
resize(NumVirtRegs);
2147 for (MachineBasicBlock &
MBB : MF)
2148 allocateBasicBlock(
MBB);
2150 if (ClearVirtRegs) {
2156 StackSlotForVirtReg.
clear();
2157 LiveDbgValueMap.
clear();
2164 RegAllocFastImpl Impl(Opts.Filter, Opts.ClearVRegs);
2165 bool Changed = Impl.runOnMachineFunction(
2176 bool PrintFilterName = Opts.FilterName !=
"all";
2177 bool PrintNoClearVRegs = !Opts.ClearVRegs;
2178 bool PrintSemicolon = PrintFilterName && PrintNoClearVRegs;
2180 OS <<
"regallocfast";
2181 if (PrintFilterName || PrintNoClearVRegs) {
2183 if (PrintFilterName)
2184 OS <<
"filter=" << Opts.FilterName;
2187 if (PrintNoClearVRegs)
2188 OS <<
"no-clear-vregs";
2196 bool ClearVirtRegs) {
2197 return new RegAllocFast(Ftor, ClearVirtRegs);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_UNLIKELY(EXPR)
This file defines the DenseMap class.
const HexagonInstrInfo * TII
This file implements an indexed map.
Register const TargetRegisterInfo * TRI
This file implements a map that provides insertion order iteration.
Promote Memory to Register
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
static Register getTiedUseReg(const MachineInstr &MI, const MachineOperand &DefMO)
The register DefMO's tied use reads, when the two end up in the same register: a subregister index on...
static bool isCoalescable(const MachineInstr &MI)
static const MachineOperand & getTiedOperand(const MachineInstr &MI, const MachineOperand &MO)
The operand MO is tied to.
static bool isLiveThroughDef(const MachineInstr &MI, const MachineOperand &MO)
Early clobber, partial def, or tied to a use that carries a value: the register is occupied while the...
static bool dominates(InstrPosIndexes &PosIndexes, const MachineInstr &A, const MachineInstr &B)
static RegisterRegAlloc fastRegAlloc("fast", "fast register allocator", createFastRegisterAllocator)
static void clearDeadsOfLiveDefs(MachineInstr &MI)
Clear dead flags on defs of any register which also has a live def on MI.
This file defines the SmallSet class.
This file defines the SmallVector class.
This file defines the SparseSet class derived from the version described in Briggs,...
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
const T & front() const
Get the first element.
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
bool test(unsigned Idx) const
Returns true if bit Idx is set.
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
void clear()
Removes all bits from the bitvector.
BitVector & set()
Set all bits in the bitvector.
Represents analyses that only rely on functions' control flow.
iterator find(const_arg_type_t< KeyT > Val)
FunctionPass class - This class is used to implement most global optimizations.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
If the specified machine instruction is a direct store to a stack slot, return the virtual or physica...
void resize(typename StorageT::size_type S)
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
unsigned getID() const
getID() - Return the register class ID number.
ArrayRef< MCPhysReg > getRegisters() const
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.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
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.
iterator_range< liveout_iterator > liveouts() const
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
iterator_range< livein_iterator > liveins() const
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
LLVM_ABI void dump() const
Instructions::iterator instr_iterator
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
bool hasDebugOperandForReg(Register Reg) const
Returns whether this debug value has at least one debug operand with the register Reg.
void setDebugValueUndef()
Sets all register debug operands in this debug value instruction to be undef.
const MachineBasicBlock * getParent() const
bool isDebugValue() const
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
LLVM_ABI void setIsRenamable(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
MachineBasicBlock * getMBB() const
void setIsDead(bool Val=true)
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
void setIsKill(bool Val=true)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void setIsUndef(bool Val=true)
bool isEarlyClobber() const
Register getReg() const
getReg - Returns the register number.
bool isInternalRead() const
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
LLVM_ABI void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
iterator_range< def_instr_iterator > def_instructions(Register Reg) const
iterator_range< use_nodbg_iterator > use_nodbg_operands(Register Reg) const
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
MachineOperand * getOneDef(Register Reg) const
Returns the defining operand if there is exactly one operand defining the specified register,...
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
LLVM_ABI void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
bool isAllocatable(MCRegister PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
iterator_range< def_iterator > def_operands(Register Reg) const
const MachineFunction & getMF() const
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
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.
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &)
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
LLVM_ABI void updateReservedRegs(const BitVector &ReservedInput)
Update cached register class information using ReservedInput, MRI's current reserved-register set.
ArrayRef< MCPhysReg > getOrder(const TargetRegisterClass *RC) const
getOrder - Returns the preferred allocation order for RC.
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
constexpr bool isValid() const
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.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void assign(size_type NumElts, ValueParamT Elt)
void push_back(const T &Elt)
typename DenseT::const_iterator const_iterator
typename DenseT::iterator iterator
Represent a constant reference to a string, i.e.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
initializer< Ty > init(const Ty &Val)
NodeAddr< DefNode * > Def
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
std::function< bool(const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, const Register Reg)> RegAllocFilterFunc
Filter function for register classes during regalloc.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Kill
The last use of a register.
@ Renamable
Register that may be renamed.
LLVM_ABI void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex, Register Reg)
Update a DBG_VALUE whose value has been spilled to FrameIndex.
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...
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
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.
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI MachineInstr * buildDbgValueForSpill(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const MachineInstr &Orig, int FrameIndex, Register SpillReg)
Clone a DBG_VALUE whose value has been spilled to FrameIndex.
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
@ End
Run the machine verifier once, at the end of the pipeline.
constexpr RegState getUndefRegState(bool B)
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.
MCRegisterClass TargetRegisterClass
static constexpr LaneBitmask getNone()