Skip to content

Commit 2b8b4a8

Browse files
MrSidimsAlexeySotkin
authored andcommitted
Fix comments
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent ce647ca commit 2b8b4a8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,8 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
16201620
spv::LoopControlMask LoopControl = getLoopControl(Branch, Parameters);
16211621

16221622
if (Branch->isUnconditional()) {
1623-
// Usually for "for" and "while" loops llvm.loop metadata is attached to
1624-
// an unconditional branch instruction.
1623+
// Usually, "for" and "while" loops llvm.loop metadata is attached to an
1624+
// unconditional branch instruction.
16251625
if (LoopControl != spv::LoopControlMaskNone) {
16261626
// SuccessorTrue is the loop header BB.
16271627
const SPIRVInstruction *Term = SuccessorTrue->getTerminateInstr();
@@ -1642,16 +1642,23 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
16421642
}
16431643
return mapValue(V, BM->addBranchInst(SuccessorTrue, BB));
16441644
}
1645-
// For "do-while" and in some cases for "for" and "while" loops llvm.loop
1646-
// metadata is attached to a conditional branch instructions
1645+
// For "do-while" (and in some cases, for "for" and "while") loops,
1646+
// llvm.loop metadata is attached to a conditional branch instructions
16471647
SPIRVLabel *SuccessorFalse =
16481648
static_cast<SPIRVLabel *>(transValue(Branch->getSuccessor(1), BB));
16491649
if (LoopControl != spv::LoopControlMaskNone) {
16501650
Function *Fun = Branch->getFunction();
16511651
DominatorTree DomTree(*Fun);
16521652
LoopInfo LI(DomTree);
16531653
for (const auto *LoopObj : LI.getLoopsInPreorder()) {
1654-
// Check whether SuccessorFalse or SuccessorTrue is the loop header BB
1654+
// Check whether SuccessorFalse or SuccessorTrue is the loop header BB.
1655+
// For example consider following LLVM IR:
1656+
// br i1 %compare, label %for.body, label %for.end
1657+
// <- SuccessorTrue is 'for.body' aka successor(0)
1658+
// br i1 %compare.not, label %for.end, label %for.body
1659+
// <- SuccessorTrue is 'for.end' aka successor(1)
1660+
// meanwhile the true successor (by definition) should be a loop header
1661+
// aka 'for.body'
16551662
if (LoopObj->getHeader() == Branch->getSuccessor(1))
16561663
// SuccessorFalse is the loop header BB.
16571664
BM->addLoopMergeInst(SuccessorTrue->getId(), // Merge Block

0 commit comments

Comments
 (0)