29 #define DEBUG_TYPE "aarch64-dead-defs"
31 STATISTIC(NumDeadDefsReplaced,
"Number of dead definitions replaced");
33 #define AARCH64_DEAD_REG_DEF_NAME "AArch64 Dead register definitions"
72 void AArch64DeadRegisterDefinitions::processMachineBasicBlock(
76 if (usesFrameIndex(
MI)) {
80 DEBUG(
dbgs() <<
" Ignoring, operand is frame index\n");
83 if (
MI.definesRegister(AArch64::XZR) ||
MI.definesRegister(AArch64::WZR)) {
86 DEBUG(
dbgs() <<
" Ignoring, XZR or WZR already used by the instruction\n");
92 switch (
MI.getOpcode()) {
100 case AArch64::SWPALd:
101 case AArch64::LDADDALb:
102 case AArch64::LDADDALh:
103 case AArch64::LDADDALs:
104 case AArch64::LDADDALd:
105 case AArch64::LDCLRALb:
106 case AArch64::LDCLRALh:
107 case AArch64::LDCLRALs:
108 case AArch64::LDCLRALd:
109 case AArch64::LDEORALb:
110 case AArch64::LDEORALh:
111 case AArch64::LDEORALs:
112 case AArch64::LDEORALd:
113 case AArch64::LDSETALb:
114 case AArch64::LDSETALh:
115 case AArch64::LDSETALs:
116 case AArch64::LDSETALd:
117 case AArch64::LDSMINALb:
118 case AArch64::LDSMINALh:
119 case AArch64::LDSMINALs:
120 case AArch64::LDSMINALd:
121 case AArch64::LDSMAXALb:
122 case AArch64::LDSMAXALh:
123 case AArch64::LDSMAXALs:
124 case AArch64::LDSMAXALd:
125 case AArch64::LDUMINALb:
126 case AArch64::LDUMINALh:
127 case AArch64::LDUMINALs:
128 case AArch64::LDUMINALd:
129 case AArch64::LDUMAXALb:
130 case AArch64::LDUMAXALh:
131 case AArch64::LDUMAXALs:
132 case AArch64::LDUMAXALd:
147 (!MO.
isDead() && !
MRI->use_nodbg_empty(Reg)))
150 DEBUG(
dbgs() <<
" Dead def operand #" <<
I <<
" in:\n ";
153 if (
MI.isRegTiedToUseOperand(
I)) {
154 DEBUG(
dbgs() <<
" Ignoring, def is tied operand.\n");
160 DEBUG(
dbgs() <<
" Ignoring, register is not a GPR.\n");
162 }
else if (RC->
contains(AArch64::WZR))
163 NewReg = AArch64::WZR;
164 else if (RC->
contains(AArch64::XZR))
165 NewReg = AArch64::XZR;
167 DEBUG(
dbgs() <<
" Ignoring, register is not a GPR.\n");
170 DEBUG(
dbgs() <<
" Replacing with zero register. New:\n ");
174 ++NumDeadDefsReplaced;
184 bool AArch64DeadRegisterDefinitions::runOnMachineFunction(
MachineFunction &MF) {
191 DEBUG(
dbgs() <<
"***** AArch64DeadRegisterDefinitions *****\n");
194 processMachineBasicBlock(MBB);
199 return new AArch64DeadRegisterDefinitions();
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void setIsDead(bool Val=true)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
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...
const HexagonInstrInfo * TII
INITIALIZE_PASS(AArch64DeadRegisterDefinitions,"aarch64-dead-defs", AARCH64_DEAD_REG_DEF_NAME, false, false) static bool usesFrameIndex(const MachineInstr &MI)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
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...
MachineOperand class - Representation of each machine instruction operand.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
#define AARCH64_DEAD_REG_DEF_NAME
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
void initializeAArch64DeadRegisterDefinitionsPass(PassRegistry &)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
FunctionPass * createAArch64DeadRegisterDefinitions()
virtual void print(raw_ostream &O, const Module *M) const
print - Print out the internal state of the pass.
StringRef - Represent a constant reference to a string, i.e.
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.