1 //===- R600ControlFlowFinalizer.cpp - Finalize Control Flow Inst ----------===//
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 compute turns all control flow pseudo instructions into native one
11 /// computing their address on the fly; it also sets STACK_SIZE info.
13 //===----------------------------------------------------------------------===//
16 #include "AMDGPUSubtarget.h"
17 #include "R600Defines.h"
18 #include "R600InstrInfo.h"
19 #include "R600MachineFunctionInfo.h"
20 #include "R600RegisterInfo.h"
21 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
22 #include "llvm/ADT/STLExtras.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/CodeGen/MachineBasicBlock.h"
26 #include "llvm/CodeGen/MachineFunction.h"
27 #include "llvm/CodeGen/MachineFunctionPass.h"
28 #include "llvm/CodeGen/MachineInstr.h"
29 #include "llvm/CodeGen/MachineInstrBuilder.h"
30 #include "llvm/CodeGen/MachineOperand.h"
31 #include "llvm/IR/CallingConv.h"
32 #include "llvm/IR/DebugLoc.h"
33 #include "llvm/IR/Function.h"
34 #include "llvm/Pass.h"
35 #include "llvm/Support/Compiler.h"
36 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/MathExtras.h"
38 #include "llvm/Support/raw_ostream.h"
48 #define DEBUG_TYPE "r600cf"
56 FIRST_NON_WQM_PUSH
= 2,
57 FIRST_NON_WQM_PUSH_W_FULL_ENTRY
= 3
60 const R600Subtarget
*ST
;
61 std::vector
<StackItem
> BranchStack
;
62 std::vector
<StackItem
> LoopStack
;
63 unsigned MaxStackSize
;
64 unsigned CurrentEntries
= 0;
65 unsigned CurrentSubEntries
= 0;
67 CFStack(const R600Subtarget
*st
, CallingConv::ID cc
) : ST(st
),
68 // We need to reserve a stack entry for CALL_FS in vertex shaders.
69 MaxStackSize(cc
== CallingConv::AMDGPU_VS
? 1 : 0) {}
71 unsigned getLoopDepth();
72 bool branchStackContains(CFStack::StackItem
);
73 bool requiresWorkAroundForInst(unsigned Opcode
);
74 unsigned getSubEntrySize(CFStack::StackItem Item
);
75 void updateMaxStackSize();
76 void pushBranch(unsigned Opcode
, bool isWQM
= false);
82 unsigned CFStack::getLoopDepth() {
83 return LoopStack
.size();
86 bool CFStack::branchStackContains(CFStack::StackItem Item
) {
87 for (std::vector
<CFStack::StackItem
>::const_iterator I
= BranchStack
.begin(),
88 E
= BranchStack
.end(); I
!= E
; ++I
) {
95 bool CFStack::requiresWorkAroundForInst(unsigned Opcode
) {
96 if (Opcode
== R600::CF_ALU_PUSH_BEFORE
&& ST
->hasCaymanISA() &&
100 if (!ST
->hasCFAluBug())
104 default: return false;
105 case R600::CF_ALU_PUSH_BEFORE
:
106 case R600::CF_ALU_ELSE_AFTER
:
107 case R600::CF_ALU_BREAK
:
108 case R600::CF_ALU_CONTINUE
:
109 if (CurrentSubEntries
== 0)
111 if (ST
->getWavefrontSize() == 64) {
112 // We are being conservative here. We only require this work-around if
113 // CurrentSubEntries > 3 &&
114 // (CurrentSubEntries % 4 == 3 || CurrentSubEntries % 4 == 0)
116 // We have to be conservative, because we don't know for certain that
117 // our stack allocation algorithm for Evergreen/NI is correct. Applying this
118 // work-around when CurrentSubEntries > 3 allows us to over-allocate stack
119 // resources without any problems.
120 return CurrentSubEntries
> 3;
122 assert(ST
->getWavefrontSize() == 32);
123 // We are being conservative here. We only require the work-around if
124 // CurrentSubEntries > 7 &&
125 // (CurrentSubEntries % 8 == 7 || CurrentSubEntries % 8 == 0)
126 // See the comment on the wavefront size == 64 case for why we are
127 // being conservative.
128 return CurrentSubEntries
> 7;
133 unsigned CFStack::getSubEntrySize(CFStack::StackItem Item
) {
137 case CFStack::FIRST_NON_WQM_PUSH
:
138 assert(!ST
->hasCaymanISA());
139 if (ST
->getGeneration() <= AMDGPUSubtarget::R700
) {
140 // +1 For the push operation.
141 // +2 Extra space required.
144 // Some documentation says that this is not necessary on Evergreen,
145 // but experimentation has show that we need to allocate 1 extra
146 // sub-entry for the first non-WQM push.
147 // +1 For the push operation.
148 // +1 Extra space required.
151 case CFStack::FIRST_NON_WQM_PUSH_W_FULL_ENTRY
:
152 assert(ST
->getGeneration() >= AMDGPUSubtarget::EVERGREEN
);
153 // +1 For the push operation.
154 // +1 Extra space required.
156 case CFStack::SUB_ENTRY
:
161 void CFStack::updateMaxStackSize() {
162 unsigned CurrentStackSize
=
163 CurrentEntries
+ (alignTo(CurrentSubEntries
, 4) / 4);
164 MaxStackSize
= std::max(CurrentStackSize
, MaxStackSize
);
167 void CFStack::pushBranch(unsigned Opcode
, bool isWQM
) {
168 CFStack::StackItem Item
= CFStack::ENTRY
;
170 case R600::CF_PUSH_EG
:
171 case R600::CF_ALU_PUSH_BEFORE
:
173 if (!ST
->hasCaymanISA() &&
174 !branchStackContains(CFStack::FIRST_NON_WQM_PUSH
))
175 Item
= CFStack::FIRST_NON_WQM_PUSH
; // May not be required on Evergreen/NI
177 // CFStack::getSubEntrySize()
178 else if (CurrentEntries
> 0 &&
179 ST
->getGeneration() > AMDGPUSubtarget::EVERGREEN
&&
180 !ST
->hasCaymanISA() &&
181 !branchStackContains(CFStack::FIRST_NON_WQM_PUSH_W_FULL_ENTRY
))
182 Item
= CFStack::FIRST_NON_WQM_PUSH_W_FULL_ENTRY
;
184 Item
= CFStack::SUB_ENTRY
;
186 Item
= CFStack::ENTRY
;
189 BranchStack
.push_back(Item
);
190 if (Item
== CFStack::ENTRY
)
193 CurrentSubEntries
+= getSubEntrySize(Item
);
194 updateMaxStackSize();
197 void CFStack::pushLoop() {
198 LoopStack
.push_back(CFStack::ENTRY
);
200 updateMaxStackSize();
203 void CFStack::popBranch() {
204 CFStack::StackItem Top
= BranchStack
.back();
205 if (Top
== CFStack::ENTRY
)
208 CurrentSubEntries
-= getSubEntrySize(Top
);
209 BranchStack
.pop_back();
212 void CFStack::popLoop() {
214 LoopStack
.pop_back();
217 class R600ControlFlowFinalizer
: public MachineFunctionPass
{
219 using ClauseFile
= std::pair
<MachineInstr
*, std::vector
<MachineInstr
*>>;
221 enum ControlFlowInstruction
{
235 const R600InstrInfo
*TII
= nullptr;
236 const R600RegisterInfo
*TRI
= nullptr;
237 unsigned MaxFetchInst
;
238 const R600Subtarget
*ST
= nullptr;
240 bool IsTrivialInst(MachineInstr
&MI
) const {
241 switch (MI
.getOpcode()) {
250 const MCInstrDesc
&getHWInstrDesc(ControlFlowInstruction CFI
) const {
252 bool isEg
= (ST
->getGeneration() >= AMDGPUSubtarget::EVERGREEN
);
255 Opcode
= isEg
? R600::CF_TC_EG
: R600::CF_TC_R600
;
258 Opcode
= isEg
? R600::CF_VC_EG
: R600::CF_VC_R600
;
261 Opcode
= isEg
? R600::CF_CALL_FS_EG
: R600::CF_CALL_FS_R600
;
264 Opcode
= isEg
? R600::WHILE_LOOP_EG
: R600::WHILE_LOOP_R600
;
267 Opcode
= isEg
? R600::END_LOOP_EG
: R600::END_LOOP_R600
;
270 Opcode
= isEg
? R600::LOOP_BREAK_EG
: R600::LOOP_BREAK_R600
;
272 case CF_LOOP_CONTINUE
:
273 Opcode
= isEg
? R600::CF_CONTINUE_EG
: R600::CF_CONTINUE_R600
;
276 Opcode
= isEg
? R600::CF_JUMP_EG
: R600::CF_JUMP_R600
;
279 Opcode
= isEg
? R600::CF_ELSE_EG
: R600::CF_ELSE_R600
;
282 Opcode
= isEg
? R600::POP_EG
: R600::POP_R600
;
285 if (ST
->hasCaymanISA()) {
286 Opcode
= R600::CF_END_CM
;
289 Opcode
= isEg
? R600::CF_END_EG
: R600::CF_END_R600
;
292 assert (Opcode
&& "No opcode selected");
293 return TII
->get(Opcode
);
296 bool isCompatibleWithClause(const MachineInstr
&MI
,
297 std::set
<unsigned> &DstRegs
) const {
298 unsigned DstMI
, SrcMI
;
299 for (MachineInstr::const_mop_iterator I
= MI
.operands_begin(),
300 E
= MI
.operands_end();
302 const MachineOperand
&MO
= *I
;
306 Register Reg
= MO
.getReg();
307 if (R600::R600_Reg128RegClass
.contains(Reg
))
310 DstMI
= TRI
->getMatchingSuperReg(Reg
,
311 AMDGPURegisterInfo::getSubRegFromChannel(TRI
->getHWRegChan(Reg
)),
312 &R600::R600_Reg128RegClass
);
315 Register Reg
= MO
.getReg();
316 if (R600::R600_Reg128RegClass
.contains(Reg
))
319 SrcMI
= TRI
->getMatchingSuperReg(Reg
,
320 AMDGPURegisterInfo::getSubRegFromChannel(TRI
->getHWRegChan(Reg
)),
321 &R600::R600_Reg128RegClass
);
324 if ((DstRegs
.find(SrcMI
) == DstRegs
.end())) {
325 DstRegs
.insert(DstMI
);
332 MakeFetchClause(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator
&I
)
334 MachineBasicBlock::iterator ClauseHead
= I
;
335 std::vector
<MachineInstr
*> ClauseContent
;
336 unsigned AluInstCount
= 0;
337 bool IsTex
= TII
->usesTextureCache(*ClauseHead
);
338 std::set
<unsigned> DstRegs
;
339 for (MachineBasicBlock::iterator E
= MBB
.end(); I
!= E
; ++I
) {
340 if (IsTrivialInst(*I
))
342 if (AluInstCount
>= MaxFetchInst
)
344 if ((IsTex
&& !TII
->usesTextureCache(*I
)) ||
345 (!IsTex
&& !TII
->usesVertexCache(*I
)))
347 if (!isCompatibleWithClause(*I
, DstRegs
))
350 ClauseContent
.push_back(&*I
);
352 MachineInstr
*MIb
= BuildMI(MBB
, ClauseHead
, MBB
.findDebugLoc(ClauseHead
),
353 getHWInstrDesc(IsTex
?CF_TC
:CF_VC
))
355 .addImm(AluInstCount
- 1); // COUNT
356 return ClauseFile(MIb
, std::move(ClauseContent
));
359 void getLiteral(MachineInstr
&MI
, std::vector
<MachineOperand
*> &Lits
) const {
360 static const unsigned LiteralRegs
[] = {
366 const SmallVector
<std::pair
<MachineOperand
*, int64_t>, 3> Srcs
=
368 for (const auto &Src
:Srcs
) {
369 if (Src
.first
->getReg() != R600::ALU_LITERAL_X
)
371 int64_t Imm
= Src
.second
;
372 std::vector
<MachineOperand
*>::iterator It
=
373 llvm::find_if(Lits
, [&](MachineOperand
*val
) {
374 return val
->isImm() && (val
->getImm() == Imm
);
377 // Get corresponding Operand
378 MachineOperand
&Operand
= MI
.getOperand(
379 TII
->getOperandIdx(MI
.getOpcode(), R600::OpName::literal
));
381 if (It
!= Lits
.end()) {
382 // Reuse existing literal reg
383 unsigned Index
= It
- Lits
.begin();
384 Src
.first
->setReg(LiteralRegs
[Index
]);
386 // Allocate new literal reg
387 assert(Lits
.size() < 4 && "Too many literals in Instruction Group");
388 Src
.first
->setReg(LiteralRegs
[Lits
.size()]);
389 Lits
.push_back(&Operand
);
394 MachineBasicBlock::iterator
insertLiterals(
395 MachineBasicBlock::iterator InsertPos
,
396 const std::vector
<unsigned> &Literals
) const {
397 MachineBasicBlock
*MBB
= InsertPos
->getParent();
398 for (unsigned i
= 0, e
= Literals
.size(); i
< e
; i
+=2) {
399 unsigned LiteralPair0
= Literals
[i
];
400 unsigned LiteralPair1
= (i
+ 1 < e
)?Literals
[i
+ 1]:0;
401 InsertPos
= BuildMI(MBB
, InsertPos
->getDebugLoc(),
402 TII
->get(R600::LITERALS
))
403 .addImm(LiteralPair0
)
404 .addImm(LiteralPair1
);
410 MakeALUClause(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator
&I
)
412 MachineInstr
&ClauseHead
= *I
;
413 std::vector
<MachineInstr
*> ClauseContent
;
415 for (MachineBasicBlock::instr_iterator E
= MBB
.instr_end(); I
!= E
;) {
416 if (IsTrivialInst(*I
)) {
420 if (!I
->isBundle() && !TII
->isALUInstr(I
->getOpcode()))
422 std::vector
<MachineOperand
*>Literals
;
424 MachineInstr
&DeleteMI
= *I
;
425 MachineBasicBlock::instr_iterator BI
= I
.getInstrIterator();
426 while (++BI
!= E
&& BI
->isBundledWithPred()) {
427 BI
->unbundleFromPred();
428 for (MachineOperand
&MO
: BI
->operands()) {
429 if (MO
.isReg() && MO
.isInternalRead())
430 MO
.setIsInternalRead(false);
432 getLiteral(*BI
, Literals
);
433 ClauseContent
.push_back(&*BI
);
436 DeleteMI
.eraseFromParent();
438 getLiteral(*I
, Literals
);
439 ClauseContent
.push_back(&*I
);
442 for (unsigned i
= 0, e
= Literals
.size(); i
< e
; i
+= 2) {
443 MachineInstrBuilder MILit
= BuildMI(MBB
, I
, I
->getDebugLoc(),
444 TII
->get(R600::LITERALS
));
445 if (Literals
[i
]->isImm()) {
446 MILit
.addImm(Literals
[i
]->getImm());
448 MILit
.addGlobalAddress(Literals
[i
]->getGlobal(),
449 Literals
[i
]->getOffset());
452 if (Literals
[i
+ 1]->isImm()) {
453 MILit
.addImm(Literals
[i
+ 1]->getImm());
455 MILit
.addGlobalAddress(Literals
[i
+ 1]->getGlobal(),
456 Literals
[i
+ 1]->getOffset());
460 ClauseContent
.push_back(MILit
);
463 assert(ClauseContent
.size() < 128 && "ALU clause is too big");
464 ClauseHead
.getOperand(7).setImm(ClauseContent
.size() - 1);
465 return ClauseFile(&ClauseHead
, std::move(ClauseContent
));
468 void EmitFetchClause(MachineBasicBlock::iterator InsertPos
,
469 const DebugLoc
&DL
, ClauseFile
&Clause
,
471 CounterPropagateAddr(*Clause
.first
, CfCount
);
472 MachineBasicBlock
*BB
= Clause
.first
->getParent();
473 BuildMI(BB
, DL
, TII
->get(R600::FETCH_CLAUSE
)).addImm(CfCount
);
474 for (unsigned i
= 0, e
= Clause
.second
.size(); i
< e
; ++i
) {
475 BB
->splice(InsertPos
, BB
, Clause
.second
[i
]);
477 CfCount
+= 2 * Clause
.second
.size();
480 void EmitALUClause(MachineBasicBlock::iterator InsertPos
, const DebugLoc
&DL
,
481 ClauseFile
&Clause
, unsigned &CfCount
) {
482 Clause
.first
->getOperand(0).setImm(0);
483 CounterPropagateAddr(*Clause
.first
, CfCount
);
484 MachineBasicBlock
*BB
= Clause
.first
->getParent();
485 BuildMI(BB
, DL
, TII
->get(R600::ALU_CLAUSE
)).addImm(CfCount
);
486 for (unsigned i
= 0, e
= Clause
.second
.size(); i
< e
; ++i
) {
487 BB
->splice(InsertPos
, BB
, Clause
.second
[i
]);
489 CfCount
+= Clause
.second
.size();
492 void CounterPropagateAddr(MachineInstr
&MI
, unsigned Addr
) const {
493 MI
.getOperand(0).setImm(Addr
+ MI
.getOperand(0).getImm());
495 void CounterPropagateAddr(const std::set
<MachineInstr
*> &MIs
,
496 unsigned Addr
) const {
497 for (MachineInstr
*MI
: MIs
) {
498 CounterPropagateAddr(*MI
, Addr
);
505 R600ControlFlowFinalizer() : MachineFunctionPass(ID
) {}
507 bool runOnMachineFunction(MachineFunction
&MF
) override
{
508 ST
= &MF
.getSubtarget
<R600Subtarget
>();
509 MaxFetchInst
= ST
->getTexVTXClauseSize();
510 TII
= ST
->getInstrInfo();
511 TRI
= ST
->getRegisterInfo();
513 R600MachineFunctionInfo
*MFI
= MF
.getInfo
<R600MachineFunctionInfo
>();
515 CFStack
CFStack(ST
, MF
.getFunction().getCallingConv());
516 for (MachineFunction::iterator MB
= MF
.begin(), ME
= MF
.end(); MB
!= ME
;
518 MachineBasicBlock
&MBB
= *MB
;
519 unsigned CfCount
= 0;
520 std::vector
<std::pair
<unsigned, std::set
<MachineInstr
*>>> LoopStack
;
521 std::vector
<MachineInstr
* > IfThenElseStack
;
522 if (MF
.getFunction().getCallingConv() == CallingConv::AMDGPU_VS
) {
523 BuildMI(MBB
, MBB
.begin(), MBB
.findDebugLoc(MBB
.begin()),
524 getHWInstrDesc(CF_CALL_FS
));
527 std::vector
<ClauseFile
> FetchClauses
, AluClauses
;
528 std::vector
<MachineInstr
*> LastAlu(1);
529 std::vector
<MachineInstr
*> ToPopAfter
;
531 for (MachineBasicBlock::iterator I
= MBB
.begin(), E
= MBB
.end();
533 if (TII
->usesTextureCache(*I
) || TII
->usesVertexCache(*I
)) {
534 LLVM_DEBUG(dbgs() << CfCount
<< ":"; I
->dump(););
535 FetchClauses
.push_back(MakeFetchClause(MBB
, I
));
537 LastAlu
.back() = nullptr;
541 MachineBasicBlock::iterator MI
= I
;
542 if (MI
->getOpcode() != R600::ENDIF
)
543 LastAlu
.back() = nullptr;
544 if (MI
->getOpcode() == R600::CF_ALU
)
545 LastAlu
.back() = &*MI
;
547 bool RequiresWorkAround
=
548 CFStack
.requiresWorkAroundForInst(MI
->getOpcode());
549 switch (MI
->getOpcode()) {
550 case R600::CF_ALU_PUSH_BEFORE
:
551 if (RequiresWorkAround
) {
553 << "Applying bug work-around for ALU_PUSH_BEFORE\n");
554 BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
), TII
->get(R600::CF_PUSH_EG
))
557 MI
->setDesc(TII
->get(R600::CF_ALU
));
559 CFStack
.pushBranch(R600::CF_PUSH_EG
);
561 CFStack
.pushBranch(R600::CF_ALU_PUSH_BEFORE
);
565 AluClauses
.push_back(MakeALUClause(MBB
, I
));
566 LLVM_DEBUG(dbgs() << CfCount
<< ":"; MI
->dump(););
569 case R600::WHILELOOP
: {
571 MachineInstr
*MIb
= BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
),
572 getHWInstrDesc(CF_WHILE_LOOP
))
574 std::pair
<unsigned, std::set
<MachineInstr
*>> Pair(CfCount
,
575 std::set
<MachineInstr
*>());
576 Pair
.second
.insert(MIb
);
577 LoopStack
.push_back(std::move(Pair
));
578 MI
->eraseFromParent();
582 case R600::ENDLOOP
: {
584 std::pair
<unsigned, std::set
<MachineInstr
*>> Pair
=
585 std::move(LoopStack
.back());
586 LoopStack
.pop_back();
587 CounterPropagateAddr(Pair
.second
, CfCount
);
588 BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
), getHWInstrDesc(CF_END_LOOP
))
589 .addImm(Pair
.first
+ 1);
590 MI
->eraseFromParent();
594 case R600::IF_PREDICATE_SET
: {
595 LastAlu
.push_back(nullptr);
596 MachineInstr
*MIb
= BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
),
597 getHWInstrDesc(CF_JUMP
))
600 IfThenElseStack
.push_back(MIb
);
601 LLVM_DEBUG(dbgs() << CfCount
<< ":"; MIb
->dump(););
602 MI
->eraseFromParent();
607 MachineInstr
* JumpInst
= IfThenElseStack
.back();
608 IfThenElseStack
.pop_back();
609 CounterPropagateAddr(*JumpInst
, CfCount
);
610 MachineInstr
*MIb
= BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
),
611 getHWInstrDesc(CF_ELSE
))
614 LLVM_DEBUG(dbgs() << CfCount
<< ":"; MIb
->dump(););
615 IfThenElseStack
.push_back(MIb
);
616 MI
->eraseFromParent();
622 if (LastAlu
.back()) {
623 ToPopAfter
.push_back(LastAlu
.back());
625 MachineInstr
*MIb
= BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
),
626 getHWInstrDesc(CF_POP
))
630 LLVM_DEBUG(dbgs() << CfCount
<< ":"; MIb
->dump(););
634 MachineInstr
*IfOrElseInst
= IfThenElseStack
.back();
635 IfThenElseStack
.pop_back();
636 CounterPropagateAddr(*IfOrElseInst
, CfCount
);
637 IfOrElseInst
->getOperand(1).setImm(1);
639 MI
->eraseFromParent();
644 MachineInstr
*MIb
= BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
),
645 getHWInstrDesc(CF_LOOP_BREAK
))
647 LoopStack
.back().second
.insert(MIb
);
648 MI
->eraseFromParent();
651 case R600::CONTINUE
: {
652 MachineInstr
*MIb
= BuildMI(MBB
, MI
, MBB
.findDebugLoc(MI
),
653 getHWInstrDesc(CF_LOOP_CONTINUE
))
655 LoopStack
.back().second
.insert(MIb
);
656 MI
->eraseFromParent();
661 DebugLoc DL
= MBB
.findDebugLoc(MI
);
662 BuildMI(MBB
, MI
, DL
, getHWInstrDesc(CF_END
));
665 BuildMI(MBB
, I
, DL
, TII
->get(R600::PAD
));
668 MI
->eraseFromParent();
669 for (unsigned i
= 0, e
= FetchClauses
.size(); i
< e
; i
++)
670 EmitFetchClause(I
, DL
, FetchClauses
[i
], CfCount
);
671 for (unsigned i
= 0, e
= AluClauses
.size(); i
< e
; i
++)
672 EmitALUClause(I
, DL
, AluClauses
[i
], CfCount
);
676 if (TII
->isExport(MI
->getOpcode())) {
677 LLVM_DEBUG(dbgs() << CfCount
<< ":"; MI
->dump(););
683 for (unsigned i
= 0, e
= ToPopAfter
.size(); i
< e
; ++i
) {
684 MachineInstr
*Alu
= ToPopAfter
[i
];
685 BuildMI(MBB
, Alu
, MBB
.findDebugLoc((MachineBasicBlock::iterator
)Alu
),
686 TII
->get(R600::CF_ALU_POP_AFTER
))
687 .addImm(Alu
->getOperand(0).getImm())
688 .addImm(Alu
->getOperand(1).getImm())
689 .addImm(Alu
->getOperand(2).getImm())
690 .addImm(Alu
->getOperand(3).getImm())
691 .addImm(Alu
->getOperand(4).getImm())
692 .addImm(Alu
->getOperand(5).getImm())
693 .addImm(Alu
->getOperand(6).getImm())
694 .addImm(Alu
->getOperand(7).getImm())
695 .addImm(Alu
->getOperand(8).getImm());
696 Alu
->eraseFromParent();
698 MFI
->CFStackSize
= CFStack
.MaxStackSize
;
704 StringRef
getPassName() const override
{
705 return "R600 Control Flow Finalizer Pass";
709 } // end anonymous namespace
711 INITIALIZE_PASS_BEGIN(R600ControlFlowFinalizer
, DEBUG_TYPE
,
712 "R600 Control Flow Finalizer", false, false)
713 INITIALIZE_PASS_END(R600ControlFlowFinalizer
, DEBUG_TYPE
,
714 "R600 Control Flow Finalizer", false, false)
716 char R600ControlFlowFinalizer::ID
= 0;
718 char &llvm::R600ControlFlowFinalizerID
= R600ControlFlowFinalizer::ID
;
720 FunctionPass
*llvm::createR600ControlFlowFinalizer() {
721 return new R600ControlFlowFinalizer();