#include "cfgexpand.h"
#include "gimplify.h"
-/* Estimate runtime of function can easilly run into huge numbers with many
- nested loops. Be sure we can compute time * INLINE_SIZE_SCALE * 2 in an
- integer. For anything larger we use gcov_type. */
-#define MAX_TIME 500000
-
/* Number of bits in integer, but we really want to be stable across different
hosts. */
#define NUM_CONDITIONS 32
/* Record SIZE and TIME under condition PRED into the inline summary. */
static void
-account_size_time (struct inline_summary *summary, int size, int time,
+account_size_time (struct inline_summary *summary, int size, sreal time,
struct predicate *pred)
{
size_time_entry *e;
/* We need to create initial empty unconitional clause, but otherwie
we don't need to account empty times and sizes. */
- if (!size && !time && summary->entry)
+ if (!size && time == 0 && summary->entry)
return;
- /* Watch overflow that might result from insane profiles. */
- if (time > MAX_TIME * INLINE_TIME_SCALE)
- time = MAX_TIME * INLINE_TIME_SCALE;
gcc_assert (time >= 0);
for (i = 0; vec_safe_iterate (summary->entry, i, &e); i++)
"\t\tReached limit on number of entries, "
"ignoring the predicate.");
}
- if (dump_file && (dump_flags & TDF_DETAILS) && (time || size))
+ if (dump_file && (dump_flags & TDF_DETAILS) && (time != 0 || size))
{
fprintf (dump_file,
"\t\tAccounting size:%3.2f, time:%3.2f on %spredicate:",
((double) size) / INLINE_SIZE_SCALE,
- ((double) time) / INLINE_TIME_SCALE, found ? "" : "new ");
+ (time.to_double ()) / INLINE_TIME_SCALE, found ? "" : "new ");
dump_predicate (dump_file, summary->conds, pred);
}
if (!found)
{
e->size += size;
e->time += time;
- if (e->time > MAX_TIME * INLINE_TIME_SCALE)
- e->time = MAX_TIME * INLINE_TIME_SCALE;
}
}
{
struct cgraph_edge *e;
- info->self_size = info->self_time = 0;
+ info->self_size = 0;
+ info->self_time = 0;
info->estimated_stack_size = 0;
info->estimated_self_stack_size = 0;
info->stack_frame_offset = 0;
fprintf (f, " contains_cilk_spawn");
if (s->fp_expressions)
fprintf (f, " fp_expression");
- fprintf (f, "\n self time: %i\n", s->self_time);
- fprintf (f, " global time: %i\n", s->time);
+ fprintf (f, "\n self time: %f\n", s->self_time.to_double ());
+ fprintf (f, " global time: %f\n", s->time.to_double ());
fprintf (f, " self size: %i\n", s->self_size);
fprintf (f, " global size: %i\n", s->size);
fprintf (f, " min size: %i\n", s->min_size);
{
fprintf (f, " size:%f, time:%f, predicate:",
(double) e->size / INLINE_SIZE_SCALE,
- (double) e->time / INLINE_TIME_SCALE);
+ e->time.to_double () / INLINE_TIME_SCALE);
dump_predicate (f, s->conds, &e->predicate);
}
if (s->loop_iterations)
static void
estimate_function_body_sizes (struct cgraph_node *node, bool early)
{
- gcov_type time = 0;
+ sreal time = 0;
/* Estimate static overhead for function prologue/epilogue and alignment. */
int size = 2;
/* Benefits are scaled by probability of elimination that is in range
{
time += this_time;
size += this_size;
- if (time > MAX_TIME * INLINE_TIME_SCALE)
- time = MAX_TIME * INLINE_TIME_SCALE;
}
/* We account everything but the calls. Calls have their own
}
}
set_hint_predicate (&inline_summaries->get (node)->array_index, array_index);
- time = (time + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
- if (time > MAX_TIME)
- time = MAX_TIME;
+ time = time / CGRAPH_FREQ_BASE;
free (order);
if (nonconstant_names.exists () && !early)
static inline void
estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size,
- int *time,
+ sreal *time,
int prob,
vec<tree> known_vals,
vec<ipa_polymorphic_call_context> known_contexts,
*size += cur_size;
if (min_size)
*min_size += cur_size;
- *time += apply_probability ((gcov_type) call_time, prob)
+ *time += call_time * prob / REG_BR_PROB_BASE
* e->frequency * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE);
- if (*time > MAX_TIME * INLINE_TIME_SCALE)
- *time = MAX_TIME * INLINE_TIME_SCALE;
}
static void
estimate_calls_size_and_time (struct cgraph_node *node, int *size,
- int *min_size, int *time,
+ int *min_size, sreal *time,
inline_hints *hints,
clause_t possible_truths,
vec<tree> known_vals,
struct inline_summary *info = inline_summaries->get (node);
size_time_entry *e;
int size = 0;
- int time = 0;
+ sreal time = 0;
int min_size = 0;
inline_hints hints = 0;
int i;
inline_param_summary);
gcc_checking_assert (prob >= 0);
gcc_checking_assert (prob <= REG_BR_PROB_BASE);
- time += apply_probability ((gcov_type) e->time, prob);
+ time += e->time * prob / REG_BR_PROB_BASE;
}
- if (time > MAX_TIME * INLINE_TIME_SCALE)
- time = MAX_TIME * INLINE_TIME_SCALE;
gcc_checking_assert (time >= 0);
}
min_size = RDIV (min_size, INLINE_SIZE_SCALE);
if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, "\n size:%i time:%i\n", (int) size, (int) time);
+ fprintf (dump_file, "\n size:%i time:%f\n", (int) size, time.to_double ());
if (ret_time)
- *ret_time = time;
+ *ret_time = time.to_int ();
if (ret_size)
*ret_size = size;
if (ret_min_size)
&toplev_predicate);
if (!false_predicate_p (&p))
{
- gcov_type add_time = ((gcov_type) e->time * edge->frequency
- + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
+ sreal add_time = e->time * edge->frequency / CGRAPH_FREQ_BASE;
int prob = predicate_probability (callee_info->conds,
&e->predicate,
clause, es->param);
- add_time = apply_probability ((gcov_type) add_time, prob);
- if (add_time > MAX_TIME * INLINE_TIME_SCALE)
- add_time = MAX_TIME * INLINE_TIME_SCALE;
+ add_time = add_time * prob / REG_BR_PROB_BASE;
if (prob != REG_BR_PROB_BASE
&& dump_file && (dump_flags & TDF_DETAILS))
{
for (i = 0; vec_safe_iterate (info->entry, i, &e); i++)
{
info->size += e->size, info->time += e->time;
- if (info->time > MAX_TIME * INLINE_TIME_SCALE)
- info->time = MAX_TIME * INLINE_TIME_SCALE;
}
estimate_calls_size_and_time (node, &info->size, &info->min_size,
&info->time, NULL,
~(clause_t) (1 << predicate_false_condition),
vNULL, vNULL, vNULL);
- info->time = (info->time + INLINE_TIME_SCALE / 2) / INLINE_TIME_SCALE;
+ info->time = info->time / INLINE_TIME_SCALE;
info->size = (info->size + INLINE_SIZE_SCALE / 2) / INLINE_SIZE_SCALE;
}
struct inline_edge_summary *es = inline_edge_summary (edge);
if (!es->predicate || !false_predicate_p (es->predicate))
{
- gcov_type time =
+ sreal time =
inline_summaries->get (node)->time + estimate_edge_time (edge);
if (time < 0)
time = 0;
- if (time > MAX_TIME)
- time = MAX_TIME;
- return time;
+ return time.to_int ();
}
- return inline_summaries->get (node)->time;
+ return inline_summaries->get (node)->time.to_int ();
}
info->estimated_stack_size
= info->estimated_self_stack_size = streamer_read_uhwi (&ib);
info->size = info->self_size = streamer_read_uhwi (&ib);
- info->time = info->self_time = streamer_read_uhwi (&ib);
+ info->time = info->self_time = sreal::stream_in (&ib);
bp = streamer_read_bitpack (&ib);
info->inlinable = bp_unpack_value (&bp, 1);
struct size_time_entry e;
e.size = streamer_read_uhwi (&ib);
- e.time = streamer_read_uhwi (&ib);
+ e.time = sreal::stream_in (&ib);
e.predicate = read_predicate (&ib);
vec_safe_push (info->entry, e);
streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
streamer_write_hwi (ob, info->estimated_self_stack_size);
streamer_write_hwi (ob, info->self_size);
- streamer_write_hwi (ob, info->self_time);
+ info->self_time.stream_out (ob);
bp = bitpack_create (ob->main_stream);
bp_pack_value (&bp, info->inlinable, 1);
bp_pack_value (&bp, info->contains_cilk_spawn, 1);
for (i = 0; vec_safe_iterate (info->entry, i, &e); i++)
{
streamer_write_uhwi (ob, e->size);
- streamer_write_uhwi (ob, e->time);
+ e->time.stream_out (ob);
write_predicate (ob, &e->predicate);
}
write_predicate (ob, info->loop_iterations);
else
uninlined_call_time = uninlined_call_time >> 11;
- int caller_time = inline_summaries->get (caller)->time;
+ sreal caller_time = inline_summaries->get (caller)->time;
return uninlined_call_time + caller_time;
}
cgraph_node *caller = (edge->caller->global.inlined_to
? edge->caller->global.inlined_to
: edge->caller);
- int caller_time = inline_summaries->get (caller)->time;
+ sreal caller_time = inline_summaries->get (caller)->time;
sreal time = edge_time;
if (edge->count && caller->count)
int growth = estimate_edge_growth (e);
inline_hints hints = estimate_edge_hints (e);
bool big_speedup = big_speedup_p (e);
+/*
+ fprintf (stderr, "%i %i %i\n",growth,hints,big_speedup);
+ dump_inline_summary (stderr, e->caller->global.inlined_to ? e->caller->global.inlined_to : e->caller);
+ dump_inline_summary (stderr, e->callee);
+ sreal time = compute_uninlined_call_time (inline_summaries->get (e->callee),
+ e);
+ sreal inlined_time = compute_inlined_call_time (e, estimate_edge_time (e));
+ fprintf (stderr, "%f %f\n", time.to_double (), inlined_time.to_double ());*/
if (growth <= 0)
;
edge_time = estimate_edge_time (edge);
hints = estimate_edge_hints (edge);
gcc_checking_assert (edge_time >= 0);
- gcc_checking_assert (edge_time <= callee_info->time);
+ /* FIXME: -1 to care of rounding issues should go away once cache is migrated.
+ to sreals. */
+ gcc_checking_assert (edge_time - 1 <= callee_info->time);
gcc_checking_assert (growth <= callee_info->size);
if (dump)
if (dump_file)
fprintf (dump_file,
"\n Inlined %i times, "
- "body grown from size %i to %i, time %i to %i\n", n,
- inline_summaries->get (master_clone)->size, inline_summaries->get (node)->size,
- inline_summaries->get (master_clone)->time, inline_summaries->get (node)->time);
+ "body grown from size %i to %i, time %f to %f\n", n,
+ inline_summaries->get (master_clone)->size,
+ inline_summaries->get (node)->size,
+ inline_summaries->get (master_clone)->time.to_double (),
+ inline_summaries->get (node)->time.to_double ());
/* Remove master clone we used for inlining. We rely that clones inlined
into master clone gets queued just before master clone so we don't
if (dump_file)
{
fprintf (dump_file,
- " Inlined into %s which now has time %i and size %i, "
+ " Inlined into %s which now has time %f and size %i, "
"net change of %+i.\n",
edge->caller->name (),
- inline_summaries->get (edge->caller)->time,
+ inline_summaries->get (edge->caller)->time.to_double (),
inline_summaries->get (edge->caller)->size,
overall_size - old_size);
}
if (!node->global.inlined_to
&& !node->alias)
{
- int time = inline_summaries->get (node)->time;
+ int time = inline_summaries->get (node)->time.to_double ();
sum += time;
sum_weighted += time * node->count;
}