summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
index e63e25aa6..6021ac891 100644
--- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
@@ -304,6 +304,23 @@ bool SearchNode(const Tree& tree, ConstNode stmt, size_t& offset) {
304 return false; 304 return false;
305} 305}
306 306
307bool AreSiblings(Node goto_stmt, Node label_stmt) noexcept {
308 Node it{goto_stmt};
309 do {
310 if (it == label_stmt) {
311 return true;
312 }
313 --it;
314 } while (it != goto_stmt->up->children.begin());
315 while (it != goto_stmt->up->children.end()) {
316 if (it == label_stmt) {
317 return true;
318 }
319 ++it;
320 }
321 return false;
322}
323
307class GotoPass { 324class GotoPass {
308public: 325public:
309 explicit GotoPass(Flow::CFG& cfg, ObjectPool<IR::Inst>& inst_pool_, 326 explicit GotoPass(Flow::CFG& cfg, ObjectPool<IR::Inst>& inst_pool_,
@@ -353,22 +370,10 @@ private:
353 } 370 }
354 } 371 }
355 } 372 }
356 // TODO: Remove this 373 // Expensive operation:
357 { 374 // if (!AreSiblings(goto_stmt, label_stmt)) {
358 Node it{goto_stmt}; 375 // throw LogicError("Goto is not a sibling with the label");
359 bool sibling{false}; 376 // }
360 do {
361 sibling |= it == label_stmt;
362 --it;
363 } while (it != goto_stmt->up->children.begin());
364 while (it != goto_stmt->up->children.end()) {
365 sibling |= it == label_stmt;
366 ++it;
367 }
368 if (!sibling) {
369 throw LogicError("Not siblings");
370 }
371 }
372 // goto_stmt and label_stmt are guaranteed to be siblings, eliminate 377 // goto_stmt and label_stmt are guaranteed to be siblings, eliminate
373 if (std::next(goto_stmt) == label_stmt) { 378 if (std::next(goto_stmt) == label_stmt) {
374 // Simply eliminate the goto if the label is next to it 379 // Simply eliminate the goto if the label is next to it