diff options
author | Gary Oblock <gary@amperecomputing.com> | 2020-08-28 17:49:40 -0700 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-09-08 09:05:47 +0200 |
commit | c731681fba1ca88791489623e7456d1719e86c09 (patch) | |
tree | a1e67ba98e38020cda2ff6f1188a1328ea130ef2 | |
parent | 00ffc35e25fcbfa7d1968d78272cd4ae2671c490 (diff) |
The unit test test_08_20c now works. There was some major
insanity happening in processing ssa_names because I was using
the wrong method of determining default_defs.
-rw-r--r-- | gcc/ipa-str-reorg-instance-interleave.c | 336 | ||||
-rw-r--r-- | gcc/ipa-structure-reorg.c | 162 | ||||
-rw-r--r-- | gcc/ipa-structure-reorg.h | 13 |
3 files changed, 395 insertions, 116 deletions
diff --git a/gcc/ipa-str-reorg-instance-interleave.c b/gcc/ipa-str-reorg-instance-interleave.c index fb08824f04f..7ba1da525f9 100644 --- a/gcc/ipa-str-reorg-instance-interleave.c +++ b/gcc/ipa-str-reorg-instance-interleave.c @@ -58,6 +58,7 @@ static void create_a_new_type ( Info_t *, tree); static unsigned int reorg_perf_qual ( Info *); static tree find_coresponding_field ( tree, tree); static void remove_default_def ( tree, struct function *); +static void set_lhs_for ( gimple *, tree); // These are local to this file by design @@ -68,6 +69,34 @@ static void remove_default_def ( tree, struct function *); // TBD Delete all this after sending a note on it // to the gcc mailing list. #define USE_BUILT_IN_FREE 1 + +/* +0000 ssa_verify error loc_3 +0001 tree_class_check err in interleave +0010 ssa_verify error arr_46 +0011 ssa_verify error loc_3 +0100 ssa_verify error loc_3 +0101 ssa_verify error arr_46 +0110 ssa_verify error arr_46 +0111 ssa_verify error arr_46 +1000 ssa_verify error loc_3 +1001 bad failure: walk return bogus op +1010 bad failure: walk return bogus op +1011 bad failure: walk return bogus op +1100 bad failure: walk return bogus op +1101 bad failure: walk return bogus op +1110 bad failure: walk return bogus op +1111 bad failure: walk return bogus op +*/ + + +#define TOGSSA1 1 +#define TOGSSA2 1 +#define TOGUPD1 1 +#define TOGUPD2 1 +// ignore TOGUPD3 +#define TOGUPD3 1 +#define TOGUPD4 1 int str_reorg_instance_interleave_qual ( Info *info) @@ -90,6 +119,9 @@ str_reorg_instance_interleave_trans ( Info *info) fprintf ( info->reorg_dump_file, "Start of str_reorg_instance_interleave_trans:\n"); print_program ( info->reorg_dump_file, PRINT_FORMAT, 4, info); } + + DEBUG ("INTERNALS PRINT\n"); + DEBUG_F (apply_to_all_gimple, print_internals, true, (void *)info); struct cgraph_node *node; FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { @@ -143,7 +175,7 @@ str_reorg_instance_interleave_trans ( Info *info) { print_gimple_stmt( info->reorg_dump_file, stmt, 0); } - + switch ( trans) { case ReorgT_StrAssign: @@ -213,7 +245,7 @@ str_reorg_instance_interleave_trans ( Info *info) DEBUG_L("ReorgT_ElemAssign: "); DEBUG_F( print_gimple_stmt, stderr, stmt, 0); - //INDENT(2); + INDENT(2); // Needed for helloworld tree lhs = gimple_assign_lhs( stmt); tree rhs = gimple_assign_rhs1( stmt); @@ -395,16 +427,37 @@ str_reorg_instance_interleave_trans ( Info *info) } // end recognize_op ( rhs, info) switch - //INDENT(-2); + INDENT(-2); } // end ReorgT_ElemAssign case break; case ReorgT_If_Null: case ReorgT_If_NotNull: - DEBUG_L("ReorgT_If_(Not)Null\n"); - /* - gimple_cond_set_rhs( stmt, - TYPE_MIN_VALUE( pointer_sized_int_node)); - */ + { + DEBUG_L("ReorgT_If_(Not)Null: "); + DEBUG_F( print_gimple_stmt, stderr, stmt, 0); + /* + gimple_cond_set_rhs( stmt, + TYPE_MAX_VALUE( pointer_sized_int_node)); + */ + // TYPE_MAX_VALUE ( TREE_TYPE ( fail_val) + gimple_stmt_iterator gsi = gsi_for_stmt( stmt); + ReorgType_t *ri = contains_a_reorgtype( stmt, info); + //tree null_val = + // make_temp_ssa_name ( ri->pointer_rep, NULL, "if_cond_null"); + gcond *cond_stmt = as_a <gcond *> (stmt); + + //tree max = TYPE_MAX_VALUE ( TREE_TYPE ( ri->pointer_rep)); + tree max = TYPE_MAX_VALUE ( ri->pointer_rep); + + DEBUG_L("max: "); + DEBUG_F(print_generic_expr, stderr, max, (dump_flags_t)0); + DEBUG("\n"); + + gimple_cond_set_rhs( cond_stmt, max); + + DEBUG_L("after: "); + DEBUG_F( print_gimple_stmt, stderr, stmt, 0); + } break; case ReorgT_IfPtrEQ: case ReorgT_IfPtrNE: @@ -413,7 +466,7 @@ str_reorg_instance_interleave_trans ( Info *info) case ReorgT_IfPtrLE: case ReorgT_IfPtrGE: DEBUG_L("ReorgT_IfPtr*\n"); - // Not needed for single pool. + // Not needed for single pool. TBD test this break; case ReorgT_PtrPlusInt: // "a = b + i" { @@ -473,19 +526,20 @@ str_reorg_instance_interleave_trans ( Info *info) gsi_remove ( &gsi, true); - //DEBUG_L(""); - //DEBUG_F( print_gimple_stmt, stderr, gPPI_rhs2_cast, 0); - //DEBUG_L(""); - //DEBUG_F( print_gimple_stmt, stderr, gPPI_adj, 0); - //DEBUG_L(""); - //DEBUG_F( print_gimple_stmt, stderr, gPPI, 0); - //DEBUG_L(""); - //DEBUG_F( print_gimple_stmt, stderr, gPPI_cast, 0); + DEBUG_L(""); + DEBUG_F( print_gimple_stmt, stderr, gPPI_rhs2_cast, 0); + DEBUG_L(""); + DEBUG_F( print_gimple_stmt, stderr, gPPI_adj, 0); + DEBUG_L(""); + DEBUG_F( print_gimple_stmt, stderr, gPPI, 0); + DEBUG_L(""); + DEBUG_F( print_gimple_stmt, stderr, gPPI_cast, 0); } break; case ReorgT_Ptr2Zero: // "a = 0" DEBUG_L("ReorgT_Ptr2Zero\n"); /* + // TBD // Note, this is way too simple... just saying. gimple_set_op( stmt, 1, TYPE_MIN_VALUE( pointer_sized_int_node)); @@ -493,10 +547,11 @@ str_reorg_instance_interleave_trans ( Info *info) break; case ReorgT_PtrDiff: // "i = a - b" DEBUG_L("ReorgT_PtrDiff\n"); - // Do nothing in the single pool case. + // Do nothing in the single pool case. TBD test this break; case ReorgT_Adr2Ptr: // "a = &x[i]" DEBUG_L("ReorgT_Adr2Ptr\n"); + // TBD /* tree *add_stmt = gimple_build_assign( @@ -513,7 +568,8 @@ str_reorg_instance_interleave_trans ( Info *info) break; case ReorgT_PtrNull: // "x = a == 0" case ReorgT_PtrNotNull: // "x = a != 0" - DEBUG_L("ReorgT_Ptr(Not)Null\n"); + DEBUG_L("ReorgT_Ptr(Not)Null\n");\ + // TBD /* gimple_set_op( stmt, 2, TYPE_MIN_VALUE( pointer_sized_int_node)); @@ -526,12 +582,12 @@ str_reorg_instance_interleave_trans ( Info *info) case ReorgT_PtrGT: // "i = a > b" case ReorgT_PtrGE: // "i = a >= b" DEBUG_L("ReorgT_Ptr*\n"); - // Not needed for single pool. + // Not needed for single pool. TBD test this break; case ReorgT_Malloc: { DEBUG_L("Transform ReorgT_Malloc\n"); - //INDENT(2); + INDENT(2); // We need to use the user malloc function // declaration rather than the builtin!!! @@ -896,7 +952,9 @@ str_reorg_instance_interleave_trans ( Info *info) gimple_build_assign ( val, CONVERT_EXPR, m_phi_val); SSA_NAME_DEF_STMT ( val) = gm_cast_phi_val; - gsi_insert_after( &gsi, gm_cast_phi_val, GSI_NEW_STMT); + //gsi_insert_after( &gsi, gm_cast_phi_val, GSI_NEW_STMT); + // TBD What does GSI_NEW_STMT do if the block isn't emply? + gsi_insert_before( &gsi, gm_cast_phi_val, GSI_NEW_STMT); //// FROM gsi_insert_after( &gsi, after_label) //gimple *gafter_label = gimple_build_label( after_label_L); @@ -916,7 +974,7 @@ str_reorg_instance_interleave_trans ( Info *info) // FROM gsi_insert_after( &gsi, "fail_val = minint") gimple *gretnull = gimple_build_assign ( fail_val, CONVERT_EXPR, - TYPE_MIN_VALUE ( TREE_TYPE ( fail_val))); + TYPE_MAX_VALUE ( TREE_TYPE ( fail_val))); SSA_NAME_DEF_STMT ( fail_val) = gretnull; gsi_insert_after( &gsi, gretnull, GSI_NEW_STMT); @@ -976,9 +1034,10 @@ str_reorg_instance_interleave_trans ( Info *info) //DEBUG_L("End of malloc:\n"); //DEBUG_F( print_program, PRINT_FORMAT, stderr, 4); } - //INDENT(-2); + INDENT(-2); break; case ReorgT_Calloc: + // TBD DEBUG_L("ReorgT_Calloc\n"); /* // This used to be almost a clone of the old version of @@ -1067,6 +1126,7 @@ str_reorg_instance_interleave_trans ( Info *info) */ break; case ReorgT_Realloc: + // TBD DEBUG_L("ReorgT_Realloc\n"); /* // This used to be closely related to the old version of @@ -1144,6 +1204,7 @@ str_reorg_instance_interleave_trans ( Info *info) */ break; case ReorgT_Free: + // TBD DEBUG_L("ReorgT_Free\n"); // We won't free the base because it a global. /* @@ -1176,6 +1237,7 @@ str_reorg_instance_interleave_trans ( Info *info) case ReorgT_Convert: // Ignore type casting because another // mini-pass sweeps up any ugly dangling types. + // TBD test this DEBUG_L("ReorgT_Convert\n"); break; case ReorgT_Return: @@ -1193,13 +1255,25 @@ str_reorg_instance_interleave_trans ( Info *info) DEBUG_L("after bulk of transformations\n"); + DEBUG_F( print_program, info->reorg_dump_file, PRINT_FORMAT, 4, info); + + DEBUG ("INTERNALS PRINT\n"); + DEBUG_F (apply_to_all_gimple, print_internals, true, (void *)info); + // A mini-pass to fixup dangling SSA temps. FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { struct function *func = DECL_STRUCT_FUNCTION ( node->decl); push_cfun ( func); + + std::vector <tree> ssa_to_delete; + + DEBUG_L("Mini-Pass on Function %s:\n", lang_hooks.decl_printable_name ( func->decl, 2)); + DEBUG_L("\n"); + DEBUG_F( wolf_fence, info); + // We need a map of old ssa_name to new ssa_name. Not currently used. std::map <tree,tree> ssa_map; @@ -1222,20 +1296,21 @@ str_reorg_instance_interleave_trans ( Info *info) // For parameters - //DEBUG_L("Dangling Types for Function Params (default defs).\n"); - //INDENT(4); + 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"); + INDENT(2); 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 @@ -1245,9 +1320,9 @@ str_reorg_instance_interleave_trans ( Info *info) 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"); + DEBUG_A("double check new param: "); + DEBUG_F( print_generic_decl, stderr, parm, (dump_flags_t)0); + DEBUG("\n"); // New default def here @@ -1274,12 +1349,13 @@ str_reorg_instance_interleave_trans ( Info *info) 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"); + // TBD REMOVE DUPLICATE! // Replace old one (not really totally hence the // remove_default_def below.) set_ssa_default_def ( func, parm, new_default_def); @@ -1291,8 +1367,8 @@ str_reorg_instance_interleave_trans ( Info *info) // new default def FOR_EACH_IMM_USE_STMT ( stmt, iter, old_default_def) // <== use other form??? Not { - //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; // The F_E_S_U_O macro was blowing up on a phi @@ -1301,25 +1377,30 @@ str_reorg_instance_interleave_trans ( Info *info) { 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 // - remove_default_def ( old_default_def, func); + //remove_default_def ( old_default_def, func); + ssa_to_delete.push_back ( old_default_def); + release_ssa_name_fn ( func, old_default_def); } } + INDENT(-2); } - //INDENT(-4); + INDENT(-4); DEBUG_L("Dangling Types for Function Local (default defs).\n"); - //INDENT(4); + INDENT(4); + DEBUG_L("\n"); + DEBUG_F( wolf_fence, info); // For locals // @@ -1332,9 +1413,9 @@ str_reorg_instance_interleave_trans ( Info *info) 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; @@ -1374,59 +1455,74 @@ str_reorg_instance_interleave_trans ( Info *info) } } } - //INDENT(-4); - + INDENT(-4); + // Normal ssa name case DEBUG_L("Dangling Types for Normal SSA Names:\n"); - //INDENT(4); + DEBUG_L("\n"); + DEBUG_F( wolf_fence, info); + + INDENT(4); // We use len instead of using func->length() in the for loop test // 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"); - 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 == NULL\n"); continue; } + bool a_default_def = SSA_NAME_IS_DEFAULT_DEF ( ssa_name); + gimple *defining_stmt = SSA_NAME_DEF_STMT ( ssa_name);; + bool no_defining_stmt = defining_stmt == NULL; + bool defined_by_nop = defining_stmt && gimple_code ( defining_stmt) == GIMPLE_NOP; 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(" %s", a_default_def ? "is default_def" : ""); + DEBUG(" %s", no_defining_stmt ? "has no defining stmt" : ""); + DEBUG(" %s", defined_by_nop ? "defined by a nop" : ""); + 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; + } + + // A default def is processed seperately + if ( a_default_def ) + { + DEBUG_L("Skip default_def\n"); continue; } + gcc_assert ( !no_defining_stmt); + gcc_assert ( !defined_by_nop); + + DEBUG_L("Defining stmt: "); + DEBUG_F ( print_gimple_stmt, stderr, defining_stmt, 0); + 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++) { @@ -1442,9 +1538,9 @@ str_reorg_instance_interleave_trans ( Info *info) imm_use_iterator iter; FOR_EACH_IMM_USE_STMT ( use_stmt, iter, ssa_name) { - //DEBUG_L("use_stmt: "); - //DEBUG_F ( print_gimple_stmt, stderr, use_stmt, 0); - + 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; @@ -1452,7 +1548,7 @@ str_reorg_instance_interleave_trans ( Info *info) //FOR_EACH_SSA_USE_OPERAND( use_p, use_stmt, ssa_iter, SSA_OP_USE ) FOR_EACH_PHI_OR_STMT_USE ( use_p, use_stmt, ssa_iter, SSA_OP_USE ) { - //DEBUG_L("use_p = %p\n",use_p); + DEBUG_L("use_p = %p\n",use_p); if ( use_p == NULL ) continue; tree use = USE_FROM_PTR (use_p); if (use == ssa_name) @@ -1461,49 +1557,80 @@ str_reorg_instance_interleave_trans ( Info *info) // Should update_stmt be called here? // It does not seem either harm or help so I'll // leave it in. +#if TOGUPD3 update_stmt ( use_stmt); +#endif } // Modify the LHS too // TBD This code needs to be more general. + DEBUG_L("What is ssa_name? "); + DEBUG_F(flexible_print, stderr, ssa_name, (dump_flags_t)0); + DEBUG("\n"); gimple *def = SSA_NAME_DEF_STMT ( ssa_name); - //DEBUG_L("def: "); - //DEBUG_F ( print_gimple_stmt, stderr, def, 0); - - // Note, the following code might be a bit overly - // simplistic. + DEBUG_L("def: "); + DEBUG_F ( print_gimple_stmt, stderr, def, 0); - if ( gimple_code ( def) == GIMPLE_ASSIGN ) - { - gimple_assign_set_lhs ( def, new_ssa_name); - } - else - if ( gimple_code ( def) == GIMPLE_CALL ) - { - gimple_call_set_lhs ( def, new_ssa_name); - } - else - continue; + set_lhs_for ( def, new_ssa_name); + #if TOGUPD4 + update_stmt ( def); + #endif // This is where we know that ssa_name needs to be replaced + #if TOGSSA2 release_ssa_name_fn ( func, ssa_name); + #endif + } - //INDENT(-4); + INDENT(-4); + + // Might be a bad idea. + #if 0 + for ( auto iter = ssa_to_delete.begin ();iter != ssa_to_delete.end (); iter++ ) + { + remove_default_def ( *iter, func); + } + #endif pop_cfun (); } DEBUG_L("after mini-passes\n"); - // TBD Should this be a diagnostic or not? - //DEBUG ("INTERNALS PRINT\n"); - //DEBUG_F (apply_to_all_gimple, print_internals, true, (void *)info); - if ( info->show_all_reorg_cands ) { fprintf ( info->reorg_dump_file, "End of str_reorg_instance_interleave_trans:\n"); print_program ( info->reorg_dump_file, PRINT_FORMAT, 4, info); } + + // TBD Should this be a diagnostic or not? + DEBUG ("INTERNALS PRINT\n"); + DEBUG_F (apply_to_all_gimple, print_internals, true, (void *)info); +} + +// Note, the following code might be a bit overly simplistic. +static void +set_lhs_for ( gimple *stmt, tree ssa_name) +{ + switch ( gimple_code ( stmt)) + { + case GIMPLE_ASSIGN: + gimple_assign_set_lhs ( stmt, ssa_name); + break; + case GIMPLE_CALL: + gimple_call_set_lhs ( stmt, ssa_name); + break; + case GIMPLE_PHI: + { + gphi *phi_stmt = as_a <gphi *> ( stmt); + gimple_phi_set_result ( phi_stmt, ssa_name); + } + break; + default: + fprintf ( stderr, "error: unprecidented gimple for set_lhs_for\n "); + print_gimple_stmt( stderr, stmt, 0); + gcc_assert ( 0); + } } // TBD no longer used... preserve it for a bit, then remove it. @@ -1585,6 +1712,9 @@ print_internals (gimple *stmt, void *data) gcc_assert ( rhs1); bool lhs_reorg = tree_contains_a_reorgtype_p ( lhs, info); + //DEBUG_L("rhs1 = "); + //DEBUG_F(flexible_print, stderr, rhs1, (dump_flags_t)0); + //DEBUG("\n"); bool rhs1_reorg = tree_contains_a_reorgtype_p ( rhs1, info); bool rhs2_reorg = tree_contains_a_reorgtype_p ( rhs2, info); bool rhs3_reorg = tree_contains_a_reorgtype_p ( rhs3, info); diff --git a/gcc/ipa-structure-reorg.c b/gcc/ipa-structure-reorg.c index 8302e140851..fbba1227d70 100644 --- a/gcc/ipa-structure-reorg.c +++ b/gcc/ipa-structure-reorg.c @@ -129,10 +129,18 @@ ipa_structure_reorg ( void) // 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); + + cgraph_node* node; + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) node->get_untransformed_body (); + DEBUG_F( ssa_check, stderr, Show_everything, Do_not_fail, false, true); + setup_debug_flags ( &info); //initial_debug_info ( &info); + DEBUG_L(""); + DEBUG_F( wolf_fence, &info); + if ( !reorg_analysis ( &info) ) { return true; @@ -142,6 +150,9 @@ ipa_structure_reorg ( void) bool qualified = reorg_qualification(&info); DEBUG_L("after reorg_qualification\n"); + DEBUG_L(""); + DEBUG_F(wolf_fence, &info); + if ( qualified ) { @@ -163,6 +174,9 @@ ipa_structure_reorg ( void) //DEBUG_L("before str_reorg_instance_interleave_qual\n"); str_reorg_instance_interleave_qual ( &info); //DEBUG_L("after str_reorg_instance_interleave_qual\n"); + DEBUG_L(""); + DEBUG_F(wolf_fence, &info); + } if ( info.show_all_reorg_cands_in_detail ) @@ -173,6 +187,8 @@ ipa_structure_reorg ( void) reorg_common_middle_code( &info); // ??? might not amount to anything DEBUG_L("after reorg_common_middle_code\n"); + DEBUG_L(""); + DEBUG_F(wolf_fence, &info); if ( flag_ipa_structure_reorg || flag_ipa_dead_field_eliminate ) { @@ -1832,7 +1848,7 @@ get_reorgtype_info ( tree type, Info* info) // Remember, the same_type_p here is my own temporary hack. //DEBUG_L(""); //DEBUG_F( print_generic_expr, stderr, type, TDF_DETAILS); - //DEBUG("\n"); + // DEBUG("\n"); if ( same_type_p ( ri->gcc_type, type) ) { //DEBUG_A( " returns %p\n", &(*ri)); @@ -1893,8 +1909,17 @@ contains_a_reorgtype ( gimple *stmt, Info *info) static tree detect_reorg_in_expr ( tree *tp, int *w_s, void *data) { + //DEBUG_L("*tp = "); + //DEBUG_F( flexible_print, stderr, *tp, (dump_flags_t)0); + //DEBUG("\n") hidden_info_t *tre_hi = ( hidden_info_t *)data; + //DEBUG_L("TREE_TYPE ( *tp) = "); + //DEBUG_F( flexible_print, stderr, TREE_TYPE ( *tp), (dump_flags_t)0); + //DEBUG("\n") tree operand = base_type_of ( TREE_TYPE ( *tp)); + //DEBUG_L("operand = %p, ", operand); + DEBUG_F( flexible_print, stderr, operand, (dump_flags_t)0); + DEBUG("\n"); ReorgType_t *ri = get_reorgtype_info ( operand, tre_hi->info); if ( ri != NULL ) { @@ -2274,7 +2299,7 @@ modify_ssa_name_type ( tree ssa_name, tree type) //DEBUG_L("TYPE_P true\n"); gcc_assert ( TYPE_MAIN_VARIANT ( type)); TREE_TYPE ( ssa_name) = TYPE_MAIN_VARIANT ( type); - if ( ssa_defined_default_def_p ( ssa_name) ) + if ( SSA_NAME_IS_DEFAULT_DEF ( ssa_name) ) { // Again this is what breaks (pretty-print) something // about expecting an integer_type. @@ -2366,6 +2391,7 @@ handle_debug_indenting ( int amount ) #endif #if DEBUGGING +#if 0 // A Wolf Fence is whatever it needs to be whenever it needs to be it. int wf_func ( tree *slot, tree *dummy) @@ -2375,38 +2401,148 @@ wf_func ( tree *slot, tree *dummy) return 0; } -#if DEBUGGING void -flexible_print( FILE *f, tree t, dump_flags_t d) +wolf_fence ( + Info *info // Pass level gobal info (might not use it) + ) { - if ( DECL_P( t) ) + struct cgraph_node *node; + + //fprintf( stderr, + // "Wolf Fence: Find wolf via gcc_assert(t_val->ssa_name.var)\n"); + + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { - print_generic_decl(f,t,d); + struct function *func = DECL_STRUCT_FUNCTION ( node->decl); + push_cfun ( func); + + DEFAULT_DEFS ( func)->traverse_noresize < tree *, wf_func> ( NULL); + + pop_cfun (); } - else + fprintf( stderr, "No Wolf\n"); +} +#endif + +#if 0 +void +wolf_fence ( + Info *info // Pass level gobal info (might not use it) + ) +{ + struct cgraph_node *node; + + //fprintf( stderr, + // "Wolf Fence: Find wolf via gcc_assert(t_val->ssa_name.var)\n"); + + fprintf( stderr, "Wolf?\n"); + + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { - print_generic_expr(f,t,d); + struct function *func = DECL_STRUCT_FUNCTION ( node->decl); + push_cfun ( func); + + unsigned int len = SSANAMES ( func)->length (); + for ( unsigned int i = 0; i < len; i++) + { + tree ssa_name = (*SSANAMES ( func))[i]; + if ( ssa_name == NULL ) continue; + if ( SSA_NAME_IS_DEFAULT_DEF ( ssa_name) ) + { + gimple *def_stmt = SSA_NAME_DEF_STMT ( ssa_name); + if ( !gimple_nop_p ( def_stmt) ) + { + fprintf ( stderr, "Wolf! : "); + print_gimple_stmt ( stderr, def_stmt, 0); + gcc_assert (0); + } + } + } + pop_cfun (); } + fprintf( stderr, "No Wolf\n"); } #endif - void wolf_fence ( Info *info // Pass level gobal info (might not use it) ) { + if ( ssa_check ( stderr, Show_failures, Fail_1st_bad, false, false) ) + { + fprintf ( stderr, "Wolf! : "); + gcc_assert (0); + } + + fprintf( stderr, "No Wolf\n"); +} + +// returns true for failure +bool +ssa_check ( FILE *file, Display display, Failure failure, bool types, bool header ) +{ + if ( header ) fprintf ( file, "ssa_check:\n"); struct cgraph_node *node; - fprintf( stderr, - "Wolf Fence: Find wolf via gcc_assert(t_val->ssa_name.var)\n"); + bool has_a_failure = false; FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node) { struct function *func = DECL_STRUCT_FUNCTION ( node->decl); push_cfun ( func); - DEFAULT_DEFS ( func)->traverse_noresize < tree *, wf_func> ( NULL); + + unsigned int len = SSANAMES ( func)->length (); + for ( unsigned int i = 0; i < len; i++) + { + tree ssa_name = (*SSANAMES ( func))[i]; + if ( ssa_name == NULL ) continue; + bool a_default_def = SSA_NAME_IS_DEFAULT_DEF ( ssa_name); + gimple *defining_stmt = SSA_NAME_DEF_STMT ( ssa_name);; + bool no_defining_stmt = defining_stmt == NULL; + bool defined_by_nop = defining_stmt && gimple_code ( defining_stmt) == GIMPLE_NOP; + bool has_type = TREE_TYPE ( ssa_name) != NULL; + tree type = TREE_TYPE ( ssa_name); + tree bottom_type = base_type_of ( type); + bool fails = !has_type || + no_defining_stmt || + (a_default_def && !defined_by_nop) || + (!a_default_def && defined_by_nop); + if (fails) has_a_failure = true; + if ( display == Show_everything || (fails && display == Show_failures) ) + { + fprintf ( file, "ssa_name = "); + print_generic_expr ( file, ssa_name, (dump_flags_t)0); + fprintf ( file, "%s", has_type ? ", has no type" : ""); + fprintf ( file, "%s", a_default_def ? ", is default_def" : ""); + fprintf ( file, "%s", no_defining_stmt ? ", has no defining stmt" : ""); + fprintf ( file, "%s", defined_by_nop ? ", defined by a nop" : ""); + if (types) + { + fprintf ( file, ", type = "); + print_generic_expr ( file, type, (dump_flags_t)0); + fprintf ( file, ", bottom_type = "); + print_generic_expr ( file, bottom_type, (dump_flags_t)0); + } + fprintf ( file, "\n"); + } + if ( has_a_failure && Fail_1st_bad == failure ) break; + } pop_cfun (); + if ( has_a_failure && Fail_1st_bad == failure ) break; + } + return failure != Do_not_fail && has_a_failure; +} + +void +flexible_print( FILE *f, tree t, dump_flags_t d) +{ + if ( DECL_P( t) ) + { + print_generic_decl(f,t,d); + } + else + { + print_generic_expr(f,t,d); } - fprintf( stderr, "Wolf Fence: Didn't find wolf!\n"); } #endif diff --git a/gcc/ipa-structure-reorg.h b/gcc/ipa-structure-reorg.h index 471590a762a..e0b22efc8ed 100644 --- a/gcc/ipa-structure-reorg.h +++ b/gcc/ipa-structure-reorg.h @@ -248,11 +248,24 @@ extern bool print_internals (gimple *, void *); #define DEBUGGING 0 #if DEBUGGING +enum Display { + Show_nothing, + Show_failures, + Show_everything +}; + +enum Failure { + Do_not_fail, + Fail_1st_bad, + Fail_at_End +}; + extern int debug_indenting; extern void handle_debug_indenting( int); extern const char *code_str( enum tree_code); extern void flexible_print( FILE *, tree, dump_flags_t); extern void wolf_fence( Info *); +extern bool ssa_check ( FILE *, Display, Failure, bool, bool); // Line numbered #define DEBUG_L(...) { fprintf( stderr, "L# %4d: %*s", __LINE__, debug_indenting, ""); fprintf( stderr, __VA_ARGS__); } |