63#define DEBUG_TYPE "regalloc"
67STATISTIC(NumCoalesced,
"Number of copies coalesced");
76class InstrPosIndexes {
78 void unsetInitialized() { IsInitialized =
false; }
80 void init(
const MachineBasicBlock &
MBB) {
82 Instr2PosIndex.
clear();
84 for (
const MachineInstr &
MI :
MBB) {
85 LastIndex += InstrDist;
86 Instr2PosIndex[&
MI] = LastIndex;
93 bool getIndex(
const MachineInstr &
MI,
uint64_t &Index) {
101 assert(
MI.getParent() == CurMBB &&
"MI is not in CurMBB");
102 auto It = Instr2PosIndex.find(&
MI);
103 if (It != Instr2PosIndex.end()) {
117 unsigned Distance = 1;
119 End = std::next(Start);
120 while (Start != CurMBB->begin() &&
121 !Instr2PosIndex.count(&*std::prev(Start))) {
125 while (
End != CurMBB->end() && !Instr2PosIndex.count(&*(
End))) {
133 Start == CurMBB->begin() ? 0 : Instr2PosIndex.at(&*std::prev(Start));
135 if (
End == CurMBB->end())
136 Step =
static_cast<uint64_t>(InstrDist);
140 assert(EndIndex > LastIndex &&
"Index must be ascending order");
141 unsigned NumAvailableIndexes = EndIndex - LastIndex - 1;
160 Step = (NumAvailableIndexes + 1) / (Distance + 1);
165 if (
LLVM_UNLIKELY(!Step || (!LastIndex && Step == InstrDist))) {
167 Index = Instr2PosIndex.at(&
MI);
171 for (
auto I = Start;
I !=
End; ++
I) {
173 Instr2PosIndex[&*
I] = LastIndex;
175 Index = Instr2PosIndex.at(&
MI);
180 bool IsInitialized =
false;
181 enum { InstrDist = 1024 };
182 const MachineBasicBlock *CurMBB =
nullptr;
183 DenseMap<const MachineInstr *, uint64_t> Instr2PosIndex;
186class RegAllocFastImpl {
189 bool ClearVirtRegs_ =
true)
190 : ShouldAllocateRegisterImpl(
F), StackSlotForVirtReg(-1),
191 ClearVirtRegs(ClearVirtRegs_) {}
194 MachineFrameInfo *MFI =
nullptr;
195 MachineRegisterInfo *MRI =
nullptr;
196 const TargetRegisterInfo *TRI =
nullptr;
197 const TargetInstrInfo *TII =
nullptr;
198 RegisterClassInfo *RegClassInfo =
nullptr;
203 bool LowerTiedOps =
false;
206 MachineBasicBlock *MBB =
nullptr;
209 IndexedMap<int, VirtReg2IndexFunctor> StackSlotForVirtReg;
214 MachineInstr *LastUse =
nullptr;
217 bool LiveOut =
false;
218 bool Reloaded =
false;
221 explicit LiveReg(
Register VirtReg) : VirtReg(VirtReg) {}
222 explicit LiveReg() =
default;
224 unsigned getSparseSetIndex()
const {
return VirtReg.virtRegIndex(); }
227 using LiveRegMap = SparseSet<LiveReg, unsigned, identity, uint16_t>;
230 LiveRegMap LiveVirtRegs;
233 DenseMap<Register, LiveReg> BundleVirtRegsMap;
235 DenseMap<Register, SmallVector<MachineOperand *, 2>> LiveDbgValueMap;
238 DenseMap<Register, SmallVector<MachineInstr *, 1>> DanglingDbgValues;
242 BitVector MayLiveAcrossBlocks;
263 std::vector<unsigned> RegUnitStates;
281 SmallVector<unsigned, 0> UsedInInstr;
286 SmallVector<unsigned, 8> DefOperandIndexes;
289 bool HasErrorDef =
false;
295 InstrPosIndexes PosIndexes;
297 void setRegUnitState(MCRegUnit Unit,
unsigned NewState);
298 unsigned getRegUnitState(MCRegUnit Unit)
const;
300 void setPhysRegState(MCRegister PhysReg,
unsigned NewState);
301 bool isPhysRegFree(MCRegister PhysReg)
const;
304 void markRegUsedInInstr(MCRegister PhysReg) {
305 for (MCRegUnit Unit : TRI->regunits(PhysReg))
306 UsedInInstr[
static_cast<unsigned>(
Unit)] = InstrGen | 1;
310 bool isClobberedByRegMasks(MCRegister PhysReg)
const {
311 return llvm::any_of(RegMasks, [PhysReg](
const uint32_t *Mask) {
317 bool isRegUsedInInstr(MCRegister PhysReg,
bool LookAtPhysRegUses)
const {
318 if (LookAtPhysRegUses && isClobberedByRegMasks(PhysReg))
320 for (MCRegUnit Unit : TRI->regunits(PhysReg))
321 if (UsedInInstr[
static_cast<unsigned>(Unit)] >=
322 (InstrGen | !LookAtPhysRegUses))
329 void markPhysRegUsedInInstr(MCRegister PhysReg) {
330 for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
331 assert(UsedInInstr[
static_cast<unsigned>(Unit)] <= InstrGen &&
332 "non-phys use before phys use?");
333 UsedInInstr[
static_cast<unsigned>(
Unit)] = InstrGen;
338 void unmarkRegUsedInInstr(MCRegister PhysReg) {
339 for (MCRegUnit Unit : TRI->regunits(PhysReg))
340 UsedInInstr[
static_cast<unsigned>(
Unit)] = 0;
345 bool hasLiveDefOfSuperReg(MCRegister PhysReg)
const {
346 return any_of(LiveDefRegs, [&](MCRegister LiveReg) {
347 return TRI->isSuperRegisterEq(PhysReg, LiveReg);
355 spillImpossible = ~0
u
361 bool runOnMachineFunction(
MachineFunction &MF, RegisterClassInfo &RCI);
364 void allocateBasicBlock(MachineBasicBlock &MBB);
365 void expandSubregPseudo(MachineInstr &
MI);
370 void findAndSortDefOperandIndexes(
const MachineInstr &
MI);
372 void allocateInstruction(MachineInstr &
MI);
373 void handleDebugValue(MachineInstr &
MI);
374 void handleBundle(MachineInstr &
MI);
376 bool usePhysReg(MachineInstr &
MI, MCRegister PhysReg);
377 bool definePhysReg(MachineInstr &
MI, MCRegister PhysReg);
378 bool displacePhysReg(MachineInstr &
MI, MCRegister PhysReg);
379 void freePhysReg(MCRegister PhysReg);
381 unsigned calcSpillCost(
MCPhysReg PhysReg)
const;
391 void assignVirtToPhysReg(MachineInstr &
MI, LiveReg &, MCRegister PhysReg);
392 void allocVirtReg(MachineInstr &
MI, LiveReg &LR,
Register Hint,
393 bool LookAtPhysRegUses =
false);
394 void allocVirtRegUndef(MachineOperand &MO);
395 void assignDanglingDebugValues(MachineInstr &Def,
Register VirtReg,
397 void defineLiveThroughVirtReg(MachineInstr &
MI, MachineOperand &MO,
399 void defineVirtReg(MachineInstr &
MI, MachineOperand &MO,
Register VirtReg,
400 bool LookAtPhysRegUses =
false);
401 void useVirtReg(MachineInstr &
MI, MachineOperand &MO,
Register VirtReg);
402 bool lowerTiedUse(MachineInstr &
MI, MachineOperand &MO, LiveReg &LR);
404 MCPhysReg getErrorAssignment(
const LiveReg &LR, MachineInstr &
MI,
408 getMBBBeginInsertionPoint(MachineBasicBlock &MBB,
409 SmallSet<Register, 2> &PrologLiveIns)
const;
411 void reloadAtBegin(MachineBasicBlock &MBB);
412 void setPhysReg(MachineOperand &MO,
const LiveReg &Assignment);
413 void addImplicitOps(MachineInstr &
MI);
417 enum ImplicitOpKind { ImplicitKill, ImplicitDead, ImplicitDef };
423 bool shouldAllocateRegister(
const Register Reg)
const;
424 int getStackSpaceFor(
Register VirtReg);
426 MCRegister AssignedReg,
bool Kill,
bool LiveOut);
433 bool mayBeSpillFromInlineAsmBr(
const MachineInstr &
MI)
const;
435 void dumpState()
const;
439 RegAllocFastImpl Impl;
445 : MachineFunctionPass(ID), Impl(
F, ClearVirtRegs_) {}
448 return Impl.runOnMachineFunction(
449 MF, getAnalysis<MachineRegisterClassInfoWrapperPass>().getRCI());
452 StringRef getPassName()
const override {
return "Fast Register Allocator"; }
454 void getAnalysisUsage(AnalysisUsage &AU)
const override {
455 AU.
addRequired<MachineRegisterClassInfoWrapperPass>();
460 MachineFunctionProperties getRequiredProperties()
const override {
461 return MachineFunctionProperties().setNoPHIs();
464 MachineFunctionProperties getSetProperties()
const override {
465 MachineFunctionProperties
P;
466 if (Impl.ClearVirtRegs)
467 P.setNoVRegs().setTiedOpsRewritten();
471 MachineFunctionProperties getClearedProperties()
const override {
472 return MachineFunctionProperties().setIsSSA();
478char RegAllocFast::ID = 0;
488 if (!ShouldAllocateRegisterImpl)
491 return ShouldAllocateRegisterImpl(*
TRI, *
MRI,
Reg);
494void RegAllocFastImpl::setRegUnitState(MCRegUnit Unit,
unsigned NewState) {
495 RegUnitStates[
static_cast<unsigned>(
Unit)] = NewState;
498unsigned RegAllocFastImpl::getRegUnitState(MCRegUnit Unit)
const {
499 return RegUnitStates[
static_cast<unsigned>(
Unit)];
502void RegAllocFastImpl::setPhysRegState(MCRegister PhysReg,
unsigned NewState) {
503 for (MCRegUnit Unit :
TRI->regunits(PhysReg))
504 setRegUnitState(Unit, NewState);
507bool RegAllocFastImpl::isPhysRegFree(MCRegister PhysReg)
const {
508 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
509 if (getRegUnitState(Unit) != regFree)
517int RegAllocFastImpl::getStackSpaceFor(
Register VirtReg) {
519 int SS = StackSlotForVirtReg[VirtReg];
526 unsigned Size =
TRI->getSpillSize(RC);
531 Align CurrentAlign =
ST.getFrameLowering()->getStackAlign();
532 if (Alignment > CurrentAlign && !
TRI->canRealignStack(MF))
539 StackSlotForVirtReg[VirtReg] = FrameIdx;
546 PosIndexes.getIndex(
A, IndexA);
549 PosIndexes.getIndex(
A, IndexA);
550 return IndexA < IndexB;
557bool RegAllocFastImpl::mayBeSpillFromInlineAsmBr(
const MachineInstr &
MI)
const {
562 for (
const auto &
Op :
MI.operands())
569bool RegAllocFastImpl::mayLiveOut(
Register VirtReg) {
575 const MachineInstr *SelfLoopDef =
nullptr;
582 if (DefInst.getParent() !=
MBB) {
586 if (!SelfLoopDef ||
dominates(PosIndexes, DefInst, *SelfLoopDef))
587 SelfLoopDef = &DefInst;
598 static const unsigned Limit = 8;
601 if (UseInst.getParent() !=
MBB || ++
C >= Limit) {
610 if (SelfLoopDef == &UseInst ||
611 !
dominates(PosIndexes, *SelfLoopDef, UseInst)) {
622bool RegAllocFastImpl::mayLiveIn(
Register VirtReg) {
627 static const unsigned Limit = 8;
630 if (DefInst.getParent() !=
MBB || ++
C >= Limit) {
642 Register VirtReg, MCRegister AssignedReg,
643 bool Kill,
bool LiveOut) {
646 int FI = getStackSpaceFor(VirtReg);
658 SmallVectorImpl<MachineOperand *> &LRIDbgOperands = LiveDbgValueMap[VirtReg];
659 SmallMapVector<MachineInstr *, SmallVector<const MachineOperand *>, 2>
661 for (MachineOperand *MO : LRIDbgOperands)
662 SpilledOperandsMap[MO->getParent()].push_back(MO);
663 for (
const auto &MISpilledOperands : SpilledOperandsMap) {
664 MachineInstr &
DBG = *MISpilledOperands.first;
666 if (
DBG.isDebugValueList())
669 *
MBB, Before, *MISpilledOperands.first, FI, MISpilledOperands.second);
672 LLVM_DEBUG(
dbgs() <<
"Inserting debug info due to spill:\n" << *NewDV);
679 MachineInstr *ClonedDV =
MBB->
getParent()->CloneMachineInstr(NewDV);
681 LLVM_DEBUG(
dbgs() <<
"Cloning debug info due to live out spill\n");
691 if (
DBG.isNonListDebugValue()) {
692 MachineOperand &MO =
DBG.getDebugOperand(0);
700 LRIDbgOperands.
clear();
705 Register VirtReg, MCRegister PhysReg) {
708 int FI = getStackSpaceFor(VirtReg);
719 MachineBasicBlock &
MBB, SmallSet<Register, 2> &PrologLiveIns)
const {
728 if (!
TII->isBasicBlockPrologue(*
I) && !mayBeSpillFromInlineAsmBr(*
I))
733 for (MachineOperand &MO :
I->operands()) {
745void RegAllocFastImpl::reloadAtBegin(MachineBasicBlock &
MBB) {
746 if (LiveVirtRegs.empty())
751 for (MachineBasicBlock::RegisterMaskPair
P :
MBB.
liveins())
752 setPhysRegState(
P.PhysReg, regLiveIn);
754 SmallSet<Register, 2> PrologLiveIns;
759 getMBBBeginInsertionPoint(
MBB, PrologLiveIns);
760 for (
const LiveReg &LR : LiveVirtRegs) {
761 MCRegister PhysReg = LR.PhysReg;
762 if (!PhysReg || LR.Error)
765 MCRegUnit FirstUnit = *
TRI->regunits(PhysReg).begin();
766 if (getRegUnitState(FirstUnit) == regLiveIn)
770 "no reload in start block. Missing vreg def?");
772 if (PrologLiveIns.
count(PhysReg)) {
776 reload(
MBB.
begin(), LR.VirtReg, PhysReg);
778 reload(InsertBefore, LR.VirtReg, PhysReg);
780 LiveVirtRegs.clear();
787bool RegAllocFastImpl::usePhysReg(MachineInstr &
MI, MCRegister
Reg) {
789 bool displacedAny = displacePhysReg(
MI,
Reg);
790 setPhysRegState(
Reg, regPreAssigned);
791 markRegUsedInInstr(
Reg);
800bool RegAllocFastImpl::definePhysReg(MachineInstr &
MI, MCRegister
Reg) {
801 bool displacedAny = displacePhysReg(
MI,
Reg);
802 setPhysRegState(
Reg, regPreAssigned);
809bool RegAllocFastImpl::displacePhysReg(MachineInstr &
MI, MCRegister PhysReg) {
810 bool displacedAny =
false;
812 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
813 switch (
unsigned VirtReg = getRegUnitState(Unit)) {
815 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
816 assert(LRI != LiveVirtRegs.end() &&
"datastructures in sync");
819 while (mayBeSpillFromInlineAsmBr(*ReloadBefore))
821 reload(ReloadBefore, VirtReg, LRI->PhysReg);
823 setPhysRegState(LRI->PhysReg, regFree);
824 LRI->PhysReg = MCRegister();
825 LRI->Reloaded =
true;
830 setRegUnitState(Unit, regFree);
840void RegAllocFastImpl::freePhysReg(MCRegister PhysReg) {
843 MCRegUnit FirstUnit = *
TRI->regunits(PhysReg).begin();
844 switch (
unsigned VirtReg = getRegUnitState(FirstUnit)) {
850 setPhysRegState(PhysReg, regFree);
853 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
854 assert(LRI != LiveVirtRegs.end());
856 setPhysRegState(LRI->PhysReg, regFree);
857 LRI->PhysReg = MCRegister();
867unsigned RegAllocFastImpl::calcSpillCost(
MCPhysReg PhysReg)
const {
868 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
869 switch (
unsigned VirtReg = getRegUnitState(Unit)) {
875 return spillImpossible;
877 bool SureSpill = StackSlotForVirtReg[VirtReg] != -1 ||
878 findLiveVirtReg(VirtReg)->LiveOut;
879 return SureSpill ? spillClean : spillDirty;
886void RegAllocFastImpl::assignDanglingDebugValues(MachineInstr &Definition,
889 auto UDBGValIter = DanglingDbgValues.
find(VirtReg);
890 if (UDBGValIter == DanglingDbgValues.
end())
893 SmallVectorImpl<MachineInstr *> &Dangling = UDBGValIter->second;
894 for (MachineInstr *DbgValue : Dangling) {
895 assert(DbgValue->isDebugValue());
896 if (!DbgValue->hasDebugOperandForReg(VirtReg))
902 MCRegister SetToReg =
Reg;
905 if (!Definition.definesRegister(
Reg,
TRI))
908 if (
I->modifiesRegister(
Reg,
TRI) || --Limit == 0) {
911 SetToReg = MCRegister();
915 for (MachineOperand &MO : DbgValue->getDebugOperandsForReg(VirtReg)) {
927void RegAllocFastImpl::assignVirtToPhysReg(MachineInstr &AtMI, LiveReg &LR,
928 MCRegister PhysReg) {
932 assert(!LR.PhysReg &&
"Already assigned a physreg");
933 assert(PhysReg &&
"Trying to assign no register");
934 LR.PhysReg = PhysReg;
935 setPhysRegState(PhysReg, VirtReg.
id());
937 assignDanglingDebugValues(AtMI, VirtReg, PhysReg);
945 return MI.getOperand(
MI.findTiedOperandIdx(
MI.getOperandNo(&MO)));
959 static const unsigned ChainLengthLimit = 3;
960 for (
unsigned C = 0;
C <= ChainLengthLimit; ++
C) {
970 Reg =
Def->getOperand(1).getReg();
986 static const unsigned DefLimit = 3;
992 Reg =
MI.getOperand(1).getReg();
993 else if (LowerTiedOps)
996 Reg = traceCopyChain(
Reg);
1001 if (++
C >= DefLimit)
1008void RegAllocFastImpl::allocVirtReg(MachineInstr &
MI, LiveReg &LR,
1009 Register Hint0,
bool LookAtPhysRegUses) {
1010 const Register VirtReg = LR.VirtReg;
1015 <<
" in class " <<
TRI->getRegClassName(&RC)
1016 <<
" with hint " <<
printReg(Hint0,
TRI) <<
'\n');
1020 !isRegUsedInInstr(Hint0, LookAtPhysRegUses)) {
1022 if (isPhysRegFree(Hint0)) {
1025 assignVirtToPhysReg(
MI, LR, Hint0);
1036 Register Hint1 = traceCopies(VirtReg);
1038 !isRegUsedInInstr(Hint1, LookAtPhysRegUses)) {
1040 if (isPhysRegFree(Hint1)) {
1043 assignVirtToPhysReg(
MI, LR, Hint1);
1054 unsigned BestCost = spillImpossible;
1056 for (
MCPhysReg PhysReg : AllocationOrder) {
1058 if (isRegUsedInInstr(PhysReg, LookAtPhysRegUses)) {
1063 unsigned Cost = calcSpillCost(PhysReg);
1067 assignVirtToPhysReg(
MI, LR, PhysReg);
1073 if (
Cost == spillImpossible)
1076 if (PhysReg == Hint0 || PhysReg == Hint1)
1077 Cost -= spillPrefBonus;
1079 if (
Cost < BestCost) {
1088 LR.PhysReg = getErrorAssignment(LR,
MI, RC);
1093 displacePhysReg(
MI, BestReg);
1094 assignVirtToPhysReg(
MI, LR, BestReg);
1097void RegAllocFastImpl::allocVirtRegUndef(MachineOperand &MO) {
1101 if (!shouldAllocateRegister(VirtReg))
1107 for (
const MachineOperand &Tied :
MI.all_uses()) {
1108 if (!Tied.isTied() || Tied.getReg() != VirtReg)
1111 for (MachineOperand &O :
MI.all_uses()) {
1112 if (
O.getReg() != VirtReg)
1115 unsigned SubIdx =
O.isTied() ? 0 :
O.getSubReg();
1116 O.setReg(SubIdx ?
TRI->getSubReg(DefReg, SubIdx) : DefReg);
1123 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
1125 bool IsRenamable =
true;
1126 if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
1127 PhysReg = LRI->PhysReg;
1131 if (AllocationOrder.
empty()) {
1137 PhysReg = getErrorAssignment(*LRI, *MO.
getParent(), RC);
1139 IsRenamable =
false;
1141 PhysReg = AllocationOrder.
front();
1145 if (SubRegIdx != 0) {
1146 PhysReg =
TRI->getSubReg(PhysReg, SubRegIdx);
1155void RegAllocFastImpl::defineLiveThroughVirtReg(MachineInstr &
MI,
1158 if (!shouldAllocateRegister(VirtReg))
1160 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
1161 if (LRI != LiveVirtRegs.end()) {
1162 MCRegister PrevReg = LRI->PhysReg;
1163 if (PrevReg && isRegUsedInInstr(PrevReg,
true)) {
1165 <<
" (tied/earlyclobber resolution)\n");
1166 freePhysReg(PrevReg);
1167 LRI->PhysReg = MCRegister();
1174 TII->get(TargetOpcode::COPY), PrevReg)
1181 defineVirtReg(
MI, MO, VirtReg,
true);
1189void RegAllocFastImpl::defineVirtReg(MachineInstr &
MI, MachineOperand &MO,
1190 Register VirtReg,
bool LookAtPhysRegUses) {
1192 if (!shouldAllocateRegister(VirtReg))
1194 LiveRegMap::iterator LRI;
1196 std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg));
1199 if (mayLiveOut(VirtReg)) {
1200 LRI->LiveOut =
true;
1207 if (!LRI->PhysReg) {
1208 allocVirtReg(
MI, *LRI,
Register(), LookAtPhysRegUses);
1210 assert((!isRegUsedInInstr(LRI->PhysReg, LookAtPhysRegUses) || LRI->Error) &&
1211 "TODO: preassign mismatch");
1213 <<
" use existing assignment to "
1217 MCRegister PhysReg = LRI->PhysReg;
1219 if (LRI->Reloaded || LRI->LiveOut) {
1220 if (!
MI.isImplicitDef()) {
1224 <<
" RL: " << LRI->Reloaded <<
'\n');
1225 bool Kill = LRI->LastUse ==
nullptr;
1226 spill(SpillBefore, VirtReg, PhysReg,
Kill, LRI->LiveOut);
1230 if (
MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
1231 int FI = StackSlotForVirtReg[VirtReg];
1233 for (MachineOperand &MO :
MI.operands()) {
1235 MachineBasicBlock *Succ = MO.
getMBB();
1244 LRI->LastUse =
nullptr;
1245 }
else if (!LRI->LastUse) {
1250 LRI->LiveOut =
false;
1251 LRI->Reloaded =
false;
1253 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
1254 BundleVirtRegsMap[VirtReg] = *LRI;
1256 markRegUsedInInstr(PhysReg);
1257 setPhysReg(MO, *LRI);
1262bool RegAllocFastImpl::lowerTiedUse(MachineInstr &
MI, MachineOperand &MO,
1275 any_of(
MI.all_uses(), [&](
const MachineOperand &O) {
1276 return &O != &MO && O.getReg() == LR.VirtReg;
1280 freePhysReg(DefReg);
1281 assignVirtToPhysReg(
MI, LR, DefReg);
1286 assert((LR.Error || !
TRI->regsOverlap(LR.PhysReg, DefReg)) &&
1287 "copy source overlaps the tied def");
1290 MCRegister
SrcReg = SubReg ?
TRI->getSubReg(LR.PhysReg, SubReg) : LR.PhysReg;
1299 markRegUsedInInstr(LR.PhysReg);
1302 auto ReadDefReg = [&](MachineOperand &
O) {
1312 for (MachineOperand &O :
MI.all_uses()) {
1313 if (
O.isTied() ||
O.getReg() != LR.VirtReg ||
O.getSubReg() != SubReg)
1322 freePhysReg(DefReg);
1323 markRegUsedInInstr(DefReg);
1328void RegAllocFastImpl::useVirtReg(MachineInstr &
MI, MachineOperand &MO,
1331 if (!shouldAllocateRegister(VirtReg))
1333 LiveRegMap::iterator LRI;
1335 std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg));
1338 if (mayLiveOut(VirtReg)) {
1339 LRI->LiveOut =
true;
1346 assert((!MO.
isKill() || LRI->LastUse == &
MI) &&
"Invalid kill flag");
1349 if (LowerTiedOps && MO.
isTied() && lowerTiedUse(
MI, MO, *LRI))
1353 if (!LRI->PhysReg) {
1356 if (
MI.isCopy() &&
MI.getOperand(1).getSubReg() == 0) {
1357 Hint =
MI.getOperand(0).getReg();
1358 if (
Hint.isVirtual()) {
1359 assert(!shouldAllocateRegister(Hint));
1363 "Copy destination should already be assigned");
1366 allocVirtReg(
MI, *LRI, Hint,
false);
1371 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
1372 BundleVirtRegsMap[VirtReg] = *LRI;
1374 markRegUsedInInstr(LRI->PhysReg);
1375 setPhysReg(MO, *LRI);
1382 MI.clearRegisterDeads(MO.
getReg());
1389MCPhysReg RegAllocFastImpl::getErrorAssignment(
const LiveReg &LR,
1403 if (AllocationOrder.
empty()) {
1407 "no registers from class available to allocate", Fn,
1412 assert(!RawRegs.
empty() &&
"register classes cannot have no registers");
1413 return RawRegs.
front();
1416 if (!LR.Error && EmitError) {
1419 if (
MI.isInlineAsm()) {
1420 MI.emitInlineAsmError(
1421 "inline assembly requires more registers than available");
1425 "ran out of registers during register allocation", Fn,
1430 return AllocationOrder.
front();
1434void RegAllocFastImpl::setPhysReg(MachineOperand &MO,
1435 const LiveReg &Assignment) {
1436 MCRegister PhysReg = Assignment.PhysReg;
1437 assert(PhysReg &&
"assignments should always be to a valid physreg");
1467 PendingImplicitOps.emplace_back(PhysReg,
ImplicitKill);
1469 PendingImplicitOps.emplace_back(PhysReg,
1470 MO.
isDead() ? ImplicitDead : ImplicitDef);
1473void RegAllocFastImpl::addImplicitOps(MachineInstr &
MI) {
1474 for (
auto [PhysReg, Kind] : PendingImplicitOps) {
1476 MI.addRegisterKilled(PhysReg,
TRI,
true);
1477 else if (Kind == ImplicitDead)
1478 MI.addRegisterDead(PhysReg,
TRI,
true);
1480 MI.addRegisterDefined(PhysReg,
TRI);
1482 PendingImplicitOps.clear();
1487void RegAllocFastImpl::dumpState()
const {
1488 for (MCRegUnit Unit :
TRI->regunits()) {
1489 switch (
unsigned VirtReg = getRegUnitState(Unit)) {
1492 case regPreAssigned:
1499 LiveRegMap::const_iterator
I = findLiveVirtReg(VirtReg);
1500 assert(
I != LiveVirtRegs.end() &&
"have LiveVirtRegs entry");
1501 if (
I->LiveOut ||
I->Reloaded) {
1509 assert(
TRI->hasRegUnit(
I->PhysReg, Unit) &&
"inverse mapping present");
1516 for (
const LiveReg &LR : LiveVirtRegs) {
1519 MCRegister PhysReg = LR.PhysReg;
1522 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
1523 assert(getRegUnitState(Unit) == VirtReg &&
"inverse map valid");
1531void RegAllocFastImpl::addRegClassDefCounts(
1533 assert(RegClassDefCounts.
size() ==
TRI->getNumRegClasses());
1536 if (!shouldAllocateRegister(
Reg))
1539 for (
unsigned RCIdx = 0, RCIdxEnd =
TRI->getNumRegClasses();
1540 RCIdx != RCIdxEnd; ++RCIdx) {
1544 ++RegClassDefCounts[RCIdx];
1550 for (
unsigned RCIdx = 0, RCIdxEnd =
TRI->getNumRegClasses();
1551 RCIdx != RCIdxEnd; ++RCIdx) {
1553 for (MCRegAliasIterator Alias(
Reg,
TRI,
true); Alias.isValid(); ++Alias) {
1555 ++RegClassDefCounts[RCIdx];
1569 !
MI.getOperand(
MI.findTiedOperandIdx(
MI.getOperandNo(&MO))).isUndef();
1575void RegAllocFastImpl::findAndSortDefOperandIndexes(
const MachineInstr &
MI) {
1576 DefOperandIndexes.
clear();
1579 for (
unsigned I = 0,
E =
MI.getNumOperands();
I <
E; ++
I) {
1580 const MachineOperand &MO =
MI.getOperand(
I);
1587 markPhysRegUsedInInstr(
Reg);
1597 if (DefOperandIndexes.
size() <= 1)
1605 SmallVector<unsigned> RegClassDefCounts(
TRI->getNumRegClasses(), 0);
1607 for (
const MachineOperand &MO :
MI.all_defs())
1608 addRegClassDefCounts(RegClassDefCounts, MO.
getReg());
1610 llvm::sort(DefOperandIndexes, [&](
unsigned I0,
unsigned I1) {
1611 const MachineOperand &MO0 =
MI.getOperand(I0);
1612 const MachineOperand &MO1 =
MI.getOperand(I1);
1620 unsigned ClassSize0 = RegClassInfo->
getOrder(&RC0).size();
1621 unsigned ClassSize1 = RegClassInfo->
getOrder(&RC1).size();
1623 bool SmallClass0 = ClassSize0 < RegClassDefCounts[RC0.
getID()];
1624 bool SmallClass1 = ClassSize1 < RegClassDefCounts[RC1.
getID()];
1625 if (SmallClass0 > SmallClass1)
1627 if (SmallClass0 < SmallClass1)
1633 if (Livethrough0 > Livethrough1)
1635 if (Livethrough0 < Livethrough1)
1643void RegAllocFastImpl::allocateInstruction(MachineInstr &
MI) {
1666 LiveDefRegs.
clear();
1667 BundleVirtRegsMap.
clear();
1668 assert(PendingImplicitOps.empty() &&
"implicit operands not added");
1671 bool HasPhysRegUse =
false;
1672 bool HasRegMask =
false;
1673 bool HasVRegDef =
false;
1674 bool HasDef =
false;
1675 bool HasEarlyClobber =
false;
1676 bool HasTiedDef =
false;
1677 bool NeedToAssignLiveThroughs =
false;
1678 for (MachineOperand &MO :
MI.operands()) {
1682 if (!shouldAllocateRegister(
Reg))
1688 HasEarlyClobber =
true;
1689 if (LowerTiedOps && MO.
isTied())
1692 NeedToAssignLiveThroughs =
true;
1698 bool displacedAny = definePhysReg(
MI,
Reg);
1700 HasEarlyClobber =
true;
1707 HasPhysRegUse =
true;
1725 if (NeedToAssignLiveThroughs) {
1726 findAndSortDefOperandIndexes(
MI);
1727 for (
unsigned OpIdx : DefOperandIndexes) {
1728 MachineOperand &MO =
MI.getOperand(OpIdx);
1732 defineLiveThroughVirtReg(
MI, MO,
Reg);
1734 defineVirtReg(
MI, MO,
Reg);
1737 for (MachineOperand &MO :
MI.all_defs())
1739 defineVirtReg(
MI, MO, MO.
getReg());
1747 for (MachineOperand &MO :
reverse(
MI.all_defs())) {
1764 "tied def assigned to clobbered register");
1779 unmarkRegUsedInInstr(
Reg);
1788 for (
const auto *RM : RegMasks)
1791 for (
const LiveReg &LR : LiveVirtRegs) {
1792 MCRegister PhysReg = LR.PhysReg;
1793 if (PhysReg && isClobberedByRegMasks(PhysReg))
1794 displacePhysReg(
MI, PhysReg);
1799 if (HasPhysRegUse) {
1800 for (MachineOperand &MO :
MI.operands()) {
1808 if (!usePhysReg(
MI,
Reg))
1817 bool HasUndefUse =
false;
1818 bool TiedOnly = HasTiedDef;
1820 for (MachineOperand &MO :
MI.all_uses()) {
1823 (TiedOnly && !MO.
isTied()))
1837 useVirtReg(
MI, MO,
Reg);
1839 }
while (std::exchange(TiedOnly,
false));
1846 for (MachineOperand &MO :
MI.all_uses()) {
1851 assert(MO.
isUndef() &&
"Should only have undef virtreg uses left");
1852 allocVirtRegUndef(MO);
1858 if (HasEarlyClobber) {
1859 for (MachineOperand &MO :
reverse(
MI.all_defs())) {
1862 assert(!MO.
getSubReg() &&
"should be already handled in def processing");
1888 (
MI.getOperand(0).getReg() ==
MI.getOperand(1).getReg() ||
1889 MI.getOperand(0).isDead()) &&
1890 MI.getNumOperands() == 2) {
1896void RegAllocFastImpl::handleDebugValue(MachineInstr &
MI) {
1899 assert(
MI.isDebugValue() &&
"not a DBG_VALUE*");
1900 for (
const auto &MO :
MI.debug_operands()) {
1906 if (!shouldAllocateRegister(
Reg))
1910 int SS = StackSlotForVirtReg[
Reg];
1920 LiveRegMap::iterator LRI = findLiveVirtReg(
Reg);
1924 if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
1926 for (
auto &RegMO : DbgOps)
1927 setPhysReg(*RegMO, *LRI);
1929 DanglingDbgValues[
Reg].push_back(&
MI);
1934 LiveDbgValueMap[
Reg].append(DbgOps.begin(), DbgOps.end());
1938void RegAllocFastImpl::handleBundle(MachineInstr &
MI) {
1941 while (BundledMI->isBundledWithPred()) {
1942 for (MachineOperand &MO : BundledMI->operands()) {
1950 auto DI = BundleVirtRegsMap.
find(
Reg);
1951 assert(DI != BundleVirtRegsMap.
end() &&
"Unassigned virtual register");
1953 setPhysReg(MO, DI->second);
1961void RegAllocFastImpl::allocateBasicBlock(MachineBasicBlock &
MBB) {
1965 PosIndexes.unsetInitialized();
1966 RegUnitStates.assign(
TRI->getNumRegUnits(), regFree);
1967 assert(LiveVirtRegs.empty() &&
"Mapping not cleared from last block?");
1970 setPhysRegState(LiveReg.PhysReg, regPreAssigned);
1982 if (
MI.isDebugValue()) {
1983 handleDebugValue(
MI);
1987 allocateInstruction(
MI);
1992 HasErrorDef =
false;
1997 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
2005 LLVM_DEBUG(
dbgs() <<
"Loading live registers at begin of block.\n");
2010 for (MachineInstr *
MI : Coalesced)
2012 NumCoalesced += Coalesced.size();
2014 for (
auto &UDBGPair : DanglingDbgValues) {
2015 for (MachineInstr *DbgValue : UDBGPair.second) {
2020 LLVM_DEBUG(
dbgs() <<
"Register did not survive for " << *DbgValue
2025 DanglingDbgValues.clear();
2033void RegAllocFastImpl::expandSubregPseudo(MachineInstr &
MI) {
2036 if (
MI.isInsertSubreg()) {
2039 const MachineOperand &BaseMO =
MI.getOperand(1);
2042 MI.getOperand(0).getReg())
2044 unsigned SubIdx =
MI.getOperand(3).getImm();
2045 MI.removeOperand(3);
2046 assert(
MI.getOperand(0).getSubReg() == 0 &&
"Unexpected subreg idx");
2047 MI.getOperand(0).setSubReg(SubIdx);
2048 MI.getOperand(0).setIsUndef(
MI.getOperand(1).isUndef());
2049 MI.removeOperand(1);
2050 MI.setDesc(
TII->get(TargetOpcode::COPY));
2063 if (
unsigned UseSubIdx =
Use.getSubReg())
2064 ReadLanes |=
TRI->getSubRegIndexLaneMask(UseSubIdx);
2066 bool DefEmitted =
false;
2067 for (
unsigned I = 1,
E =
MI.getNumOperands();
I + 1 <
E;
I += 2) {
2068 const MachineOperand &SrcMO =
MI.getOperand(
I);
2069 unsigned SubIdx =
MI.getOperand(
I + 1).getImm();
2071 (ReadLanes &
TRI->getSubRegIndexLaneMask(SubIdx)).none())
2081 MI.setDesc(
TII->get(TargetOpcode::IMPLICIT_DEF));
2082 while (
MI.getNumOperands() > 1)
2083 MI.removeOperand(
MI.getNumOperands() - 1);
2086 MI.eraseFromParent();
2090 RegisterClassInfo &RCI) {
2091 LLVM_DEBUG(
dbgs() <<
"********** FAST REGISTER ALLOCATION **********\n"
2092 <<
"********** Function: " << MF.
getName() <<
'\n');
2098 RegClassInfo = &RCI;
2102 unsigned NumRegUnits =
TRI->getNumRegUnits();
2104 UsedInInstr.
assign(NumRegUnits, 0);
2111 for (MachineBasicBlock &
MBB : MF)
2113 if (
MI.isRegSequence() ||
MI.isInsertSubreg())
2114 expandSubregPseudo(
MI);
2120 StackSlotForVirtReg.
resize(NumVirtRegs);
2121 LiveVirtRegs.setUniverse(NumVirtRegs);
2122 MayLiveAcrossBlocks.
clear();
2123 MayLiveAcrossBlocks.
resize(NumVirtRegs);
2126 for (MachineBasicBlock &
MBB : MF)
2127 allocateBasicBlock(
MBB);
2129 if (ClearVirtRegs) {
2135 StackSlotForVirtReg.
clear();
2136 LiveDbgValueMap.
clear();
2143 RegAllocFastImpl Impl(Opts.Filter, Opts.ClearVRegs);
2144 bool Changed = Impl.runOnMachineFunction(
2155 bool PrintFilterName = Opts.FilterName !=
"all";
2156 bool PrintNoClearVRegs = !Opts.ClearVRegs;
2157 bool PrintSemicolon = PrintFilterName && PrintNoClearVRegs;
2159 OS <<
"regallocfast";
2160 if (PrintFilterName || PrintNoClearVRegs) {
2162 if (PrintFilterName)
2163 OS <<
"filter=" << Opts.FilterName;
2166 if (PrintNoClearVRegs)
2167 OS <<
"no-clear-vregs";
2175 bool ClearVirtRegs) {
2176 return new RegAllocFast(Ftor, ClearVirtRegs);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
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.
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)
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
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
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
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 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()