Optimizes memory layout for Ada tagged type data
This commit improves the memory layout of type-specific data records for Ada tagged types, reducing memory consumption on 64-bit targets.
The compiler now optimizes the layout of Type_Specific_Data records used with Ada tagged types. By reordering boolean components to immediately follow natural components, the compiler saves one 64-bit word for each record on 64-bit architectures. This change directly translates to reduced memory usage for applications heavily utilizing tagged types, improving overall footprint efficiency.
In Details
In Ada, tagged types support object-oriented programming with dispatching calls. Each tagged type has associated Type_Specific_Data (TSD) that holds metadata about the type, including various flags. The libgnat/a-tags.ads file defines the structure of this TSD. This optimization reorders fields within the Type_Specific_Data record, specifically moving boolean components to improve alignment and packing, thereby reducing the overall size of the record, a common technique in data structure optimization to avoid padding bytes.
For Context
When a program runs, it stores information in memory. How this information is organized in memory can significantly affect how much memory the program uses and how fast it runs. Ada's 'tagged types' are a way to create flexible data structures, similar to classes in other languages, that can be extended. This change in the GCC Ada compiler optimizes the internal way the compiler stores special data (Type_Specific_Data) about these tagged types. By carefully rearranging the elements within this data structure, the compiler can pack the information more efficiently, especially on 64-bit computer systems. This means programs using Ada tagged types will use slightly less memory, which can be beneficial for performance and resource constrained environments.