30 #define DEBUG_TYPE "opt-phis" 32 STATISTIC(NumPHICycles,
"Number of PHI cycles replaced");
33 STATISTIC(NumDeadPHICycles,
"Number of dead PHI cycles");
59 bool IsSingleValuePHICycle(
MachineInstr *
MI,
unsigned &SingleValReg,
60 InstrSet &PHIsInCycle);
72 "Optimize machine instruction PHIs",
false,
false)
75 if (skipFunction(Fn.getFunction()))
78 MRI = &Fn.getRegInfo();
79 TII = Fn.getSubtarget().getInstrInfo();
87 Changed |= OptimizeBB(*
I);
98 unsigned &SingleValReg,
99 InstrSet &PHIsInCycle) {
100 assert(MI->
isPHI() &&
"IsSingleValuePHICycle expects a PHI instruction");
104 if (!PHIsInCycle.insert(MI).second)
108 if (PHIsInCycle.size() == 16)
114 if (SrcReg == DstReg)
119 if (SrcMI && SrcMI->
isCopy() &&
127 if (SrcMI->
isPHI()) {
128 if (!IsSingleValuePHICycle(SrcMI, SingleValReg, PHIsInCycle))
132 if (SingleValReg != 0)
134 SingleValReg = SrcReg;
142 bool OptimizePHIs::IsDeadPHICycle(
MachineInstr *MI, InstrSet &PHIsInCycle) {
143 assert(MI->
isPHI() &&
"IsDeadPHICycle expects a PHI instruction");
146 "PHI destination is not a virtual register");
149 if (!PHIsInCycle.insert(MI).second)
153 if (PHIsInCycle.size() == 16)
157 if (!
UseMI.isPHI() || !IsDeadPHICycle(&
UseMI, PHIsInCycle))
167 bool Changed =
false;
169 MII = MBB.
begin(),
E = MBB.
end(); MII !=
E; ) {
175 unsigned SingleValReg = 0;
176 InstrSet PHIsInCycle;
177 if (IsSingleValuePHICycle(MI, SingleValReg, PHIsInCycle) &&
192 if (IsDeadPHICycle(MI, PHIsInCycle)) {
193 for (InstrSetIterator PI = PHIsInCycle.begin(), PE = PHIsInCycle.end();
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
unsigned getSubReg() const
STATISTIC(NumFunctions, "Total number of functions")
void initializeOptimizePHIsPass(PassRegistry &)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Access to explicit operands of the instruction.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
TargetInstrInfo - Interface to description of machine instruction set.
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineInstrBuilder & UseMI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
INITIALIZE_PASS(OptimizePHIs, DEBUG_TYPE, "Optimize machine instruction PHIs", false, false) bool OptimizePHIs
void setPreservesCFG()
This function should be called by the pass, iff they do not:
char & OptimizePHIsID
OptimizePHIs - This pass optimizes machine instruction PHIs to take advantage of opportunities create...
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineOperand & getOperand(unsigned i) const
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const