GCC Middle and Back End API Reference
cgraphunit.c File Reference

Data Structures

struct  cgraph_order_sort

Enumerations

enum  cgraph_order_sort_kind { ORDER_UNDEFINED = 0, ORDER_FUNCTION, ORDER_VAR, ORDER_ASM }

Functions

static void expand_all_functions (void)
static void mark_functions_to_output (void)
static void expand_function (struct cgraph_node *)
static void analyze_function (struct cgraph_node *)
static void handle_alias_pairs (void)
bool decide_is_symbol_needed ()
static void enqueue_node ()
bool cgraph_process_new_functions ()
void cgraph_reset_node ()
static bool referred_to_p ()
void cgraph_finalize_function ()
void cgraph_add_new_function ()
struct asm_nodeadd_asm_node ()
static void output_asm_statements ()
static void analyze_function ()
void cgraph_process_same_body_aliases ()
static void process_common_attributes ()
static void process_function_and_variable_attributes (struct cgraph_node *first, struct varpool_node *first_var)
void varpool_finalize_decl ()
static void analyze_functions ()
basic_block init_lowered_empty_function ()
static tree thunk_adjust (gimple_stmt_iterator *bsi, tree ptr, bool this_adjusting, HOST_WIDE_INT fixed_offset, tree virtual_offset)
void expand_thunk ()
static void assemble_thunks_and_aliases ()
static void expand_function ()
static void output_in_order ()
static void ipa_passes ()
static tree get_alias_symbol ()
static void output_weakrefs ()
void init_cgraph ()
void compile ()
void finalize_compilation_unit ()

Variables

cgraph_node_set cgraph_new_nodes
FILE * cgraph_dump_file
struct asm_nodeasm_nodes
static struct asm_nodeasm_last_node
static tree vtable_entry_type
static symtab_node first = (symtab_node)(void *)1

Enumeration Type Documentation

This is used to sort the node types by the cgraph order number.   
Enumerator:
ORDER_UNDEFINED 
ORDER_FUNCTION 
ORDER_VAR 
ORDER_ASM 

Function Documentation

struct asm_node* add_asm_node ( )
read
Add a top-level asm statement to the list.   

References asm_last_node, asm_node::asm_str, asm_node::next, asm_node::order, and symtab_order.

static void analyze_function ( struct cgraph_node )
static
static void analyze_functions ( )
static
Discover all functions and variables that are trivially needed, analyze
   them as well as all functions and variables referred by them   

References analyze_function(), symtab_node_base::analyzed, bitmap_obstack_initialize(), bitmap_obstack_release(), build_type_inheritance_graph(), cgraph_edge::call_stmt, cgraph_edge::callee, cgraph_dump_file, cgraph_first_function(), cgraph_get_node(), cgraph_make_edge_direct(), cgraph_process_new_functions(), cgraph_redirect_edge_call_stmt_to_callee(), cgraph_reset_node(), CGRAPH_STATE_CONSTRUCTION, changed, cpp_implicit_aliases_done, decide_is_symbol_needed(), decl::decl, symtab_node_base::definition, dump_file, dump_possible_polymorphic_call_targets(), dump_symtab(), dyn_cast(), enqueue_node(), first, fixup_same_cpp_alias_visibility(), ggc_collect(), gimple_has_body_p(), cgraph_edge::indirect_info, method_class_type(), symtab_node_base::next, cgraph_edge::next_callee, pointer_set_create(), pointer_set_destroy(), pointer_set_insert(), cgraph_indirect_call_info::polymorphic, possible_polymorphic_call_targets(), print_gimple_stmt(), process_function_and_variable_attributes(), ipa_ref::referred, referred_to_p(), cgraph_node::symbol, varpool_node::symbol, symtab_alias_target(), symtab_node_asm_name(), symtab_node_name(), symtab_nodes, symtab_remove_node(), type_in_anonymous_namespace_p(), update_type_inheritance_graph(), cgraph_node::used_as_abstract_origin, varpool_analyze_node(), and varpool_first_variable().

Referenced by finalize_compilation_unit().

void cgraph_add_new_function ( )
Add the function FNDECL to the call graph.
   Unlike cgraph_finalize_function, this function is intended to be used
   by middle end and allows insertion of new function at arbitrary point
   of compilation.  The function can be either in high, low or SSA form
   GIMPLE.

   The function is assumed to be reachable and have address taken (so no
   API breaking optimizations are performed on it).

   Main work done by this function is to enqueue the function for later
   processing to avoid need the passes to be re-entrant.   

