2012-03-27 23:13:14 +00:00
|
|
|
|
/* The tracer pass for the GNU compiler.
|
|
|
|
|
Contributed by Jan Hubicka, SuSE Labs.
|
|
|
|
|
Adapted to work on GIMPLE instead of RTL by Robert Kidd, UIUC.
|
2022-10-27 18:55:19 +00:00
|
|
|
|
Copyright (C) 2001-2022 Free Software Foundation, Inc.
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
This file is part of GCC.
|
|
|
|
|
|
|
|
|
|
GCC is free software; you can redistribute it and/or modify it
|
|
|
|
|
under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GCC; see the file COPYING3. If not see
|
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
|
|
/* This pass performs the tail duplication needed for superblock formation.
|
|
|
|
|
For more information see:
|
|
|
|
|
|
|
|
|
|
Design and Analysis of Profile-Based Optimization in Compaq's
|
|
|
|
|
Compilation Tools for Alpha; Journal of Instruction-Level
|
|
|
|
|
Parallelism 3 (2000) 1-25
|
|
|
|
|
|
|
|
|
|
Unlike Compaq's implementation we don't do the loop peeling as most
|
|
|
|
|
probably a better job can be done by a special pass and we don't
|
|
|
|
|
need to worry too much about the code size implications as the tail
|
|
|
|
|
duplicates are crossjumped again if optimizations are not
|
|
|
|
|
performed. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "coretypes.h"
|
2017-04-10 11:32:00 +00:00
|
|
|
|
#include "backend.h"
|
2012-03-27 23:13:14 +00:00
|
|
|
|
#include "rtl.h"
|
2017-04-10 11:32:00 +00:00
|
|
|
|
#include "tree.h"
|
|
|
|
|
#include "gimple.h"
|
|
|
|
|
#include "cfghooks.h"
|
|
|
|
|
#include "tree-pass.h"
|
2015-08-28 15:33:40 +00:00
|
|
|
|
#include "profile.h"
|
|
|
|
|
#include "cfganal.h"
|
2014-09-21 17:33:12 +00:00
|
|
|
|
#include "gimple-iterator.h"
|
|
|
|
|
#include "tree-cfg.h"
|
|
|
|
|
#include "tree-ssa.h"
|
2012-03-27 23:13:14 +00:00
|
|
|
|
#include "tree-inline.h"
|
2014-09-21 17:33:12 +00:00
|
|
|
|
#include "cfgloop.h"
|
2022-10-27 18:55:19 +00:00
|
|
|
|
#include "alloc-pool.h"
|
2015-08-28 15:33:40 +00:00
|
|
|
|
#include "fibonacci_heap.h"
|
2017-04-10 11:32:00 +00:00
|
|
|
|
#include "tracer.h"
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
2022-10-27 18:55:19 +00:00
|
|
|
|
static void analyze_bb (basic_block, int *);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
static bool better_p (const_edge, const_edge);
|
|
|
|
|
static edge find_best_successor (basic_block);
|
|
|
|
|
static edge find_best_predecessor (basic_block);
|
|
|
|
|
static int find_trace (basic_block, basic_block *);
|
|
|
|
|
|
|
|
|
|
/* Minimal outgoing edge probability considered for superblock formation. */
|
|
|
|
|
static int probability_cutoff;
|
|
|
|
|
static int branch_ratio_cutoff;
|
|
|
|
|
|
|
|
|
|
/* A bit BB->index is set if BB has already been seen, i.e. it is
|
|
|
|
|
connected to some trace already. */
|
2017-10-07 00:16:47 +00:00
|
|
|
|
static sbitmap bb_seen;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
mark_bb_seen (basic_block bb)
|
|
|
|
|
{
|
2014-09-21 17:33:12 +00:00
|
|
|
|
unsigned int size = SBITMAP_SIZE (bb_seen);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
if ((unsigned int)bb->index >= size)
|
|
|
|
|
bb_seen = sbitmap_resize (bb_seen, size * 2, 0);
|
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
|
bitmap_set_bit (bb_seen, bb->index);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
|
bb_seen_p (basic_block bb)
|
|
|
|
|
{
|
2014-09-21 17:33:12 +00:00
|
|
|
|
return bitmap_bit_p (bb_seen, bb->index);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 18:55:19 +00:00
|
|
|
|
static sbitmap can_duplicate_bb;
|
|
|
|
|
|
|
|
|
|
/* Cache VAL as value of can_duplicate_bb_p for BB. */
|
|
|
|
|
static inline void
|
|
|
|
|
cache_can_duplicate_bb_p (const_basic_block bb, bool val)
|
|
|
|
|
{
|
|
|
|
|
if (val)
|
|
|
|
|
bitmap_set_bit (can_duplicate_bb, bb->index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return cached value of can_duplicate_bb_p for BB. */
|
|
|
|
|
static bool
|
|
|
|
|
cached_can_duplicate_bb_p (const_basic_block bb)
|
|
|
|
|
{
|
|
|
|
|
if (can_duplicate_bb)
|
|
|
|
|
{
|
|
|
|
|
unsigned int size = SBITMAP_SIZE (can_duplicate_bb);
|
|
|
|
|
if ((unsigned int)bb->index < size)
|
|
|
|
|
return bitmap_bit_p (can_duplicate_bb, bb->index);
|
|
|
|
|
|
|
|
|
|
/* Assume added bb's should not be duplicated. */
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return can_duplicate_block_p (bb);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-27 23:13:14 +00:00
|
|
|
|
/* Return true if we should ignore the basic block for purposes of tracing. */
|
2017-04-10 11:32:00 +00:00
|
|
|
|
bool
|
2012-03-27 23:13:14 +00:00
|
|
|
|
ignore_bb_p (const_basic_block bb)
|
|
|
|
|
{
|
|
|
|
|
if (bb->index < NUM_FIXED_BLOCKS)
|
|
|
|
|
return true;
|
|
|
|
|
if (optimize_bb_for_size_p (bb))
|
|
|
|
|
return true;
|
|
|
|
|
|
2022-10-27 18:55:19 +00:00
|
|
|
|
return !cached_can_duplicate_bb_p (bb);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return number of instructions in the block. */
|
|
|
|
|
|
2022-10-27 18:55:19 +00:00
|
|
|
|
static void
|
|
|
|
|
analyze_bb (basic_block bb, int *count)
|
2012-03-27 23:13:14 +00:00
|
|
|
|
{
|
|
|
|
|
gimple_stmt_iterator gsi;
|
2017-04-10 11:32:00 +00:00
|
|
|
|
gimple *stmt;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
|
|
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
|
|
|
|
|
{
|
|
|
|
|
stmt = gsi_stmt (gsi);
|
|
|
|
|
n += estimate_num_insns (stmt, &eni_size_weights);
|
|
|
|
|
}
|
2022-10-27 18:55:19 +00:00
|
|
|
|
*count = n;
|
|
|
|
|
|
|
|
|
|
cache_can_duplicate_bb_p (bb, can_duplicate_block_p (CONST_CAST_BB (bb)));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return true if E1 is more frequent than E2. */
|
|
|
|
|
static bool
|
|
|
|
|
better_p (const_edge e1, const_edge e2)
|
|
|
|
|
{
|
2018-12-28 15:30:48 +00:00
|
|
|
|
if ((e1->count () > e2->count ()) || (e1->count () < e2->count ()))
|
|
|
|
|
return e1->count () > e2->count ();
|
2012-03-27 23:13:14 +00:00
|
|
|
|
/* This is needed to avoid changes in the decision after
|
|
|
|
|
CFG is modified. */
|
|
|
|
|
if (e1->src != e2->src)
|
|
|
|
|
return e1->src->index > e2->src->index;
|
|
|
|
|
return e1->dest->index > e2->dest->index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return most frequent successor of basic block BB. */
|
|
|
|
|
|
|
|
|
|
static edge
|
|
|
|
|
find_best_successor (basic_block bb)
|
|
|
|
|
{
|
|
|
|
|
edge e;
|
|
|
|
|
edge best = NULL;
|
|
|
|
|
edge_iterator ei;
|
|
|
|
|
|
|
|
|
|
FOR_EACH_EDGE (e, ei, bb->succs)
|
2018-12-28 15:30:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (!e->count ().initialized_p ())
|
|
|
|
|
return NULL;
|
|
|
|
|
if (!best || better_p (e, best))
|
|
|
|
|
best = e;
|
|
|
|
|
}
|
2012-03-27 23:13:14 +00:00
|
|
|
|
if (!best || ignore_bb_p (best->dest))
|
|
|
|
|
return NULL;
|
2018-12-28 15:30:48 +00:00
|
|
|
|
if (!best->probability.initialized_p ()
|
|
|
|
|
|| best->probability.to_reg_br_prob_base () <= probability_cutoff)
|
2012-03-27 23:13:14 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
return best;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return most frequent predecessor of basic block BB. */
|
|
|
|
|
|
|
|
|
|
static edge
|
|
|
|
|
find_best_predecessor (basic_block bb)
|
|
|
|
|
{
|
|
|
|
|
edge e;
|
|
|
|
|
edge best = NULL;
|
|
|
|
|
edge_iterator ei;
|
|
|
|
|
|
|
|
|
|
FOR_EACH_EDGE (e, ei, bb->preds)
|
2018-12-28 15:30:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (!e->count ().initialized_p ())
|
|
|
|
|
return NULL;
|
|
|
|
|
if (!best || better_p (e, best))
|
|
|
|
|
best = e;
|
|
|
|
|
}
|
2012-03-27 23:13:14 +00:00
|
|
|
|
if (!best || ignore_bb_p (best->src))
|
|
|
|
|
return NULL;
|
2018-12-28 15:30:48 +00:00
|
|
|
|
if (bb->count.initialized_p ()
|
|
|
|
|
&& (best->count ().to_frequency (cfun) * REG_BR_PROB_BASE
|
|
|
|
|
< bb->count.to_frequency (cfun) * branch_ratio_cutoff))
|
2012-03-27 23:13:14 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
return best;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the trace using bb and record it in the TRACE array.
|
|
|
|
|
Return number of basic blocks recorded. */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
find_trace (basic_block bb, basic_block *trace)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
edge e;
|
|
|
|
|
|
|
|
|
|
if (dump_file)
|
2018-12-28 15:30:48 +00:00
|
|
|
|
fprintf (dump_file, "Trace seed %i [%i]", bb->index, bb->count.to_frequency (cfun));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
while ((e = find_best_predecessor (bb)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
basic_block bb2 = e->src;
|
|
|
|
|
if (bb_seen_p (bb2) || (e->flags & (EDGE_DFS_BACK | EDGE_COMPLEX))
|
|
|
|
|
|| find_best_successor (bb2) != e)
|
|
|
|
|
break;
|
|
|
|
|
if (dump_file)
|
2018-12-28 15:30:48 +00:00
|
|
|
|
fprintf (dump_file, ",%i [%i]", bb->index, bb->count.to_frequency (cfun));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
bb = bb2;
|
|
|
|
|
}
|
|
|
|
|
if (dump_file)
|
2018-12-28 15:30:48 +00:00
|
|
|
|
fprintf (dump_file, " forward %i [%i]", bb->index, bb->count.to_frequency (cfun));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
trace[i++] = bb;
|
|
|
|
|
|
|
|
|
|
/* Follow the trace in forward direction. */
|
|
|
|
|
while ((e = find_best_successor (bb)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
bb = e->dest;
|
|
|
|
|
if (bb_seen_p (bb) || (e->flags & (EDGE_DFS_BACK | EDGE_COMPLEX))
|
|
|
|
|
|| find_best_predecessor (bb) != e)
|
|
|
|
|
break;
|
|
|
|
|
if (dump_file)
|
2018-12-28 15:30:48 +00:00
|
|
|
|
fprintf (dump_file, ",%i [%i]", bb->index, bb->count.to_frequency (cfun));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
trace[i++] = bb;
|
|
|
|
|
}
|
|
|
|
|
if (dump_file)
|
|
|
|
|
fprintf (dump_file, "\n");
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 11:32:00 +00:00
|
|
|
|
/* Duplicate block BB2, placing it after BB in the CFG. Return the
|
|
|
|
|
newly created block. */
|
|
|
|
|
basic_block
|
|
|
|
|
transform_duplicate (basic_block bb, basic_block bb2)
|
|
|
|
|
{
|
|
|
|
|
edge e;
|
|
|
|
|
basic_block copy;
|
|
|
|
|
|
|
|
|
|
e = find_edge (bb, bb2);
|
|
|
|
|
|
|
|
|
|
copy = duplicate_block (bb2, e, bb);
|
|
|
|
|
flush_pending_stmts (e);
|
|
|
|
|
|
|
|
|
|
add_phi_args_after_copy (©, 1, NULL);
|
|
|
|
|
|
|
|
|
|
return (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-27 23:13:14 +00:00
|
|
|
|
/* Look for basic blocks in frequency order, construct traces and tail duplicate
|
|
|
|
|
if profitable. */
|
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
|
static bool
|
2012-03-27 23:13:14 +00:00
|
|
|
|
tail_duplicate (void)
|
|
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
|
auto_vec<fibonacci_node<long, basic_block_def>*> blocks;
|
2022-10-27 18:55:19 +00:00
|
|
|
|
blocks.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
|
2015-08-28 15:33:40 +00:00
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
|
basic_block *trace = XNEWVEC (basic_block, n_basic_blocks_for_fn (cfun));
|
|
|
|
|
int *counts = XNEWVEC (int, last_basic_block_for_fn (cfun));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
int ninsns = 0, nduplicated = 0;
|
|
|
|
|
gcov_type weighted_insns = 0, traced_insns = 0;
|
2015-08-28 15:33:40 +00:00
|
|
|
|
fibonacci_heap<long, basic_block_def> heap (LONG_MIN);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
gcov_type cover_insns;
|
|
|
|
|
int max_dup_insns;
|
|
|
|
|
basic_block bb;
|
2014-09-21 17:33:12 +00:00
|
|
|
|
bool changed = false;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
/* Create an oversized sbitmap to reduce the chance that we need to
|
|
|
|
|
resize it. */
|
2014-09-21 17:33:12 +00:00
|
|
|
|
bb_seen = sbitmap_alloc (last_basic_block_for_fn (cfun) * 2);
|
|
|
|
|
bitmap_clear (bb_seen);
|
2022-10-27 18:55:19 +00:00
|
|
|
|
can_duplicate_bb = sbitmap_alloc (last_basic_block_for_fn (cfun));
|
|
|
|
|
bitmap_clear (can_duplicate_bb);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
initialize_original_copy_tables ();
|
|
|
|
|
|
2018-12-28 15:30:48 +00:00
|
|
|
|
if (profile_info && profile_status_for_fn (cfun) == PROFILE_READ)
|
2022-10-27 18:55:19 +00:00
|
|
|
|
probability_cutoff = param_tracer_min_branch_probability_feedback;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
else
|
2022-10-27 18:55:19 +00:00
|
|
|
|
probability_cutoff = param_tracer_min_branch_probability;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
probability_cutoff = REG_BR_PROB_BASE / 100 * probability_cutoff;
|
|
|
|
|
|
|
|
|
|
branch_ratio_cutoff =
|
2022-10-27 18:55:19 +00:00
|
|
|
|
(REG_BR_PROB_BASE / 100 * param_tracer_min_branch_ratio);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
|
FOR_EACH_BB_FN (bb, cfun)
|
2012-03-27 23:13:14 +00:00
|
|
|
|
{
|
2022-10-27 18:55:19 +00:00
|
|
|
|
int n;
|
|
|
|
|
analyze_bb (bb, &n);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
if (!ignore_bb_p (bb))
|
2018-12-28 15:30:48 +00:00
|
|
|
|
blocks[bb->index] = heap.insert (-bb->count.to_frequency (cfun), bb);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
counts [bb->index] = n;
|
|
|
|
|
ninsns += n;
|
2018-12-28 15:30:48 +00:00
|
|
|
|
weighted_insns += n * bb->count.to_frequency (cfun);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 15:30:48 +00:00
|
|
|
|
if (profile_info && profile_status_for_fn (cfun) == PROFILE_READ)
|
2022-10-27 18:55:19 +00:00
|
|
|
|
cover_insns = param_tracer_dynamic_coverage_feedback;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
else
|
2022-10-27 18:55:19 +00:00
|
|
|
|
cover_insns = param_tracer_dynamic_coverage;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
cover_insns = (weighted_insns * cover_insns + 50) / 100;
|
2022-10-27 18:55:19 +00:00
|
|
|
|
max_dup_insns = (ninsns * param_tracer_max_code_growth + 50) / 100;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
while (traced_insns < cover_insns && nduplicated < max_dup_insns
|
2015-08-28 15:33:40 +00:00
|
|
|
|
&& !heap.empty ())
|
2012-03-27 23:13:14 +00:00
|
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
|
basic_block bb = heap.extract_min ();
|
2012-03-27 23:13:14 +00:00
|
|
|
|
int n, pos;
|
|
|
|
|
|
|
|
|
|
if (!bb)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
blocks[bb->index] = NULL;
|
|
|
|
|
|
|
|
|
|
if (ignore_bb_p (bb))
|
|
|
|
|
continue;
|
|
|
|
|
gcc_assert (!bb_seen_p (bb));
|
|
|
|
|
|
|
|
|
|
n = find_trace (bb, trace);
|
|
|
|
|
|
|
|
|
|
bb = trace[0];
|
2018-12-28 15:30:48 +00:00
|
|
|
|
traced_insns += bb->count.to_frequency (cfun) * counts [bb->index];
|
2012-03-27 23:13:14 +00:00
|
|
|
|
if (blocks[bb->index])
|
|
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
|
heap.delete_node (blocks[bb->index]);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
blocks[bb->index] = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (pos = 1; pos < n; pos++)
|
|
|
|
|
{
|
|
|
|
|
basic_block bb2 = trace[pos];
|
|
|
|
|
|
|
|
|
|
if (blocks[bb2->index])
|
|
|
|
|
{
|
2015-08-28 15:33:40 +00:00
|
|
|
|
heap.delete_node (blocks[bb2->index]);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
blocks[bb2->index] = NULL;
|
|
|
|
|
}
|
2018-12-28 15:30:48 +00:00
|
|
|
|
traced_insns += bb2->count.to_frequency (cfun) * counts [bb2->index];
|
2012-03-27 23:13:14 +00:00
|
|
|
|
if (EDGE_COUNT (bb2->preds) > 1
|
2014-09-21 17:33:12 +00:00
|
|
|
|
&& can_duplicate_block_p (bb2)
|
|
|
|
|
/* We have the tendency to duplicate the loop header
|
|
|
|
|
of all do { } while loops. Do not do that - it is
|
|
|
|
|
not profitable and it might create a loop with multiple
|
|
|
|
|
entries or at least rotate the loop. */
|
2015-08-28 15:33:40 +00:00
|
|
|
|
&& bb2->loop_father->header != bb2)
|
2012-03-27 23:13:14 +00:00
|
|
|
|
{
|
|
|
|
|
nduplicated += counts [bb2->index];
|
2017-04-10 11:32:00 +00:00
|
|
|
|
basic_block copy = transform_duplicate (bb, bb2);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
/* Reconsider the original copy of block we've duplicated.
|
|
|
|
|
Removing the most common predecessor may make it to be
|
|
|
|
|
head. */
|
2018-12-28 15:30:48 +00:00
|
|
|
|
blocks[bb2->index] = heap.insert (-bb2->count.to_frequency (cfun), bb2);
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
if (dump_file)
|
|
|
|
|
fprintf (dump_file, "Duplicated %i as %i [%i]\n",
|
2018-12-28 15:30:48 +00:00
|
|
|
|
bb2->index, copy->index, copy->count.to_frequency (cfun));
|
2012-03-27 23:13:14 +00:00
|
|
|
|
|
|
|
|
|
bb2 = copy;
|
2014-09-21 17:33:12 +00:00
|
|
|
|
changed = true;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
mark_bb_seen (bb2);
|
|
|
|
|
bb = bb2;
|
|
|
|
|
/* In case the trace became infrequent, stop duplicating. */
|
|
|
|
|
if (ignore_bb_p (bb))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (dump_file)
|
|
|
|
|
fprintf (dump_file, " covered now %.1f\n\n",
|
|
|
|
|
traced_insns * 100.0 / weighted_insns);
|
|
|
|
|
}
|
|
|
|
|
if (dump_file)
|
|
|
|
|
fprintf (dump_file, "Duplicated %i insns (%i%%)\n", nduplicated,
|
|
|
|
|
nduplicated * 100 / ninsns);
|
|
|
|
|
|
|
|
|
|
free_original_copy_tables ();
|
|
|
|
|
sbitmap_free (bb_seen);
|
2022-10-27 18:55:19 +00:00
|
|
|
|
sbitmap_free (can_duplicate_bb);
|
|
|
|
|
can_duplicate_bb = NULL;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
free (trace);
|
|
|
|
|
free (counts);
|
2014-09-21 17:33:12 +00:00
|
|
|
|
|
|
|
|
|
return changed;
|
2012-03-27 23:13:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 17:33:12 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const pass_data pass_data_tracer =
|
2012-03-27 23:13:14 +00:00
|
|
|
|
{
|
2014-09-21 17:33:12 +00:00
|
|
|
|
GIMPLE_PASS, /* type */
|
|
|
|
|
"tracer", /* name */
|
|
|
|
|
OPTGROUP_NONE, /* optinfo_flags */
|
|
|
|
|
TV_TRACER, /* tv_id */
|
|
|
|
|
0, /* properties_required */
|
|
|
|
|
0, /* properties_provided */
|
|
|
|
|
0, /* properties_destroyed */
|
|
|
|
|
0, /* todo_flags_start */
|
2015-08-28 15:33:40 +00:00
|
|
|
|
TODO_update_ssa, /* todo_flags_finish */
|
2012-03-27 23:13:14 +00:00
|
|
|
|
};
|
2014-09-21 17:33:12 +00:00
|
|
|
|
|
|
|
|
|
class pass_tracer : public gimple_opt_pass
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
pass_tracer (gcc::context *ctxt)
|
|
|
|
|
: gimple_opt_pass (pass_data_tracer, ctxt)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/* opt_pass methods: */
|
2015-08-28 15:33:40 +00:00
|
|
|
|
virtual bool gate (function *)
|
|
|
|
|
{
|
|
|
|
|
return (optimize > 0 && flag_tracer && flag_reorder_blocks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual unsigned int execute (function *);
|
2014-09-21 17:33:12 +00:00
|
|
|
|
|
|
|
|
|
}; // class pass_tracer
|
|
|
|
|
|
2015-08-28 15:33:40 +00:00
|
|
|
|
unsigned int
|
|
|
|
|
pass_tracer::execute (function *fun)
|
|
|
|
|
{
|
|
|
|
|
bool changed;
|
|
|
|
|
|
|
|
|
|
if (n_basic_blocks_for_fn (fun) <= NUM_FIXED_BLOCKS + 1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
mark_dfs_back_edges ();
|
|
|
|
|
if (dump_file)
|
|
|
|
|
brief_dump_cfg (dump_file, dump_flags);
|
|
|
|
|
|
|
|
|
|
/* Trace formation is done on the fly inside tail_duplicate */
|
|
|
|
|
changed = tail_duplicate ();
|
|
|
|
|
if (changed)
|
|
|
|
|
{
|
|
|
|
|
free_dominance_info (CDI_DOMINATORS);
|
|
|
|
|
/* If we changed the CFG schedule loops for fixup by cleanup_cfg. */
|
|
|
|
|
loops_state_set (LOOPS_NEED_FIXUP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dump_file)
|
|
|
|
|
brief_dump_cfg (dump_file, dump_flags);
|
|
|
|
|
|
|
|
|
|
return changed ? TODO_cleanup_cfg : 0;
|
|
|
|
|
}
|
2014-09-21 17:33:12 +00:00
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
gimple_opt_pass *
|
|
|
|
|
make_pass_tracer (gcc::context *ctxt)
|
|
|
|
|
{
|
|
|
|
|
return new pass_tracer (ctxt);
|
|
|
|
|
}
|