29#define DEBUG_TYPE "opt-phis"
31STATISTIC(NumPHICycles,
"Number of PHI cycles replaced");
32STATISTIC(NumDeadPHICycles,
"Number of dead PHI cycles");
58 bool IsSingleValuePHICycle(
MachineInstr *
MI,
unsigned &SingleValReg,
59 InstrSet &PHIsInCycle);
66char OptimizePHIs::ID = 0;
71 "Optimize machine instruction PHIs",
false,
false)
74 if (skipFunction(Fn.getFunction()))
77 MRI = &Fn.getRegInfo();
78 TII = Fn.getSubtarget().getInstrInfo();
86 Changed |= OptimizeBB(
MBB);
97 unsigned &SingleValReg,
98 InstrSet &PHIsInCycle) {
99 assert(
MI->isPHI() &&
"IsSingleValuePHICycle expects a PHI instruction");
103 if (!PHIsInCycle.insert(
MI).second)
107 if (PHIsInCycle.size() == 16)
111 for (
unsigned i = 1; i !=
MI->getNumOperands(); i += 2) {
113 if (SrcReg == DstReg)
122 SrcMI =
MRI->getVRegDef(SrcReg);
127 if (SrcMI->
isPHI()) {
128 if (!IsSingleValuePHICycle(SrcMI, SingleValReg, PHIsInCycle))
132 if (SingleValReg != 0 && SingleValReg != SrcReg)
134 SingleValReg = SrcReg;
142bool OptimizePHIs::IsDeadPHICycle(
MachineInstr *
MI, InstrSet &PHIsInCycle) {
143 assert(
MI->isPHI() &&
"IsDeadPHICycle expects a PHI instruction");
145 assert(DstReg.
isVirtual() &&
"PHI destination is not a virtual register");
148 if (!PHIsInCycle.insert(
MI).second)
152 if (PHIsInCycle.size() == 16)
156 if (!
UseMI.isPHI() || !IsDeadPHICycle(&
UseMI, PHIsInCycle))
166 bool Changed =
false;
174 unsigned SingleValReg = 0;
175 InstrSet PHIsInCycle;
176 if (IsSingleValuePHICycle(
MI, SingleValReg, PHIsInCycle) &&
179 if (!
MRI->constrainRegClass(SingleValReg,
MRI->getRegClass(OldReg)))
182 MRI->replaceRegWith(OldReg, SingleValReg);
183 MI->eraseFromParent();
186 MRI->clearKillFlags(SingleValReg);
195 if (IsDeadPHICycle(
MI, PHIsInCycle)) {
199 PhiMI->eraseFromParent();
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
unsigned getSubReg() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
char & OptimizePHIsID
OptimizePHIs - This pass optimizes machine instruction PHIs to take advantage of opportunities create...
void initializeOptimizePHIsPass(PassRegistry &)