References gcc::pass_manager::all_lowering_passes, analyze_function(), bitmap_obstack_initialize(), bitmap_obstack_release(), cgraph_create_node(), cgraph_finalize_function(), cgraph_get_create_node(), cgraph_node_set_add(), cgraph_node_set_new(), CGRAPH_STATE_CONSTRUCTION, CGRAPH_STATE_EXPANSION, CGRAPH_STATE_FINISHED, CGRAPH_STATE_IPA, CGRAPH_STATE_IPA_SSA, CGRAPH_STATE_PARSING, symtab_node_base::definition, lang_hooks::eh_personality, eh_personality_lang, gcc::pass_manager::execute_early_local_passes(), execute_pass_list(), expand_function(), symtab_node_base::force_output, function_needs_eh_personality(), g, gcc::context::get_passes(), gimple_in_ssa_p(), gimple_register_cfg_hooks(), cgraph_local_info::local, cgraph_node::local, cgraph_node::lowered, pop_cfun(), push_cfun(), and cgraph_node::symbol.

void cgraph_finalize_function ( )
DECL has been parsed.  Take it, queue it, compile it at the whim of the
   logic in effect.  If NO_COLLECT is true, then our caller cannot stand to have
   the garbage collector run at the moment.  We would need to either create
   a new GC context, or just not compile right now.   

References cgraph_get_create_node(), cgraph_reset_node(), CGRAPH_STATE_CONSTRUCTION, symtab_node_base::cpp_implicit_alias, debug_hooks, decide_is_symbol_needed(), gcc_debug_hooks::deferred_inline_function, symtab_node_base::definition, do_warn_unused_parameter(), enqueue_node(), symtab_node_base::force_output, ggc_collect(), cgraph_node::local, cgraph_node::lowered, notice_global_symbol(), cgraph_local_info::redefined_extern_inline, referred_to_p(), and cgraph_node::symbol.

void cgraph_process_same_body_aliases ( void  )
C++ frontend produce same body aliases all over the place, even before PCH
   gets streamed out. It relies on us linking the aliases with their function
   in order to do the fixups, but ipa-ref is not PCH safe.  Consequentely we
   first produce aliases without links, but once C++ FE is sure he won't sream
   PCH we build the links via this function.   

References cgraph_get_create_node(), cpp_implicit_aliases_done, symtab_resolve_alias(), and varpool_node_for_decl().

void cgraph_reset_node ( )
As an GCC extension we allow redefinition of the function.  The
   semantics when both copies of bodies differ is not well defined.
   We replace the old body with new body so in unit at a time mode
   we always use new body, while in normal mode we may end up with
   old body inlined into some functions and new body expanded and
   inlined in others.

   ??? It may make more sense to use one body for inlining and other
   body for expanding the function but this is difficult to do.   

References symtab_node_base::alias, symtab_node_base::analyzed, cgraph_node_remove_callees(), symtab_node_base::cpp_implicit_alias, symtab_node_base::definition, cgraph_node::global, ipa_remove_all_references(), cgraph_node::local, memset(), cgraph_node::process, symtab_node_base::ref_list, cgraph_node::rtl, cgraph_node::symbol, and symtab_node_base::weakref.

bool decide_is_symbol_needed ( )
Determine if symbol DECL is needed.  That is, visible to something
   either outside this translation unit, something magic in the system
   configury  

References decl::decl.

Referenced by analyze_functions(), cgraph_finalize_function(), and varpool_finalize_decl().

static void enqueue_node ( )
static
Add NODE to queue starting at FIRST. 
   The queue is linked via AUX pointers and terminated by pointer to 1.   

References first.

Referenced by analyze_functions(), cgraph_finalize_function(), cgraph_process_new_functions(), and varpool_finalize_decl().

static void expand_all_functions ( )
static
Expand all functions that must be output.

   Attempt to topologically sort the nodes so function is output when
   all called functions are already assembled to allow data to be
   propagated across the callgraph.  Use a stack to get smaller distance
   between a function and its callees (later we may choose to use a more
   sophisticated algorithm for function reordering; we will likely want
   to use subsections to make the output functions appear in top-down
   order).   

References cgraph_n_nodes, cgraph_process_new_functions(), expand_function(), free(), ipa_reverse_postorder(), order, and cgraph_node::process.

Referenced by compile().

static void expand_function ( struct cgraph_node )
static
void expand_thunk ( )
void finalize_compilation_unit ( void  )
Analyze the whole compilation unit once it is parsed completely.   

