Avoid stack overflow in verify_vssa for large functions
Reduces stack usage in `verify_vssa` by replacing recursion with iteration.
The verify_vssa function in GCC, which performs verification of the Value State SSA form, could exhaust stack space when processing very large functions, leading to an internal compiler error (ICE). This commit replaces the recursive implementation of verify_vssa with an iterative one using a worklist. This reduces stack usage and prevents stack overflows when compiling functions with an extreme number of basic blocks.
In Details
The verify_vssa function in tree-ssa.cc recursively traverses the SSA form to verify its correctness. For functions with a very large number of basic blocks, the recursive calls could exceed the available stack space, triggering an ICE. This commit replaces the recursive calls with an iterative approach that uses a worklist (a queue of basic blocks and vdefs to process). This avoids the stack overflow and allows verify_vssa to handle very large functions. The change primarily affects the internal verification process and doesn't alter the generated code.
For Context
Compilers use various internal representations of code during the compilation process. One such representation is Static Single Assignment (SSA) form, which simplifies optimization. To ensure the compiler is working correctly, it performs internal checks to verify that its internal data structures are consistent. This commit fixes a bug where one of these checks, performed by the verify_vssa function, could run out of memory (specifically, stack space) when compiling very large functions. The fix replaces a recursive algorithm with an iterative version that uses less memory, preventing the compiler from crashing.