diff options
Diffstat (limited to 'gcc/ipa-structure-reorg.c')
-rw-r--r-- | gcc/ipa-structure-reorg.c | 170 |
1 files changed, 124 insertions, 46 deletions
diff --git a/gcc/ipa-structure-reorg.c b/gcc/ipa-structure-reorg.c index 80b0acb4c83..46501b090eb 100644 --- a/gcc/ipa-structure-reorg.c +++ b/gcc/ipa-structure-reorg.c @@ -25,28 +25,29 @@ along with GCC; see the file COPYING3. If not see #include "backend.h" #include "tree.h" #include "gimple.h" +#include "gimple-iterator.h" +#include "gimple-walk.h" +#include "gimple-collector.hpp" +#include "gimple-escaper.hpp" #include "tree-pass.h" +#include "tree-cfg.h" #include "cgraph.h" -#include "gimple-iterator.h" -#include "pretty-print.h" -#include <vector> -#include <map> -#include <set> -#include "ipa-structure-reorg.h" #include "dumpfile.h" #include "pretty-print.h" #include "tree-pretty-print.h" #include "gimple-pretty-print.h" #include "langhooks.h" -#include "gimple-walk.h" -// TBD more includes go here -#include "gimple-collector.hpp" -#include "gimple-escaper.hpp" #include "collect-types.h" #include "stor-layout.h" +#include "tree-dfa.h" +#include <vector> +#include <map> +#include <set> +#include "ipa-structure-reorg.h" static void setup_debug_flags ( Info *); +static void initial_debug_info ( Info *); static void final_debug_info ( Info *); static unsigned int reorg_analysis ( Info *); static void reorg_analysis_debug ( Info *, ReorgType *); @@ -90,7 +91,7 @@ static void print_detailed_reorgs ( FILE *, int, Info *); //static void print_reorg ( FILE *, int, ReorgType_t *); static void print_progdecls ( FILE *, int, Info *); static void print_progdecl ( FILE *, int, ProgDecl_t *); -//static void print_program ( FILE *, int); +//static void print_program ( FILE *, bool, int); static void print_function ( FILE *, int, function *); static ReorgType_t *get_reorgtype( gimple *stmt, Info *, int); static int num_reorgtypes( gimple *, Info *); @@ -125,8 +126,10 @@ ipa_structure_reorg ( void) // to initialize? // Also, all functions should be references and not pointers... Info info(&Reorg_Type, &Saved_Reorg_Type, &Prog_Decl, &StructTypes); + //DEBUG_L("At init dum_deleted %d\n",info.num_deleted); setup_debug_flags ( &info); + //initial_debug_info ( &info); if ( !reorg_analysis ( &info) ) { @@ -208,12 +211,21 @@ setup_debug_flags ( Info *info) } static void +initial_debug_info ( Info *info) +{ + if ( info->reorg_dump_file ) + { + print_program ( info->reorg_dump_file, PRINT_FORMAT, 0); + } +} + +static void final_debug_info ( Info *info) { - // TBD if ( info->reorg_dump_file ) { - print_program ( info->reorg_dump_file, 0); + print_program ( info->reorg_dump_file, PRINT_FORMAT, 0); + //wolf_fence ( info); } } @@ -343,6 +355,7 @@ reorg_analysis ( Info *info) } //INDENT(-2); + //DEBUG_L("after reorg_analysis\n"); remove_deleted_types ( info, &reorg_analysis_debug); if ( info->show_all_reorg_cands ) @@ -429,10 +442,10 @@ static bool find_decls_and_types ( Info *info) struct function *fn = DECL_STRUCT_FUNCTION ( node->decl); // enable this to see error in test_1_8. Note, not a bug... - DEBUG_L( " function name = %s\n", lang_hooks.decl_printable_name ( node->decl, 2)); + //DEBUG_L( " function name = %s\n", lang_hooks.decl_printable_name ( node->decl, 2)); if ( fn == NULL ) { - DEBUG_L( " EMPTY\n"); + //DEBUG_L( " EMPTY\n"); continue; } @@ -459,7 +472,7 @@ static bool find_decls_and_types ( Info *info) typeset.insert ( base); // ??? } } - //INDENT(-2) + //INDENT(-2); } // We need this later for creating new types @@ -584,7 +597,7 @@ static bool find_decls_and_types ( Info *info) //INDENT(-2); } //INDENT(-2); - + //DEBUG_L( "after Scan all types in ReorgTypes for structure fields\n"); remove_deleted_types ( info, &initial_reorg_debug); // Disqualifying structures in interior to structures is optional @@ -706,6 +719,9 @@ add_reorg_type ( tree base, Info *info) { 0, true, base, NULL, NULL, false, false, false, { 0}, { 0}, { 0, 0, 0, NULL, 0.0, 0.0, false}}; + //DEBUG_L("add_reorg_type: "); + //DEBUG_F(print_generic_expr, base, (dump_flags_t)0); + //DEBUG("\n"); info->reorg_type->push_back ( rt); // Remember the intial assumption is the type added will be deleted // and is marked to be deleted. @@ -773,7 +789,7 @@ disqualify_struct_in_struct_or_union ( Info *info) } //INDENT(-2); } - + //DEBUG_L("after disqualify_struct_in_struct_or_union\n"); remove_deleted_types ( info, &disqualify_struct_in_struct_or_union_debug); } @@ -928,6 +944,8 @@ transformation_legality ( Info *info) { if ( reorg_recognize( stmt, node, info) == Not_Supported ) { + DEBUG_L("deleting %d reorgs for unsuported stmt: ", num); + DEBUG_F ( print_gimple_stmt, stderr, stmt, 0); int i; for ( i = 0; i < num; i++ ) { @@ -946,6 +964,7 @@ transformation_legality ( Info *info) } } + //DEBUG_L("after transformation_legality\n"); remove_deleted_types ( info, &transformation_legality_debug); return !info->reorg_type->empty (); @@ -994,9 +1013,9 @@ modify_declarations ( Info *info) static void modify_decl_core ( tree *location, Info *info) { - DEBUG_L("before modify_decl_core"); - DEBUG_F( print_generic_decl, stderr, *location, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_L("before modify_decl_core"); + //DEBUG_F( print_generic_decl, stderr, *location, (dump_flags_t)0); + //DEBUG("\n"); tree type = *location; tree base = base_type_of ( type); ReorgType_t *ri = get_reorgtype_info ( base, info); @@ -1016,20 +1035,20 @@ modify_decl_core ( tree *location, Info *info) { 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); } // 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( "LEVEL ZERO\n"); + //DEBUG_L( "LEVEL ZERO\n"); //modify_ssa_name_type ( side, ri->pointer_rep); TREE_TYPE ( *location) = TYPE_MAIN_VARIANT ( ri->pointer_rep); } else { - DEBUG_L( "LEVEL > ZERO\n"); + //DEBUG_L( "LEVEL > ZERO\n"); gcc_assert(0); } @@ -1041,36 +1060,36 @@ modify_decl_core ( tree *location, Info *info) relayout_decl ( *location); - DEBUG_L(" after modify_decl_core"); - DEBUG_F( print_generic_decl, stderr, *location, (dump_flags_t)0); - DEBUG("\n"); + //DEBUG_L(" after modify_decl_core"); + //DEBUG_F( print_generic_decl, stderr, *location, (dump_flags_t)0); + //DEBUG("\n"); } void delete_reorgtype ( ReorgType_t *rt, Info *info ) { - //DEBUG_L( "delete_reorgtype( %s ):", type_name_to_str( TYPE_NAME( rt->gcc_type))); + DEBUG_L( "delete_reorgtype( %s ):", type_name_to_str( TYPE_NAME( rt->gcc_type))); if ( !rt->delete_me ) { - //DEBUG( "TO DELETE\n"); + DEBUG( "TO DELETE\n"); info->num_deleted++; rt->delete_me = true; } else { - //DEBUG( "SKIP\n"); + DEBUG( "SKIP\n"); } } void undelete_reorgtype ( ReorgType_t *rt, Info *info ) { - //DEBUG_L( "undelete_reorgtype( %s ): ", type_name_to_str( TYPE_NAME( rt->gcc_type))); + DEBUG_L( "undelete_reorgtype( %s ): ", type_name_to_str( TYPE_NAME( rt->gcc_type))); if ( rt->delete_me ) { - //DEBUG( "UNDELETE\n"); + DEBUG( "UNDELETE\n"); info->num_deleted--; rt->delete_me = false; } else { - //DEBUG( "SKIP\n"); + DEBUG( "SKIP\n"); } } @@ -1850,10 +1869,10 @@ print_base_reorg ( FILE *file, int leading_space, ReorgType_t *reorg, bool detai field = DECL_CHAIN( field)) { fprintf ( file, "%*s", leading_space + 4, ""); - print_generic_expr ( stderr, field, (dump_flags_t)0); + print_generic_expr ( file, field, (dump_flags_t)0); fprintf ( stderr, ": "); - print_generic_expr ( stderr, TREE_TYPE ( field), (dump_flags_t)0); - fprintf ( stderr, "\n"); + print_generic_expr ( file, TREE_TYPE ( field), (dump_flags_t)0); + fprintf ( file, "\n"); } } } @@ -1907,7 +1926,7 @@ print_progdecl ( FILE *file, int leading_space, ProgDecl_t *progdecl ) } void -print_program ( FILE *file, int leading_space ) +print_program ( FILE *file, bool my_format, int leading_space ) { struct cgraph_node *node; fprintf ( file, "%*sProgram:\n", leading_space, ""); @@ -1926,11 +1945,15 @@ print_program ( FILE *file, int leading_space ) 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); + if ( my_format ) + { + print_function ( file, leading_space + 4, func); + } + else + { + dump_function_header ( file, func->decl, (dump_flags_t)0); + dump_function_to_file ( func->decl, file, (dump_flags_t)0); + } } } @@ -2019,15 +2042,50 @@ print_function ( FILE *file, int leading_space, struct function *func) ReorgType_t * get_reorgtype( gimple *stmt, Info *info, int i) { - // TBD - Straight forward - NULL; + // Looking at operands of statement, when we get to + // the ith one, return it. + int num_reorgs = 0; + unsigned num_ops = gimple_num_ops ( stmt); + unsigned j; + for ( j = 0; j < num_ops; j++ ) + { + tree op = gimple_op ( stmt, j); + if ( tree_contains_a_reorgtype_p ( op, info) ) { + num_reorgs++; + if ( num_reorgs == i ) + { + return get_reorgtype_info ( op, info); + } + } + } + gcc_assert ( 0); } int num_reorgtypes( gimple *stmt, Info *info) { - // TBD - Straight forward - 0; + //DEBUG_L("num_reorgtypes: "); + //DEBUG_F ( print_gimple_stmt, stderr, stmt, 0); + // Looking at operands of statement, count + // the number that have reorg types. + // Note, they may be (most likely are) the same as other + // reorg types in the statement. + int num_reorgs = 0; + unsigned num_ops = gimple_num_ops ( stmt); + unsigned i; + for ( i = 0; i < num_ops; i++ ) + { + tree op = gimple_op ( stmt, i); + //DEBUG_A("op%d: ",i); + //DEBUG_F( print_generic_expr, stderr, op, (dump_flags_t)-1); + if ( tree_contains_a_reorgtype_p ( op, info) ) + { + num_reorgs++; + //DEBUG(" reorg"); + } + //DEBUG( "\n"); + } + return num_reorgs; } void @@ -2042,6 +2100,8 @@ bool uses_field_of_reorgtypes( gimple *stmt, Info * info) { // TBD + // This is a bit more sophisticated than needed + // for "hello world" so I'll defer this for a bit. return false; } @@ -2053,6 +2113,7 @@ modify_ssa_name_type ( tree ssa_name, tree type) // that is part of tree-ssanames. if ( TYPE_P ( type)) { + //DEBUG_L("modify_ssa_name_type TYPE_P true\n"); TREE_TYPE ( ssa_name) = TYPE_MAIN_VARIANT ( type); SET_SSA_NAME_VAR_OR_IDENTIFIER ( ssa_name, NULL_TREE); } @@ -2131,6 +2192,23 @@ handle_debug_indenting ( int amount ) } #endif +#if DEBUGGING +// This is whatever it needs to be whenever it needss to be it. +// Note, dump_dfa_stats doesn't cause a failure!!!!! +void +wolf_fence ( Info *info) +{ + struct cgraph_node *node; + fprintf( stderr, "Wolf Fence: Attempting segfault by dumping dfa stats\n"); + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { + struct function *func = DECL_STRUCT_FUNCTION ( node->decl); + push_cfun ( func); + dump_dfa_stats ( stderr); + pop_cfun (); + } +} +#endif + //---------------- Pass Control Follows ---------------- const pass_data pass_data_ipa_structure_reorg = |