summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Oblock <gary@amperecomputing.com>2020-06-17 00:41:58 -0700
committerGary Oblock <gary@amperecomputing.com>2020-06-17 00:41:58 -0700
commit7bb28ab761e556581a6ecd4cb59c7bf903b8f4fc (patch)
treead5d6ea735d2888ea0efa2b55dcc3ebf507f88ea
parentc92726640fcf54be8ae6d0fd7049b8a09c3aa4a5 (diff)
malloc fixes
-rw-r--r--gcc/ipa-str-reorg-instance-interleave.c119
-rw-r--r--gcc/ipa-structure-reorg.c17
-rw-r--r--gcc/ipa-structure-reorg.h7
3 files changed, 80 insertions, 63 deletions
diff --git a/gcc/ipa-str-reorg-instance-interleave.c b/gcc/ipa-str-reorg-instance-interleave.c
index 699a8fbda1e..98a69ba24fe 100644
--- a/gcc/ipa-str-reorg-instance-interleave.c
+++ b/gcc/ipa-str-reorg-instance-interleave.c
@@ -54,6 +54,7 @@ static unsigned int reorg_perf_qual ( Info *);
// These are local to this file by design
#define REORG_SP_PTR_PREFIX "_reorg_SP_ptr_type_"
#define REORG_SP_PREFIX "_reorg_base_type_"
+#define REORG_SP_BASE_PREFIX "_reorg_base_var_"
int
str_reorg_instance_interleave_qual ( Info *info)
@@ -72,11 +73,10 @@ int
str_reorg_instance_interleave_trans ( Info *info)
{
struct cgraph_node *node;
- FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node)
- {
+ FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) {
struct function *func = DECL_STRUCT_FUNCTION ( node->decl);
// Ulgy GCC idiom with global pointer to current function.
- set_cfun ( func);
+ push_cfun ( func);
if ( info->show_transforms )
{
fprintf( dump_file, "Function \"%s\":\n",
@@ -176,7 +176,7 @@ str_reorg_instance_interleave_trans ( Info *info)
internal_error(
"Reached operand default in LHS enum ReorgOpTrans");
}
- }
+ }
*/
break;
case ReorgT_ElemAssign:
@@ -384,52 +384,9 @@ str_reorg_instance_interleave_trans ( Info *info)
tree field;
tree reorg_type = ri->gcc_type; // is this useful here?
tree reorg_pointer_type = ri->pointer_rep;
- tree base = ri->clone;
+ //tree base = ri->reorg_ver_type; //nopers
+ tree base = ri->instance_interleave.base;
- #if 0
- // if defed off here... move this
- // code in failure_bb
- //
- // FROM fail_val is new SSA
- // FROM gsi = gsi_start_bb ( failure_bb)
- gsi = gsi_start_bb ( failure_bb);
- // FROM gsi_insert_after ( &gsi, "goto after_label")
- gimple *goto_al = gimple_build_goto ( after_label_L);
- gsi_insert_after ( &gsi, goto_al, GSI_SAME_STMT);
- // (per field) {
- tree fndecl_free = builtin_decl_explicit( BUILT_IN_FREE);
- for( field = TYPE_FIELDS( reorg_type);
- field;
- field = DECL_CHAIN( field))
- {
- // FROM gsi_insert_after( &gsi, "base.field = 0")
- tree lhs_ass =
- build3( COMPONENT_REF, ptr_type_node, base, field, NULL_TREE);
- gimple *gzero = gimple_build_assign( lhs_ass, null_pointer_node);
- gsi_insert_after( &gsi, gzero, GSI_SAME_STMT);
-
- // FROM gsi_insert_after( &gsi, "free(field)")
- // TBD -- I'm
- tree to_free =
- make_temp_ssa_name( reorg_pointer_type, NULL, "malloc_to_free");
- gcall *free_call = gimple_build_call( fndecl_free, 1, to_free);
- gsi_insert_after( &gsi, free_call, GSI_SAME_STMT);
- tree rhs_ass =
- build3( COMPONENT_REF, ptr_type_node, base, field, NULL_TREE);
- gimple *gaddr2free = gimple_build_assign( to_free, rhs_ass);
- gsi_insert_after( &gsi, gaddr2free, GSI_SAME_STMT);
- }
- // FROM gsi_insert_after( &gsi, "fail_val = minint")
- gimple *gretnull =
- gimple_build_assign ( fail_val,
- //build_int_cst ( size_type_node,
- TYPE_MIN_VALUE ( TREE_TYPE ( fail_val))); // );
- gsi_insert_after( &gsi, gretnull, GSI_SAME_STMT);
- // FROM gsi_insert_after( &gsi, bad_field )
- gimple *gbad_field = gimple_build_label( bad_field_L);
- gsi_insert_after( &gsi, gbad_field, GSI_SAME_STMT);
- #endif
-
// loop setup trickery for gimple idioms
//
// FROM prev_order = failure_bb
@@ -613,7 +570,7 @@ str_reorg_instance_interleave_trans ( Info *info)
//tree reorg_type = ri->gcc_type; // is this useful here?
//tree reorg_pointer_type = ri->pointer_rep;
tree fndecl_free = builtin_decl_explicit( BUILT_IN_FREE);
- //tree base = ri->clone;
+ //tree base = ri->reorg_ver_type;
for( field = TYPE_FIELDS( reorg_type);
field;
field = DECL_CHAIN( field)) {
@@ -677,7 +634,7 @@ str_reorg_instance_interleave_trans ( Info *info)
gimple *gfail = gimple_build_label( lfail);
tree lnotfial = create_artificial_label( UNKNOWN_LOCATION);
gimple *gnotfail = gimple_build_label( lnotfail);
- tree base = ri->clone;
+ tree base = ri->reorg_ver_type;
for (each element of base) // TBD <==
{
// call malloc
@@ -844,6 +801,7 @@ str_reorg_instance_interleave_trans ( Info *info)
}
}
}
+ pop_cfun ();
}
}
@@ -923,9 +881,14 @@ create_a_new_type ( Info_t *info, tree type)
ReorgType_t *ri = get_reorgtype_info ( type, info);
if ( ri != NULL ) {
+ // From the comment of build_variant_type_copy it might not what
+ // is needed to here. Comment in tree:
+ // "Create a new variant of TYPE, equivalent but distinct."
+ // Now before we panic le'ts give it a try.
+ //
tree reorg_type_prime =
build_variant_type_copy ( type MEM_STAT_DECL);
- ri->clone = reorg_type_prime;
+ ri->reorg_ver_type = reorg_type_prime;
/* Multi-pool only
// Create pointer_rep
@@ -969,7 +932,7 @@ create_a_new_type ( Info_t *info, tree type)
DEBUG("\n");
// TBD ! Some of the key bits from above seem to be missing below.
- // Specifically make_node for the base type, setting the base (clone)
+ // Specifically make_node for the base type, setting the base
// in the ReorgType.
//
// Note, someplace (probably here) also has to declare a base type
@@ -1007,6 +970,8 @@ create_a_new_type ( Info_t *info, tree type)
//DEBUG_F( print_generic_decl, stderr, new_decl, TDF_DETAILS);
//DEBUG( "\n");
}
+ TYPE_FIELDS ( reorg_type_prime) = new_fields; // fix?
+
// store reversed fields back into reorg_type_prime
TYPE_FIELDS ( reorg_type_prime) = NULL;
tree next_fld;
@@ -1020,6 +985,29 @@ create_a_new_type ( Info_t *info, tree type)
}
// Fix-up the layout
layout_type ( reorg_type_prime);
+
+ // HERE
+ // Create the base element for a reorg type. This is for the single
+ // pool case only.
+ tree base_var =
+ build_decl ( UNKNOWN_LOCATION, VAR_DECL, NULL_TREE, ri->reorg_ver_type);
+
+ const char *type_name =
+ identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME ( ri->gcc_type)));
+ size_t tlen = strlen ( REORG_SP_BASE_PREFIX) + strlen ( type_name);
+ char *base_name = ( char*)alloca ( tlen + 1);
+ strcpy ( base_name, REORG_SP_BASE_PREFIX);
+ DECL_NAME ( base_var) = get_identifier ( base_name);
+
+ strcat ( base_name, type_name);
+ TREE_STATIC ( base_var) = 1;
+ TREE_ADDRESSABLE ( base_var) = 1;
+ DECL_NONALIASED ( base_var) = 1;
+ SET_DECL_ALIGN ( base_var, TYPE_ALIGN ( ri->reorg_ver_type));
+
+ varpool_node::finalize_decl ( base_var);
+
+ ri->instance_interleave.base = base_var;
}
// Mess with the original type too because it might
@@ -1060,6 +1048,31 @@ create_a_new_type ( Info_t *info, tree type)
}
}
+ // Moved it
+ #if 0
+ // Create the base element for a reorg type. This is for the single
+ // pool case only.
+ tree base_var =
+ build_decl ( UNKNOWN_LOCATION, VAR_DECL, NULL_TREE, ri->reorg_ver_type);
+
+ const char *base_type_name =
+ identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME ( ri->gcc_type)));
+ size_t tlen = strlen ( REORG_SP_PREFIX) + strlen ( base_type_name);
+ char *base_name = ( char*)alloca ( tlen + 1);
+ strcpy ( base_name, REORG_SP_PREFIX);
+ DECL_NAME ( base_var) = get_identifier ( base_name);
+
+ strcat ( base_name, base_type_name);
+ TREE_STATIC ( base_var) = 1;
+ TREE_ADDRESSABLE ( base_var) = 1;
+ DECL_NONALIASED ( base_var) = 1;
+ SET_DECL_ALIGN ( base_var, TYPE_ALIGN ( ri->reorg_ver_type));
+
+ varpool_node::finalize_decl ( base_var);
+
+ ri->instance_interleave.base = base_var;
+ #endif
+
// Mark the type as processed
( *( info->struct_types)) [ type] = { true, layout_changed};
}
diff --git a/gcc/ipa-structure-reorg.c b/gcc/ipa-structure-reorg.c
index 3e59bd38b1e..07b8996e710 100644
--- a/gcc/ipa-structure-reorg.c
+++ b/gcc/ipa-structure-reorg.c
@@ -701,8 +701,8 @@ static void
add_reorg_type ( tree base, Info *info)
{
ReorgType_t rt =
- { 0, base, true, NULL, NULL, false, false, false,
- { 0}, { 0}, { 0, 0, 0, 0.0, 0.0, false}};
+ { 0, true, base, NULL, NULL, false, false, false,
+ { 0}, { 0}, { 0, 0, 0, NULL, 0.0, 0.0, false}};
info->reorg_type->push_back ( rt);
// Remember the intial assumption is the type added will be deleted
@@ -1498,9 +1498,9 @@ is_reorg_type( tree rt, Info *info )
tree
base_type_of ( tree type)
{
- //DEBUG_L("base_type_of: ");
- //DEBUG_F( print_generic_expr, stderr, type, TDF_DETAILS);
- //DEBUG("\n");
+ DEBUG_L("base_type_of: ");
+ DEBUG_F( print_generic_expr, stderr, type, TDF_DETAILS);
+ DEBUG("\n");
for ( ; POINTER_TYPE_P ( type) ||
TREE_CODE ( type) == ARRAY_TYPE ||
TREE_CODE ( type) == VAR_DECL ||
@@ -1628,6 +1628,9 @@ detect_reorg ( tree *tp, int *dummy, void *data)
struct walk_stmt_info *walk_data = ( struct walk_stmt_info *)data;
hidden_info_t *hi = ( hidden_info_t *)walk_data->info;
//ReorgType_t *ri = get_reorgtype_info ( *tp, hi->info); // TBD I suspect this needs base_type_of( TREE_TYPE(*tp))
+ DEBUG_L( "*tp = ");
+ DEBUG_F( print_generic_expr, stderr, *tp, (dump_flags_t)-1);
+ DEBUG("\n");
tree operand = base_type_of( TREE_TYPE(*tp));
ReorgType_t *ri = get_reorgtype_info ( operand, hi->info);
if ( ri != NULL )
@@ -1714,12 +1717,12 @@ print_reorg ( FILE *file, int leading_space, ReorgType_t *reorg )
// TBD When multi-pool implemented (and found) emit pointer_rep.
fprintf ( file, "}, ");
}
- if ( reorg->clone != NULL )
+ if ( reorg->reorg_ver_type != NULL )
{
// TBD does this belong here? How will the clone be done with elim and
// reorder
const char *clone_name =
- identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME ( reorg->clone)));
+ identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME ( reorg->reorg_ver_type)));
fprintf ( file, "%s%s", clone_name, reorg->pointer_rep ? ", " : "");
}
if ( reorg->pointer_rep != NULL )
diff --git a/gcc/ipa-structure-reorg.h b/gcc/ipa-structure-reorg.h
index 818d0f4dc62..dcd5b5d5824 100644
--- a/gcc/ipa-structure-reorg.h
+++ b/gcc/ipa-structure-reorg.h
@@ -46,6 +46,7 @@ struct RT_Interleave {
int numbOfGlobalArrays; // Statically allocated only
int numbOfLocalArrays; // Statically allocated only
int numbOfDynmAllocs;
+ tree base;
double reorg_perf;
double regular_perf;
bool multi_pool; // single pool if not set
@@ -61,11 +62,11 @@ typedef struct ReorgType ReorgType_t;
// Not sure how it will evolve in the future...
struct ReorgType {
unsigned id;
- tree gcc_type; // This info is for this type.
bool delete_me;
+ tree gcc_type; // This info is for this type.
// TBD will field reordering and/or dead field elimination use
- // use the clone? I think it's likely that they can.
- tree clone; // the base
+ // use the reorg_ver_type? I think it's likely that they can.
+ tree reorg_ver_type; // the base type
tree pointer_rep; // new pointer format (multi-pool)
bool do_dead_field_elim;
bool do_field_reorder;