Skip to content

Commit c913cfb

Browse files
committed
change set into vector
Signed-off-by: Nathan Gauër <[email protected]>
1 parent 47fa67a commit c913cfb

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ static void processSwitchesConstants(MachineFunction &MF,
781781
// Some instructions are used during CodeGen but should never be emitted.
782782
// Cleaning up those.
783783
static void cleanupHelperInstructions(MachineFunction &MF) {
784-
SmallPtrSet<MachineInstr *, 8> ToEraseMI;
784+
SmallVector<MachineInstr *, 8> ToEraseMI;
785785
for (MachineBasicBlock &MBB : MF) {
786786
for (MachineInstr &MI : MBB) {
787787
if (isSpvIntrinsic(MI, Intrinsic::spv_track_constant) ||
788788
MI.getOpcode() == TargetOpcode::G_BRINDIRECT)
789-
ToEraseMI.insert(&MI);
789+
ToEraseMI.push_back(&MI);
790790
}
791791
}
792792

llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp

+9-25
Original file line numberDiff line numberDiff line change
@@ -491,26 +491,10 @@ class SPIRVStructurizer : public FunctionPass {
491491
DT.recalculate(F);
492492
}
493493

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.
511496
std::vector<BasicBlock *> getLoopConstructBlocks(BasicBlock *Header,
512-
BasicBlock *Merge,
513-
BasicBlock *Continue) {
497+
BasicBlock *Merge) {
514498
assert(DT.dominates(Header, Merge));
515499
std::vector<BasicBlock *> Output;
516500
partialOrderVisit(*Header, [&](BasicBlock *BB) {
@@ -776,10 +760,11 @@ class SPIRVStructurizer : public FunctionPass {
776760

777761
auto *Merge = getExitFor(CR);
778762
// 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.
783768
if (Merge == nullptr) {
784769
BranchInst *Br = cast<BranchInst>(BB.getTerminator());
785770
assert(cast<BranchInst>(BB.getTerminator())->isUnconditional());
@@ -1021,8 +1006,7 @@ class SPIRVStructurizer : public FunctionPass {
10211006
assert(Node->Header && Node->Merge);
10221007

10231008
if (Node->Continue) {
1024-
auto LoopBlocks =
1025-
S.getLoopConstructBlocks(Node->Header, Node->Merge, Node->Continue);
1009+
auto LoopBlocks = S.getLoopConstructBlocks(Node->Header, Node->Merge);
10261010
return BlockSet(LoopBlocks.begin(), LoopBlocks.end());
10271011
}
10281012

0 commit comments

Comments
 (0)