diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2019-11-06 10:57:18 +0000 |
---|---|---|
committer | Alexandre Oliva <aoliva@gcc.gnu.org> | 2019-11-06 10:57:18 +0000 |
commit | 3cf3da88be453f3fceaa596ee78be8d1e5aa21ca (patch) | |
tree | ead0ae87adfe46ab5e364107f3cfe9d60d9d3761 /gcc/function.c | |
parent | 5d183d1740d8d8b84991f186ce4d992ee799536f (diff) | |
download | gcc-3cf3da88be453f3fceaa596ee78be8d1e5aa21ca.zip gcc-3cf3da88be453f3fceaa596ee78be8d1e5aa21ca.tar.gz gcc-3cf3da88be453f3fceaa596ee78be8d1e5aa21ca.tar.bz2 |
introduce -fcallgraph-info option
This was first submitted many years ago
https://gcc.gnu.org/ml/gcc-patches/2010-10/msg02468.html
The command line option -fcallgraph-info is added and makes the
compiler generate another output file (xxx.ci) for each compilation
unit (or LTO partitoin), which is a valid VCG file (you can launch
your favorite VCG viewer on it unmodified) and contains the "final"
callgraph of the unit. "final" is a bit of a misnomer as this is
actually the callgraph at RTL expansion time, but since most
high-level optimizations are done at the Tree level and RTL doesn't
usually fiddle with calls, it's final in almost all cases. Moreover,
the nodes can be decorated with additional info: -fcallgraph-info=su
adds stack usage info and -fcallgraph-info=da dynamic allocation info.
for gcc/ChangeLog
From Eric Botcazou <ebotcazou@adacore.com>, Alexandre Oliva <oliva@adacore.com>
* common.opt (-fcallgraph-info[=]): New option.
* doc/invoke.texi (Developer options): Document it.
* opts.c (common_handle_option): Handle it.
* builtins.c (expand_builtin_alloca): Record allocation if
-fcallgraph-info=da.
* calls.c (expand_call): If -fcallgraph-info, record the call.
(emit_library_call_value_1): Likewise.
* flag-types.h (enum callgraph_info_type): New type.
* explow.c: Include stringpool.h.
(set_stack_check_libfunc): Set SET_SYMBOL_REF_DECL on the symbol.
* function.c (allocate_stack_usage_info): New.
(allocate_struct_function): Call it for -fcallgraph-info.
(prepare_function_start): Call it otherwise.
(record_final_call, record_dynamic_alloc): New.
* function.h (struct callinfo_callee): New.
(CALLEE_FROM_CGRAPH_P): New.
(struct callinfo_dalloc): New.
(struct stack_usage): Add callees and dallocs.
(record_final_call, record_dynamic_alloc): Declare.
* gimplify.c (gimplify_decl_expr): Record dynamically-allocated
object if -fcallgraph-info=da.
* optabs-libfuncs.c (build_libfunc_function): Keep SYMBOL_REF_DECL.
* print-tree.h (print_decl_identifier): Declare.
(PRINT_DECL_ORIGIN, PRINT_DECL_NAME, PRINT_DECL_UNIQUE_NAME): New.
* print-tree.c: Include print-tree.h.
(print_decl_identifier): New function.
* toplev.c: Include print-tree.h.
(callgraph_info_file): New global variable.
(callgraph_info_external_printed): Likewise.
(output_stack_usage): Rename to...
(output_stack_usage_1): ... this. Make it static, add cf
parameter. If -fcallgraph-info=su, print stack usage to cf.
If -fstack-usage, use print_decl_identifier for
pretty-printing.
(INDIRECT_CALL_NAME): New.
(dump_final_node_vcg_start): New.
(dump_final_callee_vcg, dump_final_node_vcg): New.
(output_stack_usage): New.
(lang_dependent_init): Open and start file if
-fcallgraph-info. Allocated callgraph_info_external_printed.
(finalize): If callgraph_info_file is not null, finish it,
close it, and release callgraph_info_external_printed.
for gcc/ada/ChangeLog
* gcc-interface/misc.c (callgraph_info_file): Delete.
Co-Authored-By: Alexandre Oliva <oliva@adacore.com>
From-SVN: r277876
Diffstat (limited to 'gcc/function.c')
-rw-r--r-- | gcc/function.c | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/gcc/function.c b/gcc/function.c index a1c76a4..3f79a38 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -4725,6 +4725,16 @@ get_last_funcdef_no (void) return funcdef_no; } +/* Allocate and initialize the stack usage info data structure for the + current function. */ +static void +allocate_stack_usage_info (void) +{ + gcc_assert (!cfun->su); + cfun->su = ggc_cleared_alloc<stack_usage> (); + cfun->su->static_stack_size = -1; +} + /* Allocate a function structure for FNDECL and set its contents to the defaults. Set cfun to the newly-allocated object. Some of the helper functions invoked during initialization assume @@ -4802,6 +4812,9 @@ allocate_struct_function (tree fndecl, bool abstract_p) if (!profile_flag && !flag_instrument_function_entry_exit) DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl) = 1; + + if (flag_callgraph_info) + allocate_stack_usage_info (); } /* Don't enable begin stmt markers if var-tracking at assignments is @@ -4846,11 +4859,8 @@ prepare_function_start (void) init_expr (); default_rtl_profile (); - if (flag_stack_usage_info) - { - cfun->su = ggc_cleared_alloc<stack_usage> (); - cfun->su->static_stack_size = -1; - } + if (flag_stack_usage_info && !flag_callgraph_info) + allocate_stack_usage_info (); cse_not_expected = ! optimize; @@ -6373,12 +6383,49 @@ rest_of_handle_thread_prologue_and_epilogue (void) cleanup_cfg (optimize ? CLEANUP_EXPENSIVE : 0); /* The stack usage info is finalized during prologue expansion. */ - if (flag_stack_usage_info) + if (flag_stack_usage_info || flag_callgraph_info) output_stack_usage (); return 0; } +/* Record a final call to CALLEE at LOCATION. */ + +void +record_final_call (tree callee, location_t location) +{ + if (!callee || CALLEE_FROM_CGRAPH_P (callee)) + return; + + struct callinfo_callee datum = { location, callee }; + vec_safe_push (cfun->su->callees, datum); +} + +/* Record a dynamic allocation made for DECL_OR_EXP. */ + +void +record_dynamic_alloc (tree decl_or_exp) +{ + struct callinfo_dalloc datum; + + if (DECL_P (decl_or_exp)) + { + datum.location = DECL_SOURCE_LOCATION (decl_or_exp); + const char *name = lang_hooks.decl_printable_name (decl_or_exp, 2); + const char *dot = strrchr (name, '.'); + if (dot) + name = dot + 1; + datum.name = ggc_strdup (name); + } + else + { + datum.location = EXPR_LOCATION (decl_or_exp); + datum.name = NULL; + } + + vec_safe_push (cfun->su->dallocs, datum); +} + namespace { const pass_data pass_data_thread_prologue_and_epilogue = |