GCC: Optimize recog_data state management
Reduces overhead of managing compiler state by using macros and pointer swapping instead of copying large data structures.
This commit refactors the management of recog_data, a global variable used by the instruction extraction process. Instead of copying the large recog_data_d structure, it is now accessed via a macro that dereferences a pointer. This allows saving and restoring its state by simply swapping pointers, significantly reducing overhead. The change also converts several backends (reload, i386, sh) to use a new RAII class recog_state_saver for managing this state, improving efficiency and code robustness.
In Details
The global recog_data structure, populated by extract_insn, represents state that needs careful management due to its non-local effects. Previously, compilers used saves/restores or an RAII class recog_data_saver to manage its state across potentially problematic calls. However, recog_data_d is large, making these operations costly. This patch transforms recog_data into a macro that dereferences a pointer, enabling efficient state management via pointer swaps. It also updates the reload, i386, and sh backends to use the recog_state_saver (renamed from recog_data_saver for clarit…
- recog_data
- A global data structure within GCC that holds state information related to instruction recognition and extraction, typically populated by functions like
extract_insn. - extract_insn
- A GCC internal function responsible for parsing and interpreting instruction patterns from the machine description files.
- RAII
- Resource Acquisition Is Initialization. A programming idiom in C++ where resource management (like acquiring and releasing memory or locks) is tied to the lifetime of objects. An RAII class ensures resources are automatically released when an object goes out of scope.
- recog_data_saver
- An RAII class designed to save and restore the state of the
recog_datastructure, ensuring its integrity across function calls that might modify it unexpectedly. - which_alternative
- A piece of state within GCC's instruction selection mechanism that indicates which specific alternative of an instruction pattern is currently being considered or matched.
- RTL
- Register Transfer Language, GCC's primary intermediate representation. It's a low-level, three-address code-like language used for optimizations and instruction selection.
- wasm backend
- The part of GCC responsible for generating code for the WebAssembly (Wasm) binary instruction format.