References analyze_functions(), compile(), current_function_decl, dump_passes(), finalize_size_functions(), handle_alias_pairs(), set_cfun(), timevar_pop(), and timevar_push().

Referenced by write_global_declarations().

static tree get_alias_symbol ( )
static
Return string alias is alias of.   

References get_identifier(), and lookup_attribute().

Referenced by output_weakrefs().

static void handle_alias_pairs ( )
static
void init_cgraph ( void  )
Initialize callgraph dump file.   

References cgraph_dump_file, dump_begin(), and TDI_cgraph.

Referenced by do_compile().

basic_block init_lowered_empty_function ( )
DECL is FUNCTION_DECL.  Initialize datastructures so DECL is a function
   in lowered gimple form.  IN_SSA is true if the gimple is in SSA.
   
   Set current_function_decl and cfun to newly constructed empty function body.
   return basic block in the function body.   

References add_bb_to_loop(), allocate_struct_function(), cfun, create_basic_block(), function::curr_properties, current_function_decl, function::gimple_df, gimple_register_cfg_hooks(), gimple_df::in_ssa_p, init_empty_tree_cfg(), init_loops_structure(), init_ssa_operands(), init_tree_ssa(), basic_block_def::loop_father, loops_for_fn(), LOOPS_MAY_HAVE_MULTIPLE_LATCHES, make_edge(), set_loops_for_fn(), and loops::state.

static void output_asm_statements ( )
static
Output all asm statements we have stored up to be output.   

References asm_node::asm_str, assemble_asm(), asm_node::next, and seen_error().

Referenced by compile().

static void output_in_order ( )
static
Output all functions, variables, and asm statements in the order
   according to their order fields, which is the order in which they
   appeared in the file.  This implements -fno-toplevel-reorder.  In
   this mode we may output functions and variables which don't really
   need to be output.   

References cgraph_order_sort::a, symtab_node_base::alias, asm_node::asm_str, assemble_asm(), symtab_node_base::decl, expand_function(), cgraph_order_sort::f, free(), cgraph_order_sort::kind, asm_node::next, symtab_node_base::order, asm_node::order, ORDER_ASM, ORDER_FUNCTION, ORDER_UNDEFINED, ORDER_VAR, cgraph_node::process, cgraph_node::symbol, varpool_node::symbol, symtab_order, cgraph_node::thunk, cgraph_thunk_info::thunk_p, cgraph_order_sort::u, cgraph_order_sort::v, varpool_assemble_decl(), and varpool_finalize_named_section_flags().

Referenced by compile().

static void output_weakrefs ( )
static
Weakrefs may be associated to external decls and thus not output
   at expansion time.  Emit all necessary aliases.   

References do_assemble_alias(), get_alias_symbol(), and symtab_alias_target().

Referenced by compile().

static void process_common_attributes ( )
static
Process attributes common for vars and functions.   

References lookup_attribute(), remove_attribute(), and warning_at().

Referenced by process_function_and_variable_attributes().

static void process_function_and_variable_attributes ( struct cgraph_node first,
struct varpool_node first_var 
)
static
Look for externally_visible and used attributes and mark cgraph nodes
   accordingly.

   We cannot mark the nodes at the point the attributes are processed (in
   handle_*_attribute) because the copy of the declarations available at that
   point may not be canonical.  For example, in:

    void f();
    void f() __attribute__((used));

   the declaration we see in handle_used_attribute will be the second
   declaration -- but the front end will subsequently merge that declaration
   with the original declaration and discard the second declaration.

   Furthermore, we can't mark these nodes in cgraph_finalize_function because:

    void f() {}
    void f() __attribute__((externally_visible));

   is valid.

   So, we walk the nodes at the end of the translation unit, applying the
   attributes at that point.   

References symtab_node_base::alias, cgraph_first_function(), cgraph_mark_force_output_node(), cgraph_next_function(), symtab_node_base::decl, symtab_node_base::definition, first, symtab_node_base::force_output, lookup_attribute(), process_common_attributes(), remove_attribute(), cgraph_node::symbol, varpool_node::symbol, varpool_finalize_decl(), varpool_first_variable(), varpool_next_variable(), and warning_at().

Referenced by analyze_functions().

static bool referred_to_p ( )
static
Return true when there are references to NODE.   

References cgraph_node::callers, and dyn_cast().

Referenced by analyze_functions(), cgraph_finalize_function(), and varpool_finalize_decl().

