@@ -491,26 +491,10 @@ class SPIRVStructurizer : public FunctionPass {
491
491
DT.recalculate (F);
492
492
}
493
493
494
- // Returns the list of blocks that belong to a SPIR-V continue construct.
495
- std::vector<BasicBlock *> getContinueConstructBlocks (BasicBlock *Header,
496
- BasicBlock *Continue) {
497
- std::vector<BasicBlock *> Output;
498
- Loop *L = LI.getLoopFor (Continue);
499
- assert (L->getLoopLatch () != nullptr );
500
-
501
- partialOrderVisit (*Continue, [&](BasicBlock *BB) {
502
- if (BB == Header)
503
- return false ;
504
- Output.push_back (BB);
505
- return true ;
506
- });
507
- return Output;
508
- }
509
-
510
- // Returns the list of blocks that belong to a SPIR-V loop construct.
494
+ // Returns the list of blocks that belong to a SPIR-V loop construct,
495
+ // including the continue construct.
511
496
std::vector<BasicBlock *> getLoopConstructBlocks (BasicBlock *Header,
512
- BasicBlock *Merge,
513
- BasicBlock *Continue) {
497
+ BasicBlock *Merge) {
514
498
assert (DT.dominates (Header, Merge));
515
499
std::vector<BasicBlock *> Output;
516
500
partialOrderVisit (*Header, [&](BasicBlock *BB) {
@@ -776,10 +760,11 @@ class SPIRVStructurizer : public FunctionPass {
776
760
777
761
auto *Merge = getExitFor (CR);
778
762
// We are indeed in a loop, but there are no exits (infinite loop).
779
- // TODO: I see no value in having real infinite loops in vulkan shaders.
780
- // For now, I need to create a Merge block, and a structurally reachable
781
- // block for it, but maybe we'd want to raise an error, as locking up the
782
- // system is probably not wanted.
763
+ // This could be caused by a bad shader, but also could be an artifact
764
+ // from an earlier optimization. It is not always clear if structurally
765
+ // reachable means runtime reachable, so we cannot error-out. What we must
766
+ // do however is to make is legal on the SPIR-V point of view, hence
767
+ // adding an unreachable merge block.
783
768
if (Merge == nullptr ) {
784
769
BranchInst *Br = cast<BranchInst>(BB.getTerminator ());
785
770
assert (cast<BranchInst>(BB.getTerminator ())->isUnconditional ());
@@ -1021,8 +1006,7 @@ class SPIRVStructurizer : public FunctionPass {
1021
1006
assert (Node->Header && Node->Merge );
1022
1007
1023
1008
if (Node->Continue ) {
1024
- auto LoopBlocks =
1025
- S.getLoopConstructBlocks (Node->Header , Node->Merge , Node->Continue );
1009
+ auto LoopBlocks = S.getLoopConstructBlocks (Node->Header , Node->Merge );
1026
1010
return BlockSet (LoopBlocks.begin (), LoopBlocks.end ());
1027
1011
}
1028
1012
0 commit comments