summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Oblock <gary@amperecomputing.com>2020-07-14 12:12:36 -0700
committerGary Oblock <gary@amperecomputing.com>2020-07-14 12:12:36 -0700
commit66228436f518a843fbb30f9aeeea9168d2c93042 (patch)
tree3a9c284c97c519d80e811187291a79618a787e78
parent39a24f9cf7602f9077b262494335cc339a9cf76a (diff)
Added fix for changing the type of ssa temps.
In the middle of program_print change to dump declarations (there are bugs with modifying decls.)
-rw-r--r--gcc/ipa-str-reorg-instance-interleave.c420
-rw-r--r--gcc/ipa-structure-reorg.c106
-rw-r--r--gcc/ipa-structure-reorg.h5
3 files changed, 401 insertions, 130 deletions
diff --git a/gcc/ipa-str-reorg-instance-interleave.c b/gcc/ipa-str-reorg-instance-interleave.c
index cc2969ab598..d3087f9e1f2 100644
--- a/gcc/ipa-str-reorg-instance-interleave.c
+++ b/gcc/ipa-str-reorg-instance-interleave.c
@@ -50,6 +50,7 @@ static void wrangle_ssa_type( tree, Info_t*);
static bool print_internals (gimple *, void *);
static void str_reorg_instance_interleave_qual_part ( Info *);
static void str_reorg_instance_interleave_type_part ( Info *);
+static void header ( bool);
static void create_new_types ( Info_t *);
static void create_a_new_type ( Info_t *, tree);
static unsigned int reorg_perf_qual ( Info *);
@@ -249,14 +250,14 @@ str_reorg_instance_interleave_trans ( Info *info)
tree rhs_faa = build3 ( COMPONENT_REF,
// ???
- //base_field_type,
- ptr_type_node, // This seems bogus
+ base_field_type,
+ //ptr_type_node, // This seems bogus
base,
- //base_field,
+ base_field,
// This almost certainly is bogus
// If this "works" the the types
// of fields are messed up.
- orig_field,
+ //orig_field,
NULL_TREE);
// Use this to access the array of element.
@@ -446,42 +447,60 @@ str_reorg_instance_interleave_trans ( Info *info)
// the type of pointer_sized_int_node is probably not correct
// even though that's the representation.
+ tree PPI_orig_lhs = gimple_assign_lhs ( stmt);
+
tree offset_type = TREE_TYPE ( TYPE_SIZE_UNIT (ri->gcc_type));
tree type = ri->pointer_rep;
- tree ptrplusint_adj = make_temp_ssa_name( type, NULL, "PtrPlusInt_Adj");
+
tree str_siz =
build_int_cst ( type, int_cst_value ( TYPE_SIZE_UNIT (ri->gcc_type)));
+
tree rhs1 = gimple_assign_rhs1( stmt);
tree rhs2 = gimple_assign_rhs2( stmt);
+
+ tree PPI_rhs1_cast = make_temp_ssa_name( type, NULL, "PPI_rhs1_cast");
+ gimple *gPPI_rhs1_cast = gimple_build_assign ( PPI_rhs1_cast, CONVERT_EXPR, rhs1);
+ SSA_NAME_DEF_STMT ( PPI_rhs1_cast) = gPPI_rhs1_cast;
+
tree PPI_rhs2_cast = make_temp_ssa_name( type, NULL, "PPI_rhs2_cast");
gimple *gPPI_rhs2_cast = gimple_build_assign ( PPI_rhs2_cast, CONVERT_EXPR, rhs2);
SSA_NAME_DEF_STMT ( PPI_rhs2_cast) = gPPI_rhs2_cast;
-
- gimple *gptrplusint_adj =
- gimple_build_assign ( ptrplusint_adj, TRUNC_DIV_EXPR, PPI_rhs2_cast, str_siz);
- SSA_NAME_DEF_STMT ( ptrplusint_adj) = gptrplusint_adj;
+
+ tree PPI_adj = make_temp_ssa_name( type, NULL, "PtrPlusInt_Adj");
+ gimple *gPPI_adj =
+ gimple_build_assign ( PPI_adj, TRUNC_DIV_EXPR, PPI_rhs2_cast, str_siz);
+ SSA_NAME_DEF_STMT ( PPI_adj) = gPPI_adj;
// Note, gimple_set_op is used in limited places so using it
// to modify existed code might be problematic. NOOOOOOOOOOOOOOOOOO!!!!!!!
// TBD <==================================================================
// Build a regular add expression here using the desination of stmt and its
// first operand along with the new second operand.
tree ptrplusint = make_temp_ssa_name( type, NULL, "PtrPlusInt");
- gimple *gptrplusint =
- gimple_build_assign ( ptrplusint, PLUS_EXPR, rhs1, ptrplusint_adj);
- SSA_NAME_DEF_STMT ( ptrplusint) = gptrplusint;
+ gimple *gPPI =
+ gimple_build_assign ( ptrplusint, PLUS_EXPR, PPI_rhs1_cast, PPI_adj);
+ SSA_NAME_DEF_STMT ( ptrplusint) = gPPI;
+ gimple *gPPI_cast =
+ gimple_build_assign ( PPI_orig_lhs, CONVERT_EXPR, ptrplusint);
+ SSA_NAME_DEF_STMT ( PPI_orig_lhs) = gPPI_cast;
//gimple_set_op( stmt, 2, tmp);
gimple_stmt_iterator gsi = gsi_for_stmt( stmt);
+ gsi_insert_before( &gsi, gPPI_rhs1_cast, GSI_SAME_STMT);
gsi_insert_before( &gsi, gPPI_rhs2_cast, GSI_SAME_STMT);
- gsi_insert_before( &gsi, gptrplusint_adj, GSI_SAME_STMT);
- gsi_insert_before( &gsi, gptrplusint, GSI_SAME_STMT);
+ gsi_insert_before( &gsi, gPPI_adj, GSI_SAME_STMT);
+ gsi_insert_before( &gsi, gPPI, GSI_SAME_STMT);
+ gsi_insert_before( &gsi, gPPI_cast, GSI_SAME_STMT);
gsi_remove ( &gsi, true);
-
+
+ DEBUG_L("");
+ DEBUG_F( print_gimple_stmt, stderr, gPPI_rhs2_cast, 0);
DEBUG_L("");
- DEBUG_F( print_gimple_stmt, stderr, gptrplusint_adj, 0);
+ DEBUG_F( print_gimple_stmt, stderr, gPPI_adj, 0);
DEBUG_L("");
- DEBUG_F( print_gimple_stmt, stderr, gptrplusint, 0);
+ DEBUG_F( print_gimple_stmt, stderr, gPPI, 0);
+ DEBUG_L("");
+ DEBUG_F( print_gimple_stmt, stderr, gPPI_cast, 0);
}
break;
@@ -679,6 +698,20 @@ str_reorg_instance_interleave_trans ( Info *info)
{
basic_block new_bb = create_empty_bb ( prev_order);
new_bb->count = prev_order->count;
+
+ tree base_field =
+ find_coresponding_field ( base, field);
+
+ DEBUG_L("base_field: %p\n", base_field);
+ DEBUG_A(" : ");
+ DEBUG_F(print_generic_expr, stderr, base_field, (dump_flags_t)0);
+ DEBUG("\n");
+
+ tree base_field_type = TREE_TYPE( base_field);
+ DEBUG_L("base_field_type: %p\n", base_field_type);
+ DEBUG_A(" : ");
+ DEBUG_F(print_generic_expr, stderr, base_field_type, (dump_flags_t)0);
+ DEBUG("\n");
gimple_stmt_iterator gsi = gsi_start_bb ( new_bb);
// Note, switching the order of edge creation and
@@ -696,7 +729,7 @@ str_reorg_instance_interleave_trans ( Info *info)
// TBD what happens if I punt on this????
//set_immediate_dominator ( CDI_DOMINATORS, new_bb, prev_bb);
- // TBD set edge probability and flags
+ // create edge and set edge probability and flags
edge fail_edge = make_edge ( new_bb, failure_bb, EDGE_FALSE_VALUE);
fail_edge->probability = profile_probability::very_unlikely ();
fail_edge->count () = new_bb->count - new_bb->count;
@@ -706,30 +739,12 @@ str_reorg_instance_interleave_trans ( Info *info)
create_artificial_label ( UNKNOWN_LOCATION);
#endif
- tree res =
- make_temp_ssa_name ( ptr_type_node, NULL, "res");
- gimple *gcond =
- gimple_build_cond ( NE_EXPR, res, null_pointer_node,
- #if USE_LABELS
- new_ok_field_L, bad_field_L
- #else
- NULL, NULL
- #endif
- );
- #if USE_LABELS
- // Moved label here from end
- gimple *gprev_ok_field = gimple_build_label ( prev_ok_field_L);
- gsi_insert_after ( &gsi, gprev_ok_field, GSI_NEW_STMT);
- #else
- // This just makes adding code after this easier
- gimple *dummy = gimple_build_nop ();
- gsi_insert_after ( &gsi, dummy, GSI_NEW_STMT);
- #endif
- //gsi_insert_after ( &gsi, gcond, GSI_SAME_STMT);
- gsi_insert_after ( &gsi, gcond, GSI_SAME_STMT);
- // FROM gsi_insert_after( &gsi, "base.field = res")
- tree lhs_ass =
- build3( COMPONENT_REF, ptr_type_node, base, field, NULL_TREE);
+ //tree lhs_ass =
+ // build3( COMPONENT_REF, ptr_type_node, base, field, NULL_TREE);
+ tree lhs_ass = build3( COMPONENT_REF,
+ base_field_type,
+ base,
+ base_field, NULL_TREE);
DEBUG_L("base: %p\n", base);
DEBUG_A(" base: ");
@@ -751,57 +766,96 @@ str_reorg_instance_interleave_trans ( Info *info)
DEBUG_A(" lhs_ass: ");
DEBUG_F(print_generic_expr, stderr, lhs_ass, (dump_flags_t)0);
DEBUG("\n");
-
- gimple *gset_field = gimple_build_assign( lhs_ass, res);
-
- gsi_insert_after( &gsi, gset_field, GSI_SAME_STMT);
-
- // FROM gsi_insert_after( &gsi, "res = malloc( mem_size)")
- // The alternative to sizetype are long_integer_type_node
- // and integer_type_node.
- // TBD NOTE! We insert the instructions into block
- // in reverse order but we don't need to create the GIMPLE
- // for them that way. This screams out for a reordering.
+
+ tree lhs_ass_type = TREE_TYPE ( lhs_ass);
+ DEBUG_L("lhs_ass_type: %p\n", lhs_ass_type);
+ DEBUG_A(" lhs_ass_type: ");
+ DEBUG_F(print_generic_expr, stderr, lhs_ass_type, (dump_flags_t)0);
+ DEBUG("\n");
+
tree mem_size =
make_temp_ssa_name( sizetype, NULL, "malloc_mem_size");
- gcall *malloc_call = gimple_build_call( fndecl_malloc, 1, mem_size);
- gimple_call_set_lhs( malloc_call, res);
- SSA_NAME_DEF_STMT ( res) = malloc_call;
- gsi_insert_after( &gsi, malloc_call, GSI_SAME_STMT);
-
- cgraph_node::get ( cfun->decl)->
- create_edge ( cgraph_node::get_create ( fndecl_malloc),
- malloc_call,
- // Nah... lets do this a bit differently
- //gimple_bb ( free_call)->count
- new_bb->count
- );
- // FROM gsi_insert_after( &gsi, "mem_size = len * field_size")
- //gimple *gsize =
- // gimple_build_assign ( mem_size, MULT_EXPR, TYPE_SIZE(field),
- // len, NULL_TREE, NULL_TREE);
-
// We need field_size to be of the correct type so
// we type cast.
tree field_size =
make_temp_ssa_name( TREE_TYPE ( mem_size), NULL, "field_size");
+
+ // Move gprev_ok_field here
+ #if USE_LABELS
+ gimple *gprev_ok_field = gimple_build_label ( prev_ok_field_L);
+ #endif
+
+ // Move gfield_size here
gimple *gfield_size =
gimple_build_assign ( field_size,
CONVERT_EXPR,
TYPE_SIZE ( TREE_TYPE ( field)));
SSA_NAME_DEF_STMT ( field_size) = gfield_size;
+ // Move gsize here
gimple *gsize =
gimple_build_assign ( mem_size,
MULT_EXPR,
field_size,
len);
SSA_NAME_DEF_STMT ( mem_size) = gsize;
+
+ tree res =
+ make_temp_ssa_name ( ptr_type_node, NULL, "res");
+
+ tree cast_res =
+ make_temp_ssa_name ( TREE_TYPE ( base_field), NULL, "cast_res");
+
+ tree res_type = TREE_TYPE( res);
+ DEBUG_L("res_type: %p\n", res_type);
+ DEBUG_A(" : ");
+ DEBUG_F(print_generic_expr, stderr, res_type, (dump_flags_t)0);
+ DEBUG("\n");
+
+ // Move malloc_call here
+ gcall *malloc_call = gimple_build_call( fndecl_malloc, 1, mem_size);
+ gimple_call_set_lhs( malloc_call, res);
+ SSA_NAME_DEF_STMT ( res) = malloc_call;
+ //gsi_insert_after( &gsi, malloc_call, GSI_SAME_STMT);
+
+ cgraph_node::get ( cfun->decl)->
+ create_edge ( cgraph_node::get_create ( fndecl_malloc),
+ malloc_call,
+ // Nah... lets do this a bit differently
+ //gimple_bb ( free_call)->count
+ new_bb->count
+ );
+
+ gimple *gcast_res =
+ gimple_build_assign ( cast_res, CONVERT_EXPR, res);
+ SSA_NAME_DEF_STMT ( cast_res) = gcast_res;
- gsi_insert_after ( &gsi, gsize, GSI_SAME_STMT);
+ // Move gset_field here
+ gimple *gset_field = gimple_build_assign ( lhs_ass, cast_res);
- gsi_insert_after ( &gsi, gfield_size, GSI_SAME_STMT);
+ // Move gcond here
+ gimple *gcond =
+ gimple_build_cond ( NE_EXPR, res, null_pointer_node,
+ #if USE_LABELS
+ new_ok_field_L, bad_field_L
+ #else
+ NULL, NULL
+ #endif
+ );
+
+ // Last is first
+ gsi_insert_before ( &gsi, gcond, GSI_NEW_STMT);
+
+ // The rest in order before the last
+ #if USE_LABELS
+ gsi_insert_before ( &gsi, gprev_ok_field, GSI_SAME_STMT);
+ #endif
+ gsi_insert_before ( &gsi, gfield_size, GSI_SAME_STMT);
+ gsi_insert_before ( &gsi, gsize, GSI_SAME_STMT);
+ gsi_insert_before ( &gsi, malloc_call, GSI_SAME_STMT);
+ gsi_insert_before ( &gsi, gcast_res, GSI_SAME_STMT);
+ gsi_insert_before ( &gsi, gset_field, GSI_SAME_STMT);
prev_bb = new_bb;
prev_order = new_bb;
@@ -881,12 +935,22 @@ str_reorg_instance_interleave_trans ( Info *info)
// Note, BBs have a sequence of phis which create_phi_node takes care of
// adding this phi too.
- gphi *der_phi = create_phi_node( val, after_bb);
- // OPS!
- //add_phi_arg( der_phi, success_val, success_edge, UNKNOWN_LOCATION);
+ tree m_phi_val =
+ make_temp_ssa_name ( TREE_TYPE ( success_val), NULL, "m_phi_val");
+ gphi *der_phi = create_phi_node( m_phi_val, after_bb);
add_phi_arg( der_phi, success_val, succ_to_after_e, UNKNOWN_LOCATION);
add_phi_arg( der_phi, fail_val, fail_to_after_e, UNKNOWN_LOCATION);
+ gimple *gm_cast_phi_val =
+ gimple_build_assign ( val, CONVERT_EXPR, m_phi_val);
+ SSA_NAME_DEF_STMT ( val) = gm_cast_phi_val;
+
+ #if USE_LABELS
+ gsi_insert_after( &gsi, gm_cast_phi_val, GSI_SAME_STMT);
+ #else
+ gsi_insert_after( &gsi, gm_cast_phi_val, GSI_NEW_STMT);
+ #endif
+
//// FROM gsi_insert_after( &gsi, after_label)
//gimple *gafter_label = gimple_build_label( after_label_L);
//gsi_insert_after( &gsi, gafter_label, GSI_SAME_STMT);
@@ -926,22 +990,29 @@ str_reorg_instance_interleave_trans ( Info *info)
// Don't use the builtin!
//tree fndecl_free = builtin_decl_explicit( BUILT_IN_FREE);
- //tree base = ri->reorg_ver_type;
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);
+
+ tree base_field =
+ find_coresponding_field ( base, field);
+ tree base_field_type = TREE_TYPE( base_field);
+
+ tree lhs_ass = build3( COMPONENT_REF,
+ base_field_type,
+ base,
+ base_field, NULL_TREE);
+
gimple *gzero = gimple_build_assign( lhs_ass, null_pointer_node);
gsi_insert_after( &gsi, gzero, GSI_SAME_STMT);
+
+ tree m_cast2free =
+ make_temp_ssa_name( ptr_type_node, NULL, "m_cast2free");
// Tried reorg_pointer_type
- //tree to_free =
- // make_temp_ssa_name( reorg_pointer_type, NULL, "malloc_to_free");
- tree to_free =
- make_temp_ssa_name( ptr_type_node, NULL, "malloc_to_free");
- gcall *free_call = gimple_build_call( fndecl_free, 1, to_free);
+ tree m_to_free =
+ make_temp_ssa_name( base_field_type, NULL, "malloc_to_free");
+ gcall *free_call = gimple_build_call( fndecl_free, 1, m_cast2free);
gsi_insert_after( &gsi, free_call, GSI_SAME_STMT);
cgraph_node::get ( cfun->decl)->
@@ -955,10 +1026,19 @@ str_reorg_instance_interleave_trans ( Info *info)
// TBD Note, this brings up the question of bb counts which is being
// punted on
- tree rhs_ass =
- build3( COMPONENT_REF, ptr_type_node, base, field, NULL_TREE);
- gimple *gaddr2free = gimple_build_assign( to_free, rhs_ass);
- SSA_NAME_DEF_STMT ( to_free) = gaddr2free;
+ tree rhs_ass = build3( COMPONENT_REF,
+ base_field_type,
+ base,
+ base_field, NULL_TREE);
+
+ gimple *gm_cast2free =
+ gimple_build_assign( m_cast2free, CONVERT_EXPR, m_to_free);
+ SSA_NAME_DEF_STMT ( m_cast2free) = gm_cast2free;
+
+ gsi_insert_after( &gsi, gm_cast2free, GSI_SAME_STMT);
+
+ gimple *gaddr2free = gimple_build_assign( m_to_free, rhs_ass);
+ SSA_NAME_DEF_STMT ( m_to_free) = gaddr2free;
gsi_insert_after( &gsi, gaddr2free, GSI_SAME_STMT);
}
@@ -1172,6 +1252,11 @@ str_reorg_instance_interleave_trans ( Info *info)
DEBUG_L("ReorgT_UserFunc\n");
break;
+ case ReorgT_Convert:
+ // Ignore type casting because another
+ // mini-pass sweeps up any ugly dangling types.
+ DEBUG_L("ReorgT_Convert\n");
+ break;
case ReorgT_Return:
// TBD The type must be adjusted (maybe.)
DEBUG_L("ReorgT_Return\n");
@@ -1191,7 +1276,7 @@ str_reorg_instance_interleave_trans ( Info *info)
int mini_pass; // Passes 0 and two are just for testing
for ( mini_pass = 0; mini_pass < 3; mini_pass++ )
{
- bool emit_header = true;
+ header ( true);
FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) {
struct function *func = DECL_STRUCT_FUNCTION ( node->decl);
// Ulgy GCC idiom with global pointer to current function.
@@ -1199,6 +1284,57 @@ str_reorg_instance_interleave_trans ( Info *info)
basic_block bb;
FOR_EACH_BB_FN ( bb, func)
{
+ gimple_seq seq = bb->il.gimple.phi_nodes;
+ if ( seq )
+ {
+ gimple_stmt_iterator phii;
+ for ( phii = gsi_start (seq); !gsi_end_p (phii); gsi_next (&phii))
+ {
+ gimple *phi_stmt = gsi_stmt ( phii);
+ if ( contains_a_reorgtype( phi_stmt, info) )
+ {
+ tree lhs = gimple_assign_lhs( phi_stmt);
+ if ( tree_contains_a_reorgtype_p ( lhs, info) )
+ {
+ if ( mini_pass == 0 || mini_pass == 2 )
+ {
+ header ( false);
+ fprintf( stderr, " LHS: ");
+ print_generic_expr ( stderr, TREE_TYPE ( lhs), (dump_flags_t)0);
+ fprintf( stderr, " ");
+ }
+ else
+ {
+ wrangle_ssa_type ( lhs, info);
+ }
+ }
+
+ // Wrangle the right hand side
+ unsigned num;
+ num = gimple_num_ops ( phi_stmt);
+ unsigned i;
+ for ( i = 1; i < num; i++ )
+ {
+ tree *op = gimple_op_ptr ( phi_stmt, i);
+ if ( tree_contains_a_reorgtype_p ( *op, info) )
+ {
+ if ( mini_pass == 0 || mini_pass == 2 )
+ {
+ header ( false);
+ fprintf( stderr, " RHS%d: ", i);
+ print_generic_expr ( stderr, TREE_TYPE ( *op), (dump_flags_t)0);
+ fprintf( stderr, " ");
+ }
+ else
+ {
+ wrangle_ssa_type ( *op, info);
+ }
+ }
+ }
+ }
+ }
+ }
+
gimple_stmt_iterator gsi;
for ( gsi = gsi_start_bb ( bb); !gsi_end_p ( gsi); gsi_next ( &gsi) )
{
@@ -1225,29 +1361,23 @@ str_reorg_instance_interleave_trans ( Info *info)
if ( mini_pass == 0 || mini_pass == 2 )
{
- if ( lhs_reorg || rhs1_reorg || rhs2_reorg|| rhs3_reorg)
- {
- if ( emit_header )
- {
- emit_header = false;
- fprintf( stderr, "SANITY CHECKING FAILURE:\n");
- }
- print_gimple_stmt ( stderr, stmt, 0);
- }
if ( lhs_reorg )
{
+ header ( false);
fprintf( stderr, " LHS%s: ", lhs_ssa ? "*" : "");
print_generic_expr ( stderr, TREE_TYPE ( lhs), (dump_flags_t)0);
fprintf( stderr, " ");
}
if ( rhs1_reorg )
{
+ header ( false);
fprintf( stderr, "%s RHS1%s: ", lhs_reorg ? ", " : "",
rhs1_ssa ? "*" : "");
print_generic_expr ( stderr, TREE_TYPE ( rhs1), (dump_flags_t)0);
}
if ( rhs2_reorg )
{
+ header ( false);
fprintf( stderr, "%s RHS2%s: ",
lhs_reorg || rhs1_reorg ? ", " : "",
rhs2_ssa ? "*" : "");
@@ -1255,6 +1385,7 @@ str_reorg_instance_interleave_trans ( Info *info)
}
if ( rhs3_reorg )
{
+ header ( false);
fprintf( stderr, "%s RHS3%s: ",
lhs_reorg || rhs1_reorg || rhs2_reorg ? ", " : "",
rhs3_ssa ? "*" : "");
@@ -1270,6 +1401,9 @@ str_reorg_instance_interleave_trans ( Info *info)
{
if ( lhs_ssa )
{
+ #if 1
+ wrangle_ssa_type ( lhs, info);
+ #else
tree lhs_type = TREE_TYPE ( lhs);
tree bottom_type = base_type_of ( lhs_type);
DEBUG_L("lhs: ");
@@ -1291,13 +1425,14 @@ str_reorg_instance_interleave_trans ( Info *info)
DEBUG_L( "prev_type: %p, type: %p\n", prev_type, type);
}
- #if 0
- // Modify type of ssa temp (dicey!)
- // This changes every instance of * reorg_type to the
- // new pointre rep in one fell swoop.
- // I sweat just thinking how crazy this is....
- TREE_TYPE ( prev_type) = ri->pointer_rep;
- #endif
+ // I thought about doing this:
+ // Modify type of ssa temp (dicey!)
+ // This changes every instance of * reorg_type to the
+ // new pointre rep in one fell swoop.
+ // I sweat just thinking how crazy this is....
+ //
+ // TREE_TYPE ( prev_type) = ri->pointer_rep;
+
// TBD might use build_pointer_type to build new type for *(N)reorg_type
// to *(N-1)ri->pointer_rep
// Fakes this for levels == 1
@@ -1316,6 +1451,7 @@ str_reorg_instance_interleave_trans ( Info *info)
gcc_assert(0);
}
}
+ #endif
}
if ( rhs1_ssa )
{
@@ -1339,7 +1475,7 @@ str_reorg_instance_interleave_trans ( Info *info)
}
fprintf ( stderr, "INTERNALS PRINT\n");
- apply_to_all_gimple ( print_internals, (void *)info);
+ apply_to_all_gimple ( print_internals, true, (void *)info);
if ( info->show_all_reorg_cands )
{
@@ -1353,7 +1489,7 @@ wrangle_ssa_type( tree side, Info_t *info )
{
tree side_type = TREE_TYPE ( side);
tree bottom_type = base_type_of ( side_type);
- DEBUG_L("side: ");
+ DEBUG_L("op: ");
DEBUG_F(print_generic_expr, stderr, side, (dump_flags_t)0);
DEBUG("\n");
DEBUG_L("bottom_type: ");
@@ -1373,20 +1509,21 @@ wrangle_ssa_type( tree side, Info_t *info )
DEBUG_L( "prev_type: %p, type: %p\n", prev_type, type);
}
-#if 0
- // Modify type of ssa temp (dicey!)
- // This changes every instance of * reorg_type to the
- // new pointre rep in one fell swoop.
- // I sweat just thinking how crazy this is....
- TREE_TYPE ( prev_type) = ri->pointer_rep;
-#endif
+ // I thought about doing this:
+ // Modify type of ssa temp (dicey!)
+ // This changes every instance of * reorg_type to the
+ // new pointre rep in one fell swoop.
+ // I sweat just thinking how crazy this is....
+ //
+ // TREE_TYPE ( prev_type) = ri->pointer_rep;
+
// TBD might use build_pointer_type to build new type for *(N)reorg_type
// to *(N-1)ri->pointer_rep
// Fakes this for levels == 1
if ( levels == 0)
{
DEBUG_L( "LEVELS ZERO\n");
- TREE_TYPE ( side) = ri->pointer_rep;
+ modify_ssa_name_type ( side, ri->pointer_rep);
}
else
{
@@ -1395,7 +1532,6 @@ wrangle_ssa_type( tree side, Info_t *info )
}
}
-
static bool
print_internals (gimple *stmt, void *data)
{
@@ -1440,11 +1576,39 @@ print_internals (gimple *stmt, void *data)
print_generic_expr ( stderr, TREE_TYPE ( rhs3), (dump_flags_t)0);
}
fprintf ( stderr, "\n");
- }
+ } else
+ if ( gimple_code ( stmt) == GIMPLE_PHI )
+ {
+ use_operand_p phi_op;
+ ssa_op_iter iter;
+ gphi *phi_stmt = dyn_cast <gphi *> ( stmt);
+
+ tree def = PHI_RESULT ( phi_stmt);
+ fprintf( stderr, " OP: ");
+ print_generic_expr ( stderr, def, (dump_flags_t)0);
+ fprintf( stderr, " TYPE: ");
+ print_generic_expr ( stderr, TREE_TYPE ( def), (dump_flags_t)0);
+ fprintf( stderr, "\n");
+
+ FOR_EACH_PHI_ARG ( phi_op, phi_stmt, iter, SSA_OP_ALL_OPERANDS)
+ {
+ tree op = USE_FROM_PTR ( phi_op);
+ fprintf( stderr, " OP: ");
+ print_generic_expr ( stderr, op, (dump_flags_t)0);
+ fprintf( stderr, " TYPE: ");
+ print_generic_expr ( stderr, TREE_TYPE ( op), (dump_flags_t)0);
+ fprintf( stderr, "\n");
+ }
+ }
+ else
+ {
+ // This is OK I believe unless checking CONDs is necessary
+ ;
+ }
+
return false;
}
-
static void
str_reorg_instance_interleave_qual_part ( Info *info)
{
@@ -1475,6 +1639,24 @@ reorg_perf_qual ( Info *info)
}
}
+static void
+header ( bool initialize )
+{
+ static bool emit_header;
+ if ( initialize )
+ {
+ emit_header = true;
+ }
+ else
+ {
+ if ( emit_header )
+ {
+ emit_header = false;
+ fprintf( stderr, "SANITY CHECKING FAILURE:\n");
+ }
+ }
+}
+
// create_new_types has to crawl "all" the
// types, create new types and transform
// other types that must be changed.
@@ -1599,7 +1781,7 @@ create_a_new_type ( Info_t *info, tree type)
tree new_fld_type = build_pointer_type ( tree_type);
tree new_decl =
build_decl ( DECL_SOURCE_LOCATION (field),
- VAR_DECL, DECL_NAME (field), new_fld_type);
+ FIELD_DECL, DECL_NAME (field), new_fld_type);
// Missing a bunch of attributes (see tree-nested.c:899)
// Let us seee what happens without them!
DECL_CHAIN ( new_decl) = new_fields; // <- bug: need decl, not type
diff --git a/gcc/ipa-structure-reorg.c b/gcc/ipa-structure-reorg.c
index f20336d4e2e..3376f00590a 100644
--- a/gcc/ipa-structure-reorg.c
+++ b/gcc/ipa-structure-reorg.c
@@ -1133,8 +1133,8 @@ reorg_recognize ( gimple *stmt, cgraph_node* node, Info_t *info )
}
case ReorgOpT_Indirect: // "a->f"
case ReorgOpT_AryDir: // "x[i].f"
- DEBUG_L("case ReorgOpT_%s\n", lhs_op == ReorgOpT_Indirect ? "Indirect" : "AryDir");
- INDENT(-4);
+ //DEBUG_L("case ReorgOpT_%s\n", lhs_op == ReorgOpT_Indirect ? "Indirect" : "AryDir");
+ //INDENT(-4);
switch ( recognize_op ( rhs, info) )
{
case ReorgOpT_Temp: // t
@@ -1156,13 +1156,24 @@ reorg_recognize ( gimple *stmt, cgraph_node* node, Info_t *info )
//INDENT(2);
tree op1 = gimple_assign_rhs1 ( stmt);
tree op2 = gimple_assign_rhs2 ( stmt);
+ //DEBUG_L("op1 = %p, op2 = %p\n", op1, op2);
+ //DEBUG_A("");
+ //DEBUG_F( print_generic_expr, stderr, op1, (dump_flags_t)-1);
+ //DEBUG("\n");
+
+ if ( CONVERT_EXPR_CODE_P ( gimple_assign_rhs_code ( stmt)))
+ {
+ //DEBUG_L("CONVERT_EXPR_CODE_P (...)\n");
+ //INDENT(-4);
+ return ReorgT_Convert;
+ }
if ( gimple_assign_rhs3 ( stmt) != NULL )
- {
- //DEBUG_L("gimple_assign_rhs3 ( stmt) != NULL\n");
- //INDENT(-4);
- return Not_Supported;
- }
+ {
+ //DEBUG_L("gimple_assign_rhs3 ( stmt) != NULL\n");
+ //INDENT(-4);
+ return Not_Supported;
+ }
// TBD The parenthesis where a disaster here in the HL Design so
// double check this!
@@ -1233,7 +1244,7 @@ reorg_recognize ( gimple *stmt, cgraph_node* node, Info_t *info )
struct cgraph_edge *edge = node->get_edge ( stmt);
gcc_assert( edge);
//DEBUG_L("called function %s gimple_body\n",
- // edge->callee->has_gimple_body_p() ? "has a" : "has no");
+ // edge->callee->has_gimple_body_p() ? "has a" : "has no");
//INDENT(-2);
if ( gimple_call_builtin_p( stmt, BUILT_IN_CALLOC ) ) return ReorgT_Calloc;
if ( gimple_call_builtin_p( stmt, BUILT_IN_MALLOC ) ) return ReorgT_Malloc;
@@ -1369,7 +1380,7 @@ remove_deleted_types ( Info *info, ReorgFn reorg_fn)
enum ReorgOpTrans
recognize_op ( tree op, Info *info)
{
- // DEBUG_L("recognize_op: ");
+ //DEBUG_L("recognize_op: ");
//DEBUG_F( print_generic_expr, stderr, op, TDF_DETAILS);
//DEBUG("\n");
enum tree_code op_code = TREE_CODE ( op);
@@ -1546,7 +1557,7 @@ find_struct_type_ptr_to_struct ( tree type, Info *info)
// The applied function func can be used to search because it forces
// a return if it returns true;
void
-apply_to_all_gimple ( bool (*function)(gimple *, void *), void *data )
+apply_to_all_gimple ( bool (*function)(gimple *, void *), bool phis_too, void *data )
{
struct cgraph_node *node;
FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node)
@@ -1556,6 +1567,19 @@ apply_to_all_gimple ( bool (*function)(gimple *, void *), void *data )
basic_block bb;
FOR_EACH_BB_FN ( bb, func)
{
+ if ( phis_too )
+ {
+ gimple_seq seq = bb->il.gimple.phi_nodes;
+ if ( seq )
+ {
+ gimple_stmt_iterator phii;
+ for ( phii = gsi_start (seq); !gsi_end_p (phii); gsi_next (&phii))
+ {
+ gimple *phi_stmt = gsi_stmt ( phii);
+ if ( (*function) ( phi_stmt, data )) return;
+ }
+ }
+ }
gimple_stmt_iterator gsi;
for ( gsi = gsi_start_bb ( bb); !gsi_end_p ( gsi); gsi_next ( &gsi) )
{
@@ -1854,11 +1878,25 @@ print_program ( FILE *file, int leading_space )
{
struct cgraph_node *node;
fprintf ( file, "%*sProgram:\n", leading_space, "");
+
+ // Print Global Decls
+ //
+ varpool_node *var;
+ FOR_EACH_VARIABLE ( var)
+ {
+ tree decl = var->decl;
+ fprintf ( file, "%*s", leading_space, "");
+ print_generic_decl ( file, decl, (dump_flags_t)0);
+ fprintf ( file, "\n");
+ }
+
FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node)
{
struct function *func = DECL_STRUCT_FUNCTION ( node->decl);
+ #if 0
// print func name
fprintf ( file, "%*sFunc: %s\n", leading_space + 2, "", lang_hooks.decl_printable_name ( node->decl, 2));
+ #endif
print_function ( file, leading_space + 4, func);
}
}
@@ -1867,6 +1905,26 @@ static void
print_function ( FILE *file, int leading_space, struct function *func)
{
basic_block bb;
+
+ fprintf ( file, "%*sFunc: ", leading_space + 2, "");
+ print_generic_expr ( file, TREE_TYPE(TREE_TYPE( func->decl)), (dump_flags_t)0);
+
+ // Print Func Name
+ fprintf ( file, " %s ( ", lang_hooks.decl_printable_name ( func->decl, 2));
+
+ // Print Parameter Decls
+ tree parm;
+ for ( parm = DECL_ARGUMENTS ( func->decl);
+ parm;
+ parm = DECL_CHAIN ( parm) )
+ {
+ print_generic_expr ( file, TREE_TYPE( parm), (dump_flags_t)0);
+ print_generic_expr ( file, parm, (dump_flags_t)0);
+ }
+ fprintf ( file, ")\n");
+
+
+ // TBD Print Local Decls
FOR_EACH_BB_FN ( bb, func)
{
@@ -1889,6 +1947,16 @@ print_function ( FILE *file, int leading_space, struct function *func)
}
fprintf ( file, "\n");
+ gimple_seq seq = bb->il.gimple.phi_nodes;
+ if ( seq )
+ {
+ gimple_stmt_iterator phii;
+ for ( phii = gsi_start (seq); !gsi_end_p (phii); gsi_next (&phii))
+ {
+ fprintf ( file, "%*s", leading_space + 2, "" );
+ print_gimple_stmt ( file, gsi_stmt ( phii), 0, TDF_DETAILS);
+ }
+ }
gimple_stmt_iterator gsi;
for ( gsi = gsi_start_bb ( bb);
@@ -1932,6 +2000,24 @@ uses_field_of_reorgtypes( gimple *stmt, Info * info)
return false;
}
+void
+modify_ssa_name_type ( tree ssa_name, tree type)
+{
+ // This rips off the code in make_ssa_name_fn.
+ // Note, this probabily be made into special function
+ // that is part of tree-ssanames.
+ if ( TYPE_P ( type))
+ {
+ TREE_TYPE ( ssa_name) = TYPE_MAIN_VARIANT ( type);
+ SET_SSA_NAME_VAR_OR_IDENTIFIER ( ssa_name, NULL_TREE);
+ }
+ else
+ {
+ TREE_TYPE ( ssa_name) = TREE_TYPE ( type);
+ SET_SSA_NAME_VAR_OR_IDENTIFIER ( ssa_name, type);
+ }
+}
+
//-- debugging only --
//static const char *
#if DEBUGGING
diff --git a/gcc/ipa-structure-reorg.h b/gcc/ipa-structure-reorg.h
index f9a687c1e44..af4219c15b2 100644
--- a/gcc/ipa-structure-reorg.h
+++ b/gcc/ipa-structure-reorg.h
@@ -136,6 +136,7 @@ enum ReorgTransformation {
ReorgT_Realloc, //
ReorgT_Free, //
ReorgT_UserFunc, //
+ ReorgT_Convert, // type casts
ReorgT_Return, // return t
Not_Supported
};
@@ -222,7 +223,7 @@ extern enum ReorgOpTrans recognize_op ( tree, Info_t *);
extern ReorgTransformation reorg_recognize ( gimple *,
cgraph_node *,
Info_t *);
-extern void apply_to_all_gimple ( bool (*)(gimple *, void *), void *);
+extern void apply_to_all_gimple ( bool (*)(gimple *, void *), bool, void *);
extern ReorgType_t *get_reorgtype_info ( tree, Info_t *);
extern void print_reorg_with_msg ( FILE *, ReorgType_t *, int, const char *);
extern ReorgType_t *contains_a_reorgtype ( gimple *, Info *);
@@ -232,6 +233,8 @@ extern tree base_type_of ( tree);
extern void print_reorg ( FILE *, int, ReorgType_t *);
extern void print_program ( FILE *, int);
extern void print_type ( FILE *, tree);
+extern void modify_ssa_name_type ( tree, tree);
+
//#define MAX(a,b) ((a) > (b) ? (a) : (b))