42 #define DEBUG_TYPE "rename-independent-subregs" 52 return "Rename Disconnected Subregister Components";
74 : ConEQ(LIS), SR(&SR),
Index(Index) {}
94 void computeMainRangesFixFlags(
const IntEqClasses &Classes,
116 "Rename Independent Subregisters",
false,
false)
122 bool RenameIndependentSubregs::renameComponents(
LiveInterval &LI)
const {
124 if (LI.valnos.size() < 2)
129 if (!findComponents(Classes, SubRangeInfos, LI))
133 unsigned Reg = LI.reg;
138 <<
" equivalence classes.\n");
140 for (
unsigned I = 1, NumClasses = Classes.
getNumClasses();
I < NumClasses;
142 unsigned NewVReg =
MRI->createVirtualRegister(RegClass);
143 LiveInterval &NewLI = LIS->createEmptyInterval(NewVReg);
149 rewriteOperands(Classes, SubRangeInfos, Intervals);
150 distribute(Classes, SubRangeInfos, Intervals);
151 computeMainRangesFixFlags(Classes, SubRangeInfos, Intervals);
155 bool RenameIndependentSubregs::findComponents(
IntEqClasses &Classes,
160 unsigned NumComponents = 0;
162 SubRangeInfos.
push_back(SubRangeInfo(*LIS, SR, NumComponents));
165 unsigned NumSubComponents = ConEQ.
Classify(SR);
166 NumComponents += NumSubComponents;
171 if (SubRangeInfos.
size() < 2)
177 Classes.
grow(NumComponents);
180 if (!MO.isDef() && !MO.readsReg())
182 unsigned SubRegIdx = MO.getSubReg();
184 unsigned MergedID = ~0u;
185 for (RenameIndependentSubregs::SubRangeInfo &SRInfo : SubRangeInfos) {
187 if ((SR.
LaneMask & LaneMask).none())
189 SlotIndex Pos = LIS->getInstructionIndex(*MO.getParent());
190 Pos = MO.isDef() ? Pos.
getRegSlot(MO.isEarlyClobber())
197 unsigned LocalID = SRInfo.ConEQ.getEqClass(VNI);
199 unsigned ID = LocalID + SRInfo.Index;
201 MergedID = MergedID == ~0u ?
ID : Classes.
join(MergedID, ID);
208 return NumClasses > 1;
211 void RenameIndependentSubregs::rewriteOperands(
const IntEqClasses &Classes,
215 unsigned Reg = Intervals[0]->reg;
217 E =
MRI->reg_nodbg_end();
I !=
E; ) {
230 for (
const SubRangeInfo &SRInfo : SubRangeInfos) {
232 if ((SR.
LaneMask & LaneMask).none())
239 unsigned LocalID = SRInfo.ConEQ.getEqClass(VNI);
241 ID = Classes[LocalID + SRInfo.Index];
245 unsigned VReg = Intervals[
ID]->reg;
248 if (MO.
isTied() && Reg != VReg) {
252 unsigned OperandNo =
MI->getOperandNo(&MO);
253 unsigned TiedIdx =
MI->findTiedOperandIdx(OperandNo);
254 MI->getOperand(TiedIdx).setReg(VReg);
257 I =
MRI->reg_nodbg_begin(Reg);
272 for (
const SubRangeInfo &SRInfo : SubRangeInfos) {
278 SubRanges.
resize(NumClasses-1,
nullptr);
279 for (
unsigned I = 0;
I < NumValNos; ++
I) {
281 unsigned LocalID = SRInfo.ConEQ.getEqClass(&VNI);
282 unsigned ID = Classes[LocalID + SRInfo.Index];
284 if (ID > 0 && SubRanges[ID-1] ==
nullptr)
285 SubRanges[ID-1] = Intervals[
ID]->createSubRange(Allocator, SR.
LaneMask);
299 void RenameIndependentSubregs::computeMainRangesFixFlags(
304 const SlotIndexes &Indexes = *LIS->getSlotIndexes();
305 for (
size_t I = 0,
E = Intervals.
size();
I <
E; ++
I) {
318 for (
unsigned I = 0;
I < SR.valnos.size(); ++
I) {
319 const VNInfo &VNI = *SR.valnos[
I];
335 SlotIndex DefIdx = LIS->InsertMachineInstrInMaps(*ImpDef);
338 VNInfo *SRVNI = SR.getNextValue(RegDefIdx, Allocator);
348 unsigned SubRegIdx = MO.getSubReg();
355 SlotIndex Pos = LIS->getInstructionIndex(*MO.getParent());
360 SlotIndex Pos = LIS->getInstructionIndex(*MO.getParent()).getDeadSlot();
368 LIS->constructMainRangeFromSubranges(LI);
373 LIS->shrinkToUses(&LI);
377 bool RenameIndependentSubregs::runOnMachineFunction(
MachineFunction &MF) {
380 if (!
MRI->subRegLivenessEnabled())
383 LLVM_DEBUG(
dbgs() <<
"Renaming independent subregister live ranges in " 386 LIS = &getAnalysis<LiveIntervals>();
392 bool Changed =
false;
393 for (
size_t I = 0,
E =
MRI->getNumVirtRegs();
I <
E; ++
I) {
395 if (!LIS->hasInterval(Reg))
401 Changed |= renameComponents(LI);
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
char & RenameIndependentSubregsID
This pass detects subregister lanes in a virtual register that are used independently of other lanes ...
void grow(unsigned N)
grow - Increase capacity to hold 0 .
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex def
The index of the defining instruction.
This class represents lattice values for constants.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
void push_back(const T &Elt)
LiveInterval - This class represents the liveness of a register, or stack slot.
Describe properties that are true of each instruction in the target description file.
MachineBasicBlock::iterator findPHICopyInsertPoint(MachineBasicBlock *MBB, MachineBasicBlock *SuccMBB, unsigned SrcReg)
findPHICopyInsertPoint - Find a safe place in MBB to insert a copy from SrcReg when following the CFG...
unsigned getSubReg() const
void compress()
compress - Compress equivalence classes by numbering them 0 .
A live range for subregisters.
This represents a simple continuous liveness interval for a value.
unsigned const TargetRegisterInfo * TRI
void reserve(size_type N)
VNInfo - Value Number Information.
bool isUnused() const
Returns true if this value is unused.
bool isEarlyClobber() const
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator_range< subrange_iterator > subranges()
bool hasSubRanges() const
Returns true if subregister liveness information is available.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register. ...
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
virtual const TargetInstrInfo * getInstrInfo() const
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
static void DistributeRange(LiveRangeT &LR, LiveRangeT *SplitLRs[], EqClassesT VNIClasses)
Helper function that distributes live range value numbers and the corresponding segments of a master ...
TargetInstrInfo - Interface to description of machine instruction set.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
IdxPair distribute(unsigned Nodes, unsigned Elements, unsigned Capacity, const unsigned *CurSize, unsigned NewSize[], unsigned Position, bool Grow)
IntervalMapImpl::distribute - Compute a new distribution of node elements after an overflow or underf...
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Allocate memory in an ever growing pool, as if by bump-pointer.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
unsigned Classify(const LiveRange &LR)
Classify the values in LR into connected components.
unsigned getNumClasses() const
getNumClasses - Return the number of equivalence classes after compress() was called.
Rename Independent Subregisters
Represent the analysis usage information of a pass.
iterator_range< pred_iterator > predecessors()
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...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
unsigned join(unsigned a, unsigned b)
Join the equivalence classes of a and b.
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
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...
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
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.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
pointer data()
Return a pointer to the vector's buffer, even if empty().
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
INITIALIZE_PASS_BEGIN(RenameIndependentSubregs, DEBUG_TYPE, "Rename Independent Subregisters", false, false) INITIALIZE_PASS_END(RenameIndependentSubregs
void setReg(unsigned Reg)
Change the register this operand corresponds to.
static bool subRangeLiveAt(const LiveInterval &LI, SlotIndex Pos)
StringRef - Represent a constant reference to a string, i.e.
SlotIndex - An opaque wrapper around machine indexes.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...