37#define DEBUG_TYPE "lrshrink"
40 "Number of insructions hoisted to shrink live range.");
50 void getAnalysisUsage(AnalysisUsage &AU)
const override {
55 StringRef getPassName()
const override {
return "Live Range Shrink"; }
57 bool runOnMachineFunction(MachineFunction &MF)
override;
62char LiveRangeShrink::ID = 0;
78 const InstOrderMap &M) {
79 auto NewIter = M.find(&New);
80 if (NewIter == M.end())
84 unsigned OrderOld = M.find(Old)->second;
85 unsigned OrderNew = NewIter->second;
86 if (OrderOld != OrderNew)
87 return OrderOld < OrderNew ? &New : Old;
90 for (
MachineInstr *
I = Old->getNextNode(); M.find(
I)->second == OrderNew;
102 return MI.hasUnmodeledSideEffects() && !
MI.isPseudoProbe();
132 DenseMap<Register, std::pair<unsigned, MachineInstr *>> UseMap;
134 for (MachineBasicBlock &
MBB : MF) {
150 bool SawStore =
false;
156 unsigned CurrentOrder = IOM[&
MI];
158 MachineInstr *BarrierMI =
nullptr;
159 for (
const MachineOperand &MO :
MI.operands()) {
160 if (!MO.isReg() || MO.isDebug())
163 UseMap[MO.getReg()] = std::make_pair(CurrentOrder, &
MI);
164 else if (MO.isDead()) {
167 auto It = UseMap.
find(MO.getReg());
168 if (It != UseMap.
end() && Barrier < It->second.first)
169 std::tie(Barrier, BarrierMI) = It->second;
173 if (!
MI.isSafeToMove(SawStore)) {
184 const MachineOperand *DefMO =
nullptr;
185 MachineInstr *
Insert =
nullptr;
189 unsigned NumEligibleUse = 0;
191 for (
const MachineOperand &MO :
MI.operands()) {
192 if (!MO.isReg() || MO.isDead() || MO.isDebug())
218 if (!
TII.isCopyInstr(DefInstr))
229 for (MachineInstr *
I = Insert;
I && IOM[
I] ==
Barrier;
230 I =
I->getNextNode())
231 if (
I == BarrierMI) {
236 if (DefMO && Insert && NumEligibleUse > 1 && Barrier <= IOM[Insert]) {
239 while (
I !=
MBB.
end() && (
I->isPHI() ||
I->isDebugOrPseudoInstr()))
241 if (
I ==
MI.getIterator())
247 unsigned NewOrder = IOM[&*
I];
249 NumInstrsHoistedToShrinkLiveRange++;
253 if (
MI.getOperand(0).isReg())
254 for (; EndIter !=
MBB.
end() && EndIter->isDebugValue() &&
255 EndIter->hasDebugOperandForReg(
MI.getOperand(0).getReg());
257 IOM[&*EndIter] = NewOrder;
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.
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
def_instr_iterator def_instr_begin(Register RegNo) const
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
LLVM_ABI bool isConstantPhysReg(MCRegister PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
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.
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next