43#define DEBUG_TYPE "rename-independent-subregs"
47class RenameIndependentSubregs {
61 : ConEQ(LIS), SR(&SR), Index(Index) {}
81 void computeMainRangesFixFlags(
const IntEqClasses &Classes,
102 return "Rename Disconnected Subregister Components";
117char RenameIndependentSubregsLegacy::ID;
122 "Rename Independent Subregisters",
false,
false)
128bool RenameIndependentSubregs::renameComponents(
LiveInterval &LI)
const {
130 if (LI.valnos.size() < 2)
135 if (!findComponents(Classes, SubRangeInfos, LI))
144 <<
" equivalence classes.\n");
146 for (
unsigned I = 1, NumClasses = Classes.
getNumClasses();
I < NumClasses;
148 Register NewVReg =
MRI->createVirtualRegister(RegClass);
149 LiveInterval &NewLI = LIS->createEmptyInterval(NewVReg);
155 rewriteOperands(Classes, SubRangeInfos, Intervals);
156 distribute(Classes, SubRangeInfos, Intervals);
157 computeMainRangesFixFlags(Classes, SubRangeInfos, Intervals);
161bool RenameIndependentSubregs::findComponents(
IntEqClasses &Classes,
166 unsigned NumComponents = 0;
168 SubRangeInfos.
push_back(SubRangeInfo(*LIS, SR, NumComponents));
171 unsigned NumSubComponents = ConEQ.
Classify(SR);
172 NumComponents += NumSubComponents;
177 if (SubRangeInfos.
size() < 2)
183 Classes.
grow(NumComponents);
186 if (!MO.isDef() && !MO.readsReg())
188 unsigned SubRegIdx = MO.getSubReg();
190 unsigned MergedID = ~0
u;
191 for (RenameIndependentSubregs::SubRangeInfo &SRInfo : SubRangeInfos) {
193 if ((SR.
LaneMask & LaneMask).none())
195 SlotIndex Pos = LIS->getInstructionIndex(*MO.getParent());
196 Pos = MO.isDef() ? Pos.
getRegSlot(MO.isEarlyClobber())
203 unsigned LocalID = SRInfo.ConEQ.getEqClass(VNI);
205 unsigned ID = LocalID + SRInfo.Index;
207 MergedID = MergedID == ~0
u ?
ID : Classes.
join(MergedID,
ID);
214 return NumClasses > 1;
217void RenameIndependentSubregs::rewriteOperands(
const IntEqClasses &Classes,
223 E =
MRI->reg_nodbg_end();
I != E; ) {
236 for (
const SubRangeInfo &SRInfo : SubRangeInfos) {
238 if ((SR.
LaneMask & LaneMask).none())
245 unsigned LocalID = SRInfo.ConEQ.getEqClass(VNI);
247 ID = Classes[LocalID + SRInfo.Index];
254 if (MO.
isTied() && Reg != VReg) {
259 unsigned TiedIdx =
MI->findTiedOperandIdx(OperandNo);
260 MI->getOperand(TiedIdx).setReg(VReg);
263 I =
MRI->reg_nodbg_begin(Reg);
271void RenameIndependentSubregs::distribute(
const IntEqClasses &Classes,
278 for (
const SubRangeInfo &SRInfo : SubRangeInfos) {
284 SubRanges.
resize(NumClasses-1,
nullptr);
285 for (
unsigned I = 0;
I < NumValNos; ++
I) {
287 unsigned LocalID = SRInfo.ConEQ.getEqClass(&VNI);
288 unsigned ID = Classes[LocalID + SRInfo.Index];
290 if (
ID > 0 && SubRanges[
ID-1] ==
nullptr)
291 SubRanges[
ID-1] = Intervals[
ID]->createSubRange(Allocator, SR.
LaneMask);
305void RenameIndependentSubregs::computeMainRangesFixFlags(
310 const SlotIndexes &Indexes = *LIS->getSlotIndexes();
311 for (
size_t I = 0, E = Intervals.
size();
I < E; ++
I) {
341 SlotIndex DefIdx = LIS->InsertMachineInstrInMaps(*ImpDef);
381 LIS->constructMainRangeFromSubranges(LI);
386 LIS->shrinkToUses(&LI);
394 if (!RenameIndependentSubregs(&LIS).run(MF))
403bool RenameIndependentSubregsLegacy::runOnMachineFunction(
MachineFunction &MF) {
404 auto &LIS = getAnalysis<LiveIntervalsWrapperPass>().getLIS();
405 return RenameIndependentSubregs(&LIS).
run(MF);
411 if (!
MRI->subRegLivenessEnabled())
414 LLVM_DEBUG(
dbgs() <<
"Renaming independent subregister live ranges in "
422 bool Changed =
false;
423 for (
size_t I = 0, E =
MRI->getNumVirtRegs();
I < E; ++
I) {
425 if (!LIS->hasInterval(Reg))
431 Changed |= renameComponents(LI);
unsigned const MachineRegisterInfo * MRI
const HexagonInstrInfo * TII
This file contains helper functions to modify live ranges.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Rename Independent Subregisters
static bool subRangeLiveAt(const LiveInterval &LI, SlotIndex Pos)
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Allocate memory in an ever growing pool, as if by bump-pointer.
Represents analyses that only rely on functions' control flow.
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
LLVM_ABI unsigned Classify(const LiveRange &LR)
Classify the values in LR into connected components.
LLVM_ABI void compress()
compress - Compress equivalence classes by numbering them 0 .
unsigned getNumClasses() const
getNumClasses - Return the number of equivalence classes after compress() was called.
LLVM_ABI unsigned join(unsigned a, unsigned b)
Join the equivalence classes of a and b.
LLVM_ABI void grow(unsigned N)
grow - Increase capacity to hold 0 .
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
LLVM_ABI void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
SubRange * createSubRange(BumpPtrAllocator &Allocator, LaneBitmask LaneMask)
Creates a new empty subregister live range.
LLVM_ABI iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
bool liveAt(SlotIndex index) const
LLVM_ABI VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
VNInfo * getNextValue(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
Describe properties that are true of each instruction in the target description file.
iterator_range< pred_iterator > predecessors()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
LLVM_ABI unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
void setIsDead(bool Val=true)
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void setIsUndef(bool Val=true)
bool isEarlyClobber() const
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
VNInfo - Value Number Information.
bool isUnused() const
Returns true if this value is unused.
SlotIndex def
The index of the defining instruction.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Reg
All possible values of the reg field in the ModR/M byte.
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
static void DistributeRange(LiveRangeT &LR, LiveRangeT *SplitLRs[], EqClassesT VNIClasses)
Helper function that distributes live range value numbers and the corresponding segments of a primary...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineBasicBlock::iterator findPHICopyInsertPoint(MachineBasicBlock *MBB, MachineBasicBlock *SuccMBB, Register SrcReg)
findPHICopyInsertPoint - Find a safe place in MBB to insert a copy from SrcReg when following the CFG...
LLVM_ABI char & RenameIndependentSubregsID
This pass detects subregister lanes in a virtual register that are used independently of other lanes ...
LLVM_ABI 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.
This represents a simple continuous liveness interval for a value.