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() &&
129 if (SrcMI->
isPHI()) {
130 if (!IsSingleValuePHICycle(SrcMI, SingleValReg, PHIsInCycle))
134 if (SingleValReg != 0 && SingleValReg != SrcReg)
136 SingleValReg = SrcReg;
144 bool OptimizePHIs::IsDeadPHICycle(
MachineInstr *MI, InstrSet &PHIsInCycle) {
145 assert(MI->
isPHI() &&
"IsDeadPHICycle expects a PHI instruction");
148 "PHI destination is not a virtual register");
151 if (!PHIsInCycle.insert(MI).second)
155 if (PHIsInCycle.size() == 16)
159 if (!
UseMI.isPHI() || !IsDeadPHICycle(&
UseMI, PHIsInCycle))
169 bool Changed =
false;
171 MII = MBB.
begin(),
E = MBB.
end(); MII !=
E; ) {
177 unsigned SingleValReg = 0;
178 InstrSet PHIsInCycle;
179 if (IsSingleValuePHICycle(MI, SingleValReg, PHIsInCycle) &&
197 if (IsDeadPHICycle(MI, PHIsInCycle)) {
198 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.
This class represents lattice values for constants.
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
Retuns the total number of operands.
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 ...
void clearKillFlags(unsigned Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
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