Cobol: Reduce VAR_DECL count and improve GENERIC representation
Cobol front-end reduces generated VAR_DECLs by over half, speeding up compilation and lowering memory usage.
The COBOL front-end has been significantly refactored to reduce the number of VAR_DECL nodes generated, particularly for large programs. This optimization stems from a better understanding of when variables need to be materialized versus when they can remain as temporary expression tree nodes. The changes also improve the consistency of GENERIC representation with other front-ends and fix several type-related bugs.
In Details
The COBOL front-end's initial implementation, developed while learning GCC internals, created an excessive number of VAR_DECLs. This commit revises variable materialization logic, reducing VAR_DECL counts from 2.28 million to 0.8 million for a large test case, thereby improving compile times and memory footprint. It also aligns GENERIC generation with other front-ends and resolves type mismatches in function return values.
- VAR_DECL
- A GCC internal Abstract Syntax Tree (AST) node representing a variable declaration. Excessive VAR_DECLs can increase memory usage and compilation time.
- GENERIC
- An intermediate representation (IR) in GCC, used after the front-end parses the source code and before optimization passes.
- expression tree nodes
- Internal data structures used by the compiler to represent parts of the code, such as expressions. If a variable can be represented by a temporary expression node, it may not need a full VAR_DECL.