1 //===-- SILowerControlFlow.cpp - Use predicates for control flow ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This pass lowers the pseudo control flow instructions to real
11 /// machine instructions.
13 /// All control flow is handled using predicated instructions and
14 /// a predicate stack. Each Scalar ALU controls the operations of 64 Vector
15 /// ALUs. The Scalar ALU can update the predicate for any of the Vector ALUs
16 /// by writting to the 64-bit EXEC register (each bit corresponds to a
17 /// single vector ALU). Typically, for predicates, a vector ALU will write
18 /// to its bit of the VCC register (like EXEC VCC is 64-bits, one for each
19 /// Vector ALU) and then the ScalarALU will AND the VCC register with the
20 /// EXEC to update the predicates.
23 /// %vcc = V_CMP_GT_F32 %vgpr1, %vgpr2
24 /// %sgpr0 = SI_IF %vcc
25 /// %vgpr0 = V_ADD_F32 %vgpr0, %vgpr0
26 /// %sgpr0 = SI_ELSE %sgpr0
27 /// %vgpr0 = V_SUB_F32 %vgpr0, %vgpr0
32 /// %sgpr0 = S_AND_SAVEEXEC_B64 %vcc // Save and update the exec mask
33 /// %sgpr0 = S_XOR_B64 %sgpr0, %exec // Clear live bits from saved exec mask
34 /// S_CBRANCH_EXECZ label0 // This instruction is an optional
35 /// // optimization which allows us to
36 /// // branch if all the bits of
38 /// %vgpr0 = V_ADD_F32 %vgpr0, %vgpr0 // Do the IF block of the branch
41 /// %sgpr0 = S_OR_SAVEEXEC_B64 %sgpr0 // Restore the exec mask for the Then block
42 /// %exec = S_XOR_B64 %sgpr0, %exec // Update the exec mask
43 /// S_BRANCH_EXECZ label1 // Use our branch optimization
44 /// // instruction again.
45 /// %vgpr0 = V_SUB_F32 %vgpr0, %vgpr // Do the THEN block
47 /// %exec = S_OR_B64 %exec, %sgpr0 // Re-enable saved exec mask bits
48 //===----------------------------------------------------------------------===//
51 #include "AMDGPUSubtarget.h"
52 #include "SIInstrInfo.h"
53 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
54 #include "llvm/ADT/SetVector.h"
55 #include "llvm/ADT/SmallSet.h"
56 #include "llvm/ADT/SmallVector.h"
57 #include "llvm/ADT/StringRef.h"
58 #include "llvm/CodeGen/LiveIntervals.h"
59 #include "llvm/CodeGen/MachineBasicBlock.h"
60 #include "llvm/CodeGen/MachineFunction.h"
61 #include "llvm/CodeGen/MachineFunctionPass.h"
62 #include "llvm/CodeGen/MachineInstr.h"
63 #include "llvm/CodeGen/MachineInstrBuilder.h"
64 #include "llvm/CodeGen/MachineOperand.h"
65 #include "llvm/CodeGen/MachineRegisterInfo.h"
66 #include "llvm/CodeGen/Passes.h"
67 #include "llvm/CodeGen/SlotIndexes.h"
68 #include "llvm/CodeGen/TargetRegisterInfo.h"
69 #include "llvm/MC/MCRegisterInfo.h"
70 #include "llvm/Pass.h"
76 #define DEBUG_TYPE "si-lower-control-flow"
79 RemoveRedundantEndcf("amdgpu-remove-redundant-endcf",
80 cl::init(true), cl::ReallyHidden);
84 class SILowerControlFlow : public MachineFunctionPass {
86 const SIRegisterInfo *TRI = nullptr;
87 const SIInstrInfo *TII = nullptr;
88 LiveIntervals *LIS = nullptr;
89 MachineRegisterInfo *MRI = nullptr;
90 SetVector<MachineInstr*> LoweredEndCf;
91 DenseSet<Register> LoweredIf;
92 SmallSet<MachineInstr *, 16> NeedsKillCleanup;
94 const TargetRegisterClass *BoolRC = nullptr;
95 bool InsertKillCleanups;
100 unsigned Andn2TermOpc;
101 unsigned XorTermrOpc;
102 unsigned OrSaveExecOpc;
105 void emitIf(MachineInstr &MI);
106 void emitElse(MachineInstr &MI);
107 void emitIfBreak(MachineInstr &MI);
108 void emitLoop(MachineInstr &MI);
109 void emitEndCf(MachineInstr &MI);
111 void findMaskOperands(MachineInstr &MI, unsigned OpNo,
112 SmallVectorImpl<MachineOperand> &Src) const;
114 void combineMasks(MachineInstr &MI);
116 void process(MachineInstr &MI);
118 // Skip to the next instruction, ignoring debug instructions, and trivial
119 // block boundaries (blocks that have one (typically fallthrough) successor,
120 // and the successor has one predecessor.
121 MachineBasicBlock::iterator
122 skipIgnoreExecInstsTrivialSucc(MachineBasicBlock &MBB,
123 MachineBasicBlock::iterator It) const;
125 // Remove redundant SI_END_CF instructions.
126 void optimizeEndCf();
131 SILowerControlFlow() : MachineFunctionPass(ID) {}
133 bool runOnMachineFunction(MachineFunction &MF) override;
135 StringRef getPassName() const override {
136 return "SI Lower control flow pseudo instructions";
139 void getAnalysisUsage(AnalysisUsage &AU) const override {
140 // Should preserve the same set that TwoAddressInstructions does.
141 AU.addPreserved<SlotIndexes>();
142 AU.addPreserved<LiveIntervals>();
143 AU.addPreservedID(LiveVariablesID);
144 AU.addPreservedID(MachineLoopInfoID);
145 AU.addPreservedID(MachineDominatorsID);
146 AU.setPreservesCFG();
147 MachineFunctionPass::getAnalysisUsage(AU);
151 } // end anonymous namespace
153 char SILowerControlFlow::ID = 0;
155 INITIALIZE_PASS(SILowerControlFlow, DEBUG_TYPE,
156 "SI lower control flow", false, false)
158 static void setImpSCCDefDead(MachineInstr &MI, bool IsDead) {
159 MachineOperand &ImpDefSCC = MI.getOperand(3);
160 assert(ImpDefSCC.getReg() == AMDGPU::SCC && ImpDefSCC.isDef());
162 ImpDefSCC.setIsDead(IsDead);
165 char &llvm::SILowerControlFlowID = SILowerControlFlow::ID;
167 static bool hasKill(const MachineBasicBlock *Begin,
168 const MachineBasicBlock *End, const SIInstrInfo *TII) {
169 DenseSet<const MachineBasicBlock*> Visited;
170 SmallVector<MachineBasicBlock *, 4> Worklist(Begin->succ_begin(),
173 while (!Worklist.empty()) {
174 MachineBasicBlock *MBB = Worklist.pop_back_val();
176 if (MBB == End || !Visited.insert(MBB).second)
178 for (auto &Term : MBB->terminators())
179 if (TII->isKillTerminator(Term.getOpcode()))
182 Worklist.append(MBB->succ_begin(), MBB->succ_end());
188 static bool isSimpleIf(const MachineInstr &MI, const MachineRegisterInfo *MRI) {
189 Register SaveExecReg = MI.getOperand(0).getReg();
190 auto U = MRI->use_instr_nodbg_begin(SaveExecReg);
192 if (U == MRI->use_instr_nodbg_end() ||
193 std::next(U) != MRI->use_instr_nodbg_end() ||
194 U->getOpcode() != AMDGPU::SI_END_CF)
200 void SILowerControlFlow::emitIf(MachineInstr &MI) {
201 MachineBasicBlock &MBB = *MI.getParent();
202 const DebugLoc &DL = MI.getDebugLoc();
203 MachineBasicBlock::iterator I(&MI);
204 Register SaveExecReg = MI.getOperand(0).getReg();
205 MachineOperand& Cond = MI.getOperand(1);
206 assert(Cond.getSubReg() == AMDGPU::NoSubRegister);
208 MachineOperand &ImpDefSCC = MI.getOperand(4);
209 assert(ImpDefSCC.getReg() == AMDGPU::SCC && ImpDefSCC.isDef());
211 // If there is only one use of save exec register and that use is SI_END_CF,
212 // we can optimize SI_IF by returning the full saved exec mask instead of
213 // just cleared bits.
214 bool SimpleIf = isSimpleIf(MI, MRI);
216 if (InsertKillCleanups) {
217 // Check for SI_KILL_*_TERMINATOR on full path of control flow and
218 // flag the associated SI_END_CF for insertion of a kill cleanup.
219 auto UseMI = MRI->use_instr_nodbg_begin(SaveExecReg);
220 while (UseMI->getOpcode() != AMDGPU::SI_END_CF) {
221 assert(std::next(UseMI) == MRI->use_instr_nodbg_end());
222 assert(UseMI->getOpcode() == AMDGPU::SI_ELSE);
223 MachineOperand &NextExec = UseMI->getOperand(0);
224 Register NextExecReg = NextExec.getReg();
225 if (NextExec.isDead()) {
229 UseMI = MRI->use_instr_nodbg_begin(NextExecReg);
231 if (UseMI->getOpcode() == AMDGPU::SI_END_CF) {
232 if (hasKill(MI.getParent(), UseMI->getParent(), TII)) {
233 NeedsKillCleanup.insert(&*UseMI);
237 } else if (SimpleIf) {
238 // Check for SI_KILL_*_TERMINATOR on path from if to endif.
239 // if there is any such terminator simplifications are not safe.
240 auto UseMI = MRI->use_instr_nodbg_begin(SaveExecReg);
241 SimpleIf = !hasKill(MI.getParent(), UseMI->getParent(), TII);
244 // Add an implicit def of exec to discourage scheduling VALU after this which
245 // will interfere with trying to form s_and_saveexec_b64 later.
246 Register CopyReg = SimpleIf ? SaveExecReg
247 : MRI->createVirtualRegister(BoolRC);
248 MachineInstr *CopyExec =
249 BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), CopyReg)
251 .addReg(Exec, RegState::ImplicitDefine);
252 LoweredIf.insert(CopyReg);
254 Register Tmp = MRI->createVirtualRegister(BoolRC);
257 BuildMI(MBB, I, DL, TII->get(AndOpc), Tmp)
261 setImpSCCDefDead(*And, true);
263 MachineInstr *Xor = nullptr;
266 BuildMI(MBB, I, DL, TII->get(XorOpc), SaveExecReg)
269 setImpSCCDefDead(*Xor, ImpDefSCC.isDead());
272 // Use a copy that is a terminator to get correct spill code placement it with
274 MachineInstr *SetExec =
275 BuildMI(MBB, I, DL, TII->get(MovTermOpc), Exec)
276 .addReg(Tmp, RegState::Kill);
278 // Insert the S_CBRANCH_EXECZ instruction which will be optimized later
279 // during SIRemoveShortExecBranches.
280 MachineInstr *NewBr = BuildMI(MBB, I, DL, TII->get(AMDGPU::S_CBRANCH_EXECZ))
281 .add(MI.getOperand(2));
284 MI.eraseFromParent();
288 LIS->InsertMachineInstrInMaps(*CopyExec);
290 // Replace with and so we don't need to fix the live interval for condition
292 LIS->ReplaceMachineInstrInMaps(MI, *And);
295 LIS->InsertMachineInstrInMaps(*Xor);
296 LIS->InsertMachineInstrInMaps(*SetExec);
297 LIS->InsertMachineInstrInMaps(*NewBr);
299 LIS->removeAllRegUnitsForPhysReg(AMDGPU::EXEC);
300 MI.eraseFromParent();
302 // FIXME: Is there a better way of adjusting the liveness? It shouldn't be
303 // hard to add another def here but I'm not sure how to correctly update the
305 LIS->removeInterval(SaveExecReg);
306 LIS->createAndComputeVirtRegInterval(SaveExecReg);
307 LIS->createAndComputeVirtRegInterval(Tmp);
309 LIS->createAndComputeVirtRegInterval(CopyReg);
312 void SILowerControlFlow::emitElse(MachineInstr &MI) {
313 MachineBasicBlock &MBB = *MI.getParent();
314 const DebugLoc &DL = MI.getDebugLoc();
316 Register DstReg = MI.getOperand(0).getReg();
318 bool ExecModified = MI.getOperand(3).getImm() != 0;
319 MachineBasicBlock::iterator Start = MBB.begin();
321 // We are running before TwoAddressInstructions, and si_else's operands are
322 // tied. In order to correctly tie the registers, split this into a copy of
323 // the src like it does.
324 Register CopyReg = MRI->createVirtualRegister(BoolRC);
325 MachineInstr *CopyExec =
326 BuildMI(MBB, Start, DL, TII->get(AMDGPU::COPY), CopyReg)
327 .add(MI.getOperand(1)); // Saved EXEC
329 // This must be inserted before phis and any spill code inserted before the
331 Register SaveReg = ExecModified ?
332 MRI->createVirtualRegister(BoolRC) : DstReg;
333 MachineInstr *OrSaveExec =
334 BuildMI(MBB, Start, DL, TII->get(OrSaveExecOpc), SaveReg)
337 MachineBasicBlock *DestBB = MI.getOperand(2).getMBB();
339 MachineBasicBlock::iterator ElsePt(MI);
343 BuildMI(MBB, ElsePt, DL, TII->get(AndOpc), DstReg)
348 LIS->InsertMachineInstrInMaps(*And);
352 BuildMI(MBB, ElsePt, DL, TII->get(XorTermrOpc), Exec)
356 MachineInstr *Branch =
357 BuildMI(MBB, ElsePt, DL, TII->get(AMDGPU::S_CBRANCH_EXECZ))
361 MI.eraseFromParent();
365 LIS->RemoveMachineInstrFromMaps(MI);
366 MI.eraseFromParent();
368 LIS->InsertMachineInstrInMaps(*CopyExec);
369 LIS->InsertMachineInstrInMaps(*OrSaveExec);
371 LIS->InsertMachineInstrInMaps(*Xor);
372 LIS->InsertMachineInstrInMaps(*Branch);
374 // src reg is tied to dst reg.
375 LIS->removeInterval(DstReg);
376 LIS->createAndComputeVirtRegInterval(DstReg);
377 LIS->createAndComputeVirtRegInterval(CopyReg);
379 LIS->createAndComputeVirtRegInterval(SaveReg);
381 // Let this be recomputed.
382 LIS->removeAllRegUnitsForPhysReg(AMDGPU::EXEC);
385 void SILowerControlFlow::emitIfBreak(MachineInstr &MI) {
386 MachineBasicBlock &MBB = *MI.getParent();
387 const DebugLoc &DL = MI.getDebugLoc();
388 auto Dst = MI.getOperand(0).getReg();
390 // Skip ANDing with exec if the break condition is already masked by exec
391 // because it is a V_CMP in the same basic block. (We know the break
392 // condition operand was an i1 in IR, so if it is a VALU instruction it must
393 // be one with a carry-out.)
394 bool SkipAnding = false;
395 if (MI.getOperand(1).isReg()) {
396 if (MachineInstr *Def = MRI->getUniqueVRegDef(MI.getOperand(1).getReg())) {
397 SkipAnding = Def->getParent() == MI.getParent()
398 && SIInstrInfo::isVALU(*Def);
402 // AND the break condition operand with exec, then OR that into the "loop
404 MachineInstr *And = nullptr, *Or = nullptr;
406 Register AndReg = MRI->createVirtualRegister(BoolRC);
407 And = BuildMI(MBB, &MI, DL, TII->get(AndOpc), AndReg)
409 .add(MI.getOperand(1));
410 Or = BuildMI(MBB, &MI, DL, TII->get(OrOpc), Dst)
412 .add(MI.getOperand(2));
414 LIS->createAndComputeVirtRegInterval(AndReg);
416 Or = BuildMI(MBB, &MI, DL, TII->get(OrOpc), Dst)
417 .add(MI.getOperand(1))
418 .add(MI.getOperand(2));
422 LIS->InsertMachineInstrInMaps(*And);
423 LIS->ReplaceMachineInstrInMaps(MI, *Or);
426 MI.eraseFromParent();
429 void SILowerControlFlow::emitLoop(MachineInstr &MI) {
430 MachineBasicBlock &MBB = *MI.getParent();
431 const DebugLoc &DL = MI.getDebugLoc();
433 MachineInstr *AndN2 =
434 BuildMI(MBB, &MI, DL, TII->get(Andn2TermOpc), Exec)
436 .add(MI.getOperand(0));
438 MachineInstr *Branch =
439 BuildMI(MBB, &MI, DL, TII->get(AMDGPU::S_CBRANCH_EXECNZ))
440 .add(MI.getOperand(1));
443 LIS->ReplaceMachineInstrInMaps(MI, *AndN2);
444 LIS->InsertMachineInstrInMaps(*Branch);
447 MI.eraseFromParent();
450 MachineBasicBlock::iterator
451 SILowerControlFlow::skipIgnoreExecInstsTrivialSucc(
452 MachineBasicBlock &MBB, MachineBasicBlock::iterator It) const {
454 SmallSet<const MachineBasicBlock *, 4> Visited;
455 MachineBasicBlock *B = &MBB;
457 if (!Visited.insert(B).second)
461 for ( ; It != E; ++It) {
462 if (It->getOpcode() == AMDGPU::SI_KILL_CLEANUP)
464 if (TII->mayReadEXEC(*MRI, *It))
471 if (B->succ_size() != 1)
474 // If there is one trivial successor, advance to the next block.
475 MachineBasicBlock *Succ = *B->succ_begin();
482 void SILowerControlFlow::emitEndCf(MachineInstr &MI) {
483 MachineBasicBlock &MBB = *MI.getParent();
484 MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
485 unsigned CFMask = MI.getOperand(0).getReg();
486 MachineInstr *Def = MRI.getUniqueVRegDef(CFMask);
487 const DebugLoc &DL = MI.getDebugLoc();
489 MachineBasicBlock::iterator InsPt =
490 Def && Def->getParent() == &MBB ? std::next(MachineBasicBlock::iterator(Def))
492 MachineInstr *NewMI = BuildMI(MBB, InsPt, DL, TII->get(OrOpc), Exec)
494 .add(MI.getOperand(0));
496 LoweredEndCf.insert(NewMI);
498 // If this ends control flow which contains kills (as flagged in emitIf)
499 // then insert an SI_KILL_CLEANUP immediately following the exec mask
500 // manipulation. This can be lowered to early termination if appropriate.
501 MachineInstr *CleanUpMI = nullptr;
502 if (NeedsKillCleanup.count(&MI))
503 CleanUpMI = BuildMI(MBB, InsPt, DL, TII->get(AMDGPU::SI_KILL_CLEANUP));
506 LIS->ReplaceMachineInstrInMaps(MI, *NewMI);
508 LIS->InsertMachineInstrInMaps(*CleanUpMI);
511 MI.eraseFromParent();
514 LIS->handleMove(*NewMI);
517 // Returns replace operands for a logical operation, either single result
518 // for exec or two operands if source was another equivalent operation.
519 void SILowerControlFlow::findMaskOperands(MachineInstr &MI, unsigned OpNo,
520 SmallVectorImpl<MachineOperand> &Src) const {
521 MachineOperand &Op = MI.getOperand(OpNo);
522 if (!Op.isReg() || !Register::isVirtualRegister(Op.getReg())) {
527 MachineInstr *Def = MRI->getUniqueVRegDef(Op.getReg());
528 if (!Def || Def->getParent() != MI.getParent() ||
529 !(Def->isFullCopy() || (Def->getOpcode() == MI.getOpcode())))
532 // Make sure we do not modify exec between def and use.
533 // A copy with implcitly defined exec inserted earlier is an exclusion, it
534 // does not really modify exec.
535 for (auto I = Def->getIterator(); I != MI.getIterator(); ++I)
536 if (I->modifiesRegister(AMDGPU::EXEC, TRI) &&
537 !(I->isCopy() && I->getOperand(0).getReg() != Exec))
540 for (const auto &SrcOp : Def->explicit_operands())
541 if (SrcOp.isReg() && SrcOp.isUse() &&
542 (Register::isVirtualRegister(SrcOp.getReg()) || SrcOp.getReg() == Exec))
543 Src.push_back(SrcOp);
546 // Search and combine pairs of equivalent instructions, like
547 // S_AND_B64 x, (S_AND_B64 x, y) => S_AND_B64 x, y
548 // S_OR_B64 x, (S_OR_B64 x, y) => S_OR_B64 x, y
549 // One of the operands is exec mask.
550 void SILowerControlFlow::combineMasks(MachineInstr &MI) {
551 assert(MI.getNumExplicitOperands() == 3);
552 SmallVector<MachineOperand, 4> Ops;
553 unsigned OpToReplace = 1;
554 findMaskOperands(MI, 1, Ops);
555 if (Ops.size() == 1) OpToReplace = 2; // First operand can be exec or its copy
556 findMaskOperands(MI, 2, Ops);
557 if (Ops.size() != 3) return;
559 unsigned UniqueOpndIdx;
560 if (Ops[0].isIdenticalTo(Ops[1])) UniqueOpndIdx = 2;
561 else if (Ops[0].isIdenticalTo(Ops[2])) UniqueOpndIdx = 1;
562 else if (Ops[1].isIdenticalTo(Ops[2])) UniqueOpndIdx = 1;
565 Register Reg = MI.getOperand(OpToReplace).getReg();
566 MI.RemoveOperand(OpToReplace);
567 MI.addOperand(Ops[UniqueOpndIdx]);
568 if (MRI->use_empty(Reg))
569 MRI->getUniqueVRegDef(Reg)->eraseFromParent();
572 void SILowerControlFlow::optimizeEndCf() {
573 // If the only instruction immediately following this END_CF is an another
574 // END_CF in the only successor we can avoid emitting exec mask restore here.
575 if (!RemoveRedundantEndcf)
578 for (MachineInstr *MI : LoweredEndCf) {
579 MachineBasicBlock &MBB = *MI->getParent();
581 skipIgnoreExecInstsTrivialSucc(MBB, std::next(MI->getIterator()));
582 if (Next == MBB.end() || !LoweredEndCf.count(&*Next))
584 // Only skip inner END_CF if outer ENDCF belongs to SI_IF.
585 // If that belongs to SI_ELSE then saved mask has an inverted value.
587 = TII->getNamedOperand(*Next, AMDGPU::OpName::src1)->getReg();
588 assert(SavedExec.isVirtual() && "Expected saved exec to be src1!");
590 const MachineInstr *Def = MRI->getUniqueVRegDef(SavedExec);
591 if (Def && LoweredIf.count(SavedExec)) {
592 LLVM_DEBUG(dbgs() << "Skip redundant "; MI->dump());
594 LIS->RemoveMachineInstrFromMaps(*MI);
595 MI->eraseFromParent();
600 void SILowerControlFlow::process(MachineInstr &MI) {
601 MachineBasicBlock &MBB = *MI.getParent();
602 MachineBasicBlock::iterator I(MI);
603 MachineInstr *Prev = (I != MBB.begin()) ? &*(std::prev(I)) : nullptr;
605 switch (MI.getOpcode()) {
610 case AMDGPU::SI_ELSE:
614 case AMDGPU::SI_IF_BREAK:
618 case AMDGPU::SI_LOOP:
622 case AMDGPU::SI_END_CF:
627 assert(false && "Attempt to process unsupported instruction");
631 MachineBasicBlock::iterator Next;
632 for (I = Prev ? Prev->getIterator() : MBB.begin(); I != MBB.end(); I = Next) {
634 MachineInstr &MaskMI = *I;
635 switch (MaskMI.getOpcode()) {
636 case AMDGPU::S_AND_B64:
637 case AMDGPU::S_OR_B64:
638 case AMDGPU::S_AND_B32:
639 case AMDGPU::S_OR_B32:
640 // Cleanup bit manipulations on exec mask
641 combineMasks(MaskMI);
650 bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
651 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
652 TII = ST.getInstrInfo();
653 TRI = &TII->getRegisterInfo();
655 // This doesn't actually need LiveIntervals, but we can preserve them.
656 LIS = getAnalysisIfAvailable<LiveIntervals>();
657 MRI = &MF.getRegInfo();
658 BoolRC = TRI->getBoolRC();
660 MF.getFunction().getCallingConv() == CallingConv::AMDGPU_PS;
663 AndOpc = AMDGPU::S_AND_B32;
664 OrOpc = AMDGPU::S_OR_B32;
665 XorOpc = AMDGPU::S_XOR_B32;
666 MovTermOpc = AMDGPU::S_MOV_B32_term;
667 Andn2TermOpc = AMDGPU::S_ANDN2_B32_term;
668 XorTermrOpc = AMDGPU::S_XOR_B32_term;
669 OrSaveExecOpc = AMDGPU::S_OR_SAVEEXEC_B32;
670 Exec = AMDGPU::EXEC_LO;
672 AndOpc = AMDGPU::S_AND_B64;
673 OrOpc = AMDGPU::S_OR_B64;
674 XorOpc = AMDGPU::S_XOR_B64;
675 MovTermOpc = AMDGPU::S_MOV_B64_term;
676 Andn2TermOpc = AMDGPU::S_ANDN2_B64_term;
677 XorTermrOpc = AMDGPU::S_XOR_B64_term;
678 OrSaveExecOpc = AMDGPU::S_OR_SAVEEXEC_B64;
682 SmallVector<MachineInstr *, 32> Worklist;
684 MachineFunction::iterator NextBB;
685 for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
686 BI != BE; BI = NextBB) {
687 NextBB = std::next(BI);
688 MachineBasicBlock &MBB = *BI;
690 MachineBasicBlock::iterator I, Next;
691 for (I = MBB.begin(); I != MBB.end(); I = Next) {
693 MachineInstr &MI = *I;
695 switch (MI.getOpcode()) {
700 case AMDGPU::SI_ELSE:
701 case AMDGPU::SI_IF_BREAK:
702 case AMDGPU::SI_LOOP:
703 case AMDGPU::SI_END_CF:
704 // Only build worklist if SI_IF instructions must be processed first.
705 if (InsertKillCleanups)
706 Worklist.push_back(&MI);
717 for (MachineInstr *MI : Worklist)
722 LoweredEndCf.clear();
724 NeedsKillCleanup.clear();