Skip to content

Commit e00a2ba

Browse files
committed
pr-feedback
Signed-off-by: Nathan Gauër <[email protected]>
1 parent eed75a9 commit e00a2ba

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ class SPIRVStructurizer : public FunctionPass {
449449
createAliasBlocksForComplexEdges(std::vector<Edge> Edges) {
450450
std::unordered_map<BasicBlock *, BasicBlock *> Seen;
451451
std::vector<Edge> Output;
452+
Output.reserve(Edges.size());
452453

453454
for (auto &[Src, Dst] : Edges) {
454455
auto [iterator, inserted] = Seen.insert({Src, Dst});
@@ -613,6 +614,8 @@ class SPIRVStructurizer : public FunctionPass {
613614
// adding an unreachable merge block.
614615
if (Merge == nullptr) {
615616
BranchInst *Br = cast<BranchInst>(BB.getTerminator());
617+
assert(Br &&
618+
"This assumes the branch is not a switch. Maybe that's wrong?");
616619
assert(cast<BranchInst>(BB.getTerminator())->isUnconditional());
617620

618621
Merge = CreateUnreachable(F);
@@ -864,20 +867,21 @@ class SPIRVStructurizer : public FunctionPass {
864867

865868
// Fixup the construct |Node| to respect a set of rules defined by the SPIR-V
866869
// spec.
867-
void fixupConstruct(Splitter &S, DivergentConstruct *Node) {
870+
bool fixupConstruct(Splitter &S, DivergentConstruct *Node) {
871+
bool Modified = false;
868872
for (auto &Child : Node->Children)
869-
fixupConstruct(S, Child.get());
873+
Modified |= fixupConstruct(S, Child.get());
870874

871875
// This construct is the root construct. Does not represent any real
872876
// construct, just a way to access the first level of the forest.
873877
if (Node->Parent == nullptr)
874-
return;
878+
return Modified;
875879

876880
// This node's parent is the root. Meaning this is a top-level construct.
877881
// There can be multiple exists, but all are guaranteed to exit at most 1
878882
// construct since we are at first level.
879883
if (Node->Parent->Header == nullptr)
880-
return;
884+
return Modified;
881885

882886
// Health check for the structure.
883887
assert(Node->Header && Node->Merge);
@@ -888,7 +892,7 @@ class SPIRVStructurizer : public FunctionPass {
888892

889893
// No edges exiting the construct.
890894
if (Edges.size() < 1)
891-
return;
895+
return Modified;
892896

893897
bool HasBadEdge = Node->Merge == Node->Parent->Merge ||
894898
Node->Merge == Node->Parent->Continue;
@@ -914,7 +918,7 @@ class SPIRVStructurizer : public FunctionPass {
914918
}
915919

916920
if (!HasBadEdge)
917-
return;
921+
return Modified;
918922

919923
// Create a single exit node gathering all exit edges.
920924
BasicBlock *NewExit = S.createSingleExitNode(Node->Header, Edges);
@@ -940,6 +944,7 @@ class SPIRVStructurizer : public FunctionPass {
940944
Node->Merge = NewExit;
941945
// Regenerate the dom trees.
942946
S.invalidate();
947+
return true;
943948
}
944949

945950
bool splitCriticalEdges(Function &F) {
@@ -949,9 +954,7 @@ class SPIRVStructurizer : public FunctionPass {
949954
DivergentConstruct Root;
950955
BlockSet Visited;
951956
constructDivergentConstruct(Visited, S, &*F.begin(), &Root);
952-
fixupConstruct(S, &Root);
953-
954-
return true;
957+
return fixupConstruct(S, &Root);
955958
}
956959

957960
// Simplify branches when possible:
@@ -1170,7 +1173,7 @@ class SPIRVStructurizer : public FunctionPass {
11701173

11711174
// STEP 3:
11721175
// Sort selection merge, the largest construct goes first.
1173-
// This simpligies the next step.
1176+
// This simplifies the next step.
11741177
Modified |= sortSelectionMergeHeaders(F);
11751178

11761179
// STEP 4: As this stage, we can have a single basic block with multiple

0 commit comments

Comments
 (0)