20 #define DEBUG_TYPE "regalloc"
22 void LiveRangeCalc::resetLiveOutMap() {
54 assert(MRI && Indexes &&
"call reset() first");
62 if (!MO.isDef() && !MO.readsReg())
65 unsigned SubReg = MO.getSubReg();
66 if (LI.
hasSubRanges() || (SubReg != 0 && TrackSubRegs)) {
83 unsigned LRest = S.LaneMask & ~Mask;
90 assert(Common == S.LaneMask);
120 extendToUses(S, Reg, S.LaneMask);
126 extendToUses(LI, Reg, ~0u);
132 assert(MRI && Indexes &&
"call reset() first");
141 void LiveRangeCalc::extendToUses(
LiveRange &LR,
unsigned Reg,
unsigned Mask) {
162 if ((SubRegMask & Mask) == 0)
171 assert(!MO.isDef() &&
"Cannot handle PHI def of partial register.");
177 bool isEarlyClobber =
false;
180 isEarlyClobber = MO.isEarlyClobber();
196 void LiveRangeCalc::updateFromLiveIns() {
198 for (
const LiveInBlock &
I : LiveIn) {
202 assert(
I.Value &&
"No live-in value found");
206 if (
I.Kill.isValid())
213 Map[MBB] = LiveOutPair(
I.Value,
nullptr);
216 Updater.
add(Start, End,
I.Value);
223 assert(Use.
isValid() &&
"Invalid SlotIndex");
224 assert(Indexes &&
"Missing SlotIndexes");
225 assert(DomTree &&
"Missing dominator tree");
228 assert(UseMBB &&
"No MBB at Use");
238 if (findReachingDefs(LR, *UseMBB, Use, PhysReg))
250 assert(Indexes &&
"Missing SlotIndexes");
251 assert(DomTree &&
"Missing dominator tree");
265 bool UniqueVNI =
true;
269 for (
unsigned i = 0; i != WorkList.size(); ++i) {
276 <<
" does not have a corresponding definition on every path:\n";
279 errs() << Use <<
" " << *
MI;
287 <<
" needs to be live in to BB#" << MBB->
getNumber()
288 <<
", but is missing from the live-in list.\n";
294 PE = MBB->
pred_end(); PI != PE; ++PI) {
299 if (
VNInfo *VNI = Map[Pred].first) {
300 if (TheVNI && TheVNI != VNI)
315 if (TheVNI && TheVNI != VNI)
334 if (WorkList.size() > 4)
341 E = WorkList.end();
I != E; ++
I) {
345 if (*
I == UseMBBNum && Use.
isValid())
349 Updater.
add(Start, End, TheVNI);
356 LiveIn.reserve(WorkList.size());
358 I = WorkList.begin(), E = WorkList.end();
I != E; ++
I) {
362 LiveIn.back().Kill = Use;
371 void LiveRangeCalc::updateSSA() {
372 assert(Indexes &&
"Missing SlotIndexes");
373 assert(DomTree &&
"Missing dominator tree");
381 for (LiveInBlock &
I : LiveIn) {
388 LiveOutPair IDomValue;
392 bool needPHI = !IDom || !Seen.
test(IDom->
getBlock()->getNumber());
401 if (IDomValue.first && !IDomValue.second)
402 Map[IDom->
getBlock()].second = IDomValue.second =
406 PE = MBB->
pred_end(); PI != PE; ++PI) {
407 LiveOutPair &
Value = Map[*PI];
408 if (!Value.first || Value.first == IDomValue.first)
419 if (DomTree->
dominates(IDom, Value.second)) {
429 LiveOutPair &LOP = Map[MBB];
434 assert(Alloc &&
"Need VNInfo allocator to create PHI-defs");
444 if (
I.Kill.isValid())
445 LR.
addSegment(LiveInterval::Segment(Start,
I.Kill, VNI));
447 LR.
addSegment(LiveInterval::Segment(Start, End, VNI));
448 LOP = LiveOutPair(VNI, Node);
450 }
else if (IDomValue.first) {
452 I.Value = IDomValue.first;
455 if (
I.Kill.isValid())
460 if (LOP.first == IDomValue.first)
void add(LiveRange::Segment)
Add a segment to LR and coalesce when possible, just like LR.addSegment().
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg=0)
Extend the live range of LR to reach Use.
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void createDeadDefs(LiveRange &LR, unsigned Reg)
createDeadDefs - Create a dead def in LI for every def operand of Reg.
MachineBasicBlock * getMBB() const
int getNumber() const
getNumber - MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a M...
void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI)
setLiveOutValue - Indicate that VNI is live out from MBB.
LiveInterval - This class represents the liveness of a register, or stack slot.
void constructMainRangeFromSubranges(const SlotIndexes &Indexes, VNInfo::Allocator &VNIAllocator)
Construct main live range by merging the SubRanges of LI.
void verify(Pass *p=nullptr, const char *Banner=nullptr) const
verify - Run the current MachineFunction through the machine code verifier, useful for debugger use...
A live range for subregisters.
VNInfo - Value Number Information.
This class represents the liveness of a register, stack slot, etc.
SubRange * createSubRangeFrom(BumpPtrAllocator &Allocator, unsigned LaneMask, const LiveRange &CopyFrom)
Like createSubRange() but the new range is filled with a copy of the liveness information in CopyFrom...
unsigned getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
void clear()
clear - Clear all bits.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const TargetRegisterInfo * getTargetRegisterInfo() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator_range< subrange_iterator > subranges()
Reg
All possible values of the reg field in the ModR/M byte.
PrintReg - Helper class for printing registers on a raw_ostream.
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
void addLiveInBlock(LiveRange &LR, MachineDomTreeNode *DomNode, SlotIndex Kill=SlotIndex())
addLiveInBlock - Add a block with an unknown live-in value.
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
Base class for the actual dominator tree node.
std::vector< MachineBasicBlock * >::iterator pred_iterator
VNInfo * extendInBlock(SlotIndex StartIdx, SlotIndex Use)
If this range is live before Use in the basic block that starts at StartIdx, extend it to be live up ...
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
iterator_range< def_iterator > def_operands(unsigned Reg) const
bool isEarlyClobber() const
void reset(const MachineFunction *MF, SlotIndexes *, MachineDominatorTree *, VNInfo::Allocator *)
reset - Prepare caches for a new set of non-overlapping live ranges.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
bool isValid() const
Returns true if this is a valid index.
Allocate memory in an ever growing pool, as if by bump-pointer.
unsigned getSubRegIndexLaneMask(unsigned SubIdx) const
getSubRegIndexLaneMask - Return a bitmask representing the parts of a register that are covered by Su...
const MachineOperand & getOperand(unsigned i) const
unsigned getSubReg(unsigned Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
void setDest(LiveRange *lr)
Select a different destination live range.
void resize(typename StorageT::size_type s)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
SlotIndex getInstructionIndex(const MachineInstr *MI) const
Returns the base index for the given instruction.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
DomTreeNodeBase< NodeT > * getIDom() const
MachineOperand class - Representation of each machine instruction operand.
bool test(unsigned Idx) const
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
void calculate(LiveInterval &LI, bool TrackSubRegs)
Calculates liveness for the register specified in live interval LI.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
isPhysicalRegister - Return true if the specified register number is in the physical register namespa...
bool isLiveIn(unsigned Reg) const
isLiveIn - Return true if the specified register is in the live in set.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
createDeadDef - Make sure the range has a value defined at Def.
SubRange * createSubRange(BumpPtrAllocator &Allocator, unsigned LaneMask)
Creates a new empty subregister live range.
static void createDeadDef(SlotIndexes &Indexes, VNInfo::Allocator &Alloc, LiveRange &LR, const MachineOperand &MO)
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
Helper class for performant LiveRange bulk updates.
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
iterator_range< reg_nodbg_iterator > reg_nodbg_operands(unsigned Reg) const
LLVM Value Representation.
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
SlotIndex - An opaque wrapper around machine indexes.
void calculateValues()
calculateValues - Calculate the value that will be live-in to each block added with addLiveInBlock...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.