33#define DEBUG_TYPE "machine-latecleanup"
35STATISTIC(NumRemoved,
"Number of redundant instructions removed.");
44 struct Reg2MIMap :
public SmallDenseMap<Register, MachineInstr *> {
47 return MI &&
MI->isIdenticalTo(*ArgMI);
51 std::vector<Reg2MIMap> RegDefs;
52 std::vector<Reg2MIMap> RegKills;
78 MachineFunctionProperties::Property::NoVRegs);
84char MachineLateInstrsCleanup::ID = 0;
89 "Machine Late Instructions Cleanup Pass",
false,
false)
92 if (skipFunction(MF.getFunction()))
95 TRI = MF.getSubtarget().getRegisterInfo();
96 TII = MF.getSubtarget().getInstrInfo();
99 RegDefs.resize(MF.getNumBlockIDs());
101 RegKills.resize(MF.getNumBlockIDs());
104 bool Changed =
false;
107 Changed |= processBlock(
MBB);
114void MachineLateInstrsCleanup::clearKillsForDef(
Register Reg,
121 KillMI->clearRegisterKills(Reg,
TRI);
135 if (!VisitedPreds.
test(Pred->getNumber()))
136 clearKillsForDef(Reg, Pred, VisitedPreds);
139void MachineLateInstrsCleanup::removeRedundantDef(
MachineInstr *
MI) {
141 BitVector VisitedPreds(
MI->getMF()->getNumBlockIDs());
142 clearKillsForDef(Reg,
MI->getParent(), VisitedPreds);
143 MI->eraseFromParent();
155 bool SawStore =
true;
156 if (!
MI->isSafeToMove(SawStore) ||
MI->isImplicitDef() ||
MI->isInlineAsm())
158 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
176 bool Changed =
false;
188 return RegDefs[Pred->getNumber()].hasIdentical(Reg, DefMI);
203 if (
MI.modifiesRegister(FrameReg,
TRI)) {
213 if (IsCandidate && MBBDefs.hasIdentical(DefedReg, &
MI)) {
216 removeRedundantDef(&
MI);
224 if (
MI.modifiesRegister(Reg,
TRI)) {
227 }
else if (
MI.findRegisterUseOperandIdx(Reg,
TRI,
true ) != -1)
236 MBBDefs[DefedReg] = &
MI;
237 assert(!MBBKills.count(DefedReg) &&
"Should already have been removed.");
MachineInstrBuilder MachineInstrBuilder & DefMI
This file implements the BitVector class.
const HexagonInstrInfo * TII
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
static bool isCandidate(const MachineInstr *MI, Register &DefedReg, Register FrameReg)
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:
bool test(unsigned Idx) const
static constexpr unsigned NoRegister
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
bool isEHPad() const
Returns true if the block is a landing pad.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
pred_iterator pred_begin()
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< pred_iterator > predecessors()
bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
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...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
MachineOperand class - Representation of each machine instruction operand.
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
char & MachineLateInstrsCleanupID
MachineLateInstrsCleanup - This pass removes redundant identical instructions after register allocati...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeMachineLateInstrsCleanupPass(PassRegistry &)
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.