39 #define DEBUG_TYPE "regalloc" 44 void LiveRangeCalc::resetLiveOutMap() {
76 assert(MRI && Indexes &&
"call reset() first");
84 if (!MO.isDef() && !MO.readsReg())
87 unsigned SubReg = MO.getSubReg();
88 if (LI.
hasSubRanges() || (SubReg != 0 && TrackSubRegs)) {
120 SubLRC.
reset(MF, Indexes, DomTree, Alloc);
121 SubLRC.extendToUses(S, Reg, S.LaneMask, &LI);
135 "Expect empty main liverange");
138 for (
const VNInfo *VNI : SR.valnos) {
148 assert(MRI && Indexes &&
"call reset() first");
163 bool IsSubRange = !Mask.
all();
174 if (!MO.readsReg() || (IsSubRange && MO.isDef()))
177 unsigned SubReg = MO.getSubReg();
183 if ((SLM & Mask).none())
192 assert(!MO.isDef() &&
"Cannot handle PHI def of partial register.");
198 bool isEarlyClobber =
false;
201 isEarlyClobber = MO.isEarlyClobber();
212 extend(LR, UseIdx, Reg, Undefs);
216 void LiveRangeCalc::updateFromLiveIns() {
218 for (
const LiveInBlock &
I : LiveIn) {
222 assert(
I.Value &&
"No live-in value found");
226 if (
I.Kill.isValid())
233 Map[MBB] = LiveOutPair(
I.Value,
nullptr);
236 Updater.
add(Start, End,
I.Value);
244 assert(Indexes &&
"Missing SlotIndexes");
245 assert(DomTree &&
"Missing dominator tree");
248 assert(UseMBB &&
"No MBB at Use");
252 if (EP.first !=
nullptr || EP.second)
259 if (findReachingDefs(LR, *UseMBB, Use, PhysReg, Undefs))
270 assert(Indexes &&
"Missing SlotIndexes");
271 assert(DomTree &&
"Missing dominator tree");
282 if (UndefOnEntry[BN])
287 DefOnEntry[S->getNumber()] =
true;
288 DefOnEntry[BN] =
true;
296 WorkList.
insert(
P->getNumber());
298 for (
unsigned i = 0; i != WorkList.
size(); ++i) {
300 unsigned N = WorkList[i];
303 const LiveOutPair &LOB = Map[&
B];
304 if (LOB.first !=
nullptr && LOB.first != &
UndefVNI)
305 return MarkDefined(B);
315 if (UB != LR.
begin()) {
317 if (Seg.
end > Begin) {
324 return MarkDefined(B);
330 if (UndefOnEntry[N] || LR.
isUndefIn(Undefs, Begin, End)) {
331 UndefOnEntry[
N] =
true;
335 return MarkDefined(B);
339 WorkList.
insert(
P->getNumber());
342 UndefOnEntry[BN] =
true;
355 bool UniqueVNI =
true;
358 bool FoundUndef =
false;
361 for (
unsigned i = 0; i != WorkList.
size(); ++i) {
368 <<
" does not have a corresponding definition on every path:\n";
371 errs() << Use <<
" " << *
MI;
381 <<
", but is missing from the live-in list.\n";
389 if (Seen.
test(Pred->getNumber())) {
391 if (TheVNI && TheVNI != VNI)
405 FoundUndef |= EP.second;
408 if (TheVNI && TheVNI != VNI)
412 if (VNI || EP.second)
425 FoundUndef |= (TheVNI ==
nullptr || TheVNI == &
UndefVNI);
426 if (!Undefs.
empty() && FoundUndef)
431 if (WorkList.
size() > 4)
438 for (
unsigned BN : WorkList) {
442 if (BN == UseMBBNum && Use.
isValid())
446 Updater.
add(Start, End, TheVNI);
454 std::tie(Entry, DidInsert) = EntryInfos.
insert(
459 Entry->second.first.resize(N);
460 Entry->second.second.resize(N);
462 BitVector &DefOnEntry = Entry->second.first;
463 BitVector &UndefOnEntry = Entry->second.second;
468 for (
unsigned BN : WorkList) {
470 if (!Undefs.
empty() &&
471 !isDefOnEntry(LR, Undefs, *MBB, DefOnEntry, UndefOnEntry))
475 LiveIn.
back().Kill = Use;
483 void LiveRangeCalc::updateSSA() {
484 assert(Indexes &&
"Missing SlotIndexes");
485 assert(DomTree &&
"Missing dominator tree");
493 for (LiveInBlock &
I : LiveIn) {
500 LiveOutPair IDomValue;
504 bool needPHI = !IDom || !Seen.
test(IDom->
getBlock()->getNumber());
513 if (IDomValue.first && IDomValue.first != &
UndefVNI &&
515 Map[IDom->
getBlock()].second = IDomValue.second =
520 LiveOutPair &
Value = Map[Pred];
521 if (!Value.first || Value.first == IDomValue.first)
536 if (DomTree->
dominates(IDom, Value.second)) {
546 LiveOutPair &LOP = Map[MBB];
551 assert(Alloc &&
"Need VNInfo allocator to create PHI-defs");
561 if (
I.Kill.isValid()) {
567 LOP = LiveOutPair(VNI, Node);
569 }
else if (IDomValue.first && IDomValue.first != &
UndefVNI) {
571 I.Value = IDomValue.first;
574 if (
I.Kill.isValid())
579 if (LOP.first == IDomValue.first)
598 for (
unsigned i = 0; i != PredQueue.
size(); ++i) {
599 unsigned BN = PredQueue[i];
604 PredQueue.
insert(
P->getNumber());
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.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
A common definition of LaneBitmask for use in TableGen and CodeGen.
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.
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
MachineBasicBlock * getMBB() const
SlotIndex def
The index of the defining instruction.
void createDeadDefs(LiveRange &LR, unsigned Reg)
createDeadDefs - Create a dead def in LI for every def operand of Reg.
LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI)
setLiveOutValue - Indicate that VNI is live out from MBB.
Segments::iterator iterator
void push_back(const T &Elt)
bool isUndefIn(ArrayRef< SlotIndex > Undefs, SlotIndex Begin, SlotIndex End) const
Returns true if there is an explicit "undef" between Begin End.
LiveInterval - This class represents the liveness of a register, or stack slot.
iterator_range< reg_nodbg_iterator > reg_nodbg_operands(unsigned Reg) const
bool test(unsigned Idx) const
void constructMainRangeFromSubranges(LiveInterval &LI)
For live interval LI with correct SubRanges construct matching information for the main live range...
A live range for subregisters.
bool isValid() const
Returns true if this is a valid index.
This represents a simple continuous liveness interval for a value.
unsigned const TargetRegisterInfo * TRI
void reserve(size_type N)
SubRange * createSubRangeFrom(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, const LiveRange &CopyFrom)
Like createSubRange() but the new range is filled with a copy of the liveness information in CopyFrom...
VNInfo - Value Number Information.
This class represents the liveness of a register, stack slot, etc.
bool isUnused() const
Returns true if this value is unused.
bool isEarlyClobber() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
void clear()
clear - Removes all bits from the bitvector. Does not change capacity.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
A Use represents the edge between a Value definition and its users.
iterator_range< subrange_iterator > subranges()
static constexpr LaneBitmask getAll()
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
bool insert(const value_type &X)
Insert a new element into the SetVector.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
void addLiveInBlock(LiveRange &LR, MachineDomTreeNode *DomNode, SlotIndex Kill=SlotIndex())
addLiveInBlock - Add a block with an unknown live-in value.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
iterator_range< def_iterator > def_operands(unsigned Reg) const
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg, ArrayRef< SlotIndex > Undefs)
Extend the live range of LR to reach Use.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
const TargetRegisterInfo * getTargetRegisterInfo() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Allocate memory in an ever growing pool, as if by bump-pointer.
DomTreeNodeBase * getIDom() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
void setDest(LiveRange *lr)
Select a different destination live range.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
void resize(typename StorageT::size_type s)
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
constexpr bool all() const
iterator_range< pred_iterator > predecessors()
void refineSubRanges(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, std::function< void(LiveInterval::SubRange &)> Apply)
Refines the subranges to support LaneMask.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
void reset(const MachineFunction *mf, SlotIndexes *SI, MachineDominatorTree *MDT, VNInfo::Allocator *VNIA)
reset - Prepare caches for a new set of non-overlapping live ranges.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
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)
Return true if the specified register number is in the physical register namespace.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
LLVM_NODISCARD bool empty() const
static void createDeadDef(SlotIndexes &Indexes, VNInfo::Allocator &Alloc, LiveRange &LR, const MachineOperand &MO)
auto upper_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Helper class for performant LiveRange bulk updates.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static VNInfo UndefVNI(0xbad, SlotIndex())
std::pair< VNInfo *, bool > extendInBlock(ArrayRef< SlotIndex > Undefs, SlotIndex StartIdx, SlotIndex Kill)
Attempt to extend a value defined after StartIdx to include Use.
LLVM Value Representation.
A vector that has set insertion semantics.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
const MachineOperand & getOperand(unsigned i) 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...
static LLVM_ATTRIBUTE_UNUSED bool isJointlyDominated(const MachineBasicBlock *MBB, ArrayRef< SlotIndex > Defs, const SlotIndexes &Indexes)
A diagnostic function to check if the end of the block MBB is jointly dominated by the blocks corresp...
bool empty() const
empty - Check if the array is empty.