fix block split point

This commit is contained in:
fanfuqiang 2018-11-27 17:15:25 +08:00
parent 141965e6b7
commit c235f9882f
3 changed files with 240 additions and 13 deletions

View File

@ -0,0 +1,135 @@
Incremental SSA update started at block: 0
Number of blocks in CFG: 15
Number of blocks to update: 14 ( 93%)
main ()
{
long int hl_cfi_hash.7;
long int hl_cfi_hash.6;
long int hl_cfi_hash.5;
long int hl_cfi_hash.4;
static const char __PRETTY_FUNCTION__[5] = "main";
int (*<T561>) (double) lp[2];
int r2;
int r1;
int l2;
int l1;
int D.2229;
int D.2225;
double D.2224;
int (*<T561>) (double) D.2223;
int D.2222;
double D.2221;
int g2.3;
int (*<T561>) (double) D.2219;
int (*<T561>) (double) D.2218;
int D.2217;
double D.2216;
int (*<T561>) (double) D.2215;
int D.2214;
double D.2213;
int g1.2;
int (*<T561>) (double) D.2211;
int (*<T561>) (double) D.2210;
int l2.1;
int l1.0;
int (*<T561>) (double) _7;
int (*<T561>) (double) _8;
double _10;
int _11;
int (*<T561>) (double) _13;
double _14;
int _15;
int (*<T561>) (double) _17;
int (*<T561>) (double) _18;
double _20;
int _21;
int (*<T561>) (double) _23;
double _24;
int _25;
int _27;
<bb 2>:
gimple_assign <integer_cst, l1.0_1, 1, NULL, NULL>
gimple_assign <ssa_name, g1, l1.0_1, NULL, NULL>
gimple_assign <ssa_name, l1_2, l1.0_1, NULL, NULL>
gimple_assign <integer_cst, l2.1_3, 2, NULL, NULL>
gimple_assign <ssa_name, g2, l2.1_3, NULL, NULL>
gimple_assign <ssa_name, l2_4, l2.1_3, NULL, NULL>
gimple_assign <integer_cst, r2_5, 10, NULL, NULL>
gimple_assign <ssa_name, r1_6, r2_5, NULL, NULL>
gimple_assign <addr_expr, lp[0], foo, NULL, NULL>
gimple_assign <array_ref, _7, lp[0], NULL, NULL>
gimple_assign <ssa_name, gp[0], _7, NULL, NULL>
gimple_assign <array_ref, _8, gp[0], NULL, NULL>
gimple_assign <var_decl, g1.2_9, g1, NULL, NULL>
gimple_assign <float_expr, _10, g1.2_9, NULL, NULL>
gimple_assign <mem_ref, hl_cfi_hash.4_28, MEM[(int *)_8 + -8B], NULL, NULL>
gimple_cond <ne_expr, hl_cfi_hash.4_28, 2130853107, NULL, NULL>
gimple_call <_8, _11, _10>
<bb 3>:
gimple_assign <plus_expr, r1_12, _11, r1_6, NULL>
gimple_assign <array_ref, _13, lp[0], NULL, NULL>
gimple_assign <float_expr, _14, l1_2, NULL, NULL>
gimple_assign <mem_ref, hl_cfi_hash.5_29, MEM[(int *)_13 + -8B], NULL, NULL>
gimple_cond <ne_expr, hl_cfi_hash.5_29, 2130853107, NULL, NULL>
gimple_call <_13, _15, _14>
<bb 4>:
gimple_assign <plus_expr, r2_16, _15, r2_5, NULL>
gimple_assign <addr_expr, lp[1], bar, NULL, NULL>
gimple_assign <array_ref, _17, lp[1], NULL, NULL>
gimple_assign <ssa_name, gp[1], _17, NULL, NULL>
gimple_assign <array_ref, _18, gp[1], NULL, NULL>
gimple_assign <var_decl, g2.3_19, g2, NULL, NULL>
gimple_assign <float_expr, _20, g2.3_19, NULL, NULL>
gimple_assign <mem_ref, hl_cfi_hash.6_30, MEM[(int *)_18 + -8B], NULL, NULL>
gimple_cond <ne_expr, hl_cfi_hash.6_30, 2130853107, NULL, NULL>
gimple_call <_18, _21, _20>
<bb 5>:
gimple_assign <plus_expr, r1_22, _21, r1_12, NULL>
gimple_assign <array_ref, _23, lp[1], NULL, NULL>
gimple_assign <float_expr, _24, l2_4, NULL, NULL>
gimple_assign <mem_ref, hl_cfi_hash.7_31, MEM[(int *)_23 + -8B], NULL, NULL>
gimple_cond <ne_expr, hl_cfi_hash.7_31, 2130853107, NULL, NULL>
gimple_call <_23, _25, _24>
<bb 6>:
gimple_assign <plus_expr, r2_26, _25, r2_16, NULL>
gimple_cond <eq_expr, r1_22, r2_26, NULL, NULL>
goto <bb 11>;
else
goto <bb 12>;
<bb 7>:
gimple_call <__builtin_trap, NULL>
<bb 8>:
gimple_call <__builtin_trap, NULL>
<bb 9>:
gimple_call <__builtin_trap, NULL>
<bb 10>:
gimple_call <__builtin_trap, NULL>
<bb 11>:
gimple_call <__builtin_puts, NULL, &"yes"[0]>
goto <bb 13>;
<bb 12>:
gimple_call <__assert_fail, NULL, "! \"error\"", "../../testcase/cfi1.c", 30, &__PRETTY_FUNCTION__>
<bb 13>:
gimple_assign <integer_cst, _27, 0, NULL, NULL>
gimple_assign <constructor, lp, {CLOBBER}, NULL, NULL>
gimple_label <<L4>>
gimple_return <_27>
}

