24#define DEBUG_TYPE "process-implicit-defs"
44class ProcessImplicitDefs {
59char ProcessImplicitDefsLegacy::ID = 0;
63 "Process Implicit Definitions",
false,
false)
65void ProcessImplicitDefsLegacy::getAnalysisUsage(
AnalysisUsage &AU)
const {
71bool ProcessImplicitDefs::canTurnIntoImplicitDef(
MachineInstr *
MI) {
72 if (!
MI->isCopyLike() &&
73 !
MI->isInsertSubreg() &&
74 !
MI->isRegSequence() &&
77 for (
const MachineOperand &MO :
MI->all_uses())
83void ProcessImplicitDefs::processImplicitDef(MachineInstr *
MI) {
87 for (
unsigned i =
MI->getNumOperands() - 1; i; --i)
95 bool AllUsesUndef =
true;
97 MachineInstr *UserMI = MO.getParent();
103 if (!canTurnIntoImplicitDef(UserMI))
106 UserMI->
setDesc(
TII->get(TargetOpcode::IMPLICIT_DEF));
107 WorkList.insert(UserMI);
110 MI->eraseFromParent();
125 bool ImplicitDefIsDead =
false;
126 bool SearchedWholeBlock =
true;
127 constexpr unsigned SearchLimit = 35;
129 for (++SearchMI; SearchMI != SearchE; ++SearchMI) {
130 if (SearchMI->isDebugInstr())
132 if (++
Count > SearchLimit) {
133 SearchedWholeBlock =
false;
136 for (MachineOperand &MO : SearchMI->operands()) {
144 if (
TRI->isSubRegisterEq(
Reg, SearchReg)) {
152 if (
TRI->isSubRegisterEq(SearchReg,
Reg)) {
153 ImplicitDefIsDead =
true;
161 if (ImplicitDefIsDead) {
169 if (ImplicitDefIsDead || (SearchedWholeBlock &&
MBB->
succ_empty())) {
171 MI->eraseFromParent();
177 return Succ->isLiveInOverlappedWith(Reg, *TRI);
179 MI->eraseFromParent();
182bool ProcessImplicitDefsLegacy::runOnMachineFunction(
MachineFunction &MF) {
183 return ProcessImplicitDefs().run(MF);
189 if (!ProcessImplicitDefs().
run(MF))
194 .preserve<AAManager>();
201 LLVM_DEBUG(
dbgs() <<
"********** PROCESS IMPLICIT DEFS **********\n"
202 <<
"********** Function: " << MF.
getName() <<
'\n');
209 assert(WorkList.empty() &&
"Inconsistent worklist state");
214 if (
MI.isImplicitDef())
215 WorkList.insert(&
MI);
217 if (WorkList.empty())
221 <<
" implicit defs.\n");
225 do processImplicitDef(WorkList.pop_back_val());
226 while (!WorkList.empty());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file implements a set that has insertion order iteration characteristics.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
Represent the analysis usage information of a pass.
Represents analyses that only rely on functions' control flow.
LLVM_ABI iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
Instructions::iterator instr_iterator
instr_iterator instr_end()
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
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.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
LLVM_ABI bool hasTiedAndOtherReadOf(Register Reg, unsigned SubReg) const
Return true if two operands read (Reg, SubReg) and one is tied to a def of another register.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
iterator_range< use_nodbg_iterator > use_nodbg_operands(Register Reg) const
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
A SetVector that performs no allocations if smaller than a certain size.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
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 raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI char & ProcessImplicitDefsID
ProcessImpicitDefs pass - This pass removes IMPLICIT_DEFs.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.