static tree thunk_adjust ( gimple_stmt_iterator bsi,
tree  ptr,
bool  this_adjusting,
HOST_WIDE_INT  fixed_offset,
tree  virtual_offset 
)
static
Adjust PTR by the constant FIXED_OFFSET, and by the vtable
   offset indicated by VIRTUAL_OFFSET, if that is
   non-null. THIS_ADJUSTING is nonzero for a this adjusting thunk and
   zero for a result adjusting thunk.   

References build_pointer_type(), create_tmp_reg(), fold_build_pointer_plus_hwi_loc(), fold_build_pointer_plus_loc(), force_gimple_operand_gsi(), GSI_CONTINUE_LINKING, gsi_insert_after(), GSI_NEW_STMT, input_location, layout_type(), and vtable_entry_type.

Referenced by expand_thunk().

void varpool_finalize_decl ( )

Variable Documentation

struct asm_node* asm_last_node
static
Last node in cgraph_asm_nodes.   

Referenced by add_asm_node().

struct asm_node* asm_nodes
Linked list of cgraph asm nodes.   

Referenced by lto_output_toplevel_asms().

cgraph_node_set cgraph_new_nodes
@verbatim Driver of optimization process

Copyright (C) 2003-2013 Free Software Foundation, Inc. Contributed by Jan Hubicka

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 module implements main driver of compilation process.

   The main scope of this file is to act as an interface in between
   tree based frontends and the backend.

   The front-end is supposed to use following functionality:

    - cgraph_finalize_function

      This function is called once front-end has parsed whole body of function
      and it is certain that the function body nor the declaration will change.

      (There is one exception needed for implementing GCC extern inline
        function.)

    - varpool_finalize_decl

      This function has same behavior as the above but is used for static
      variables.

    - add_asm_node

      Insert new toplevel ASM statement

    - finalize_compilation_unit

      This function is called once (source level) compilation unit is finalized
      and it will no longer change.

      The symbol table is constructed starting from the trivially needed
      symbols finalized by the frontend.  Functions are lowered into
      GIMPLE representation and callgraph/reference lists are constructed.
      Those are used to discover other necessary functions and variables.

      At the end the bodies of unreachable functions are removed.

      The function can be called multiple times when multiple source level
      compilation units are combined.

    - compile

      This passes control to the back-end.  Optimizations are performed and
      final assembler is generated.  This is done in the following way. Note
      that with link time optimization the process is split into three
      stages (compile time, linktime analysis and parallel linktime as
      indicated bellow).

      Compile time:

        1) Inter-procedural optimization.
           (ipa_passes)

           This part is further split into:

           a) early optimizations. These are local passes executed in
              the topological order on the callgraph.

              The purpose of early optimiations is to optimize away simple
              things that may otherwise confuse IP analysis. Very simple
              propagation across the callgraph is done i.e. to discover
              functions without side effects and simple inlining is performed.

           b) early small interprocedural passes.

              Those are interprocedural passes executed only at compilation
              time.  These include, for example, transational memory lowering,
              unreachable code removal and other simple transformations.

           c) IP analysis stage.  All interprocedural passes do their
              analysis.

              Interprocedural passes differ from small interprocedural
              passes by their ability to operate across whole program
              at linktime.  Their analysis stage is performed early to
              both reduce linking times and linktime memory usage by    
              not having to represent whole program in memory.

           d) LTO sreaming.  When doing LTO, everything important gets
              streamed into the object file.

       Compile time and or linktime analysis stage (WPA):

              At linktime units gets streamed back and symbol table is
              merged.  Function bodies are not streamed in and not
              available.
           e) IP propagation stage.  All IP passes execute their
              IP propagation. This is done based on the earlier analysis
              without having function bodies at hand.
           f) Ltrans streaming.  When doing WHOPR LTO, the program
              is partitioned and streamed into multple object files.

       Compile time and/or parallel linktime stage (ltrans)

              Each of the object files is streamed back and compiled
              separately.  Now the function bodies becomes available
              again.

         2) Virtual clone materialization
            (cgraph_materialize_clone)

            IP passes can produce copies of existing functoins (such
            as versioned clones or inline clones) without actually
            manipulating their bodies by creating virtual clones in
            the callgraph. At this time the virtual clones are
            turned into real functions
         3) IP transformation

            All IP passes transform function bodies based on earlier
            decision of the IP propagation.

         4) late small IP passes

            Simple IP passes working within single program partition.

         5) Expansion
            (expand_all_functions)

            At this stage functions that needs to be output into
            assembler are identified and compiled in topological order
         6) Output of variables and aliases
            Now it is known what variable references was not optimized
            out and thus all variables are output to the file.

            Note that with -fno-toplevel-reorder passes 5 and 6
            are combined together in cgraph_output_in_order.  

   Finally there are functions to manipulate the callgraph from
   backend.
    - cgraph_add_new_function is used to add backend produced
      functions introduced after the unit is finalized.
      The functions are enqueue for later processing and inserted
      into callgraph with cgraph_process_new_functions.

    - cgraph_function_versioning

      produces a copy of function into new one (a version)
      and apply simple transformations
