43 #define DEBUG_TYPE "aarch64-cond-br-tuning" 44 #define AARCH64_CONDBR_TUNING_NAME "AArch64 Conditional Branch Tuning" 75 void AArch64CondBrTuning::getAnalysisUsage(
AnalysisUsage &AU)
const {
83 return MRI->getUniqueVRegDef(MO.
getReg());
100 unsigned NewOpc =
TII->convertToFlagSettingOpc(MI.
getOpcode(), Is64Bit);
103 NewDestReg = Is64Bit ? AArch64::XZR : AArch64::WZR;
106 TII->get(NewOpc), NewDestReg);
142 bool AArch64CondBrTuning::tryToTuneBranch(
MachineInstr &MI,
148 bool IsFlagSetting =
true;
154 case AArch64::ADDWri:
155 case AArch64::ADDWrr:
156 case AArch64::ADDWrs:
157 case AArch64::ADDWrx:
158 case AArch64::ANDWri:
159 case AArch64::ANDWrr:
160 case AArch64::ANDWrs:
161 case AArch64::BICWrr:
162 case AArch64::BICWrs:
163 case AArch64::SUBWri:
164 case AArch64::SUBWrr:
165 case AArch64::SUBWrs:
166 case AArch64::SUBWrx:
167 IsFlagSetting =
false;
169 case AArch64::ADDSWri:
170 case AArch64::ADDSWrr:
171 case AArch64::ADDSWrs:
172 case AArch64::ADDSWrx:
173 case AArch64::ANDSWri:
174 case AArch64::ANDSWrr:
175 case AArch64::ANDSWrs:
176 case AArch64::BICSWrr:
177 case AArch64::BICSWrs:
178 case AArch64::SUBSWri:
179 case AArch64::SUBSWrr:
180 case AArch64::SUBSWrs:
181 case AArch64::SUBSWrx:
191 if ((MIOpc == AArch64::TBZW || MIOpc == AArch64::TBNZW) &&
198 for (
I = std::next(
I);
I !=
E; ++
I) {
199 if (
I->modifiesRegister(AArch64::NZCV,
TRI) ||
200 I->readsRegister(AArch64::NZCV,
TRI))
208 NewCmp = convertToFlagSetting(DefMI, IsFlagSetting);
209 NewBr = convertToCondBr(MI);
214 case AArch64::ADDXri:
215 case AArch64::ADDXrr:
216 case AArch64::ADDXrs:
217 case AArch64::ADDXrx:
218 case AArch64::ANDXri:
219 case AArch64::ANDXrr:
220 case AArch64::ANDXrs:
221 case AArch64::BICXrr:
222 case AArch64::BICXrs:
223 case AArch64::SUBXri:
224 case AArch64::SUBXrr:
225 case AArch64::SUBXrs:
226 case AArch64::SUBXrx:
227 IsFlagSetting =
false;
229 case AArch64::ADDSXri:
230 case AArch64::ADDSXrr:
231 case AArch64::ADDSXrs:
232 case AArch64::ADDSXrx:
233 case AArch64::ANDSXri:
234 case AArch64::ANDSXrr:
235 case AArch64::ANDSXrs:
236 case AArch64::BICSXrr:
237 case AArch64::BICSXrs:
238 case AArch64::SUBSXri:
239 case AArch64::SUBSXrr:
240 case AArch64::SUBSXrs:
241 case AArch64::SUBSXrx:
249 case AArch64::TBNZX: {
251 if ((MIOpc == AArch64::TBZX || MIOpc == AArch64::TBNZX) &&
257 for (
I = std::next(
I);
I !=
E; ++
I) {
258 if (
I->modifiesRegister(AArch64::NZCV,
TRI) ||
259 I->readsRegister(AArch64::NZCV,
TRI))
267 NewCmp = convertToFlagSetting(DefMI, IsFlagSetting);
268 NewBr = convertToCondBr(MI);
274 (void)NewCmp; (void)NewBr;
275 assert(NewCmp && NewBr &&
"Expected new instructions.");
296 dbgs() <<
"********** AArch64 Conditional Branch Tuning **********\n" 297 <<
"********** Function: " << MF.
getName() <<
'\n');
303 bool Changed =
false;
305 bool LocalChange =
false;
322 LocalChange = (DefMI && tryToTuneBranch(MI, *DefMI));
337 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 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
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
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())
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Wrapper class representing virtual and physical registers.