30#define DEBUG_TYPE "opt-phis"
32STATISTIC(NumPHICycles,
"Number of PHI cycles replaced");
33STATISTIC(NumDeadPHICycles,
"Number of dead PHI cycles");
49 InstrSet &PHIsInCycle);
57 OptimizePHIsLegacy() : MachineFunctionPass(ID) {}
59 bool runOnMachineFunction(MachineFunction &MF)
override {
66 void getAnalysisUsage(AnalysisUsage &AU)
const override {
74char OptimizePHIsLegacy::ID = 0;
79 "Optimize machine instruction PHIs",
false,
false)
101 for (MachineBasicBlock &
MBB : Fn)
112bool OptimizePHIs::IsSingleValuePHICycle(MachineInstr *
MI,
114 InstrSet &PHIsInCycle) {
115 assert(
MI->isPHI() &&
"IsSingleValuePHICycle expects a PHI instruction");
119 if (!PHIsInCycle.insert(
MI).second)
123 if (PHIsInCycle.size() == 16)
127 for (
unsigned i = 1; i !=
MI->getNumOperands(); i += 2) {
129 if (SrcReg == DstReg)
131 MachineInstr *SrcMI = MRI->
getVRegDef(SrcReg);
143 if (SrcMI->
isPHI()) {
144 if (!IsSingleValuePHICycle(SrcMI, SingleValReg, PHIsInCycle))
148 if (SingleValReg && SingleValReg != SrcReg)
150 SingleValReg = SrcReg;
158bool OptimizePHIs::IsDeadPHICycle(MachineInstr *
MI, InstrSet &PHIsInCycle) {
159 assert(
MI->isPHI() &&
"IsDeadPHICycle expects a PHI instruction");
161 assert(DstReg.
isVirtual() &&
"PHI destination is not a virtual register");
164 if (!PHIsInCycle.insert(
MI).second)
168 if (PHIsInCycle.size() == 16)
172 if (!
UseMI.isPHI() || !IsDeadPHICycle(&
UseMI, PHIsInCycle))
181bool OptimizePHIs::OptimizeBB(MachineBasicBlock &
MBB) {
185 MachineInstr *
MI = &*MII++;
191 InstrSet PHIsInCycle;
192 if (IsSingleValuePHICycle(
MI, SingleValReg, PHIsInCycle) && SingleValReg) {
198 MI->eraseFromParent();
210 if (IsDeadPHICycle(
MI, PHIsInCycle)) {
211 for (MachineInstr *PhiMI : PHIsInCycle) {
214 PhiMI->eraseFromParent();
MachineInstrBuilder & UseMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
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)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
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.
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.
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,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI void clearKillFlags(Register Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
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.
virtual const TargetInstrInfo * getInstrInfo() const
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI char & OptimizePHIsLegacyID
OptimizePHIs - This pass optimizes machine instruction PHIs to take advantage of opportunities create...