ifcvt: use auto_bitmap for the local hand-managed bitmaps
Replaces manual bitmap management with RAII-style auto_bitmap for improved safety in the ifcvt pass.
Several functions within GCC’s ifcvt pass that manually managed bitmaps using BITMAP_ALLOC and BITMAP_FREE have been updated to use auto_bitmap. This RAII-style approach ensures bitmaps are automatically freed upon exiting the scope, preventing potential memory leaks from incorrect BITMAP_FREE calls, especially when new exit paths are introduced. This change enhances robustness without altering optimization behavior.
In Details
The ifcvt pass frequently uses bitmaps to track sets of basic blocks or instructions. Several helpers previously relied on manual BITMAP allocation and deallocation, which is error-prone. This commit converts these manual allocations to auto_bitmap within functions like dead_or_predicable, bbs_ok_for_cmove_arith, bb_valid_for_noce_process_p, and noce_convert_multiple_sets. This leverages RAII for safer bitmap management and eliminates the need for explicit BITMAP_FREE calls, particularly at goto cleanup labels.
- ifcvt
- The 'if-conversion' optimization pass in GCC. It analyzes conditional branches and attempts to transform them into predicated instructions or other forms that reduce control flow overhead.
- auto_bitmap
- A C++ class in GCC that provides RAII (Resource Acquisition Is Initialization) for bitmaps. It automatically allocates a bitmap on construction and deallocates it on destruction, ensuring memory safety without manual free calls.
- BITMAP_ALLOC
- A macro in GCC used to dynamically allocate memory for a bitmap data structure.
- BITMAP_FREE
- A macro in GCC used to deallocate memory previously allocated for a bitmap.
- RAII
- Resource Acquisition Is Initialization. A C++ programming idiom where resource management (like memory allocation/deallocation) is tied to object lifetimes. Ensures resources are released automatically when objects go out of scope.
- basic block
- A sequence of instructions with a single entry point and a single exit point. Compilers often analyze code at the basic block level.