Go to the documentation of this file.
38 #define DEBUG_TYPE "regalloc"
44 struct CompSpillWeight {
46 return A->weight() <
B->weight();
64 std::unique_ptr<Spiller> SpillerInstance;
65 std::priority_queue<const LiveInterval *, std::vector<const LiveInterval *>,
73 bool LRE_CanEraseVirtReg(
Register)
override;
74 void LRE_WillShrinkVirtReg(
Register)
override;
80 StringRef getPassName()
const override {
return "Basic Register Allocator"; }
85 void releaseMemory()
override;
87 Spiller &spiller()
override {
return *SpillerInstance; }
145 bool RABasic::LRE_CanEraseVirtReg(
Register VirtReg) {
147 if (VRM->hasPhys(VirtReg)) {
149 aboutToRemoveInterval(LI);
160 void RABasic::LRE_WillShrinkVirtReg(
Register VirtReg) {
161 if (!VRM->hasPhys(VirtReg))
196 MachineFunctionPass::getAnalysisUsage(AU);
199 void RABasic::releaseMemory() {
200 SpillerInstance.reset();
207 bool RABasic::spillInterferences(
const LiveInterval &VirtReg,
218 if (!Intf->isSpillable() || Intf->weight() > VirtReg.
weight())
220 Intfs.push_back(Intf);
224 <<
" interferences with " << VirtReg <<
"\n");
225 assert(!Intfs.empty() &&
"expected interference");
228 for (
unsigned i = 0,
e = Intfs.size();
i !=
e; ++
i) {
232 if (!VRM->hasPhys(Spill.
reg()))
240 LiveRangeEdit LRE(&Spill, SplitVRegs, *MF, *LIS, VRM,
this, &DeadRemats);
241 spiller().spill(LRE);
265 AllocationOrder::create(VirtReg.
reg(), *VRM, RegClassInfo,
Matrix);
269 switch (
Matrix->checkInterference(VirtReg, PhysReg)) {
270 case LiveRegMatrix::IK_Free:
274 case LiveRegMatrix::IK_VirtReg:
276 PhysRegSpillCands.push_back(PhysReg);
286 for (
MCRegister &PhysReg : PhysRegSpillCands) {
287 if (!spillInterferences(VirtReg, PhysReg, SplitVRegs))
291 "Interference after spill.");
300 LiveRangeEdit LRE(&VirtReg, SplitVRegs, *MF, *LIS, VRM,
this, &DeadRemats);
301 spiller().spill(LRE);
309 LLVM_DEBUG(
dbgs() <<
"********** BASIC REGISTER ALLOCATION **********\n"
310 <<
"********** Function: " << mf.
getName() <<
'\n');
314 getAnalysis<LiveIntervals>(),
315 getAnalysis<LiveRegMatrix>());
316 VirtRegAuxInfo VRAI(*MF, *LIS, *VRM, getAnalysis<MachineLoopInfo>(),
317 getAnalysis<MachineBlockFrequencyInfo>());
318 VRAI.calculateSpillWeightsAndHints();
333 return new RABasic();
337 return new RABasic(
F);
This is an optimization pass for GlobalISel generic memory operations.
char & RABasicID
Basic register allocator.
bool isSpillable() const
isSpillable - Can this interval be spilled?
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Calculate auxiliary information for a virtual register such as its spill weight and allocation hint.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Properties which a MachineFunction may have at a given point in time.
unsigned const TargetRegisterInfo * TRI
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Spiller * createInlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM, VirtRegAuxInfo &VRAI)
Create and return a spiller that will insert spill code directly instead of deferring though VirtRegM...
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Represent the analysis usage information of a pass.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineFunctionProperties & set(Property P)
INITIALIZE_PASS_BEGIN(RABasic, "regallocbasic", "Basic Register Allocator", false, false) INITIALIZE_PASS_END(RABasic
LiveInterval - This class represents the liveness of a register, or stack slot.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
std::function< bool(const TargetRegisterInfo &TRI, const TargetRegisterClass &RC)> RegClassFilterFunc
initializer< Ty > init(const Ty &Val)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setPreservesCFG()
This function should be called by the pass, iff they do not:
StringRef - Represent a constant reference to a string, i.e.
AnalysisUsage & addPreservedID(const void *ID)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
const SmallVectorImpl< const LiveInterval * > & interferingVRegs(unsigned MaxInterferingRegs=std::numeric_limits< unsigned >::max())
Wrapper class representing virtual and physical registers.
static bool allocateAllRegClasses(const TargetRegisterInfo &, const TargetRegisterClass &)
Default register class filter function for register allocation.
RegAllocBase provides the register allocation driver and interface that can be extended to add intere...
Query interferences between a single live virtual register and a live interval union.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
AnalysisUsage & addRequiredID(const void *ID)
Callback methods for LiveRangeEdit owners.
AnalysisUsage & addRequired()
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
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.
static RegisterRegAlloc basicRegAlloc("basic", "basic register allocator", createBasicRegisterAllocator)
Wrapper class representing physical registers. Should be passed by value.