util: Replace recursive DFS with iterative implementation
authorMatt Turner <mattst88@gmail.com>
Thu, 5 Aug 2021 01:47:02 +0000 (18:47 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 17 Aug 2021 17:54:09 +0000 (17:54 +0000)
commitdcf1d8d7a4fe5657a24d4a6799532a39aa117977
tree27ebade816f9c95fddc0ca9686cc85472c337d90
parent9261a020280ea597d1862288bf81771672c10f75
util: Replace recursive DFS with iterative implementation

Doesn't fix, but improves the situation in issue #5163. The
VK.spirv_assembly.instruction.graphics.spirv_ids_abuse.lots_ids_* tests
emit about 160k instructions. ir3_sched blows out the stack after
dag_traverse_bottom_up_node reaches a depth of about 130k frames.

This patch replaces the recursively-implemented post-order traversal
with an iterative implementation using a stack, allowing us to process
DAGs as large as memory can hold.

Definitely makes you appreciate the elegance of recursion...

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12232>
src/util/dag.c