74 #define DEBUG_TYPE "si-lower-control-flow"
106 return "SI Lower control flow pseudo instructions";
126 "SI lower control flow",
false,
false)
145 Cond.
getSubReg() == AMDGPU::NoSubRegister);
147 unsigned SaveExecReg = SaveExec.
getReg();
154 unsigned CopyReg =
MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass);
156 BuildMI(MBB, I, DL,
TII->get(AMDGPU::COPY), CopyReg)
157 .addReg(AMDGPU::EXEC)
160 unsigned Tmp =
MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass);
163 BuildMI(MBB, I, DL,
TII->get(AMDGPU::S_AND_B64), Tmp)
167 setImpSCCDefDead(*And,
true);
170 BuildMI(MBB, I, DL,
TII->get(AMDGPU::S_XOR_B64), SaveExecReg)
173 setImpSCCDefDead(*Xor, ImpDefSCC.
isDead());
178 BuildMI(MBB, I, DL,
TII->get(AMDGPU::S_MOV_B64_term), AMDGPU::EXEC)
191 LIS->InsertMachineInstrInMaps(*CopyExec);
195 LIS->ReplaceMachineInstrInMaps(MI, *And);
197 LIS->InsertMachineInstrInMaps(*Xor);
198 LIS->InsertMachineInstrInMaps(*SetExec);
199 LIS->InsertMachineInstrInMaps(*NewBr);
207 LIS->removeInterval(SaveExecReg);
208 LIS->createAndComputeVirtRegInterval(SaveExecReg);
209 LIS->createAndComputeVirtRegInterval(Tmp);
210 LIS->createAndComputeVirtRegInterval(CopyReg);
226 unsigned CopyReg =
MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass);
228 BuildMI(MBB, Start, DL,
TII->get(AMDGPU::COPY), CopyReg)
233 unsigned SaveReg = ExecModified ?
234 MRI->createVirtualRegister(&AMDGPU::SReg_64RegClass) : DstReg;
236 BuildMI(MBB, Start, DL,
TII->get(AMDGPU::S_OR_SAVEEXEC_B64), SaveReg)
245 BuildMI(MBB, ElsePt, DL,
TII->get(AMDGPU::S_AND_B64), DstReg)
246 .addReg(AMDGPU::EXEC)
250 LIS->InsertMachineInstrInMaps(*And);
254 BuildMI(MBB, ElsePt, DL,
TII->get(AMDGPU::S_XOR_B64_term), AMDGPU::EXEC)
255 .addReg(AMDGPU::EXEC)
259 BuildMI(MBB, ElsePt, DL,
TII->get(AMDGPU::SI_MASK_BRANCH))
267 LIS->RemoveMachineInstrFromMaps(MI);
270 LIS->InsertMachineInstrInMaps(*CopyExec);
271 LIS->InsertMachineInstrInMaps(*OrSaveExec);
273 LIS->InsertMachineInstrInMaps(*Xor);
274 LIS->InsertMachineInstrInMaps(*Branch);
277 LIS->removeInterval(DstReg);
278 LIS->createAndComputeVirtRegInterval(DstReg);
279 LIS->createAndComputeVirtRegInterval(CopyReg);
281 LIS->createAndComputeVirtRegInterval(SaveReg);
293 .addReg(AMDGPU::EXEC)
297 LIS->ReplaceMachineInstrInMaps(MI, *Or);
301 void SILowerControlFlow::emitIfBreak(
MachineInstr &MI) {
305 void SILowerControlFlow::emitElseBreak(
MachineInstr &MI) {
314 BuildMI(MBB, &MI, DL,
TII->get(AMDGPU::S_ANDN2_B64_term), AMDGPU::EXEC)
315 .addReg(AMDGPU::EXEC)
319 BuildMI(MBB, &MI, DL,
TII->get(AMDGPU::S_CBRANCH_EXECNZ))
323 LIS->ReplaceMachineInstrInMaps(MI, *AndN2);
324 LIS->InsertMachineInstrInMaps(*Branch);
336 BuildMI(MBB, InsPt, DL,
TII->get(AMDGPU::S_OR_B64), AMDGPU::EXEC)
337 .addReg(AMDGPU::EXEC)
341 LIS->ReplaceMachineInstrInMaps(MI, *NewMI);
346 LIS->handleMove(*NewMI);
351 void SILowerControlFlow::findMaskOperands(
MachineInstr &MI,
unsigned OpNo,
368 if (
I->modifiesRegister(AMDGPU::EXEC, TRI) &&
369 !(
I->isCopy() &&
I->getOperand(0).getReg() != AMDGPU::EXEC))
373 if (SrcOp.isUse() && (!SrcOp.isReg() ||
375 SrcOp.getReg() == AMDGPU::EXEC))
383 void SILowerControlFlow::combineMasks(
MachineInstr &MI) {
386 unsigned OpToReplace = 1;
387 findMaskOperands(MI, 1, Ops);
388 if (Ops.size() == 1) OpToReplace = 2;
389 findMaskOperands(MI, 2, Ops);
390 if (Ops.size() != 3)
return;
392 unsigned UniqueOpndIdx;
393 if (Ops[0].isIdenticalTo(Ops[1])) UniqueOpndIdx = 2;
394 else if (Ops[0].isIdenticalTo(Ops[2])) UniqueOpndIdx = 1;
395 else if (Ops[1].isIdenticalTo(Ops[2])) UniqueOpndIdx = 1;
401 if (
MRI->use_empty(Reg))
402 MRI->getUniqueVRegDef(Reg)->eraseFromParent();
411 LIS = getAnalysisIfAvailable<LiveIntervals>();
416 BI != BE; BI = NextBB) {
417 NextBB = std::next(BI);
422 for (I = MBB.
begin(), Last = MBB.
end(); I != MBB.
end(); I = Next) {
431 case AMDGPU::SI_ELSE:
435 case AMDGPU::SI_BREAK:
439 case AMDGPU::SI_IF_BREAK:
443 case AMDGPU::SI_ELSE_BREAK:
447 case AMDGPU::SI_LOOP:
451 case AMDGPU::SI_END_CF:
455 case AMDGPU::S_AND_B64:
456 case AMDGPU::S_OR_B64:
468 Next = (Last == MBB.
end()) ? MBB.
begin() : Last;
void push_back(const T &Elt)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
AMDGPU specific subclass of TargetSubtarget.
MachineBasicBlock * getMBB() const
iterator_range< mop_iterator > explicit_operands()
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
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
const SIInstrInfo * getInstrInfo() const override
void setIsDead(bool Val=true)
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
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
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Reg
All possible values of the reg field in the ModR/M byte.
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
AnalysisUsage & addPreservedID(const void *ID)
bool IsDead MachineOperand & ImpDefSCC
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
char & LiveVariablesID
LiveVariables pass - This pass computes the set of blocks in which each variable is life and sets mac...
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.
self_iterator getIterator()
unsigned getSubReg() const
Iterator for intrusive lists based on ilist_node.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
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...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
INITIALIZE_PASS(SILowerControlFlow, DEBUG_TYPE,"SI lower control flow", false, false) static void setImpSCCDefDead(MachineInstr &MI
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
char & SILowerControlFlowID
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.
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.