50#define DEBUG_TYPE "regalloc"
54STATISTIC(NumCoalesced,
"Number of copies coalesced");
70 bool ClearVirtRegs_ =
true)
72 StackSlotForVirtReg(-1), ClearVirtRegs(ClearVirtRegs_) {}
96 bool Reloaded =
false;
99 explicit LiveReg(
Register VirtReg) : VirtReg(VirtReg) {}
101 unsigned getSparseSetIndex()
const {
109 LiveRegMap LiveVirtRegs;
143 std::vector<unsigned> RegUnitStates;
150 RegUnitSet UsedInInstr;
151 RegUnitSet PhysRegUses;
156 void setPhysRegState(
MCPhysReg PhysReg,
unsigned NewState);
157 bool isPhysRegFree(
MCPhysReg PhysReg)
const;
160 void markRegUsedInInstr(
MCPhysReg PhysReg) {
162 UsedInInstr.insert(Unit);
166 bool isClobberedByRegMasks(
MCPhysReg PhysReg)
const {
173 bool isRegUsedInInstr(
MCPhysReg PhysReg,
bool LookAtPhysRegUses)
const {
174 if (LookAtPhysRegUses && isClobberedByRegMasks(PhysReg))
177 if (UsedInInstr.count(Unit))
179 if (LookAtPhysRegUses && PhysRegUses.count(Unit))
187 void markPhysRegUsedInInstr(
MCPhysReg PhysReg) {
189 PhysRegUses.insert(Unit);
193 void unmarkRegUsedInInstr(
MCPhysReg PhysReg) {
195 UsedInInstr.erase(Unit);
202 spillImpossible = ~0
u
215 MachineFunctionProperties::Property::NoPHIs);
221 MachineFunctionProperties::Property::NoVRegs);
229 MachineFunctionProperties::Property::IsSSA);
237 void addRegClassDefCounts(std::vector<unsigned> &RegClassDefCounts,
251 unsigned calcSpillCost(
MCPhysReg PhysReg)
const;
263 bool LookAtPhysRegUses =
false);
270 bool LookAtPhysRegUses =
false);
283 bool shouldAllocateRegister(
const Register Reg)
const;
284 int getStackSpaceFor(
Register VirtReg);
286 MCPhysReg AssignedReg,
bool Kill,
bool LiveOut);
293 void dumpState()
const;
298char RegAllocFast::ID = 0;
306 return ShouldAllocateClass(*
TRI, RC);
309void RegAllocFast::setPhysRegState(
MCPhysReg PhysReg,
unsigned NewState) {
311 RegUnitStates[Unit] = NewState;
314bool RegAllocFast::isPhysRegFree(
MCPhysReg PhysReg)
const {
316 if (RegUnitStates[Unit] != regFree)
324int RegAllocFast::getStackSpaceFor(
Register VirtReg) {
326 int SS = StackSlotForVirtReg[VirtReg];
333 unsigned Size =
TRI->getSpillSize(RC);
334 Align Alignment =
TRI->getSpillAlign(RC);
338 StackSlotForVirtReg[VirtReg] = FrameIdx;
350 for (; &*
I !=
A && &*
I !=
B; ++
I)
357bool RegAllocFast::mayLiveOut(
Register VirtReg) {
370 if (DefInst.getParent() !=
MBB) {
375 SelfLoopDef = &DefInst;
386 static const unsigned Limit = 8;
388 for (
const MachineInstr &UseInst :
MRI->use_nodbg_instructions(VirtReg)) {
389 if (UseInst.getParent() !=
MBB || ++
C >= Limit) {
398 if (SelfLoopDef == &UseInst ||
410bool RegAllocFast::mayLiveIn(
Register VirtReg) {
415 static const unsigned Limit = 8;
418 if (DefInst.getParent() !=
MBB || ++
C >= Limit) {
430 MCPhysReg AssignedReg,
bool Kill,
bool LiveOut) {
433 int FI = getStackSpaceFor(VirtReg);
450 SpilledOperandsMap[MO->getParent()].push_back(MO);
451 for (
auto MISpilledOperands : SpilledOperandsMap) {
457 *
MBB,
Before, *MISpilledOperands.first, FI, MISpilledOperands.second);
460 LLVM_DEBUG(
dbgs() <<
"Inserting debug info due to spill:\n" << *NewDV);
469 LLVM_DEBUG(
dbgs() <<
"Cloning debug info due to live out spill\n");
485 LRIDbgOperands.clear();
493 int FI = getStackSpaceFor(VirtReg);
513 if (!
TII->isBasicBlockPrologue(*
I))
531 if (LiveVirtRegs.empty())
538 setPhysRegState(Reg, regLiveIn);
546 getMBBBeginInsertionPoint(
MBB, PrologLiveIns);
547 for (
const LiveReg &LR : LiveVirtRegs) {
553 if (RegUnitStates[FirstUnit] == regLiveIn)
557 "no reload in start block. Missing vreg def?");
559 if (PrologLiveIns.
count(PhysReg)) {
563 reload(
MBB.
begin(), LR.VirtReg, PhysReg);
565 reload(InsertBefore, LR.VirtReg, PhysReg);
567 LiveVirtRegs.clear();
575 bool displacedAny = displacePhysReg(
MI, Reg);
576 setPhysRegState(Reg, regPreAssigned);
577 markRegUsedInInstr(Reg);
582 bool displacedAny = displacePhysReg(
MI, Reg);
583 setPhysRegState(Reg, regPreAssigned);
591 bool displacedAny =
false;
594 switch (
unsigned VirtReg = RegUnitStates[Unit]) {
596 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
597 assert(LRI != LiveVirtRegs.end() &&
"datastructures in sync");
600 reload(ReloadBefore, VirtReg, LRI->PhysReg);
602 setPhysRegState(LRI->PhysReg, regFree);
604 LRI->Reloaded =
true;
609 RegUnitStates[Unit] = regFree;
619void RegAllocFast::freePhysReg(
MCPhysReg PhysReg) {
623 switch (
unsigned VirtReg = RegUnitStates[FirstUnit]) {
629 setPhysRegState(PhysReg, regFree);
632 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
633 assert(LRI != LiveVirtRegs.end());
635 setPhysRegState(LRI->PhysReg, regFree);
646unsigned RegAllocFast::calcSpillCost(
MCPhysReg PhysReg)
const {
648 switch (
unsigned VirtReg = RegUnitStates[Unit]) {
654 return spillImpossible;
656 bool SureSpill = StackSlotForVirtReg[VirtReg] != -1 ||
657 findLiveVirtReg(VirtReg)->LiveOut;
658 return SureSpill ? spillClean : spillDirty;
665void RegAllocFast::assignDanglingDebugValues(
MachineInstr &Definition,
667 auto UDBGValIter = DanglingDbgValues.
find(VirtReg);
668 if (UDBGValIter == DanglingDbgValues.
end())
674 if (!
DbgValue->hasDebugOperandForReg(VirtReg))
683 if (
I->modifiesRegister(Reg,
TRI) || --Limit == 0) {
702void RegAllocFast::assignVirtToPhysReg(
MachineInstr &AtMI, LiveReg &LR,
707 assert(LR.PhysReg == 0 &&
"Already assigned a physreg");
708 assert(PhysReg != 0 &&
"Trying to assign no register");
709 LR.PhysReg = PhysReg;
710 setPhysRegState(PhysReg, VirtReg);
712 assignDanglingDebugValues(AtMI, VirtReg, PhysReg);
718 static const unsigned ChainLengthLimit = 3;
721 if (
Reg.isPhysical())
729 }
while (++
C <= ChainLengthLimit);
737 static const unsigned DefLimit = 3;
742 Reg = traceCopyChain(Reg);
755 bool LookAtPhysRegUses) {
756 const Register VirtReg = LR.VirtReg;
761 <<
" in class " <<
TRI->getRegClassName(&RC)
766 !isRegUsedInInstr(Hint0, LookAtPhysRegUses)) {
768 if (isPhysRegFree(Hint0)) {
771 assignVirtToPhysReg(
MI, LR, Hint0);
782 Register Hint1 = traceCopies(VirtReg);
784 !isRegUsedInInstr(Hint1, LookAtPhysRegUses)) {
786 if (isPhysRegFree(Hint1)) {
789 assignVirtToPhysReg(
MI, LR, Hint1);
800 unsigned BestCost = spillImpossible;
804 if (isRegUsedInInstr(PhysReg, LookAtPhysRegUses)) {
809 unsigned Cost = calcSpillCost(PhysReg);
813 assignVirtToPhysReg(
MI, LR, PhysReg);
817 if (PhysReg == Hint0 || PhysReg == Hint1)
818 Cost -= spillPrefBonus;
820 if (
Cost < BestCost) {
829 if (
MI.isInlineAsm())
830 MI.emitError(
"inline assembly requires more registers than available");
832 MI.emitError(
"ran out of registers during register allocation");
839 displacePhysReg(
MI, BestReg);
840 assignVirtToPhysReg(
MI, LR, BestReg);
847 if (!shouldAllocateRegister(VirtReg))
850 LiveRegMap::const_iterator LRI = findLiveVirtReg(VirtReg);
852 if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
853 PhysReg = LRI->PhysReg;
862 if (SubRegIdx != 0) {
863 PhysReg =
TRI->getSubReg(PhysReg, SubRegIdx);
873bool RegAllocFast::defineLiveThroughVirtReg(
MachineInstr &
MI,
unsigned OpNum,
875 if (!shouldAllocateRegister(VirtReg))
877 LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg);
878 if (LRI != LiveVirtRegs.end()) {
880 if (PrevReg != 0 && isRegUsedInInstr(PrevReg,
true)) {
882 <<
" (tied/earlyclobber resolution)\n");
883 freePhysReg(PrevReg);
885 allocVirtReg(
MI, *LRI, 0,
true);
891 TII->get(TargetOpcode::COPY), PrevReg)
899 return defineVirtReg(
MI, OpNum, VirtReg,
true);
910 Register VirtReg,
bool LookAtPhysRegUses) {
912 if (!shouldAllocateRegister(VirtReg))
915 LiveRegMap::iterator LRI;
917 std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg));
920 if (mayLiveOut(VirtReg)) {
928 if (LRI->PhysReg == 0) {
929 allocVirtReg(
MI, *LRI, 0, LookAtPhysRegUses);
940 assert(!isRegUsedInInstr(LRI->PhysReg, LookAtPhysRegUses) &&
941 "TODO: preassign mismatch");
943 <<
" use existing assignment to "
948 if (LRI->Reloaded || LRI->LiveOut) {
949 if (!
MI.isImplicitDef()) {
953 <<
" RL: " << LRI->Reloaded <<
'\n');
954 bool Kill = LRI->LastUse ==
nullptr;
955 spill(SpillBefore, VirtReg, PhysReg, Kill, LRI->LiveOut);
959 if (
MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
960 int FI = StackSlotForVirtReg[VirtReg];
973 LRI->LastUse =
nullptr;
975 LRI->LiveOut =
false;
976 LRI->Reloaded =
false;
978 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
979 BundleVirtRegsMap[VirtReg] = PhysReg;
981 markRegUsedInInstr(PhysReg);
982 return setPhysReg(
MI, MO, PhysReg);
990 if (!shouldAllocateRegister(VirtReg))
993 LiveRegMap::iterator LRI;
995 std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg));
999 if (mayLiveOut(VirtReg)) {
1000 LRI->LiveOut =
true;
1007 assert((!MO.
isKill() || LRI->LastUse == &
MI) &&
"Invalid kill flag");
1011 if (LRI->PhysReg == 0) {
1014 if (
MI.isCopy() &&
MI.getOperand(1).getSubReg() == 0) {
1015 Hint =
MI.getOperand(0).getReg();
1017 assert(!shouldAllocateRegister(Hint));
1021 "Copy destination should already be assigned");
1024 allocVirtReg(
MI, *LRI, Hint,
false);
1036 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
1037 BundleVirtRegsMap[VirtReg] = LRI->PhysReg;
1039 markRegUsedInInstr(LRI->PhysReg);
1040 return setPhysReg(
MI, MO, LRI->PhysReg);
1065 MI.addRegisterKilled(PhysReg,
TRI,
true);
1074 MI.addRegisterDead(PhysReg,
TRI,
true);
1076 MI.addRegisterDefined(PhysReg,
TRI);
1085void RegAllocFast::dumpState()
const {
1086 for (
unsigned Unit = 1, UnitE =
TRI->getNumRegUnits(); Unit != UnitE;
1088 switch (
unsigned VirtReg = RegUnitStates[Unit]) {
1091 case regPreAssigned:
1098 LiveRegMap::const_iterator
I = findLiveVirtReg(VirtReg);
1099 assert(
I != LiveVirtRegs.end() &&
"have LiveVirtRegs entry");
1100 if (
I->LiveOut ||
I->Reloaded) {
1108 assert(
TRI->hasRegUnit(
I->PhysReg, Unit) &&
"inverse mapping present");
1115 for (
const LiveReg &LR : LiveVirtRegs) {
1122 assert(RegUnitStates[Unit] == VirtReg &&
"inverse map valid");
1130void RegAllocFast::addRegClassDefCounts(
1131 std::vector<unsigned> &RegClassDefCounts,
Register Reg)
const {
1132 assert(RegClassDefCounts.size() ==
TRI->getNumRegClasses());
1134 if (
Reg.isVirtual()) {
1135 if (!shouldAllocateRegister(Reg))
1138 for (
unsigned RCIdx = 0, RCIdxEnd =
TRI->getNumRegClasses();
1139 RCIdx != RCIdxEnd; ++RCIdx) {
1143 ++RegClassDefCounts[RCIdx];
1149 for (
unsigned RCIdx = 0, RCIdxEnd =
TRI->getNumRegClasses();
1150 RCIdx != RCIdxEnd; ++RCIdx) {
1154 ++RegClassDefCounts[RCIdx];
1164void RegAllocFast::findAndSortDefOperandIndexes(
const MachineInstr &
MI) {
1165 DefOperandIndexes.
clear();
1168 std::vector<unsigned> RegClassDefCounts(
TRI->getNumRegClasses(), 0);
1169 assert(RegClassDefCounts[0] == 0);
1172 for (
unsigned I = 0,
E =
MI.getNumOperands();
I <
E; ++
I) {
1178 if (
Reg.isPhysical()) {
1180 markPhysRegUsedInInstr(Reg);
1185 if (
Reg.isVirtual() && shouldAllocateRegister(Reg))
1188 addRegClassDefCounts(RegClassDefCounts, Reg);
1202 unsigned ClassSize0 = RegClassInfo.
getOrder(&RC0).
size();
1203 unsigned ClassSize1 = RegClassInfo.
getOrder(&RC1).
size();
1205 bool SmallClass0 = ClassSize0 < RegClassDefCounts[RC0.
getID()];
1206 bool SmallClass1 = ClassSize1 < RegClassDefCounts[RC1.
getID()];
1207 if (SmallClass0 > SmallClass1)
1209 if (SmallClass0 < SmallClass1)
1217 if (Livethrough0 > Livethrough1)
1219 if (Livethrough0 < Livethrough1)
1240 UsedInInstr.clear();
1242 BundleVirtRegsMap.
clear();
1246 unsigned TiedIdx =
MI.findTiedOperandIdx(
Idx);
1251 bool HasPhysRegUse =
false;
1252 bool HasRegMask =
false;
1253 bool HasVRegDef =
false;
1254 bool HasDef =
false;
1255 bool HasEarlyClobber =
false;
1256 bool NeedToAssignLiveThroughs =
false;
1257 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I) {
1261 if (
Reg.isVirtual()) {
1262 if (!shouldAllocateRegister(Reg))
1268 HasEarlyClobber =
true;
1269 NeedToAssignLiveThroughs =
true;
1271 if ((MO.
isTied() && !TiedOpIsUndef(MO,
I)) ||
1273 NeedToAssignLiveThroughs =
true;
1275 }
else if (
Reg.isPhysical()) {
1276 if (!
MRI->isReserved(Reg)) {
1279 bool displacedAny = definePhysReg(
MI, Reg);
1281 HasEarlyClobber =
true;
1286 HasPhysRegUse =
true;
1300 bool ReArrangedImplicitOps =
true;
1308 if (NeedToAssignLiveThroughs) {
1309 PhysRegUses.clear();
1311 while (ReArrangedImplicitOps) {
1312 ReArrangedImplicitOps =
false;
1313 findAndSortDefOperandIndexes(
MI);
1314 for (
uint16_t OpIdx : DefOperandIndexes) {
1319 (MO.
isTied() && !TiedOpIsUndef(MO, OpIdx)) ||
1321 ReArrangedImplicitOps = defineLiveThroughVirtReg(
MI, OpIdx, Reg);
1323 ReArrangedImplicitOps = defineVirtReg(
MI, OpIdx, Reg);
1325 if (ReArrangedImplicitOps) {
1334 while (ReArrangedImplicitOps) {
1335 ReArrangedImplicitOps =
false;
1336 for (
unsigned I = 0,
E =
MI.getNumOperands();
I <
E; ++
I) {
1341 if (
Reg.isVirtual()) {
1342 ReArrangedImplicitOps = defineVirtReg(
MI,
I, Reg);
1343 if (ReArrangedImplicitOps) {
1355 for (
signed I =
MI.getNumOperands() - 1;
I >= 0; --
I) {
1370 "tied def assigned to clobbered register");
1377 if (
Reg.isVirtual()) {
1378 assert(!shouldAllocateRegister(Reg));
1382 if (
MRI->isReserved(Reg))
1385 unmarkRegUsedInInstr(Reg);
1393 for (
const auto *RM : RegMasks)
1394 MRI->addPhysRegsUsedFromRegMask(RM);
1397 for (
const LiveReg &LR : LiveVirtRegs) {
1399 if (PhysReg != 0 && isClobberedByRegMasks(PhysReg))
1400 displacePhysReg(
MI, PhysReg);
1405 if (HasPhysRegUse) {
1410 if (!
Reg.isPhysical())
1412 if (
MRI->isReserved(Reg))
1414 bool displacedAny = usePhysReg(
MI, Reg);
1423 bool HasUndefUse =
false;
1424 bool ReArrangedImplicitMOs =
true;
1425 while (ReArrangedImplicitMOs) {
1426 ReArrangedImplicitMOs =
false;
1427 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I) {
1432 if (!
Reg.isVirtual() || !shouldAllocateRegister(Reg))
1446 ReArrangedImplicitMOs = useVirtReg(
MI,
I, Reg);
1447 if (ReArrangedImplicitMOs)
1458 if (!
Reg.isVirtual() || !shouldAllocateRegister(Reg))
1461 assert(MO.
isUndef() &&
"Should only have undef virtreg uses left");
1462 allocVirtRegUndef(MO);
1467 if (HasEarlyClobber) {
1471 assert(!MO.
getSubReg() &&
"should be already handled in def processing");
1476 if (
Reg.isVirtual()) {
1477 assert(!shouldAllocateRegister(Reg));
1480 assert(
Reg.isPhysical() &&
"should have register assigned");
1488 if (
MI.readsRegister(Reg,
TRI))
1496 if (
MI.isCopy() &&
MI.getOperand(0).getReg() ==
MI.getOperand(1).getReg() &&
1497 MI.getNumOperands() == 2) {
1506 assert(
MI.isDebugValue() &&
"not a DBG_VALUE*");
1507 for (
const auto &MO :
MI.debug_operands()) {
1511 if (!
Reg.isVirtual())
1513 if (!shouldAllocateRegister(Reg))
1517 int SS = StackSlotForVirtReg[
Reg];
1527 LiveRegMap::iterator LRI = findLiveVirtReg(Reg);
1532 if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
1534 for (
auto &RegMO : DbgOps)
1535 setPhysReg(
MI, *RegMO, LRI->PhysReg);
1537 DanglingDbgValues[
Reg].push_back(&
MI);
1542 LiveDbgValueMap[
Reg].append(DbgOps.
begin(), DbgOps.
end());
1549 while (BundledMI->isBundledWithPred()) {
1555 if (!
Reg.isVirtual() || !shouldAllocateRegister(Reg))
1559 DI = BundleVirtRegsMap.
find(Reg);
1560 assert(DI != BundleVirtRegsMap.
end() &&
"Unassigned virtual register");
1562 setPhysReg(
MI, MO, DI->second);
1573 RegUnitStates.assign(
TRI->getNumRegUnits(), regFree);
1574 assert(LiveVirtRegs.empty() &&
"Mapping not cleared from last block?");
1577 setPhysRegState(LiveReg.PhysReg, regPreAssigned);
1587 if (
MI.isDebugValue()) {
1588 handleDebugValue(
MI);
1592 allocateInstruction(
MI);
1596 if (
MI.getOpcode() == TargetOpcode::BUNDLE) {
1604 LLVM_DEBUG(
dbgs() <<
"Loading live registers at begin of block.\n");
1611 NumCoalesced += Coalesced.size();
1613 for (
auto &UDBGPair : DanglingDbgValues) {
1617 if (!
DbgValue->hasDebugOperandForReg(UDBGPair.first))
1624 DanglingDbgValues.clear();
1630 LLVM_DEBUG(
dbgs() <<
"********** FAST REGISTER ALLOCATION **********\n"
1631 <<
"********** Function: " << MF.
getName() <<
'\n');
1637 MRI->freezeReservedRegs(MF);
1639 unsigned NumRegUnits =
TRI->getNumRegUnits();
1640 UsedInInstr.clear();
1641 UsedInInstr.setUniverse(NumRegUnits);
1642 PhysRegUses.clear();
1643 PhysRegUses.setUniverse(NumRegUnits);
1647 unsigned NumVirtRegs =
MRI->getNumVirtRegs();
1648 StackSlotForVirtReg.
resize(NumVirtRegs);
1649 LiveVirtRegs.setUniverse(NumVirtRegs);
1650 MayLiveAcrossBlocks.
clear();
1651 MayLiveAcrossBlocks.
resize(NumVirtRegs);
1655 allocateBasicBlock(
MBB);
1657 if (ClearVirtRegs) {
1660 MRI->clearVirtRegs();
1663 StackSlotForVirtReg.
clear();
1664 LiveDbgValueMap.
clear();
1671 bool ClearVirtRegs) {
1672 return new RegAllocFast(Ftor, ClearVirtRegs);
unsigned const MachineRegisterInfo * MRI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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 DenseMap class.
const HexagonInstrInfo * TII
This file implements an indexed map.
unsigned const TargetRegisterInfo * TRI
This file implements a map that provides insertion order iteration.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool dominates(MachineBasicBlock &MBB, MachineBasicBlock::const_iterator A, MachineBasicBlock::const_iterator B)
static bool isCoalescable(const MachineInstr &MI)
static cl::opt< bool > IgnoreMissingDefs("rafast-ignore-missing-defs", cl::Hidden)
static RegisterRegAlloc fastRegAlloc("fast", "fast register allocator", createFastRegisterAllocator)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
Class recording the (high level) value of a variable.
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool test(unsigned Idx) const
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void clear()
clear - Removes all bits from the bitvector.
This class represents an Operation in the Expression.
iterator find(const_arg_type_t< KeyT > Val)
Lightweight error class with error context and mandatory checking.
FunctionPass class - This class is used to implement most global optimizations.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) 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, const TargetRegisterInfo *TRI, Register VReg) const override
Load the specified register of the given register class from the specified stack frame index.
void resize(typename StorageT::size_type s)
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
static constexpr unsigned NoRegister
iterator_range< liveout_iterator > liveouts() const
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
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
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.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int CreateSpillStackObject(uint64_t Size, Align Alignment)
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...
virtual MachineFunctionProperties getClearedProperties() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual MachineFunctionProperties getSetProperties() const
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
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.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
bool isDebugValueList() const
const MachineBasicBlock * getParent() const
bool isNonListDebugValue() const
MachineOperand & getDebugOperand(unsigned Index)
const MachineOperand & getOperand(unsigned i) 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.
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)
void setReg(Register Reg)
Change the register this operand corresponds to.
void setIsKill(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.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
void runOnMachineFunction(const MachineFunction &MF)
runOnFunction - Prepare to answer questions about MF.
ArrayRef< MCPhysReg > getOrder(const TargetRegisterClass *RC) const
getOrder - Returns the preferred allocation order for RC.
Wrapper class representing virtual and physical registers.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
typename DenseT::iterator iterator
typename DenseT::const_iterator const_iterator
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getID() const
Return the register class ID number.
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ Kill
The last use of a register.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex, Register Reg)
Update a DBG_VALUE whose value has been spilled to FrameIndex.
Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
static bool allocateAllRegClasses(const TargetRegisterInfo &, const TargetRegisterClass &)
Default register class filter function for register allocation.
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)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
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.
std::function< bool(const TargetRegisterInfo &TRI, const TargetRegisterClass &RC)> RegClassFilterFunc
This struct is a compact representation of a valid (non-zero power of two) alignment.
Pair of physical register and lane mask.
A MapVector that performs no allocations if smaller than a certain size.