41 #define DEBUG_TYPE "si-insert-skips"
44 "amdgpu-skip-threshold",
45 cl::desc(
"Number of instructions before jumping over divergent control flow"),
54 unsigned SkipThreshold = 0;
76 return "SI insert s_cbranch_execz instructions";
89 "SI insert s_cbranch_execz instructions",
false,
false)
95 case TargetOpcode::IMPLICIT_DEF:
97 case TargetOpcode::BUNDLE:
98 case TargetOpcode::CFI_INSTRUCTION:
100 case TargetOpcode::GC_LABEL:
101 case TargetOpcode::DBG_VALUE:
113 unsigned NumInstr = 0;
117 MBBI !=
End && MBBI != ToI; ++MBBI) {
121 NumInstr < SkipThreshold &&
I !=
E; ++
I) {
131 if (
I->getOpcode() == AMDGPU::S_CBRANCH_VCCNZ ||
132 I->getOpcode() == AMDGPU::S_CBRANCH_VCCZ)
135 if (
I->isInlineAsm()) {
137 const char *AsmStr =
I->getOperand(0).getSymbolName();
147 if (NumInstr >= SkipThreshold)
168 BuildMI(&MBB, DL,
TII->get(AMDGPU::S_CBRANCH_EXECNZ))
174 BuildMI(*SkipBB, Insert, DL,
TII->get(AMDGPU::EXP_DONE))
185 BuildMI(*SkipBB, Insert, DL,
TII->get(AMDGPU::S_ENDPGM));
204 if (Op.
getImm() & 0x80000000) {
205 BuildMI(MBB, &MI, DL,
TII->get(AMDGPU::S_MOV_B64), AMDGPU::EXEC)
209 BuildMI(MBB, &MI, DL,
TII->get(AMDGPU::V_CMPX_LE_F32_e32))
234 if (!shouldSkip(**SrcMBB.
succ_begin(), *DestBB))
240 BuildMI(SrcMBB, InsPt, DL,
TII->get(AMDGPU::S_CBRANCH_EXECZ))
252 bool HaveKill =
false;
253 bool MadeChange =
false;
263 BI != BE; BI = NextBB) {
264 NextBB = std::next(BI);
266 bool HaveSkipBlock =
false;
268 if (!ExecBranchStack.
empty() && ExecBranchStack.
back() == &MBB) {
273 if (HaveKill && ExecBranchStack.
empty()) {
280 for (I = MBB.
begin(); I != MBB.
end(); I = Next) {
286 case AMDGPU::SI_MASK_BRANCH:
288 MadeChange |= skipMaskBranch(MI, MBB);
291 case AMDGPU::S_BRANCH:
296 }
else if (HaveSkipBlock) {
304 case AMDGPU::SI_KILL_TERMINATOR:
308 if (ExecBranchStack.
empty()) {
309 if (skipIfDead(MI, *NextBB)) {
310 HaveSkipBlock =
true;
311 NextBB = std::next(BI);
321 case AMDGPU::SI_RETURN_TO_EPILOG:
330 if (!EmptyMBBAtEnd) {
337 .addMBB(EmptyMBBAtEnd);
338 I->eraseFromParent();
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
AMDGPU specific subclass of TargetSubtarget.
MachineBasicBlock * getMBB() const
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const SIInstrInfo * getInstrInfo() const override
Calling convention used for Mesa geometry shaders.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
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
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
LLVM_NODISCARD bool empty() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
char & SIInsertSkipsPassID
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.
static const unsigned End
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
self_iterator getIterator()
succ_iterator succ_begin()
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const SIRegisterInfo * getRegisterInfo() const override
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Calling convention used for Mesa pixel shaders.
unsigned getInlineAsmLength(const char *Str, const MCAsmInfo &MAI) const override
Measure the specified inline asm to determine an approximation of its length.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Representation of each machine instruction.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
unsigned getMaxInstLength() const
const MachineBasicBlock & back() const
StringRef - Represent a constant reference to a string, i.e.
static cl::opt< unsigned > SkipThresholdFlag("amdgpu-skip-threshold", cl::desc("Number of instructions before jumping over divergent control flow"), cl::init(12), cl::Hidden)
static INITIALIZE_PASS(SIInsertSkips, DEBUG_TYPE,"SI insert s_cbranch_execz instructions", false, false) char &llvm bool opcodeEmitsNoInsts(unsigned Opc)
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.