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)
128 if (SrcMI->
isPHI()) {
129 if (!IsSingleValuePHICycle(SrcMI, SingleValReg, PHIsInCycle))
133 if (SingleValReg != 0 && SingleValReg != SrcReg)
135 SingleValReg = SrcReg;
143 bool OptimizePHIs::IsDeadPHICycle(
MachineInstr *MI, InstrSet &PHIsInCycle) {
144 assert(MI->
isPHI() &&
"IsDeadPHICycle expects a PHI instruction");
147 "PHI destination is not a virtual register");
150 if (!PHIsInCycle.insert(MI).second)
154 if (PHIsInCycle.size() == 16)
158 if (!
UseMI.isPHI() || !IsDeadPHICycle(&
UseMI, PHIsInCycle))
168 bool Changed =
false;
170 MII = MBB.
begin(),
E = MBB.
end(); MII !=
E; ) {
176 unsigned SingleValReg = 0;
177 InstrSet PHIsInCycle;
178 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...
This class represents lattice values for constants.
unsigned getSubReg() const
STATISTIC(NumFunctions, "Total number of functions")
void initializeOptimizePHIsPass(PassRegistry &)
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
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())
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const
Wrapper class representing virtual and physical registers.