View File

@ -0,0 +1,91 @@
Incremental SSA update started at block: 0
Number of blocks in CFG: 6
Number of blocks to update: 5 ( 83%)
Incremental SSA update started at block: 0
Number of blocks in CFG: 6
Number of blocks to update: 5 ( 83%)
Incremental SSA update started at block: 0
Number of blocks in CFG: 4
Number of blocks to update: 3 ( 75%)
bar (double d)
{
long int hl_cfi_hash.2;
int D.1741;
int D.1740;
int (*<T383>) () fp.1;
int D.1738;
int _2;
int _4;
int _5;
<bb 2>:
gimple_assign <var_decl, fp.1_1, fp, NULL, NULL>
gimple_assign <mem_ref, hl_cfi_hash.2_6, MEM[(int *)fp.1_1 + -8B], NULL, NULL>
gimple_cond <ne_expr, hl_cfi_hash.2_6, 1700646216, NULL, NULL>
gimple_call <fp.1_1, _2>
<bb 3>:
gimple_assign <fix_trunc_expr, _4, d_3(D), NULL, NULL>
gimple_assign <minus_expr, _5, _2, _4, NULL>
goto <bb 5> (<L0>);
<bb 4>:
gimple_call <__builtin_trap, NULL>
gimple_label <<L0>>
gimple_return <_5>
}
foo (double d)
{
long int hl_cfi_hash.3;
int D.1736;
int D.1735;
int (*<T383>) () fp.0;
int D.1733;
int _2;
int _4;
int _5;
<bb 2>:
gimple_assign <var_decl, fp.0_1, fp, NULL, NULL>
gimple_assign <mem_ref, hl_cfi_hash.3_6, MEM[(int *)fp.0_1 + -8B], NULL, NULL>
gimple_cond <ne_expr, hl_cfi_hash.3_6, 1700646216, NULL, NULL>
gimple_call <fp.0_1, _2>
<bb 3>:
gimple_assign <fix_trunc_expr, _4, d_3(D), NULL, NULL>
gimple_assign <plus_expr, _5, _2, _4, NULL>
goto <bb 5> (<L0>);
<bb 4>:
gimple_call <__builtin_trap, NULL>
gimple_label <<L0>>
gimple_return <_5>
}
internal ()
{
int D.1731;
int _1;
<bb 2>:
gimple_assign <integer_cst, _1, 42, NULL, NULL>
gimple_label <<L0>>
gimple_return <_1>
}

