42 #define DEBUG_TYPE "regalloc"
48 struct CompSpillWeight {
68 std::unique_ptr<Spiller> SpillerInstance;
69 std::priority_queue<LiveInterval*, std::vector<LiveInterval*>,
70 CompSpillWeight>
Queue;
76 bool LRE_CanEraseVirtReg(
unsigned)
override;
77 void LRE_WillShrinkVirtReg(
unsigned)
override;
83 StringRef getPassName()
const override {
return "Basic Register Allocator"; }
88 void releaseMemory()
override;
90 Spiller &spiller()
override {
return *SpillerInstance; }
118 bool spillInterferences(
LiveInterval &VirtReg,
unsigned PhysReg,
145 bool RABasic::LRE_CanEraseVirtReg(
unsigned VirtReg) {
146 if (VRM->hasPhys(VirtReg)) {
149 aboutToRemoveInterval(LI);
157 void RABasic::LRE_WillShrinkVirtReg(
unsigned VirtReg) {
158 if (!VRM->hasPhys(VirtReg))
191 MachineFunctionPass::getAnalysisUsage(AU);
194 void RABasic::releaseMemory() {
195 SpillerInstance.reset();
202 bool RABasic::spillInterferences(
LiveInterval &VirtReg,
unsigned PhysReg,
219 DEBUG(
dbgs() <<
"spilling " << TRI->getName(PhysReg) <<
220 " interferences with " << VirtReg <<
"\n");
224 for (
unsigned i = 0, e = Intfs.
size(); i != e; ++i) {
228 if (!VRM->hasPhys(Spill.
reg))
236 LiveRangeEdit LRE(&Spill, SplitVRegs, *MF, *LIS, VRM,
this, &DeadRemats);
237 spiller().spill(LRE);
261 while (
unsigned PhysReg = Order.next()) {
263 switch (
Matrix->checkInterference(VirtReg, PhysReg)) {
264 case LiveRegMatrix::IK_Free:
268 case LiveRegMatrix::IK_VirtReg:
281 PhysRegE = PhysRegSpillCands.
end(); PhysRegI != PhysRegE; ++PhysRegI) {
282 if (!spillInterferences(VirtReg, *PhysRegI, SplitVRegs))
285 assert(!
Matrix->checkInterference(VirtReg, *PhysRegI) &&
286 "Interference after spill.");
292 DEBUG(
dbgs() <<
"spilling: " << VirtReg <<
'\n');
295 LiveRangeEdit LRE(&VirtReg, SplitVRegs, *MF, *LIS, VRM,
this, &DeadRemats);
296 spiller().spill(LRE);
304 DEBUG(
dbgs() <<
"********** BASIC REGISTER ALLOCATION **********\n"
305 <<
"********** Function: "
310 getAnalysis<LiveIntervals>(),
311 getAnalysis<LiveRegMatrix>());
314 getAnalysis<MachineLoopInfo>(),
315 getAnalysis<MachineBlockFrequencyInfo>());
323 DEBUG(
dbgs() <<
"Post alloc VirtRegMap:\n" << *VRM <<
"\n");
331 return new RABasic();
void push_back(const T &Elt)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool isSpillable() const
isSpillable - Can this interval be spilled?
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Callback methods for LiveRangeEdit owners.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Query interferences between a single live virtual register and a live interval union.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
static RegisterRegAlloc basicRegAlloc("basic","basic register allocator", createBasicRegisterAllocator)
RegAllocBase provides the register allocation driver and interface that can be extended to add intere...
LLVM_NODISCARD bool empty() const
const SmallVectorImpl< LiveInterval * > & interferingVRegs() const
AnalysisUsage & addPreservedID(const void *ID)
RegisterRegAlloc class - Track the registration of register allocators.
char & RABasicID
Basic register allocator.
unsigned collectInterferingVRegs(unsigned MaxInterferingRegs=std::numeric_limits< unsigned >::max())
initializer< Ty > init(const Ty &Val)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF, VirtRegMap *VRM, const MachineLoopInfo &MLI, const MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo::NormalizingFn norm=normalizeSpillWeight)
Compute spill weights and allocation hints for all virtual register live intervals.
AnalysisUsage & addRequiredID(const void *ID)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
Promote Memory to Register
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineFunctionProperties & set(Property P)
Spiller * createInlineSpiller(MachineFunctionPass &pass, MachineFunction &mf, VirtRegMap &vrm)
Create and return a spiller that will insert spill code directly instead of deferring though VirtRegM...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
INITIALIZE_PASS_BEGIN(RABasic,"regallocbasic","Basic Register Allocator", false, false) INITIALIZE_PASS_END(RABasic
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Properties which a MachineFunction may have at a given point in time.