Hello,

I am working on a struct reorganization optimization pass.
I am able to identify which structs I want to reorganize
and I am also able to create new structs with these modifications.
The way the new structs are generated is the following code
(I am keeping it high-level for conciseness but feel free to ask
for more details).

static tree
get_sorted_record(tree record)
{
  gcc_assert(TREE_CODE(record) == RECORD_TYPE);
  log(2, "printing original");
  print_record(record);
  tree copy = copy_record(record);
  sort_fields_in_place(copy);
  log(2, "printing sorted copy");
  print_record(copy);
  return copy;
}

Output:

[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_record(tree):183)printing record aStruct
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)e,boolean_type,8
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)a,integer_type,32
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)b,integer_type,8
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)c,real_type,32
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)d,real_type,64
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)f,boolean_type,8
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)h,integer_type,64
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:tree_node* 
get_sorted_record(tree):218)printing sorted copy
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_record(tree):183)printing record aStruct
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)e,boolean_type,8
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)b,integer_type,8
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)f,boolean_type,8
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)a,integer_type,32
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)c,real_type,32
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)d,real_type,64
[log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void 
print_field(tree):199)h,integer_type,64

Basically, we copy the tree of structs of interest.
We modify the DECL_CHAIN so that the fields are in the order that
we want. And finally, we would like to replace trees of type `record`
with `copy`.

At the moment, IDENTIFIER_POINTER for copy and record are the same.
However, I want to keep my design as general as possible.
If I understand correctly, with the current design it is possible
to change all trees of type record with those of type copy.
However, if one wished to change only a subset of these trees,
wouldn't there be a need for a different IDENTIFIER_NODE in clone?
Otherwise, there would be confusion as to how clone and record
differ. (Their IDENTIFIER_POINTERS are the same.)

So, is the correct way to specialize a type is to modify the
identifier myself or is there an API that allows me to do so?

Thanks!

Reply via email to