44 #define DEBUG_TYPE "aarch64-cond-br-tuning" 45 #define AARCH64_CONDBR_TUNING_NAME "AArch64 Conditional Branch Tuning" 76 void AArch64CondBrTuning::getAnalysisUsage(
AnalysisUsage &AU)
const {
84 return MRI->getUniqueVRegDef(MO.
getReg());
101 unsigned NewOpc =
TII->convertToFlagSettingOpc(MI.
getOpcode(), Is64Bit);
104 NewDestReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
107 TII->get(NewOpc), NewDestReg);
143 bool AArch64CondBrTuning::tryToTuneBranch(
MachineInstr &MI,
149 bool IsFlagSetting =
true;
155 case AArch64::ADDWri:
156 case AArch64::ADDWrr:
157 case AArch64::ADDWrs:
158 case AArch64::ADDWrx:
159 case AArch64::ANDWri:
160 case AArch64::ANDWrr:
161 case AArch64::ANDWrs:
162 case AArch64::BICWrr:
163 case AArch64::BICWrs:
164 case AArch64::SUBWri:
165 case AArch64::SUBWrr:
166 case AArch64::SUBWrs:
167 case AArch64::SUBWrx:
168 IsFlagSetting =
false;
170 case AArch64::ADDSWri:
171 case AArch64::ADDSWrr:
172 case AArch64::ADDSWrs:
173 case AArch64::ADDSWrx:
174 case AArch64::ANDSWri:
175 case AArch64::ANDSWrr:
176 case AArch64::ANDSWrs:
177 case AArch64::BICSWrr:
178 case AArch64::BICSWrs:
179 case AArch64::SUBSWri:
180 case AArch64::SUBSWrr:
181 case AArch64::SUBSWrs:
182 case AArch64::SUBSWrx:
192 if ((MIOpc == AArch64::TBZW || MIOpc == AArch64::TBNZW) &&
199 for (
I = std::next(
I);
I !=
E; ++
I) {
200 if (
I->modifiesRegister(AArch64::NZCV,
TRI) ||
201 I->readsRegister(AArch64::NZCV,
TRI))
209 NewCmp = convertToFlagSetting(DefMI, IsFlagSetting);
210 NewBr = convertToCondBr(MI);
215 case AArch64::ADDXri:
216 case AArch64::ADDXrr:
217 case AArch64::ADDXrs:
218 case AArch64::ADDXrx:
219 case AArch64::ANDXri:
220 case AArch64::ANDXrr:
221 case AArch64::ANDXrs:
222 case AArch64::BICXrr:
223 case AArch64::BICXrs:
224 case AArch64::SUBXri:
225 case AArch64::SUBXrr:
226 case AArch64::SUBXrs:
227 case AArch64::SUBXrx:
228 IsFlagSetting =
false;
230 case AArch64::ADDSXri:
231 case AArch64::ADDSXrr:
232 case AArch64::ADDSXrs:
233 case AArch64::ADDSXrx:
234 case AArch64::ANDSXri:
235 case AArch64::ANDSXrr:
236 case AArch64::ANDSXrs:
237 case AArch64::BICSXrr:
238 case AArch64::BICSXrs:
239 case AArch64::SUBSXri:
240 case AArch64::SUBSXrr:
241 case AArch64::SUBSXrs:
242 case AArch64::SUBSXrx:
250 case AArch64::TBNZX: {
252 if ((MIOpc == AArch64::TBZX || MIOpc == AArch64::TBNZX) &&
258 for (
I = std::next(
I);
I !=
E; ++
I) {
259 if (
I->modifiesRegister(AArch64::NZCV,
TRI) ||
260 I->readsRegister(AArch64::NZCV,
TRI))
268 NewCmp = convertToFlagSetting(DefMI, IsFlagSetting);
269 NewBr = convertToCondBr(MI);
275 (void)NewCmp; (void)NewBr;
276 assert(NewCmp && NewBr &&
"Expected new instructions.");
297 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();
const MachineInstrBuilder & add(const MachineOperand &MO) const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned const TargetRegisterInfo * TRI
void setIsDead(bool Val=true)
#define AARCH64_CONDBR_TUNING_NAME
INITIALIZE_PASS(AArch64CondBrTuning, "aarch64-cond-br-tuning", AARCH64_CONDBR_TUNING_NAME, false, false) void AArch64CondBrTuning
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
virtual const TargetInstrInfo * getInstrInfo() const
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
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 TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
MachineOperand class - Representation of each machine instruction operand.
MachineInstrBuilder MachineInstrBuilder & DefMI
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineBasicBlock * getParent() const
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 &)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
const MachineOperand & getOperand(unsigned i) const