23 #define DEBUG_TYPE "lrshrink"
25 STATISTIC(NumInstrsHoistedToShrinkLiveRange,
26 "Number of insructions hoisted to shrink live range.");
44 StringRef getPassName()
const override {
return "Live Range Shrink"; }
64 const InstOrderMap &M) {
65 auto NewIter = M.find(&New);
66 if (NewIter == M.end())
70 unsigned OrderOld = M.find(Old)->second;
71 unsigned OrderNew = NewIter->second;
72 if (OrderOld != OrderNew)
73 return OrderOld < OrderNew ? &New : Old;
112 BuildInstOrderMap(MBB.begin(), IOM);
123 unsigned CurrentOrder = IOM[&
MI];
127 if (!MO.isReg() || MO.isDebug())
130 UseMap[MO.getReg()] = std::make_pair(CurrentOrder, &MI);
131 else if (MO.isDead() && UseMap.
count(MO.getReg()))
134 if (Barrier < UseMap[MO.getReg()].first) {
135 Barrier = UseMap[MO.getReg()].first;
136 BarrierMI = UseMap[MO.getReg()].second;
145 BuildInstOrderMap(Next, IOM);
156 unsigned NumEligibleUse = 0;
159 if (!MO.isReg() || MO.isDead() || MO.isDebug())
161 unsigned Reg = MO.getReg();
187 Insert = FindDominatedInstruction(DefInstr, Insert, IOM);
197 I =
I->getNextNode())
198 if (
I == BarrierMI) {
203 if (DefMO && Insert && NumEligibleUse > 1 && Barrier <= IOM[Insert]) {
206 while (I != MBB.end() && (I->isPHI() || I->isDebugValue()))
214 unsigned NewOrder = IOM[&*
I];
216 NumInstrsHoistedToShrinkLiveRange++;
221 for (; EndIter != MBB.end() && EndIter->isDebugValue() &&
222 EndIter->getOperand(0).isReg() &&
225 IOM[&*EndIter] = NewOrder;
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
iterator_range< mop_iterator > operands()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
bool isDebugValue() const
char & LiveRangeShrinkID
LiveRangeShrink pass.
unsigned const MachineRegisterInfo * MRI
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
self_iterator getIterator()
void initializeLiveRangeShrinkPass(PassRegistry &)
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
MachineOperand class - Representation of each machine instruction operand.
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.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
STATISTIC(NumInstrsHoistedToShrinkLiveRange,"Number of insructions hoisted to shrink live range.")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
INITIALIZE_PASS(LiveRangeShrink,"lrshrink","Live Range Shrink Pass", false, false) namespace
def_instr_iterator def_instr_begin(unsigned RegNo) const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool hasOneNonDBGUse(unsigned RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
bool isConstantPhysReg(unsigned PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
unsigned getReg() const
getReg - Returns the register number.
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.