Skip to content

[SPIR-V] Add partial order tests, assert reducible #117887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,11 @@ bool PartialOrderingVisitor::CanBeVisited(BasicBlock *BB) const {
}

size_t PartialOrderingVisitor::GetNodeRank(BasicBlock *BB) const {
size_t result = 0;
auto It = BlockToOrder.find(BB);
if (It != BlockToOrder.end())
return It->second.Rank;

size_t result = 0;
for (BasicBlock *P : predecessors(BB)) {
// Ignore back-edges.
if (DT.dominates(BB, P))
Expand Down Expand Up @@ -552,15 +555,20 @@ size_t PartialOrderingVisitor::visit(BasicBlock *BB, size_t Unused) {
ToVisit.push(BB);
Queued.insert(BB);

size_t QueueIndex = 0;
while (ToVisit.size() != 0) {
BasicBlock *BB = ToVisit.front();
ToVisit.pop();

if (!CanBeVisited(BB)) {
ToVisit.push(BB);
assert(QueueIndex < ToVisit.size() &&
"No valid candidate in the queue. Is the graph reducible?");
QueueIndex++;
continue;
}

QueueIndex = 0;
size_t Rank = GetNodeRank(BB);
OrderInfo Info = {Rank, BlockToOrder.size()};
BlockToOrder.emplace(BB, Info);
Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class SPIRVSubtarget;
// ignores back-edges. The cycle is visited from the entry in the same
// topological-like ordering.
//
// Note: this visitor REQUIRES a reducible graph.
//
// This means once we visit a node, we know all the possible ancestors have been
// visited.
//
Expand Down Expand Up @@ -84,10 +86,11 @@ class PartialOrderingVisitor {
// Visits |BB| with the current rank being |Rank|.
size_t visit(BasicBlock *BB, size_t Rank);

size_t GetNodeRank(BasicBlock *BB) const;
bool CanBeVisited(BasicBlock *BB) const;

public:
size_t GetNodeRank(BasicBlock *BB) const;

// Build the visitor to operate on the function F.
PartialOrderingVisitor(Function &F);

Expand Down
14 changes: 7 additions & 7 deletions llvm/test/CodeGen/SPIRV/structurizer/cf.switch.ifstmt.simple2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
; b += 2;
; break;
; case 3:
; {
; b += 3;
; break;
; }
; {
; b += 3;
; break;
; }
; case t:
; b += t;
; case 4:
; case 5:
; b += 5;
; break;
; case 6: {
; case 7:
; break;}
; case 7:
; break;}
; default:
; break;
; break;
; }
;
; return a + b + c;
Expand Down
1 change: 1 addition & 0 deletions llvm/unittests/Target/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ set(LLVM_LINK_COMPONENTS
add_llvm_target_unittest(SPIRVTests
SPIRVConvergenceRegionAnalysisTests.cpp
SPIRVSortBlocksTests.cpp
SPIRVPartialOrderingVisitorTests.cpp
SPIRVAPITest.cpp
)
Loading
Loading