36#define DEBUG_TYPE "lrshrink"
39 "Number of insructions hoisted to shrink live range.");
49 void getAnalysisUsage(AnalysisUsage &AU)
const override {
54 StringRef getPassName()
const override {
return "Live Range Shrink"; }
56 bool runOnMachineFunction(MachineFunction &MF)
override;
61char LiveRangeShrink::ID = 0;
77 const InstOrderMap &M) {
78 auto NewIter = M.find(&New);
79 if (NewIter == M.end())
83 unsigned OrderOld = M.find(Old)->second;
84 unsigned OrderNew = NewIter->second;
85 if (OrderOld != OrderNew)
86 return OrderOld < OrderNew ? &New : Old;
89 for (
MachineInstr *
I = Old->getNextNode(); M.find(
I)->second == OrderNew;
101 return MI.hasUnmodeledSideEffects() && !
MI.isPseudoProbe();
131 DenseMap<Register, std::pair<unsigned, MachineInstr *>> UseMap;
133 for (MachineBasicBlock &
MBB : MF) {
149 bool SawStore =
false;
155 unsigned CurrentOrder = IOM[&
MI];
157 MachineInstr *BarrierMI =
nullptr;
158 for (
const MachineOperand &MO :
MI.operands()) {
159 if (!MO.isReg() || MO.isDebug())
162 UseMap[MO.getReg()] = std::make_pair(CurrentOrder, &
MI);
163 else if (MO.isDead()) {
166 auto It = UseMap.
find(MO.getReg());
167 if (It != UseMap.
end() && Barrier < It->second.first)
168 std::tie(Barrier, BarrierMI) = It->second;
172 if (!
MI.isSafeToMove(SawStore)) {
183 const MachineOperand *DefMO =
nullptr;
184 MachineInstr *
Insert =
nullptr;
188 unsigned NumEligibleUse = 0;
190 for (
const MachineOperand &MO :
MI.operands()) {
191 if (!MO.isReg() || MO.isDead() || MO.isDebug())
209 }
else if (
MRI.hasOneNonDBGUse(
Reg) &&
MRI.hasOneDef(
Reg) && DefMO &&
211 MRI.getRegClass(MO.getReg())) {
216 MachineInstr &DefInstr = *
MRI.def_instr_begin(
Reg);
217 if (!
TII.isCopyInstr(DefInstr))
228 for (MachineInstr *
I = Insert;
I && IOM[
I] ==
Barrier;
229 I =
I->getNextNode())
230 if (
I == BarrierMI) {
235 if (DefMO && Insert && NumEligibleUse > 1 && Barrier <= IOM[Insert]) {
238 while (
I !=
MBB.
end() && (
I->isPHI() ||
I->isDebugOrPseudoInstr()))
240 if (
I ==
MI.getIterator())
246 unsigned NewOrder = IOM[&*
I];
248 NumInstrsHoistedToShrinkLiveRange++;
252 if (
MI.getOperand(0).isReg())
253 for (; EndIter !=
MBB.
end() && EndIter->isDebugValue() &&
254 EndIter->hasDebugOperandForReg(
MI.getOperand(0).getReg());
256 IOM[&*EndIter] = NewOrder;
unsigned const MachineRegisterInfo * MRI
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static bool isCodeMotionBarrier(MachineInstr &MI)
Returns whether this instruction is considered a code motion barrier by this pass.
static MachineInstr * FindDominatedInstruction(MachineInstr &New, MachineInstr *Old, const InstOrderMap &M)
Returns New if it's dominated by Old, otherwise return Old.
static void BuildInstOrderMap(MachineBasicBlock::iterator Start, InstOrderMap &M)
Builds Instruction to its dominating order number map M by traversing from instruction Start.
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
iterator find(const_arg_type_t< KeyT > Val)
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_ABI iterator SkipPHIsLabelsAndDebug(iterator I, Register Reg=Register(), bool SkipPseudoOp=true)
Return the first instruction in MBB after I that is not a PHI, label or debug.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
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.
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
Register getReg() const
getReg - Returns the register number.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
virtual const TargetInstrInfo * getInstrInfo() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI char & LiveRangeShrinkID
LiveRangeShrink pass.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionAddr VTableAddr Next