36 #define DEBUG_TYPE "lrshrink" 38 STATISTIC(NumInstrsHoistedToShrinkLiveRange,
39 "Number of insructions hoisted to shrink live range.");
56 StringRef getPassName()
const override {
return "Live Range Shrink"; }
67 INITIALIZE_PASS(LiveRangeShrink,
"lrshrink",
"Live Range Shrink Pass",
false,
79 const InstOrderMap &M) {
80 auto NewIter = M.find(&New);
81 if (NewIter == M.end())
85 unsigned OrderOld = M.find(Old)->second;
86 unsigned OrderNew = NewIter->second;
87 if (OrderOld != OrderNew)
88 return OrderOld < OrderNew ? &New : Old;
91 for (MachineInstr *
I = Old->getNextNode(); M.find(
I)->second == OrderNew;
126 bool SawStore =
false;
138 unsigned CurrentOrder = IOM[&
MI];
142 if (!MO.isReg() || MO.isDebug())
145 UseMap[MO.getReg()] = std::make_pair(CurrentOrder, &MI);
146 else if (MO.isDead() && UseMap.
count(MO.getReg()))
149 if (Barrier < UseMap[MO.getReg()].first) {
150 Barrier = UseMap[MO.getReg()].first;
151 BarrierMI = UseMap[MO.getReg()].second;
171 unsigned NumEligibleUse = 0;
174 if (!MO.isReg() || MO.isDead() || MO.isDebug())
176 unsigned Reg = MO.getReg();
212 I =
I->getNextNode())
213 if (
I == BarrierMI) {
218 if (DefMO && Insert && NumEligibleUse > 1 && Barrier <= IOM[Insert]) {
221 while (I != MBB.end() && (I->isPHI() || I->isDebugInstr()))
229 unsigned NewOrder = IOM[&*
I];
231 NumInstrsHoistedToShrinkLiveRange++;
236 for (; EndIter != MBB.end() && EndIter->isDebugValue() &&
237 EndIter->getOperand(0).isReg() &&
240 IOM[&*EndIter] = NewOrder;
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
This class represents lattice values for constants.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
STATISTIC(NumFunctions, "Total number of functions")
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
iterator_range< mop_iterator > operands()
static MachineInstr * FindDominatedInstruction(MachineInstr &New, MachineInstr *Old, const InstOrderMap &M)
Returns New if it's dominated by Old, otherwise return Old.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
INITIALIZE_PASS(LiveRangeShrink, "lrshrink", "Live Range Shrink Pass", false, false) using InstOrderMap
static void BuildInstOrderMap(MachineBasicBlock::iterator Start, InstOrderMap &M)
Builds Instruction to its dominating order number map M by traversing from instruction Start...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
char & LiveRangeShrinkID
LiveRangeShrink pass.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
self_iterator getIterator()
void initializeLiveRangeShrinkPass(PassRegistry &)
bool isDebugInstr() const
bool isConstantPhysReg(unsigned PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
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:
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
def_instr_iterator def_instr_begin(unsigned RegNo) const
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.
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...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.