Queue of cgraph nodes scheduled to be added into cgraph.  This is a
   secondary queue used during optimization to accommodate passes that
   may generate new functions that need to be optimized and expanded.   

Referenced by can_remove_node_now_p_1().

symtab_node first = (symtab_node)(void *)1
static
Head of the queue of nodes to be processed while building callgraph  

Referenced by add_cfis_to_fde(), add_pseudo_to_slot(), analyze_functions(), append_to_statement_list_1(), assign_by_spills(), assign_discriminators(), branch_prob(), break_out_comdat_types(), canon_reg(), coalesce_spill_slots(), collect_spilled_coalesced_allocnos(), combine_instructions(), combine_predictions_for_bb(), compute_antic_aux(), connect_traces(), copy_reg_eh_region_note_backward(), create_outofssa_var_map(), cse_insn(), debug_dominance_tree_1(), DFS_write_tree(), dump_bb_info(), dump_generic_node(), eliminate_tail_call(), emit_group_load_1(), emit_insn_after_1(), emit_insn_modes_h(), emit_pattern_before_setloc(), enqueue_node(), expand_vector_operations_1(), extract_split_bit_field(), factor_tests(), find_split_points(), find_traces(), form_reserv_sets_list(), generate_results(), generate_skeleton_bottom_up(), get_narrower(), gimple_block_label(), gimple_redirect_edge_and_branch(), gsi_insert_seq_after_without_update(), gsi_insert_seq_before_without_update(), gsi_insert_seq_nodes_after(), gsi_insert_seq_nodes_before(), haifa_htab_i1_traverse(), hash_scc(), init_rtlanal(), ipa_dump_param_adjustments(), ira_add_allocno_copy_to_list(), ira_copy_live_range_list(), ira_create_copy(), ira_flattening(), ira_merge_live_ranges(), ira_sort_regnos_for_alter_reg(), vec< T, A, vl_embed >::lower_bound(), lra_copy_live_range_list(), lra_merge_live_ranges(), lst_perfect_nestify(), lto_input_eh_catch_list(), lto_input_scc(), lto_symtab_merge_decls_1(), lto_symtab_merge_decls_2(), make_automaton_attrs(), merge_allocnos(), merge_pseudos(), model_promote_predecessors(), modify_move_list(), nearest_common_dominator_for_set(), new_basic_block(), omega_pretty_print_problem(), omega_print_eqn(), omega_print_term(), optimize_macinfo_range(), optimize_range_tests(), output_die(), output_loc_operands(), output_peephole2_scratches(), print_bitmap_set(), process_copy_to_form_thread(), process_function_and_variable_attributes(), process_incoming_edges(), propagate_dereference_distances(), ready_sort(), real_to_decimal_for_mode(), real_to_hexadecimal(), reload_cse_regs(), reload_pseudo_compare_func(), reposition_prologue_and_epilogue_notes(), restore_last_backtrack_point(), rtl_dump_bb_for_graph(), same_succ_hash(), sel_bb_empty_or_nop_p(), set_multilib_dir(), setup_coalesced_allocno_costs_and_nums(), simplify_const_unary_operation(), sort_and_splice_var_accesses(), split_insn(), store_killed_before(), streamer_read_chain(), suitable_component_p(), symtab_remove_unreachable_nodes(), toggle_cancelled_flags(), tree_optimize_tail_calls_1(), try_combine(), try_forward_edges(), undistribute_ops_list(), uniform_vector_p(), unionfind_union(), unlink_insn_chain(), varpool_remove_unreferenced_decls(), vect_is_slp_reduction(), vect_operation_fits_smaller_type(), vect_recog_over_widening_pattern(), vrp_visit_phi_node(), and vt_find_locations().

tree vtable_entry_type
static
Used for vtable lookup in thunk adjusting.   

Referenced by thunk_adjust().