On Wed, Jun 20, 2012 at 12:30 PM, Eric Botcazou <ebotca...@adacore.com> wrote: > Hi, > > this is a repost of > http://gcc.gnu.org/ml/gcc-patches/2010-10/msg02468.html > earlier in the development cycle, so with hopefully more time for discussion. > > The command line option -fcallgraph-info is added and makes the compiler > generate another output file (xxx.ci) for each compilation unit, 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. > > This is useful for embedded applications with stringent requirements in terms > of memory usage for example. You can provide the .ci files (or an aggregated > version) for pre-compiled libraries. > > This is again strictly orthogonal to code and debug info generation. There > are a few non-obvious changes to libfuncs.h, builtins.c, expr.c and optabs.c > to deal with quirks of the RTL expander, but this mostly removes dead code. > > This version takes into account Joseph's comments for the first submission. > As for Richard's comments, the implementation is low-level by design because > we > want to be able to trust it and the IPA callgraph isn't suitable for this, as > the RTL expander can introduce function calls that need to be accounted for.
Hmm. I wonder why we cannot do the following (some of this might be already the case): 1) preserve cgraph nodes of functions we expanded 2) at expand time, remove call edges from the cgraph node of the currently expanding function (they are not kept up-to-date anyway) 3) add cgraph edges to the regular cgraph when expand_call expands a call (what about indirect calls? you seem to ignore those ...) 4) for dynamic allocs simply record an edge to a callgraph node for alloca Thus, go away with the notion of a "final cgraph". And make it possible to specify the dump should be emitted at other useful points of the compilation (LTO WPA phase comes to my mind, similar the callgraph as constructed by the frontend). Thus, make the whole thing a little less "special case" and more useful in general? (yeah, I still detest VCG and prefer DOT ... maybe we can think of a simple abstraction layer that would allow switching the output format ...) Thanks, Richard. > Tested on x86_64-suse-linux. > > > 2012-06-20 Eric Botcazou <ebotca...@adacore.com> > > Callgraph info support > * common.opt (-fcallgraph-info[=]): New option. > * doc/invoke.texi (Debugging options): Document it. > * opts.c (common_handle_option): Handle it. > * flag-types.h (enum callgraph_info_type): New type. > * builtins.c (set_builtin_user_assembler_name): Do not initialize > memcpy_libfunc and memset_libfunc. > * calls.c (expand_call): If -fcallgraph-info, record the call. > (emit_library_call_value_1): Likewise. > * cgraph.h (struct cgraph_final_info): New structure. > (struct cgraph_dynamic_alloc): Likewise. > (cgraph_final_edge): Likewise. > (cgraph_node): Add 'final' field. > (dump_cgraph_final_vcg): Declare. > (cgraph_final_record_call): Likewise. > (cgraph_final_record_dynamic_alloc): Likewise. > (cgraph_final_info): Likewise. > * cgraph.c: Include expr.h and output.h. > (cgraph_create_empty_node): Initialize 'final' field. > (final_create_edge): New static function. > (cgraph_final_record_call): New global function. > (cgraph_final_record_dynamic_alloc): Likewise. > (cgraph_final_info): Likewise. > (dump_cgraph_final_indirect_call_node_vcg): New static function. > (dump_cgraph_final_edge_vcg): Likewise. > (dump_cgraph_final_node_vcg): Likewise. > (external_node_needed_p): Likewise. > (dump_cgraph_final_vcg): New global function. > * expr.c (emit_block_move_via_libcall): Set input_location on the call. > (set_storage_via_libcall): Likewise. > (block_move_fn): Make global. > Do not include gt-expr.h. > * expr.h (block_move_fn): Declare. > * gimplify.c (gimplify_decl_expr): Record dynamically-allocated object > by calling cgraph_final_record_dynamic_alloc if -fcallgraph-info=da. > * libfuncs.h (enum libfunc_index): Delete LTI_memcpy and LTI_memset. > (memcpy_libfunc): Delete. > (memset_libfunc): Likewise. > * optabs.c (init_one_libfunc): Do not zap the SYMBOL_REF_DECL. > (init_optabs): Do not initialize memcpy_libfunc and memset_libfunc. > * print-tree.c (print_decl_identifier): New function. > * output.h (enum stack_usage_kind_type): New type. > (stack_usage_qual): Declare. > * toplev.c (callgraph_info_file): New global variable. > (stack_usage_qual): Likewise. > (output_stack_usage): If -fcallgraph-info=su, set stack_usage_kind > and stack_usage of associated callgraph node. If -fstack-usage, use > print_decl_identifier for pretty-printing. > (lang_dependent_init): Open file if -fcallgraph-info. > (finalize): If callgraph_info_file is not null, invoke dump_cgraph_vcg > and close file. > * tree.h (print_decl_identifier): Declare. > (PRINT_DECL_ORIGIN, PRINT_DECL_NAME, PRINT_DECL_UNIQUE_NAME): New. > * Makefile.in (expr.o): Remove gt-expr.h. > (cgraph.o): Add $(EXPR_H) and output.h. > * config/picochip/picochip.c: Adjust comment. > > > -- > Eric Botcazou