45 #define DEBUG_TYPE "aarch64-cond-br-tuning"
46 #define AARCH64_CONDBR_TUNING_NAME "AArch64 Conditional Branch Tuning"
77 void AArch64CondBrTuning::getAnalysisUsage(
AnalysisUsage &AU)
const {
85 return MRI->getUniqueVRegDef(MO.
getReg());
102 unsigned NewOpc =
TII->convertToFlagSettingOpc(MI.
getOpcode(), Is64Bit);
105 NewDestReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
108 TII->get(NewOpc), NewDestReg);
144 bool AArch64CondBrTuning::tryToTuneBranch(
MachineInstr &MI,
150 bool IsFlagSetting =
true;
156 case AArch64::ADDWri:
157 case AArch64::ADDWrr:
158 case AArch64::ADDWrs:
159 case AArch64::ADDWrx:
160 case AArch64::ANDWri:
161 case AArch64::ANDWrr:
162 case AArch64::ANDWrs:
163 case AArch64::BICWrr:
164 case AArch64::BICWrs:
165 case AArch64::SUBWri:
166 case AArch64::SUBWrr:
167 case AArch64::SUBWrs:
168 case AArch64::SUBWrx:
169 IsFlagSetting =
false;
171 case AArch64::ADDSWri:
172 case AArch64::ADDSWrr:
173 case AArch64::ADDSWrs:
174 case AArch64::ADDSWrx:
175 case AArch64::ANDSWri:
176 case AArch64::ANDSWrr:
177 case AArch64::ANDSWrs:
178 case AArch64::BICSWrr:
179 case AArch64::BICSWrs:
180 case AArch64::SUBSWri:
181 case AArch64::SUBSWrr:
182 case AArch64::SUBSWrs:
183 case AArch64::SUBSWrx:
193 if ((MIOpc == AArch64::TBZW || MIOpc == AArch64::TBNZW) &&
200 for (
I = std::next(
I);
I !=
E; ++
I) {
201 if (
I->modifiesRegister(AArch64::NZCV, TRI) ||
202 I->readsRegister(AArch64::NZCV, TRI))
205 DEBUG(
dbgs() <<
" Replacing instructions:\n ");
210 NewCmp = convertToFlagSetting(DefMI, IsFlagSetting);
211 NewBr = convertToCondBr(MI);
216 case AArch64::ADDXri:
217 case AArch64::ADDXrr:
218 case AArch64::ADDXrs:
219 case AArch64::ADDXrx:
220 case AArch64::ANDXri:
221 case AArch64::ANDXrr:
222 case AArch64::ANDXrs:
223 case AArch64::BICXrr:
224 case AArch64::BICXrs:
225 case AArch64::SUBXri:
226 case AArch64::SUBXrr:
227 case AArch64::SUBXrs:
228 case AArch64::SUBXrx:
229 IsFlagSetting =
false;
231 case AArch64::ADDSXri:
232 case AArch64::ADDSXrr:
233 case AArch64::ADDSXrs:
234 case AArch64::ADDSXrx:
235 case AArch64::ANDSXri:
236 case AArch64::ANDSXrr:
237 case AArch64::ANDSXrs:
238 case AArch64::BICSXrr:
239 case AArch64::BICSXrs:
240 case AArch64::SUBSXri:
241 case AArch64::SUBSXrr:
242 case AArch64::SUBSXrs:
243 case AArch64::SUBSXrx:
251 case AArch64::TBNZX: {
253 if ((MIOpc == AArch64::TBZX || MIOpc == AArch64::TBNZX) &&
259 for (
I = std::next(
I);
I !=
E; ++
I) {
260 if (
I->modifiesRegister(AArch64::NZCV, TRI) ||
261 I->readsRegister(AArch64::NZCV, TRI))
264 DEBUG(
dbgs() <<
" Replacing instructions:\n ");
269 NewCmp = convertToFlagSetting(DefMI, IsFlagSetting);
270 NewBr = convertToCondBr(MI);
276 (void)NewCmp; (void)NewBr;
277 assert(NewCmp && NewBr &&
"Expected new instructions.");
279 DEBUG(
dbgs() <<
" with instruction:\n ");
297 DEBUG(
dbgs() <<
"********** AArch64 Conditional Branch Tuning **********\n"
298 <<
"********** Function: " << MF.
getName() <<
'\n');
304 bool Changed =
false;
306 bool LocalChange =
false;
323 LocalChange = (DefMI && tryToTuneBranch(MI, *DefMI));
338 return new AArch64CondBrTuning();
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MachineInstrBuilder & add(const MachineOperand &MO) const
void setIsDead(bool Val=true)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
#define AARCH64_CONDBR_TUNING_NAME
void print(raw_ostream &OS, bool SkipOpers=false, bool SkipDebugLoc=false, const TargetInstrInfo *TII=nullptr) const
Debugging supportPrint this MI to OS.
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
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
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...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineOperand class - Representation of each machine instruction operand.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
llvm_unreachable("Unknown RegBank!")
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.
FunctionPass * createAArch64CondBrTuning()
void initializeAArch64CondBrTuningPass(PassRegistry &)
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.