From 8eb34491762368af8b58d9bfdff2bca96ab1757f Mon Sep 17 00:00:00 2001 From: Gary Oblock Date: Wed, 12 Aug 2020 21:58:44 -0700 Subject: More clean up. --- gcc/ipa-str-reorg-instance-interleave.c | 261 ++++++++++++++++---------------- 1 file changed, 129 insertions(+), 132 deletions(-) (limited to 'gcc/ipa-str-reorg-instance-interleave.c') diff --git a/gcc/ipa-str-reorg-instance-interleave.c b/gcc/ipa-str-reorg-instance-interleave.c index 168204d2346..d90669372f7 100644 --- a/gcc/ipa-str-reorg-instance-interleave.c +++ b/gcc/ipa-str-reorg-instance-interleave.c @@ -1,4 +1,4 @@ -/* Interprocedural scalar replacement of aggregates +/* Interprocedural structure reorganization Copyright (C) 2019-2020 Free Software Foundation, Inc. Contributed by Gary Oblock @@ -285,13 +285,12 @@ str_reorg_instance_interleave_trans ( Info *info) // offset = index * size_of_field tree size_of_field = TYPE_SIZE_UNIT ( base_field_type); gcc_assert ( sizetype); - tree offset = make_temp_ssa_name( sizetype, NULL, "offset"); // TBD sizetype ??? + tree offset = make_temp_ssa_name( sizetype, NULL, "offset"); gimple *get_offset = gimple_build_assign ( offset, MULT_EXPR, index, size_of_field); SSA_NAME_DEF_STMT ( offset) = get_offset; // field_addr = field_array + offset - // bug fix here (TBD) type must be *double not double gcc_assert ( base_field_type); tree field_addr = make_temp_ssa_name( base_field_type, NULL, "field_addr"); @@ -455,11 +454,7 @@ str_reorg_instance_interleave_trans ( Info *info) 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 *gPPI = gimple_build_assign ( ptrplusint, PLUS_EXPR, PPI_rhs1_cast, PPI_adj); @@ -586,7 +581,7 @@ str_reorg_instance_interleave_trans ( Info *info) //tree len = make_temp_ssa_name( sizetype, NULL, "fail_val"); // The above segfaulted ??? note, it's not an idiom seen in gcc tree int_ptrsize_type = signed_type_for ( ptr_type_node); - DEBUG_L("int_ptrsize_type = %p\n", TREE_TYPE ( size)); + //DEBUG_L("int_ptrsize_type = %p\n", TREE_TYPE ( size)); gcc_assert ( TREE_TYPE ( size)); tree len = make_temp_ssa_name ( TREE_TYPE ( size), NULL, "malloc_len"); gimple_stmt_iterator gsi = gsi_for_stmt( stmt); @@ -623,7 +618,7 @@ str_reorg_instance_interleave_trans ( Info *info) // seem to be direct way of doing this... failure_bb->count = prev_bb->count - prev_bb->count; - // TBD set edge probability and flags + // set edge probability and flags edge fail_to_after_e = make_edge ( failure_bb, after_bb, EDGE_FALLTHRU); fail_to_after_e->probability = profile_probability::very_unlikely (); @@ -658,8 +653,10 @@ str_reorg_instance_interleave_trans ( Info *info) // Generate all the real allocation code // - // TBD! I think their are ramifications of built in malloc (and free) + // Note, I think there are ramifications of built in malloc (and free) // so I'm going try and use the malloc in the call transformed!!! + // Actually, I ended up using the built in free and it was + // the way to go. // //tree fndecl_malloc = builtin_decl_explicit( BUILT_IN_MALLOC); @@ -688,21 +685,23 @@ str_reorg_instance_interleave_trans ( Info *info) 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"); + //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"); + //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 // setting dominator seems to make no difference - // TBD set edge probability and flags + + // set edge probability and flags + // edge_flags depends on whether or not the predecessor // block was created in this loop. edge ok_edge = make_edge ( prev_bb, new_bb, edge_flags); @@ -964,14 +963,9 @@ str_reorg_instance_interleave_trans ( Info *info) cgraph_node::get ( cfun->decl)-> create_edge ( cgraph_node::get_create ( fndecl_free), free_call, - // Nah... lets do this a bit differently - //gimple_bb ( free_call)->count failure_bb->count ); - // TBD Note, this brings up the question of bb counts which is being - // punted on - tree rhs_ass = build3( COMPONENT_REF, base_field_type, base, @@ -1226,12 +1220,7 @@ str_reorg_instance_interleave_trans ( Info *info) DEBUG_L("after bulk of transformations\n"); - // New technique // A mini-pass to fixup dangling SSA temps. - // TBD Important, transform all fuction decls - // before doing anything else. - // TBD Call init_ssa_name_imm_use for certain - // ssa names. FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { @@ -1256,44 +1245,50 @@ str_reorg_instance_interleave_trans ( Info *info) // subsitute it into operand. For the left hand side we also // set the statement definition. - // STUFF TO USE - // release_ssa_name_fn - // FOR_EACH_IMM_USE_STMT - // Default defs case first + // For parameters - DEBUG_L("Dangling Types for Function Params (default defs).\n"); + + //DEBUG_L("Dangling Types for Function Params (default defs).\n"); INDENT(4); tree parm; for ( parm = DECL_ARGUMENTS ( func->decl); parm; parm = DECL_CHAIN ( parm) ) { - DEBUG_A("param: "); - DEBUG_F( print_generic_decl, stderr, parm, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_A("param: "); + //DEBUG_F( print_generic_decl, stderr, parm, (dump_flags_t)0); + //DEBUG("\n"); tree old_default_def = ssa_default_def ( func, parm); - DEBUG_A("old_default_def: "); - DEBUG_F( print_generic_expr, stderr, old_default_def, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_A("old_default_def: "); + //DEBUG_F( print_generic_expr, stderr, old_default_def, (dump_flags_t)0); + //DEBUG("\n"); tree new_default_def; // Modify prameter and do the default def stuff - // TBD The possibility exists that we'll need to create - // a new decl rather than modify the existing one. + + // Need to create a new decl rather than modify the existing + // one. + if ( modify_decl_core ( &parm, info) ) { //DEBUG_A("double check new param: "); //DEBUG_F( print_generic_decl, stderr, parm, (dump_flags_t)0); //DEBUG("\n"); - // TBD New default def here + + // New default def here // If the variable of the decl is initialized // then it shouldn't be associated with a default def. if ( old_default_def ) { - // TBD Do we delete the old one and if so, - // do we do it here and how do we do it? + // We must delete the old one or tranversing ssa names of + // the function will stumple across an SSA name associated + // with nothing, causing grief. + // + // We do it at the bottom of this code using a + // something I had to write (there was no existing + // mechanism.) // Create new default def here. // NOTE parm looks correct here but type of new_default_def @@ -1305,15 +1300,15 @@ str_reorg_instance_interleave_trans ( Info *info) // ??? these instead new_default_def = make_ssa_name_fn ( func, parm, gimple_build_nop ()); set_ssa_default_def ( func, parm, new_default_def); - - DEBUG_A("new_default_def: "); - DEBUG_F(print_generic_expr, stderr, new_default_def, (dump_flags_t)0); - DEBUG(", TYPE: "); - DEBUG_F(print_generic_expr, stderr, TREE_TYPE(new_default_def), (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_A("new_default_def: "); + //DEBUG_F(print_generic_expr, stderr, new_default_def, (dump_flags_t)0); + //DEBUG(", TYPE: "); + //DEBUG_F(print_generic_expr, stderr, TREE_TYPE(new_default_def), (dump_flags_t)0); + //DEBUG("\n"); - // Replace old one (PROBABLY DID THIS WRONG!) + // Replace old one (not really totally hence the + // remove_default_def below.) set_ssa_default_def ( func, parm, new_default_def); imm_use_iterator iter; @@ -1323,22 +1318,22 @@ str_reorg_instance_interleave_trans ( Info *info) // new default def FOR_EACH_IMM_USE_STMT ( stmt, iter, old_default_def) { - DEBUG_A("before: "); - DEBUG_F ( print_gimple_stmt, stderr, stmt, 0); + //DEBUG_A("before: "); + //DEBUG_F ( print_gimple_stmt, stderr, stmt, 0); use_operand_p use_p; ssa_op_iter ssa_iter; FOR_EACH_SSA_USE_OPERAND( use_p, stmt, ssa_iter, SSA_OP_USE ) { if ( use_p == NULL ) continue; tree use = USE_FROM_PTR (use_p); - DEBUG_A("use to replace: "); - DEBUG_F( print_generic_expr, stderr, use, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_A("use to replace: "); + //DEBUG_F( print_generic_expr, stderr, use, (dump_flags_t)0); + //DEBUG("\n"); if (use == old_default_def) SET_USE ( use_p, new_default_def); } - DEBUG_A("after: "); - DEBUG_F ( print_gimple_stmt, stderr, stmt, 0); + //DEBUG_A("after: "); + //DEBUG_F ( print_gimple_stmt, stderr, stmt, 0); } // Get rid of the old default def because it confuses // @@ -1347,27 +1342,35 @@ str_reorg_instance_interleave_trans ( Info *info) } } INDENT(-4); - // TBD reverse chain here? ... Hopefully not! DEBUG_L("Dangling Types for Function Local (default defs).\n"); INDENT(4); + // For locals + // + // Note, the code below looks half baked and might simply not + // encountered anything that breaks it (see the code for the + // parameters above how it might need to look.) + // + unsigned i; tree decl; FOR_EACH_LOCAL_DECL ( func, i, decl) { - DEBUG_A("local: "); - DEBUG_F( print_generic_decl, stderr, decl, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_A("local: "); + //DEBUG_F( print_generic_decl, stderr, decl, (dump_flags_t)0); + //DEBUG("\n"); tree old_default_def = ssa_default_def ( func, decl); tree new_default_def; // Modify prameter and do the default def stuff - // TBD The possibility exists that we'll need to create - // a new decl rather than modify the existing one. + + // Again we'll need to create a new decl rather than modify + // the existing one. + if ( modify_decl_core ( &decl, info) ) { - // TBD New default def here + // New default def here // If the variable of the decl is initialized // then it shouldn't be associated with a default def. @@ -1405,56 +1408,56 @@ str_reorg_instance_interleave_trans ( Info *info) // because new ssa names are created in the loop body and we // shouldn't process them. unsigned int len = SSANAMES ( func)->length (); - DEBUG_L("len = %d\n",len); + //DEBUG_L("len = %d\n",len); for ( unsigned int i = 0; i < len; i++) { - DEBUG_L("SSANAMES(func)[%d]\n",i); + //DEBUG_L("SSANAMES(func)[%d]\n",i); tree ssa_name = (*SSANAMES ( func))[i]; if( ssa_name == NULL ) { - DEBUG_L("Skip, ssa_name == NULL\n"); + //DEBUG_L("Skip, ssa_name == NULL\n"); continue; } if ( ssa_defined_default_def_p ( ssa_name)) { - DEBUG_L("Skip, ssa_name "); - DEBUG_F(print_generic_expr, stderr, ssa_name, (dump_flags_t)0); - DEBUG(" is default_def\n"); + //DEBUG_L("Skip, ssa_name "); + //DEBUG_F(print_generic_expr, stderr, ssa_name, (dump_flags_t)0); + //DEBUG(" is default_def\n"); continue; } tree type = TREE_TYPE ( ssa_name); tree bottom_type = base_type_of ( type); ReorgType_t *ri = get_reorgtype_info ( bottom_type, info); - DEBUG_L("ssa_name = "); - DEBUG_F(print_generic_expr, stderr, ssa_name, (dump_flags_t)0); - DEBUG(", type = "); - DEBUG_F(print_generic_expr, stderr, type, (dump_flags_t)0); - DEBUG(", bottom_type = "); - DEBUG_F(print_generic_expr, stderr, bottom_type, (dump_flags_t)0); - DEBUG(", ri = %p\n",ri); + //DEBUG_L("ssa_name = "); + //DEBUG_F(print_generic_expr, stderr, ssa_name, (dump_flags_t)0); + //DEBUG(", type = "); + //DEBUG_F(print_generic_expr, stderr, type, (dump_flags_t)0); + //DEBUG(", bottom_type = "); + //DEBUG_F(print_generic_expr, stderr, bottom_type, (dump_flags_t)0); + //DEBUG(", ri = %p\n",ri); // If it's not a dangling type we don't care if ( ri == NULL ) { - DEBUG_L("Skip, ri == NULL\n"); + //DEBUG_L("Skip, ri == NULL\n"); continue; } tree new_type = ri->pointer_rep; tree new_ssa_name = make_temp_ssa_name( new_type, NULL, "dedangled"); - DEBUG_L("new_ssa_name = "); - DEBUG_F(print_generic_expr, stderr, new_ssa_name, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_L("new_ssa_name = "); + //DEBUG_F(print_generic_expr, stderr, new_ssa_name, (dump_flags_t)0); + //DEBUG("\n"); #if DEBUGGING for ( unsigned int j = 0; j < SSANAMES ( func)->length (); j++) { if ( (*SSANAMES ( func))[j] == new_ssa_name ) { - DEBUG_L("new name at j = %d\n",j); + //DEBUG_L("new name at j = %d\n",j); break; } } @@ -1464,16 +1467,10 @@ str_reorg_instance_interleave_trans ( Info *info) imm_use_iterator iter; FOR_EACH_IMM_USE_STMT ( use_stmt, iter, ssa_name) { - // The statement should be an assign and the - // ssa name should be on the left hand side. - // This is because all other ssa names uses - // should have been transformed out of existence - // at this point in time. - // TBD -- put in asserts to this effect - DEBUG_L("use_stmt: "); - DEBUG_F ( print_gimple_stmt, stderr, use_stmt, 0); - - // !!! FIX it with operand walk! + //DEBUG_L("use_stmt: "); + //DEBUG_F ( print_gimple_stmt, stderr, use_stmt, 0); + + // Deal with the uses use_operand_p use_p; ssa_op_iter ssa_iter; FOR_EACH_SSA_USE_OPERAND( use_p, use_stmt, ssa_iter, SSA_OP_USE ) @@ -1485,7 +1482,7 @@ str_reorg_instance_interleave_trans ( Info *info) SET_USE ( use_p, new_ssa_name); } // Should update_stmt be called here? - // It does seem either harm or help so I'll + // It does not seem either harm or help so I'll // leave it in. update_stmt ( use_stmt); } @@ -1493,8 +1490,11 @@ str_reorg_instance_interleave_trans ( Info *info) // TBD This code needs to be more general. gimple *def = SSA_NAME_DEF_STMT ( ssa_name); - DEBUG_L("def: "); - DEBUG_F ( print_gimple_stmt, stderr, def, 0); + //DEBUG_L("def: "); + //DEBUG_F ( print_gimple_stmt, stderr, def, 0); + + // Note, the following code might be a bit overly + // simplistic. if ( gimple_code ( def) != GIMPLE_ASSIGN ) continue; @@ -1521,29 +1521,30 @@ str_reorg_instance_interleave_trans ( Info *info) } } +// TBD no longer used... preserve it for a bit, then remove it. static void wrangle_ssa_type( tree side, Info_t *info ) { tree side_type = TREE_TYPE ( side); tree bottom_type = base_type_of ( side_type); - DEBUG_L("op: "); - DEBUG_F(print_generic_expr, stderr, side, (dump_flags_t)0); - DEBUG("\n"); - DEBUG_L("bottom_type: "); - DEBUG_F(print_generic_expr, stderr, bottom_type, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_L("op: "); + //DEBUG_F(print_generic_expr, stderr, side, (dump_flags_t)0); + //DEBUG("\n"); + //DEBUG_L("bottom_type: "); + //DEBUG_F(print_generic_expr, stderr, bottom_type, (dump_flags_t)0); + //DEBUG("\n"); // Maybe we sould pass in ri as an argument??? ReorgType_t *ri = get_reorgtype_info ( bottom_type, info); tree prev_type = side_type; tree type = TREE_TYPE ( prev_type); - DEBUG_L( "prev_type: %p, type: %p\n", prev_type, type); + //DEBUG_L( "prev_type: %p, type: %p\n", prev_type, type); int levels; for ( levels = 0; TREE_CODE ( type) == POINTER_TYPE; levels++ ) { prev_type = type; type = TREE_TYPE ( prev_type); - DEBUG_L( "prev_type: %p, type: %p\n", prev_type, type); + //DEBUG_L( "prev_type: %p, type: %p\n", prev_type, type); } // I thought about doing this: @@ -1559,13 +1560,13 @@ wrangle_ssa_type( tree side, Info_t *info ) // Fakes this for levels == 1 if ( levels == 0) { - DEBUG_L( "LEVELS ZERO\n"); + //DEBUG_L( "LEVELS ZERO\n"); modify_ssa_name_type ( side, ri->pointer_rep); - DEBUG_L("after modify_ssa_name_type\n"); + //DEBUG_L("after modify_ssa_name_type\n"); } else { - DEBUG_L( "LEVELS > ZERO\n"); + //DEBUG_L( "LEVELS > ZERO\n"); gcc_assert(0); } } @@ -1722,7 +1723,7 @@ header ( bool initialize ) static void create_new_types ( Info_t *info) { - std::map < tree, BoolPair_t>::iterator tmi; // TBD what is + std::map < tree, BoolPair_t>::iterator tmi; for( tmi = info->struct_types->begin (); tmi != info->struct_types->end (); tmi++ ) { @@ -1763,9 +1764,9 @@ create_a_new_type ( Info_t *info, tree type) tree reorg_type_prime = lang_hooks.types.make_type (RECORD_TYPE); ri->reorg_ver_type = reorg_type_prime; - DEBUG_L("TYPE_SIZE(reorg_type_prime): %p, ", TYPE_SIZE(reorg_type_prime)); + //DEBUG_L("TYPE_SIZE(reorg_type_prime): %p, ", TYPE_SIZE(reorg_type_prime)); //DEBUG_F( print_generic_expr, stderr, TYPE_SIZE(reorg_type_prime), (dump_flags_t)-1); - DEBUG("\n"); + //DEBUG("\n"); /* Multi-pool only // Create pointer_rep @@ -1803,23 +1804,17 @@ create_a_new_type ( Info_t *info, tree type) strcat ( name, gcc_name); TYPE_NAME ( pointer_rep) = get_identifier ( name); ri->pointer_rep = pointer_rep; - DEBUG_L("pointer_rep = "); - DEBUG_F( print_generic_expr, stderr, pointer_rep, (dump_flags_t)-1); - DEBUG("\n"); - DEBUG_A("TYPE_MAIN_VARIANT ( pointer_rep) = "); - DEBUG_F( print_generic_expr, stderr, TYPE_MAIN_VARIANT ( pointer_rep), (dump_flags_t)-1); - 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 - // in the ReorgType. - // - // Note, someplace (probably here) also has to declare a base type - // variable (probably globally.) Doesn't this variable also belong - // in the ReorgType? + //DEBUG_L("pointer_rep = "); + //DEBUG_F( print_generic_expr, stderr, pointer_rep, (dump_flags_t)-1); + //DEBUG("\n"); + //DEBUG_A("TYPE_MAIN_VARIANT ( pointer_rep) = "); + //DEBUG_F( print_generic_expr, stderr, TYPE_MAIN_VARIANT ( pointer_rep), (dump_flags_t)-1); + //DEBUG("\n"); + + // Note, we also declare a base type variable (globally.) + // This variable also belong in the ReorgType. // Set name of reorg_type_prime - // TBD shouldn't base_type_name be different from gcc_name above const char *base_type_name = identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME ( ri->gcc_type))); len = strlen ( REORG_SP_PREFIX) + strlen ( base_type_name); @@ -1827,7 +1822,7 @@ create_a_new_type ( Info_t *info, tree type) strcpy ( rec_name, REORG_SP_PREFIX); strcat ( rec_name, base_type_name); - DEBUG_L("TYPE_SIZE(reorg_type_prime): %p\n", TYPE_SIZE(reorg_type_prime)); + //DEBUG_L("TYPE_SIZE(reorg_type_prime): %p\n", TYPE_SIZE(reorg_type_prime)); // Build the new pointer type fields TYPE_NAME ( reorg_type_prime) = get_identifier ( rec_name); @@ -1843,8 +1838,10 @@ create_a_new_type ( Info_t *info, tree type) FIELD_DECL, DECL_NAME (field), new_fld_type); DECL_CONTEXT ( new_decl) = reorg_type_prime; layout_decl ( new_decl, 0); - // Missing a bunch of attributes (see tree-nested.c:899) - // Let us seee what happens without them! + + // We might be missing a bunch of attributes (see + // tree-nested.c:899) But we seem without without them! + DECL_CHAIN ( new_decl) = new_fields; // <- bug: need decl, not type new_fields = new_decl; //DEBUG( "built new pointer type field:"); @@ -1852,7 +1849,7 @@ create_a_new_type ( Info_t *info, tree type) //DEBUG( "\n"); } - DEBUG_L("TYPE_SIZE(reorg_type_prime): %p\n", TYPE_SIZE(reorg_type_prime)); + //DEBUG_L("TYPE_SIZE(reorg_type_prime): %p\n", TYPE_SIZE(reorg_type_prime)); // store reversed fields into reorg_type_prime TYPE_FIELDS ( reorg_type_prime) = NULL; @@ -1865,7 +1862,7 @@ create_a_new_type ( Info_t *info, tree type) DECL_CHAIN ( field) = TYPE_FIELDS ( reorg_type_prime); TYPE_FIELDS ( reorg_type_prime) = field; } - DEBUG_L("TYPE_SIZE(reorg_type_prime): %p\n", TYPE_SIZE(reorg_type_prime)); + //DEBUG_L("TYPE_SIZE(reorg_type_prime): %p\n", TYPE_SIZE(reorg_type_prime)); // Fix-up the layout layout_type ( reorg_type_prime); -- cgit v1.2.3