View File

@ -634,9 +634,10 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
tree t_,
tree t_t)
{
gimple cs, g;
const gimple cs = gsi_stmt (*gp);
gimple g;
gimple_stmt_iterator gsi;
//gimple assign // used for dumps.
gimple assign; // used for dumps.
gimple cond; // test gimple we insert.
gimple call; // call label gimple we insert.
basic_block old_bb;
@ -647,7 +648,7 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
tree lhs_1;
gsi = *gp;
cs = gsi_stmt (gsi);
//cs = gsi_stmt (gsi);
gcc_assert (is_gimple_call (cs));
/* Possible??? */
//gcc_assert (! stmt_ends_bb_p (cs));
@ -670,8 +671,7 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
/* lhs_1 = t_ */
lhs = create_tmp_var (t_t, "hl_cfi_hash");
gcc_assert (is_gimple_reg (lhs));
//assign =
g = gimple_build_assign (lhs, t_);
assign = g = gimple_build_assign (lhs, t_);
lhs_1 = make_ssa_name (lhs, g);
gimple_assign_set_lhs (g, lhs_1);
// Complete the ssa define statement.
@ -705,7 +705,7 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
/* Get the original bb, Thers is only one.
For now the basic block is clean. */
old_bb = gimple_bb (cs);
edge_false = split_block (old_bb, cs);
edge_false = split_block (old_bb, cond);
gcc_assert (edge_false->flags == EDGE_FALLTHRU);
edge_false->flags &= ~EDGE_FALLTHRU;
edge_false->flags |= EDGE_FALSE_VALUE;
@ -723,7 +723,7 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
if (old_bb->loop_father->latch == old_bb)
old_bb->loop_father->latch = catch_bb;
}
edge_true = make_single_succ_edge (old_bb, catch_bb, EDGE_TRUE_VALUE);
edge_true = make_edge (old_bb, catch_bb, EDGE_TRUE_VALUE);
edge_true->probability = REG_BR_PROB_BASE * ERR_PROB;
edge_true->count =
apply_probability (old_bb->count, edge_true->probability);
@ -737,11 +737,11 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
{
fprintf (dump_file, "Found protected indirect call: ");
print_gimple_stmt (dump_file, cs, 0, TDF_SLIM);
//fprintf (dump_file, "Indirect call gadget will become: ");
//print_gimple_stmt (dump_file, assign, 0, TDF_SLIM);
//print_gimple_stmt (dump_file, cond, 0, TDF_SLIM);
//print_gimple_stmt (dump_file, catch_bb->il.gimple.seq, 0, TDF_SLIM);
//print_gimple_stmt (dump_file, cs, 0, TDF_SLIM);
fprintf (dump_file, "Indirect call gadget will become: ");
print_gimple_stmt (dump_file, assign, 0, TDF_SLIM);
print_gimple_stmt (dump_file, cond, 0, TDF_SLIM);
print_gimple_stmt (dump_file, catch_bb->il.gimple.seq, 0, TDF_SLIM);
print_gimple_stmt (dump_file, cs, 0, TDF_SLIM);
fprintf (dump_file, "\n");
}
@ -784,7 +784,8 @@ build_cfi (gimple_stmt_iterator *gp)
/* Wrap up gcc internal dump functions ignore conditions.
???cc1 could not recongnize the hl_cfi dump command line options. */
void
static void
hijack_gcc_pass_init_dump_file ()
{
// make sure we have been initialized.