Change the discriminator assignment algorithm to make it more robust.
2013-05-24 Dehao Chen <dehao@google.com> * gcc/testsuite/gcc.dg/debug/dwarf2/discriminator.c: New Testcase. * gcc/tree-cfg.c (locus_descrim_hasher::hash): Change discrminator hash function. (locus_descrim_hasher::equal): Likewise. (build_gimple_cfg): New discrminator assignmnet algorithm (make_edges): Likewise. (next_discriminator_for_locus): Likewise. (same_line_p): Likewise. (assign_discriminators): Likewise. (make_cond_expr_edges): Likewise. (make_gimple_switch_edges): Likewise. (make_goto_expr_edges): Likewise. (make_gimple_asm_edges): Likewise. From-SVN: r199295
This commit is contained in:
parent
06d50e2171
commit
25e25c732c
|
@ -1,3 +1,19 @@
|
||||||
|
2013-05-24 Dehao Chen <dehao@google.com>
|
||||||
|
|
||||||
|
* gcc/testsuite/gcc.dg/debug/dwarf2/discriminator.c: New Testcase.
|
||||||
|
* gcc/tree-cfg.c (locus_descrim_hasher::hash): Change discrminator
|
||||||
|
hash function.
|
||||||
|
(locus_descrim_hasher::equal): Likewise.
|
||||||
|
(build_gimple_cfg): New discrminator assignmnet algorithm
|
||||||
|
(make_edges): Likewise.
|
||||||
|
(next_discriminator_for_locus): Likewise.
|
||||||
|
(same_line_p): Likewise.
|
||||||
|
(assign_discriminators): Likewise.
|
||||||
|
(make_cond_expr_edges): Likewise.
|
||||||
|
(make_gimple_switch_edges): Likewise.
|
||||||
|
(make_goto_expr_edges): Likewise.
|
||||||
|
(make_gimple_asm_edges): Likewise.
|
||||||
|
|
||||||
2013-05-24 Ian Bolton <ian.bolton@arm.com>
|
2013-05-24 Ian Bolton <ian.bolton@arm.com>
|
||||||
|
|
||||||
* config/aarch64/aarch64.c (aarch64_print_operand): Change the
|
* config/aarch64/aarch64.c (aarch64_print_operand): Change the
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */
|
||||||
|
/* { dg-options "-O0 -gdwarf-2" } */
|
||||||
|
/* { dg-final { scan-assembler "loc \[0-9] 9 \[0-9]( is_stmt \[0-9])?\n" } } */
|
||||||
|
/* { dg-final { scan-assembler "loc \[0-9] 9 \[0-9]( is_stmt \[0-9])? discriminator 2\n" } } */
|
||||||
|
/* { dg-final { scan-assembler "loc \[0-9] 9 \[0-9]( is_stmt \[0-9])? discriminator 1\n" } } */
|
||||||
|
|
||||||
|
int foo(int n) {
|
||||||
|
int i, ret = 0;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
if (i % 10 == 1)
|
||||||
|
ret++;
|
||||||
|
else
|
||||||
|
ret--;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -105,7 +105,7 @@ struct locus_descrim_hasher : typed_free_remove <locus_discrim_map>
|
||||||
inline hashval_t
|
inline hashval_t
|
||||||
locus_descrim_hasher::hash (const value_type *item)
|
locus_descrim_hasher::hash (const value_type *item)
|
||||||
{
|
{
|
||||||
return item->locus;
|
return LOCATION_LINE (item->locus);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Equality function for the locus-to-discriminator map. A and B
|
/* Equality function for the locus-to-discriminator map. A and B
|
||||||
|
@ -114,7 +114,7 @@ locus_descrim_hasher::hash (const value_type *item)
|
||||||
inline bool
|
inline bool
|
||||||
locus_descrim_hasher::equal (const value_type *a, const compare_type *b)
|
locus_descrim_hasher::equal (const value_type *a, const compare_type *b)
|
||||||
{
|
{
|
||||||
return a->locus == b->locus;
|
return LOCATION_LINE (a->locus) == LOCATION_LINE (b->locus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static hash_table <locus_descrim_hasher> discriminator_per_locus;
|
static hash_table <locus_descrim_hasher> discriminator_per_locus;
|
||||||
|
@ -125,11 +125,11 @@ static void factor_computed_gotos (void);
|
||||||
|
|
||||||
/* Edges. */
|
/* Edges. */
|
||||||
static void make_edges (void);
|
static void make_edges (void);
|
||||||
|
static void assign_discriminators (void);
|
||||||
static void make_cond_expr_edges (basic_block);
|
static void make_cond_expr_edges (basic_block);
|
||||||
static void make_gimple_switch_edges (basic_block);
|
static void make_gimple_switch_edges (basic_block);
|
||||||
static void make_goto_expr_edges (basic_block);
|
static void make_goto_expr_edges (basic_block);
|
||||||
static void make_gimple_asm_edges (basic_block);
|
static void make_gimple_asm_edges (basic_block);
|
||||||
static void assign_discriminator (location_t, basic_block);
|
|
||||||
static edge gimple_redirect_edge_and_branch (edge, basic_block);
|
static edge gimple_redirect_edge_and_branch (edge, basic_block);
|
||||||
static edge gimple_try_redirect_by_replacing_jump (edge, basic_block);
|
static edge gimple_try_redirect_by_replacing_jump (edge, basic_block);
|
||||||
static unsigned int split_critical_edges (void);
|
static unsigned int split_critical_edges (void);
|
||||||
|
@ -231,6 +231,7 @@ build_gimple_cfg (gimple_seq seq)
|
||||||
/* Create the edges of the flowgraph. */
|
/* Create the edges of the flowgraph. */
|
||||||
discriminator_per_locus.create (13);
|
discriminator_per_locus.create (13);
|
||||||
make_edges ();
|
make_edges ();
|
||||||
|
assign_discriminators ();
|
||||||
cleanup_dead_labels ();
|
cleanup_dead_labels ();
|
||||||
discriminator_per_locus.dispose ();
|
discriminator_per_locus.dispose ();
|
||||||
}
|
}
|
||||||
|
@ -690,11 +691,7 @@ make_edges (void)
|
||||||
fallthru = true;
|
fallthru = true;
|
||||||
|
|
||||||
if (fallthru)
|
if (fallthru)
|
||||||
{
|
make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
|
||||||
make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
|
|
||||||
if (last)
|
|
||||||
assign_discriminator (gimple_location (last), bb->next_bb);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root_omp_region)
|
if (root_omp_region)
|
||||||
|
@ -717,7 +714,8 @@ next_discriminator_for_locus (location_t locus)
|
||||||
|
|
||||||
item.locus = locus;
|
item.locus = locus;
|
||||||
item.discriminator = 0;
|
item.discriminator = 0;
|
||||||
slot = discriminator_per_locus.find_slot_with_hash (&item, locus, INSERT);
|
slot = discriminator_per_locus.find_slot_with_hash (
|
||||||
|
&item, LOCATION_LINE (locus), INSERT);
|
||||||
gcc_assert (slot);
|
gcc_assert (slot);
|
||||||
if (*slot == HTAB_EMPTY_ENTRY)
|
if (*slot == HTAB_EMPTY_ENTRY)
|
||||||
{
|
{
|
||||||
|
@ -752,22 +750,37 @@ same_line_p (location_t locus1, location_t locus2)
|
||||||
&& filename_cmp (from.file, to.file) == 0);
|
&& filename_cmp (from.file, to.file) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assign a unique discriminator value to block BB if it begins at the same
|
/* Assign discriminators to each basic block. */
|
||||||
LOCUS as its predecessor block. */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
assign_discriminator (location_t locus, basic_block bb)
|
assign_discriminators (void)
|
||||||
{
|
{
|
||||||
gimple first_in_to_bb, last_in_to_bb;
|
basic_block bb;
|
||||||
|
|
||||||
if (locus == 0 || bb->discriminator != 0)
|
FOR_EACH_BB (bb)
|
||||||
return;
|
{
|
||||||
|
edge e;
|
||||||
|
edge_iterator ei;
|
||||||
|
gimple last = last_stmt (bb);
|
||||||
|
location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
|
||||||
|
|
||||||
first_in_to_bb = first_non_label_stmt (bb);
|
if (locus == UNKNOWN_LOCATION)
|
||||||
last_in_to_bb = last_stmt (bb);
|
continue;
|
||||||
if ((first_in_to_bb && same_line_p (locus, gimple_location (first_in_to_bb)))
|
|
||||||
|| (last_in_to_bb && same_line_p (locus, gimple_location (last_in_to_bb))))
|
FOR_EACH_EDGE (e, ei, bb->succs)
|
||||||
bb->discriminator = next_discriminator_for_locus (locus);
|
{
|
||||||
|
gimple first = first_non_label_stmt (e->dest);
|
||||||
|
gimple last = last_stmt (e->dest);
|
||||||
|
if ((first && same_line_p (locus, gimple_location (first)))
|
||||||
|
|| (last && same_line_p (locus, gimple_location (last))))
|
||||||
|
{
|
||||||
|
if (e->dest->discriminator != 0 && bb->discriminator == 0)
|
||||||
|
bb->discriminator = next_discriminator_for_locus (locus);
|
||||||
|
else
|
||||||
|
e->dest->discriminator = next_discriminator_for_locus (locus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the edges for a GIMPLE_COND starting at block BB. */
|
/* Create the edges for a GIMPLE_COND starting at block BB. */
|
||||||
|
@ -780,13 +793,10 @@ make_cond_expr_edges (basic_block bb)
|
||||||
basic_block then_bb, else_bb;
|
basic_block then_bb, else_bb;
|
||||||
tree then_label, else_label;
|
tree then_label, else_label;
|
||||||
edge e;
|
edge e;
|
||||||
location_t entry_locus;
|
|
||||||
|
|
||||||
gcc_assert (entry);
|
gcc_assert (entry);
|
||||||
gcc_assert (gimple_code (entry) == GIMPLE_COND);
|
gcc_assert (gimple_code (entry) == GIMPLE_COND);
|
||||||
|
|
||||||
entry_locus = gimple_location (entry);
|
|
||||||
|
|
||||||
/* Entry basic blocks for each component. */
|
/* Entry basic blocks for each component. */
|
||||||
then_label = gimple_cond_true_label (entry);
|
then_label = gimple_cond_true_label (entry);
|
||||||
else_label = gimple_cond_false_label (entry);
|
else_label = gimple_cond_false_label (entry);
|
||||||
|
@ -796,14 +806,10 @@ make_cond_expr_edges (basic_block bb)
|
||||||
else_stmt = first_stmt (else_bb);
|
else_stmt = first_stmt (else_bb);
|
||||||
|
|
||||||
e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
|
e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
|
||||||
assign_discriminator (entry_locus, then_bb);
|
|
||||||
e->goto_locus = gimple_location (then_stmt);
|
e->goto_locus = gimple_location (then_stmt);
|
||||||
e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
|
e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
e->goto_locus = gimple_location (else_stmt);
|
||||||
assign_discriminator (entry_locus, else_bb);
|
|
||||||
e->goto_locus = gimple_location (else_stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We do not need the labels anymore. */
|
/* We do not need the labels anymore. */
|
||||||
gimple_cond_set_true_label (entry, NULL_TREE);
|
gimple_cond_set_true_label (entry, NULL_TREE);
|
||||||
|
@ -923,11 +929,8 @@ static void
|
||||||
make_gimple_switch_edges (basic_block bb)
|
make_gimple_switch_edges (basic_block bb)
|
||||||
{
|
{
|
||||||
gimple entry = last_stmt (bb);
|
gimple entry = last_stmt (bb);
|
||||||
location_t entry_locus;
|
|
||||||
size_t i, n;
|
size_t i, n;
|
||||||
|
|
||||||
entry_locus = gimple_location (entry);
|
|
||||||
|
|
||||||
n = gimple_switch_num_labels (entry);
|
n = gimple_switch_num_labels (entry);
|
||||||
|
|
||||||
for (i = 0; i < n; ++i)
|
for (i = 0; i < n; ++i)
|
||||||
|
@ -935,7 +938,6 @@ make_gimple_switch_edges (basic_block bb)
|
||||||
tree lab = CASE_LABEL (gimple_switch_label (entry, i));
|
tree lab = CASE_LABEL (gimple_switch_label (entry, i));
|
||||||
basic_block label_bb = label_to_block (lab);
|
basic_block label_bb = label_to_block (lab);
|
||||||
make_edge (bb, label_bb, 0);
|
make_edge (bb, label_bb, 0);
|
||||||
assign_discriminator (entry_locus, label_bb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1020,7 +1022,6 @@ make_goto_expr_edges (basic_block bb)
|
||||||
basic_block label_bb = label_to_block (dest);
|
basic_block label_bb = label_to_block (dest);
|
||||||
edge e = make_edge (bb, label_bb, EDGE_FALLTHRU);
|
edge e = make_edge (bb, label_bb, EDGE_FALLTHRU);
|
||||||
e->goto_locus = gimple_location (goto_t);
|
e->goto_locus = gimple_location (goto_t);
|
||||||
assign_discriminator (e->goto_locus, label_bb);
|
|
||||||
gsi_remove (&last, true);
|
gsi_remove (&last, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1035,7 +1036,6 @@ static void
|
||||||
make_gimple_asm_edges (basic_block bb)
|
make_gimple_asm_edges (basic_block bb)
|
||||||
{
|
{
|
||||||
gimple stmt = last_stmt (bb);
|
gimple stmt = last_stmt (bb);
|
||||||
location_t stmt_loc = gimple_location (stmt);
|
|
||||||
int i, n = gimple_asm_nlabels (stmt);
|
int i, n = gimple_asm_nlabels (stmt);
|
||||||
|
|
||||||
for (i = 0; i < n; ++i)
|
for (i = 0; i < n; ++i)
|
||||||
|
@ -1043,7 +1043,6 @@ make_gimple_asm_edges (basic_block bb)
|
||||||
tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
|
tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
|
||||||
basic_block label_bb = label_to_block (label);
|
basic_block label_bb = label_to_block (label);
|
||||||
make_edge (bb, label_bb, 0);
|
make_edge (bb, label_bb, 0);
|
||||||
assign_discriminator (stmt_loc, label_bb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue