42 #define DEBUG_TYPE "si-insert-skips" 45 "amdgpu-skip-threshold",
46 cl::desc(
"Number of instructions before jumping over divergent control flow"),
55 unsigned SkipThreshold = 0;
77 return "SI insert s_cbranch_execz instructions";
90 "SI insert s_cbranch_execz instructions",
false,
false)
96 case TargetOpcode::IMPLICIT_DEF:
98 case TargetOpcode::BUNDLE:
99 case TargetOpcode::CFI_INSTRUCTION:
101 case TargetOpcode::GC_LABEL:
102 case TargetOpcode::DBG_VALUE:
114 unsigned NumInstr = 0;
118 MBBI != End && MBBI != ToI; ++MBBI) {
122 NumInstr < SkipThreshold &&
I !=
E; ++
I) {
132 if (
I->getOpcode() == AMDGPU::S_CBRANCH_VCCNZ ||
133 I->getOpcode() == AMDGPU::S_CBRANCH_VCCZ)
136 if (
TII->hasUnwantedEffectsWhenEXECEmpty(*
I))
140 if (NumInstr >= SkipThreshold)
161 BuildMI(&MBB, DL,
TII->get(AMDGPU::S_CBRANCH_EXECNZ))
167 BuildMI(*SkipBB, Insert, DL,
TII->get(AMDGPU::EXP_DONE))
178 BuildMI(*SkipBB, Insert, DL,
TII->get(AMDGPU::S_ENDPGM));
188 case AMDGPU::SI_KILL_F32_COND_IMM_TERMINATOR: {
196 Opcode = AMDGPU::V_CMPX_EQ_F32_e64;
200 Opcode = AMDGPU::V_CMPX_LT_F32_e64;
204 Opcode = AMDGPU::V_CMPX_LE_F32_e64;
208 Opcode = AMDGPU::V_CMPX_GT_F32_e64;
212 Opcode = AMDGPU::V_CMPX_GE_F32_e64;
216 Opcode = AMDGPU::V_CMPX_LG_F32_e64;
219 Opcode = AMDGPU::V_CMPX_O_F32_e64;
222 Opcode = AMDGPU::V_CMPX_U_F32_e64;
225 Opcode = AMDGPU::V_CMPX_NLG_F32_e64;
228 Opcode = AMDGPU::V_CMPX_NGE_F32_e64;
231 Opcode = AMDGPU::V_CMPX_NGT_F32_e64;
234 Opcode = AMDGPU::V_CMPX_NLE_F32_e64;
237 Opcode = AMDGPU::V_CMPX_NLT_F32_e64;
240 Opcode = AMDGPU::V_CMPX_NEQ_F32_e64;
265 case AMDGPU::SI_KILL_I1_TERMINATOR: {
268 assert(KillVal == 0 || KillVal == -1);
272 int64_t Imm = Op.
getImm();
273 assert(Imm == 0 || Imm == -1);
276 BuildMI(MBB, &MI, DL,
TII->get(AMDGPU::S_MOV_B64), AMDGPU::EXEC)
281 unsigned Opcode = KillVal ? AMDGPU::S_ANDN2_B64 : AMDGPU::S_AND_B64;
282 BuildMI(MBB, &MI, DL,
TII->get(Opcode), AMDGPU::EXEC)
283 .addReg(AMDGPU::EXEC)
311 if (!shouldSkip(**SrcMBB.
succ_begin(), *DestBB))
317 BuildMI(SrcMBB, InsPt, DL,
TII->get(AMDGPU::S_CBRANCH_EXECZ))
329 bool HaveKill =
false;
330 bool MadeChange =
false;
340 BI != BE; BI = NextBB) {
341 NextBB = std::next(BI);
343 bool HaveSkipBlock =
false;
345 if (!ExecBranchStack.
empty() && ExecBranchStack.
back() == &MBB) {
350 if (HaveKill && ExecBranchStack.
empty()) {
357 for (I = MBB.
begin(); I != MBB.
end(); I = Next) {
363 case AMDGPU::SI_MASK_BRANCH:
365 MadeChange |= skipMaskBranch(MI, MBB);
368 case AMDGPU::S_BRANCH:
373 }
else if (HaveSkipBlock) {
381 case AMDGPU::SI_KILL_F32_COND_IMM_TERMINATOR:
382 case AMDGPU::SI_KILL_I1_TERMINATOR:
386 if (ExecBranchStack.
empty()) {
387 if (skipIfDead(MI, *NextBB)) {
388 HaveSkipBlock =
true;
389 NextBB = std::next(BI);
399 case AMDGPU::SI_RETURN_TO_EPILOG:
408 if (!EmptyMBBAtEnd) {
415 .addMBB(EmptyMBBAtEnd);
416 I->eraseFromParent();
void push_back(const T &Elt)
const MachineInstrBuilder & add(const MachineOperand &MO) const
AMDGPU specific subclass of TargetSubtarget.
MachineBasicBlock * getMBB() const
Compute iterated dominance frontiers using a linear time algorithm.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned getReg() const
getReg - Returns the register number.
const SIInstrInfo * getInstrInfo() const override
unsigned const TargetRegisterInfo * TRI
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Calling convention used for Mesa/AMDPAL pixel shaders.
static const AMDGPUSubtarget & get(const MachineFunction &MF)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
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)
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")
char & SIInsertSkipsPassID
Represent the analysis usage information of a pass.
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()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
LLVM_READONLY int getVOPe32(uint16_t Opcode)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
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...
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 Function & getFunction() const
Return the LLVM function that this machine code represents.
const MachineBasicBlock * getParent() const
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
const MachineBasicBlock & back() const
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
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)
const MachineOperand & getOperand(unsigned i) const
const SIRegisterInfo * getRegisterInfo() const override