Skip to content

Commit ab015c2

Browse files
committed
Fix discriminators of gimple PHI arguments
while gimple PHI itself does not have locations, the arguments does and they can be used to determine count of edges in CFG. Assign_discriminators already knows how to handle goto_locus and PHI args should be handled same way as done by this patch. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: * auto-profile.cc (function_instance::match): Sanity check that gimple PHI has no location. * tree-cfg.cc (assign_discriminators): Also remap locations of gimple PHI arguments.
1 parent 69ac957 commit ab015c2

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

gcc/auto-profile.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,13 @@ function_instance::match (cgraph_node *node,
13711371
gphi *phi = gpi.phi ();
13721372
inline_stack stack;
13731373

1374+
/* We do not assign discriminators to PHI nodes.
1375+
In case we every start using them, we wil need to
1376+
update tree-cfg.cc::assign_discriminators. */
1377+
gcc_assert (gimple_location (phi) == UNKNOWN_LOCATION);
13741378
get_inline_stack_in_node (gimple_location (phi), &stack, node);
13751379
count_info *info = lookup_count (gimple_location (phi), stack, node);
1376-
if (info)
1377-
counts.add (info);
1380+
gcc_assert (!info);
13781381
dump_stmt (phi, info, NULL, stack);
13791382
counts.add (info);
13801383
for (edge e : bb->succs)

gcc/tree-cfg.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,8 @@ assign_discriminators (void)
11321132
{
11331133
location_t prev_loc = UNKNOWN_LOCATION, prev_replacement = UNKNOWN_LOCATION;
11341134
/* Traverse the basic block, if two function calls within a basic block
1135-
are mapped to the same line, assign a new discriminator because a call
1136-
stmt could be a split point of a basic block. */
1135+
are mapped to the same line, assign a new discriminator because a call
1136+
stmt could be a split point of a basic block. */
11371137
for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
11381138
!gsi_end_p (gsi); gsi_next (&gsi))
11391139
{
@@ -1149,8 +1149,8 @@ assign_discriminators (void)
11491149
prev_replacement = assign_discriminator (loc, bb_id, map);
11501150
gimple_set_location (stmt, prev_replacement);
11511151
}
1152-
/* Break basic blocks after each call. This is requires so each
1153-
call site has unque discriminator.
1152+
/* Break basic blocks after each call. This is required so each
1153+
call site has unique discriminator.
11541154
More correctly, we can break after each statement that can possibly
11551155
terinate execution of the basic block, but for auto-profile this
11561156
precision is probably not useful. */
@@ -1160,16 +1160,27 @@ assign_discriminators (void)
11601160
bb_id++;
11611161
}
11621162
}
1163-
/* IF basic block has multiple sucessors, consdier every edge as a separate
1164-
block. */
1163+
/* If basic block has multiple sucessors, consdier every edge as a
1164+
separate block. */
11651165
if (!single_succ_p (bb))
11661166
bb_id++;
11671167
for (edge e : bb->succs)
1168-
if (e->goto_locus != UNKNOWN_LOCATION)
1169-
{
1168+
{
1169+
if (e->goto_locus != UNKNOWN_LOCATION)
11701170
e->goto_locus = assign_discriminator (e->goto_locus, bb_id, map);
1171-
bb_id++;
1172-
}
1171+
for (gphi_iterator gpi = gsi_start_phis (bb);
1172+
!gsi_end_p (gpi); gsi_next (&gpi))
1173+
{
1174+
gphi *phi = gpi.phi ();
1175+
location_t phi_loc
1176+
= gimple_phi_arg_location_from_edge (phi, e);
1177+
if (phi_loc == UNKNOWN_LOCATION)
1178+
continue;
1179+
gimple_phi_arg_set_location
1180+
(phi, e->dest_idx, assign_discriminator (phi_loc, bb_id, map));
1181+
}
1182+
bb_id++;
1183+
}
11731184
bb_id++;
11741185
}
11751186

0 commit comments

Comments
 (0)