summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Oblock <gary@amperecomputing.com>2020-07-07 23:39:19 -0700
committerGary Oblock <gary@amperecomputing.com>2020-07-07 23:39:19 -0700
commit061e06f24817635ee21f807930b50b6d28d7748b (patch)
treef8891126d793be0ac8cbccf2a6e25c4e0bb373cf
parent9a9b4853cb637f1a9766d20837f6d33d5ebc06de (diff)
Modified print_program to print BB successors and edge flags.
Fixed control flow bugs for 06_11. Fixed type problem with cast.
-rw-r--r--gcc/ipa-str-reorg-instance-interleave.c96
-rw-r--r--gcc/ipa-structure-reorg.c16
2 files changed, 90 insertions, 22 deletions
diff --git a/gcc/ipa-str-reorg-instance-interleave.c b/gcc/ipa-str-reorg-instance-interleave.c
index b5fec97685e..d71f6e051ea 100644
--- a/gcc/ipa-str-reorg-instance-interleave.c
+++ b/gcc/ipa-str-reorg-instance-interleave.c
@@ -59,6 +59,10 @@ static tree find_coresponding_field ( tree, tree);
#define REORG_SP_PTR_PREFIX "_reorg_SP_ptr_type_"
#define REORG_SP_PREFIX "_reorg_base_type_"
#define REORG_SP_BASE_PREFIX "_reorg_base_var_"
+
+// We use labels and gotos. This is incorrect but
+// for now it better shows the structure of the code emitted.
+#define USE_LABELS 0
int
str_reorg_instance_interleave_qual ( Info *info)
@@ -560,7 +564,12 @@ str_reorg_instance_interleave_trans ( Info *info)
tree len = make_temp_ssa_name ( int_ptrsize_type, NULL, "malloc_len");
gimple_stmt_iterator gsi = gsi_for_stmt( stmt);
//gimple *glen =
- // gimple_build_assign ( len, TRUNC_DIV_EXPR, val, size);
+ // gimple_build_assign ( len, TRUNC_DIV_EXPR, val, size);
+
+ // This makes me nervous...
+ TREE_TYPE (len) = TREE_TYPE ( size);
+ TREE_TYPE (arg) = TREE_TYPE ( size);
+
gimple *glen =
gimple_build_assign ( len, TRUNC_DIV_EXPR, arg, size);
SSA_NAME_DEF_STMT ( len) = glen;
@@ -569,25 +578,21 @@ str_reorg_instance_interleave_trans ( Info *info)
// Note in other places in this doc this would
// be "insert glen before stmt" instead of this but
// here we need to create new basic blocks.
- // FROM edge = split this block after stmt
edge new_edge = split_block ( bb, stmt);
// FROM before_bb = edge->src // same as this bb
basic_block before_bb = new_edge->src; //
- // FROM after_bb = edge->dest
basic_block after_bb = new_edge->dest;
- // FROM delete edge
remove_edge ( new_edge);
- // FROM prev_bb = before_bb
basic_block prev_bb = before_bb;
- // FROM prev_ok_field is new label
+ #if USE_LABELS
tree prev_ok_field_L =
create_artificial_label ( UNKNOWN_LOCATION);
- // FROM after_label is new label
tree after_label_L =
create_artificial_label ( UNKNOWN_LOCATION);
- // FROM add goto for prev_ok_field to end of before_bb
gimple *goto_pof = gimple_build_goto ( prev_ok_field_L);
gsi_insert_before ( &gsi, goto_pof, GSI_SAME_STMT); // TBD insert after???
+ #endif
+
// FROM failure_bb = create_empty_block(prev_bb)
basic_block failure_bb = create_empty_bb ( prev_bb);
// I need to set the count to zero and there doesn't
@@ -599,10 +604,12 @@ str_reorg_instance_interleave_trans ( Info *info)
after_bb, EDGE_FALLTHRU);
fail_to_after_e->probability = profile_probability::very_unlikely ();
fail_to_after_e->count () = failure_bb->count;
-
+
+ #if USE_LABELS
// FROM bad_field is new label
tree bad_field_L =
create_artificial_label ( UNKNOWN_LOCATION);
+ #endif
// Note, this should remove this call from the call graph
cgraph_update_edges_for_call_stmt ( stmt, gimple_call_fndecl ( stmt), NULL);
@@ -624,6 +631,7 @@ str_reorg_instance_interleave_trans ( Info *info)
basic_block prev_order = failure_bb;
// FROM prev_bb = before_bb
prev_bb = before_bb;
+ int edge_flags = EDGE_FALLTHRU;
// Generate all the real allocation code
//
@@ -656,7 +664,11 @@ str_reorg_instance_interleave_trans ( Info *info)
// setting dominator seems to make no difference
// TBD set edge probability and flags
// VERIFIED EDGE_TRUE_VALUE
- edge ok_edge = make_edge ( prev_bb, new_bb, EDGE_TRUE_VALUE);
+ // 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);
+ edge_flags = EDGE_TRUE_VALUE;
+
ok_edge->probability = profile_probability::very_likely ();
ok_edge->count () = prev_bb->count;
add_bb_to_loop ( new_bb, before_bb->loop_father);
@@ -670,18 +682,31 @@ str_reorg_instance_interleave_trans ( Info *info)
fail_edge->probability = profile_probability::very_unlikely ();
fail_edge->count () = new_bb->count - new_bb->count;
+ #if USE_LABELS
new_ok_field_L =
create_artificial_label ( UNKNOWN_LOCATION);
+ #endif
tree res =
make_temp_ssa_name ( ptr_type_node, NULL, "res");
// VERIFIED new_ok_field_L,bad_field_L
gimple *gcond =
gimple_build_cond ( NE_EXPR, res, null_pointer_node,
- new_ok_field_L, bad_field_L);
+ #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")
@@ -716,6 +741,9 @@ str_reorg_instance_interleave_trans ( Info *info)
// 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 mem_size =
make_temp_ssa_name( sizetype, NULL, "malloc_mem_size");
gcall *malloc_call = gimple_build_call( fndecl_malloc, 1, mem_size);
@@ -734,24 +762,38 @@ str_reorg_instance_interleave_trans ( Info *info)
//gimple *gsize =
// gimple_build_assign ( mem_size, MULT_EXPR, TYPE_SIZE(field),
// len, NULL_TREE, NULL_TREE);
+
+ // This make me nervous (and breaks things)
+ //tree field_size = TYPE_SIZE ( TREE_TYPE ( field));
+ //TREE_TYPE ( field_size) = TREE_TYPE ( mem_size);
+ // We need field_size to be of the correct type so...
+ tree field_size =
+ make_temp_ssa_name( TREE_TYPE ( mem_size), NULL, "field_size");
+ gimple *gfield_size =
+ gimple_build_assign ( field_size,
+ CONVERT_EXPR,
+ TYPE_SIZE ( TREE_TYPE ( field)));
+
gimple *gsize =
gimple_build_assign ( mem_size,
MULT_EXPR,
- TYPE_SIZE ( TREE_TYPE ( field)),
+ field_size,
len);
SSA_NAME_DEF_STMT ( mem_size) = gsize;
- gsi_insert_after( &gsi, gsize, GSI_SAME_STMT);
+ gsi_insert_after ( &gsi, gsize, GSI_SAME_STMT);
+
+ gsi_insert_after ( &gsi, gfield_size, GSI_SAME_STMT);
+
// Moved label to top
//// FROM gsi_insert_after( &gsi, prev_ok_field)
//gimple *gprev_ok_field = gimple_build_label ( prev_ok_field_L);
//gsi_insert_after ( &gsi, gprev_ok_field, GSI_SAME_STMT);
- // FROM prev_bb = new_bb
prev_bb = new_bb;
- // FROM prev_order = new_bb
prev_order = new_bb;
- // FROM prev_ok_field = new_ok_field
+ #if USE_LABELS
prev_ok_field_L = new_ok_field_L;
+ #endif
}
// Loop cleaup fo failure code bb here. There is loop state
@@ -786,18 +828,23 @@ str_reorg_instance_interleave_trans ( Info *info)
gsi = gsi_start_bb ( success_bb); // used to be failure_bb
+ #if USE_LABELS
// Emit the label first and then everything else after it
gimple *gnew_ok_field = gimple_build_label ( new_ok_field_L);
gsi_insert_after ( &gsi, gnew_ok_field, GSI_NEW_STMT);
gimple *goto_al_succ = gimple_build_goto( after_label_L);
gsi_insert_after( &gsi, goto_al_succ, GSI_SAME_STMT);
- // FROM gsi_insert_after( &gsi, "success_val = 0")
+ #else
+ gimple *dummy = gimple_build_nop ();
+ gsi_insert_after ( &gsi, dummy, GSI_NEW_STMT);
+ #endif
+
gimple *set_succ =
gimple_build_assign ( success_val,
build_int_cst ( reorg_pointer_type, 0));
SSA_NAME_DEF_STMT ( success_val) = set_succ;
- gsi_insert_after( &gsi, set_succ, GSI_SAME_STMT);
+ gsi_insert_after( &gsi, set_succ, GSI_SAME_STMT);
// FROM gsi_insert_after( &gsi, new_ok_field )
//gimple *gnew_ok_field = gimple_build_label ( new_ok_field_L);
//gsi_insert_after ( &gsi, gnew_ok_field, GSI_SAME_STMT);
@@ -809,10 +856,12 @@ str_reorg_instance_interleave_trans ( Info *info)
//gimple_stmt_iterator gsi = gsi_start_bb( after_bb);
gsi = gsi_start_bb( after_bb);
+ #if USE_LABELS
// put the label first
// FROM gsi_insert_after( &gsi, after_label)
gimple *gafter_label = gimple_build_label( after_label_L);
gsi_insert_after( &gsi, gafter_label, GSI_NEW_STMT);
+ #endif
// FROM gsi_insert_after( &gsi, "lhs = "phi(success_val, fail_val)
@@ -841,14 +890,20 @@ str_reorg_instance_interleave_trans ( Info *info)
// FROM gsi = gsi_start_bb ( failure_bb)
gsi = gsi_start_bb ( failure_bb);
+ #if USE_LABELS
// Put the label first
// FROM gsi_insert_after( &gsi, bad_field )
gimple *gbad_field = gimple_build_label( bad_field_L);
gsi_insert_after( &gsi, gbad_field, GSI_NEW_STMT);
-
+
// 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);
+ #else
+ gimple *dummy_fail = gimple_build_nop ();
+ gsi_insert_after ( &gsi, dummy_fail, GSI_NEW_STMT);
+ #endif
+
// (per field) {
//tree field; // defined above
//tree reorg_type = ri->gcc_type; // is this useful here?
@@ -856,7 +911,7 @@ 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;
@@ -865,7 +920,6 @@ str_reorg_instance_interleave_trans ( Info *info)
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)")
diff --git a/gcc/ipa-structure-reorg.c b/gcc/ipa-structure-reorg.c
index b58264c6d09..a60f111a01d 100644
--- a/gcc/ipa-structure-reorg.c
+++ b/gcc/ipa-structure-reorg.c
@@ -1837,11 +1837,25 @@ print_function ( FILE *file, int leading_space, struct function *func)
FOR_EACH_BB_FN ( bb, func)
{
// print bb num
- fprintf ( file, "%*sBB %d:\n", leading_space, "", bb->index );
+ fprintf ( file, "%*sBB %d:", leading_space, "", bb->index );
// Tried to use function gimple_dump_bb is here instead of
// the following loop but it's worthless.
+ edge e;
+ edge_iterator ei;
+
+ FOR_EACH_EDGE ( e, ei, bb->succs )
+ {
+ basic_block succ_bb = e->dest;
+ fprintf ( file, " BB%d", succ_bb->index);
+ if ( e->flags & EDGE_TRUE_VALUE ) fprintf ( file, " true");
+ if ( e->flags & EDGE_FALSE_VALUE ) fprintf ( file, " false");
+ if ( e->flags & EDGE_FALLTHRU ) fprintf ( file, " fallthru");
+ }
+ fprintf ( file, "\n");
+
+
gimple_stmt_iterator gsi;
for ( gsi = gsi_start_bb ( bb);
!gsi_end_p ( gsi);