38 #define DEBUG_TYPE "aarch64-copyelim"
40 STATISTIC(NumCopiesRemoved,
"Number of copies removed.");
60 return "AArch64 Redundant Copy Elimination";
67 "AArch64 redundant copy elimination pass",
false,
false)
70 unsigned Opc = MI.getOpcode();
73 if ((Opc == AArch64::CBZW || Opc == AArch64::CBZX) &&
74 MBB == MI.getOperand(1).getMBB())
76 else if ((Opc == AArch64::CBNZW || Opc == AArch64::CBNZX) &&
77 MBB != MI.getOperand(1).getMBB())
90 if (CompBr == PredMBB->
end() || PredMBB->
succ_size() != 2)
96 if (guaranteesZeroRegInBlock(*CompBr, MBB))
98 }
while (CompBr != PredMBB->
begin() && CompBr->isTerminator());
101 if (!guaranteesZeroRegInBlock(*CompBr, MBB))
104 unsigned TargetReg = CompBr->getOperand(0).getReg();
108 "Expect physical register");
115 bool Changed =
false;
117 unsigned SmallestDef = TargetReg;
128 if ((SrcReg == AArch64::XZR || SrcReg == AArch64::WZR) &&
129 !
MRI->isReserved(DefReg) &&
130 (TargetReg == DefReg || TRI->isSuperRegister(DefReg, TargetReg))) {
131 DEBUG(
dbgs() <<
"Remove redundant Copy : ");
139 TRI->isSubRegister(SmallestDef, DefReg) ? DefReg : SmallestDef;
153 CompBr->clearRegisterKills(SmallestDef, TRI);
160 MMI.clearRegisterKills(SmallestDef, TRI);
165 bool AArch64RedundantCopyElimination::runOnMachineFunction(
171 bool Changed =
false;
173 Changed |= optimizeCopy(&MBB);
178 return new AArch64RedundantCopyElimination();
unsigned succ_size() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
void initializeAArch64RedundantCopyEliminationPass(PassRegistry &)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
Reg
All possible values of the reg field in the ModR/M byte.
FunctionPass * createAArch64RedundantCopyEliminationPass()
bool insert(const value_type &X)
Insert a new element into the SetVector.
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
unsigned const MachineRegisterInfo * MRI
INITIALIZE_PASS(AArch64RedundantCopyElimination,"aarch64-copyelim","AArch64 redundant copy elimination pass", false, false) static bool guaranteesZeroRegInBlock(MachineInstr &MI
const MachineOperand & getOperand(unsigned i) const
MCRegAliasIterator enumerates all registers aliasing Reg.
FunctionPass class - This class is used to implement most global optimizations.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
A SetVector that performs no allocations if smaller than a certain size.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
unsigned pred_size() const
bool modifiesRegister(unsigned Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register...
Properties which a MachineFunction may have at a given point in time.