Fortran delayed tree node creation after early return
Fortran compiler now defers creation of unused tree nodes in early return paths.
In the Fortran frontend, the trans_scalar_class_assign function previously created tree nodes that were not utilized if an early return path was taken. This commit optimizes the function by delaying the creation of these nodes until they are actually needed. This change avoids unnecessary computation and memory allocation when the early exit condition is met, improving the efficiency of the Fortran compiler’s expression translation.
In Details
The trans_scalar_class_assign function within gcc/fortran/trans-expr.cc exhibited a minor inefficiency where it would construct GCC tree nodes even if an early return path was taken. This commit modifies the function to defer the creation of these potentially unused tree nodes until after the early return check, ensuring that resources are only consumed when the nodes are essential for subsequent processing. This addresses an optimization opportunity in the Fortran expression lowering pipeline.
- tree nodes
- Internal data structures used by GCC to represent the abstract syntax tree (AST) or intermediate representation (IR) of the code being compiled.
- early return
- A control flow mechanism where a function exits prematurely based on a condition, often before completing all intended operations.
- expression translation
- The process within a compiler where source code expressions are converted into an intermediate representation that the optimizer and code generator can process.
- Fortran frontend
- The part of the GCC compiler responsible for parsing and analyzing Fortran source code.