This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ standard compliant behaviour of the -fipa-struct-reorg option


Hello all, I have a question about whether the -fipa-struct-reorg option:

"Perform structure reorganization optimization, that change C-like
structures layout in order to better utilize spatial locality."

... can behave in a C++standard compliant mode...

In just the C-compliant mode, as far as my distant memory serves me,
one would generally expect the order of declaration of variables (like
ints) in a struct to be consistent with the memory-layout progression
(padding aside for the moment):
struct s {
int a;
int b;
int c;
};

So, semantically, we could observe, for example:
s s1;
&s1 == &s1.a
&&
&s1.a < &s1.b
&&
&s1.b < &s1.c

In C++ this is, partially, upheld -- but *only* within the grouping of
a given access specifier:
class s {
public:
int a;
int b;
int c;
};
will yield the same requirements, pretty much, as per C.

However

class s {
public: int a;
protected: int b;
private: int c;
};

or an even more explicit/to-the-point example:

class s {
public: int a;
public: int b;
public: int c;
};

will allow, as per standard, some members of s1 to be re-arranged
(memory-layout wise... the initialization order is not being
questioned here, just the memory layout) -- i.e. the memory-layout
progression w.r.t. 'b' and 'c' may be shuffled and the
"-fipa-struct-reorg" option may be made to honor/comply-with the C++
standard?

So, I was wondering if this is currently (or in the works) possible
(to maintain the C++ standard compliance whilst at the same time
allowing for legitimate/legal structure/class member re-shuffling
memory-layout-wise for more efficient spacial utilisation)?

... Also, possibly, hooking the info from 'frequently-used' struct
variables (to be grouped together) from the profiled runs (if so
desired)

... or just for aiming to conserve the memory-space whilst still
allowing for padding/alignment requirements of a given machine
architecture...

Kind regards
Leon.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]