Avoiding overflow in printing time
Richard Kenner
kenner@vlsi1.ultra.nyu.edu
Sat Apr 15 10:01:00 GMT 2000
This uses floating-point to calculate percentages of time. That's the
way it was originally and I have no idea why it was changed to int,
which will overflow on almost all machines. long helps on 64-bit machines,
but that's it.
Sat Apr 15 10:59:19 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* toplev.c: Make *_time variable long to reduce chance of overflow.
(TIMEVAR): Likewise for `otime'.
(print_time): Arg is now long; compute percentage in FP and round.
* toplev.h (print_time): Arg is long.
* tree.c: Minor whitespace changes.
*** toplev.c 2000/04/07 09:23:29 1.316
--- toplev.c 2000/04/15 16:40:53
*************** read_integral_parameter (p, pname, defva
*** 1404,1437 ****
/* Time accumulators, to count the total time spent in various passes. */
! int parse_time;
! int varconst_time;
! int integration_time;
! int jump_time;
! int cse_time;
! int gcse_time;
! int loop_time;
! int cse2_time;
! int branch_prob_time;
! int flow_time;
! int combine_time;
! int regmove_time;
! int sched_time;
! int local_alloc_time;
! int global_alloc_time;
! int flow2_time;
! int peephole2_time;
! int sched2_time;
! int dbr_sched_time;
! int reorder_blocks_time;
! int rename_registers_time;
! int shorten_branch_time;
! int stack_reg_time;
! int to_ssa_time;
! int from_ssa_time;
! int final_time;
! int symout_time;
! int dump_time;
! int gc_time;
! int all_time;
/* Return time used so far, in microseconds. */
--- 1404,1437 ----
/* Time accumulators, to count the total time spent in various passes. */
! long parse_time;
! long varconst_time;
! long integration_time;
! long jump_time;
! long cse_time;
! long gcse_time;
! long loop_time;
! long cse2_time;
! long branch_prob_time;
! long flow_time;
! long combine_time;
! long regmove_time;
! long sched_time;
! long local_alloc_time;
! long global_alloc_time;
! long flow2_time;
! long peephole2_time;
! long sched2_time;
! long dbr_sched_time;
! long reorder_blocks_time;
! long rename_registers_time;
! long shorten_branch_time;
! long stack_reg_time;
! long to_ssa_time;
! long from_ssa_time;
! long final_time;
! long symout_time;
! long dump_time;
! long gc_time;
! long all_time;
/* Return time used so far, in microseconds. */
*************** get_run_time ()
*** 1504,1519 ****
}
! #define TIMEVAR(VAR, BODY) \
! do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
void
print_time (str, total)
const char *str;
! int total;
{
fprintf (stderr,
! "time in %s: %d.%06d (%d%%)\n",
str, total / 1000000, total % 1000000,
! all_time == 0 ? 0 : (100 * total) / all_time);
}
--- 1504,1524 ----
}
! #define TIMEVAR(VAR, BODY) \
! do { \
! long otime = get_run_time (); \
! BODY; \
! VAR += get_run_time () - otime; \
! } while (0)
void
print_time (str, total)
const char *str;
! long total;
{
fprintf (stderr,
! "time in %s: %ld.%06ld (%ld%%)\n",
str, total / 1000000, total % 1000000,
! all_time == 0 ? 0
! : (long) (((100.0 * (double) total) / (double) all_time) + .5));
}
*************** decl_name (decl, verbosity)
*** 1529,1532 ****
--- 1534,1538 ----
/* Mark P for GC. Also mark main_input_filename and input_filename. */
+
static void
mark_file_stack (p)
*** toplev.h 2000/03/28 17:01:49 1.35
--- toplev.h 2000/04/15 16:40:54
*************** extern int read_integral_parameter PARAM
*** 31,35 ****
extern int count_error PARAMS ((int));
extern void strip_off_ending PARAMS ((char *, int));
! extern void print_time PARAMS ((const char *, int));
extern void debug_start_source_file PARAMS ((char *));
extern void debug_end_source_file PARAMS ((unsigned));
--- 31,35 ----
extern int count_error PARAMS ((int));
extern void strip_off_ending PARAMS ((char *, int));
! extern void print_time PARAMS ((const char *, long));
extern void debug_start_source_file PARAMS ((char *));
extern void debug_end_source_file PARAMS ((unsigned));
*** tree.c 2000/04/12 13:10:42 1.137
--- tree.c 2000/04/15 16:41:23
*************** int_fits_type_p (c, type)
*** 5171,5175 ****
/* Given a DECL or TYPE, return the scope in which it was declared, or
! NUL_TREE if there is no containing scope. */
tree
--- 5171,5175 ----
/* Given a DECL or TYPE, return the scope in which it was declared, or
! NULL_TREE if there is no containing scope. */
tree
*************** decl_function_context (decl)
*** 5194,5197 ****
--- 5194,5198 ----
if (TREE_CODE (decl) == SAVE_EXPR)
context = SAVE_EXPR_CONTEXT (decl);
+
/* C++ virtual functions use DECL_CONTEXT for the class of the vtable
where we look up the function at runtime. Such functions always take
*************** decl_function_context (decl)
*** 5201,5206 ****
and use something else for the "virtual context". */
else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
! context = TYPE_MAIN_VARIANT
! (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
else
context = DECL_CONTEXT (decl);
--- 5202,5208 ----
and use something else for the "virtual context". */
else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
! context
! = TYPE_MAIN_VARIANT
! (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
else
context = DECL_CONTEXT (decl);
More information about the Gcc-patches
mailing list