GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "gimple.h"
#include "cfghooks.h"
#include "regset.h"
#include "alloc-pool.h"
#include "tree-pass.h"
#include "stringpool.h"
#include "gimple-ssa.h"
#include "cgraph.h"
#include "coverage.h"
#include "lto-streamer.h"
#include "fold-const.h"
#include "varasm.h"
#include "stor-layout.h"
#include "output.h"
#include "cfgcleanup.h"
#include "gimple-iterator.h"
#include "gimple-fold.h"
#include "gimplify.h"
#include "gimplify-me.h"
#include "tree-cfg.h"
#include "tree-into-ssa.h"
#include "tree-ssa.h"
#include "langhooks.h"
#include "toplev.h"
#include "debug.h"
#include "symbol-summary.h"
#include "tree-vrp.h"
#include "sreal.h"
#include "ipa-cp.h"
#include "ipa-prop.h"
#include "gimple-pretty-print.h"
#include "plugin.h"
#include "ipa-fnsummary.h"
#include "ipa-utils.h"
#include "except.h"
#include "cfgloop.h"
#include "context.h"
#include "pass_manager.h"
#include "tree-nested.h"
#include "dbgcnt.h"
#include "lto-section-names.h"
#include "attribs.h"
#include "ipa-inline.h"
#include "omp-offload.h"
#include "symtab-thunks.h"
Data Structures | |
struct | cgraph_order_sort |
Enumerations | |
enum | cgraph_order_sort_kind { ORDER_FUNCTION , ORDER_VAR , ORDER_VAR_UNDEF , ORDER_ASM } |
Variables | |
vec< cgraph_node * > | cgraph_new_nodes |
static symtab_node | symtab_terminator (SYMTAB_SYMBOL) |
static symtab_node * | queued_nodes = &symtab_terminator |
static cgraph_node * | first_analyzed |
static varpool_node * | first_analyzed_var |
static int | debuginfo_early_dump_nr |
static FILE * | debuginfo_early_dump_file |
static dump_flags_t | debuginfo_early_dump_flags |
static int | debuginfo_dump_nr |
static FILE * | debuginfo_dump_file |
static dump_flags_t | debuginfo_dump_flags |
|
static |
FIRST_TIME is set to TRUE for the first time we are called for a translation unit from finalize_compilation_unit() or false otherwise.
References symtab_node::alias, cgraph_node::analyze(), varpool_node::analyze(), symtab_node::analyzed, symtab_node::aux, bitmap_obstack_initialize(), bitmap_obstack_release(), build_type_inheritance_graph(), cgraph_node::callees, changed, check_global_declaration(), symtab_node::comdat_local_p(), CONSTRUCTION, symtab_node::cpp_implicit_alias, debug_hooks, symtab_node::decl, DECL_ABSTRACT_ORIGIN, DECL_ATTRIBUTES, DECL_EXTERNAL, decl_function_context(), DECL_STRUCT_FUNCTION, symtab_node::definition, cgraph_node::dispatcher_function, symtab_node::dump_asm_name(), symtab_node::dump_name(), dyn_cast(), enqueue_node(), first_analyzed, first_analyzed_var, symtab_node::fixup_same_cpp_alias_visibility(), FOR_EACH_SYMBOL, gcc_assert, symtab_node::get_alias_target(), symtab_node::get_comdat_group_id(), cgraph_node::get_create(), gimple_has_body_p(), i, cgraph_node::indirect_calls, input_location, symtab_node::iterate_reference(), lookup_attribute(), symtab_node::needed_p(), symtab_node::next, NULL, omp_discover_implicit_declare_target(), opt_for_fn, thunk_info::process_early_thunks(), process_function_and_variable_attributes(), queued_nodes, cgraph_node::redefined_extern_inline, ipa_ref::referred, symtab_node::referred_to_p(), symtab_node::remove(), symtab_node::reset(), symtab_node::same_comdat_group, seen_error(), symtab, symtab_terminator, cgraph_node::thunk, TREE_CODE, TREE_READONLY, TREE_TYPE, TYPE_NEEDS_CONSTRUCTING, TYPE_P, UNKNOWN_LOCATION, update_type_inheritance_graph(), cgraph_node::used_as_abstract_origin, VAR_P, and walk_polymorphic_call_targets().
Referenced by symbol_table::finalize_compilation_unit().
|
static |
Compare cgraph_order_sort by order.
References cgraph_order_sort::order.
Referenced by output_in_order().
void cgraphunit_cc_finalize | ( | void | ) |
Reset all state within cgraphunit.cc so that we can rerun the compiler within the same process. For use by toplev::finalize.
References cgraph_new_nodes, first_analyzed, first_analyzed_var, gcc_assert, NULL, queued_nodes, and symtab_terminator.
Referenced by toplev::finalize().
|
static |
Issue appropriate warnings for the global declaration DECL.
References symtab_node::decl, DECL_ABSTRACT_ORIGIN, DECL_ARTIFICIAL, DECL_EXTERNAL, DECL_IN_SYSTEM_HEADER, DECL_INITIAL, DECL_NAME, DECL_REGISTER, DECL_SOURCE_FILE, DECL_SOURCE_LOCATION, DECL_STATIC_CONSTRUCTOR, DECL_STATIC_DESTRUCTOR, lang_hooks::decls, input_location, NULL, pedwarn(), symtab_node::referred_to_p(), TREE_CODE, TREE_PUBLIC, TREE_READONLY, TREE_THIS_VOLATILE, TREE_USED, VAR_P, lang_hooks_for_decls::warn_unused_global, warning(), warning_at(), and warning_suppressed_p().
Referenced by analyze_functions().
void debuginfo_early_init | ( | void | ) |
Register the debug and earlydebug dump files.
References debuginfo_dump_nr, debuginfo_early_dump_nr, DK_tree, gcc::dump_manager::dump_register(), g, and OPTGROUP_NONE.
Referenced by general_init().
void debuginfo_early_start | ( | void | ) |
Set dump_file to the earlydebug dump file.
References debuginfo_early_dump_file, and set_dump_file().
Referenced by symbol_table::finalize_compilation_unit().
void debuginfo_early_stop | ( | void | ) |
Undo setting dump_file to the earlydebug dump file.
References NULL, and set_dump_file().
Referenced by symbol_table::finalize_compilation_unit().
void debuginfo_fini | ( | void | ) |
Finalize the debug and earlydebug dump files.
References debuginfo_dump_file, debuginfo_dump_nr, debuginfo_early_dump_file, debuginfo_early_dump_nr, and dump_end().
Referenced by finalize().
void debuginfo_init | ( | void | ) |
Initialize the debug and earlydebug dump files.
References debuginfo_dump_file, debuginfo_dump_flags, debuginfo_dump_nr, debuginfo_early_dump_file, debuginfo_early_dump_flags, debuginfo_early_dump_nr, dump_begin(), g, gcc::dump_manager::get_dump_file_info(), NULL, and dump_file_info::pflags.
Referenced by do_compile().
void debuginfo_start | ( | void | ) |
Set dump_file to the debug dump file.
References debuginfo_dump_file, and set_dump_file().
Referenced by compile_file().
void debuginfo_stop | ( | void | ) |
Undo setting dump_file to the debug dump file.
References NULL, and set_dump_file().
Referenced by compile_file().
|
static |
Add NODE to queue starting at QUEUED_NODES. The queue is linked via AUX pointers and terminated by pointer to 1.
References symtab_node::aux, gcc_checking_assert, and queued_nodes.
Referenced by analyze_functions(), varpool_node::finalize_decl(), cgraph_node::finalize_function(), symbol_table::process_new_functions(), symbol_table::remove_unreachable_nodes(), symbol_table::remove_unreferenced_decls(), and walk_polymorphic_call_targets().
|
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 CDI_DOMINATORS, CDI_POST_DOMINATORS, symtab_node::decl, DECL_ASSEMBLER_NAME, DECL_STRUCT_FUNCTION, symtab_node::dump_asm_name(), dump_file, cgraph_node::expand(), free(), free_dominance_info(), free_gimplify_stack(), cgraph_node::gc_candidate, gcc_assert, i, IDENTIFIER_POINTER, ipa_reverse_postorder(), ipa_saved_clone_sources, NULL, opt_for_fn, cgraph_node::process, qsort, cgraph_node::release_body(), symtab, cgraph_node::tp_first_run, and tp_first_run_node_cmp().
Referenced by symbol_table::compile().
|
static |
Translate the ugly representation of aliases as alias pairs into nice representation in callgraph. We don't handle all cases yet, unfortunately.
References symtab_node::alias, alias_pairs, symtab_node::alias_target, cgraph_node::create_alias(), varpool_node::create_alias(), alias_pair::decl, symtab_node::decl, DECL_ATTRIBUTES, DECL_EXTERNAL, DECL_SOURCE_LOCATION, DECL_VIRTUAL_P, symtab_node::definition, error(), cgraph_node::get(), symtab_node::get(), symtab_node::get_for_asmname(), i, inform(), is_a(), lookup_attribute(), maybe_diag_alias_attributes(), maybe_diag_incompatible_alias(), NULL, symtab_node::reset(), alias_pair::target, symtab_node::transparent_alias, TREE_CODE, VAR_P, vec_free(), and symtab_node::weakref.
Referenced by symbol_table::finalize_compilation_unit(), and symbol_table::process_new_functions().
basic_block init_lowered_empty_function | ( | tree | decl, |
bool | in_ssa, | ||
profile_count | count ) |
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(), profile_probability::always(), BLOCK_SUPERCONTEXT, cfun, basic_block_def::count, count, create_basic_block(), current_function_decl, DECL_INITIAL, DECL_SAVED_TREE, ENTRY_BLOCK_PTR_FOR_FN, error_mark_node, EXIT_BLOCK_PTR_FOR_FN, ggc_cleared_alloc(), gimple_register_cfg_hooks(), init_empty_tree_cfg(), init_loops_structure(), init_ssa_operands(), init_tree_ssa(), loops_for_fn(), LOOPS_MAY_HAVE_MULTIPLE_LATCHES, make_edge(), make_node(), NULL, PROP_cfg, PROP_gimple_any, PROP_gimple_lcf, PROP_gimple_leh, PROP_loops, PROP_ssa, set_loops_for_fn(), and loops::state.
Referenced by expand_thunk().
|
static |
References gcc::pass_manager::all_regular_ipa_passes, gcc::pass_manager::all_small_ipa_passes, bitmap_obstack_initialize(), bitmap_obstack_release(), coverage_finish(), current_function_decl, execute_ipa_pass_list(), execute_ipa_summary_passes(), g, gimple_register_cfg_hooks(), INCREMENTAL_LINK_LTO, invoke_plugin_callbacks(), IPA_SSA, ipa_write_summaries(), LTO_SECTION_NAME_PREFIX, lto_stream_offload_p, NULL, OFFLOAD_SECTION_NAME_PREFIX, section_name_prefix, seen_error(), set_cfun(), symtab, and targetm.
Referenced by symbol_table::compile().
|
static |
Figure out what functions we want to assemble.
References symtab_node::alias, symtab_node::analyzed, cgraph_node::clones, symtab_node::comdat_local_p(), cgraph_node::debug(), symtab_node::decl, DECL_ARTIFICIAL, DECL_EXTERNAL, dyn_cast(), FOR_EACH_FUNCTION, gcc_assert, gimple_has_body_p(), symtab_node::in_other_partition, cgraph_node::inlined_to, internal_error(), cgraph_node::process, symtab_node::same_comdat_group, cgraph_node::thunk, and TREE_ASM_WRITTEN.
Referenced by symbol_table::compile().
Check declaration of the type of ALIAS for compatibility with its TARGET (which may be an ifunc resolver) and issue a diagnostic when they are not compatible according to language rules (plus a C++ extension for non-static member functions).
References build_function_type(), build_pointer_type(), DECL_SOURCE_LOCATION, error_at(), FUNC_OR_METHOD_TYPE_P, cgraph_node::get(), symtab_node::ifunc_resolver, inform(), POINTER_TYPE_P, prototype_p(), TREE_CODE, TREE_TYPE, TYPE_ARG_TYPES, types_compatible_p(), VOID_TYPE_P, and warning_at().
Referenced by handle_alias_pairs().
|
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 symtab_node::alias, cgraph_order_cmp(), symtab_node::decl, DECL_HARD_REGISTER, DECL_HAS_VALUE_EXPR_P, varpool_node::finalize_named_section_flags(), FOR_EACH_DEFINED_FUNCTION, FOR_EACH_VARIABLE, FOR_EACH_VEC_ELT, i, cgraph_order_sort::kind, asm_node::next, symtab_node::no_reorder, ORDER_VAR, cgraph_node::process, cgraph_order_sort::process(), symtab, cgraph_node::thunk, cgraph_order_sort::u, and cgraph_order_sort::v.
Referenced by symbol_table::compile().
|
static |
Process attributes common for vars and functions.
References DECL_ATTRIBUTES, DECL_SOURCE_LOCATION, DECL_WEAK, lookup_attribute(), symtab_node::no_reorder, process_symver_attribute(), remove_attribute(), and warning_at().
Referenced by process_function_and_variable_attributes().
|
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 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::alias, symtab_node::decl, DECL_ATTRIBUTES, DECL_DECLARED_INLINE_P, DECL_EXTERNAL, DECL_INITIAL, DECL_P, DECL_PRESERVE_P, DECL_SOURCE_LOCATION, DECL_UNINLINABLE, DECL_WEAK, symtab_node::definition, error_mark_node, varpool_node::finalize_decl(), symtab_node::force_output, symtab_node::get_alias_target_tree(), lookup_attribute(), cgraph_node::mark_force_output(), process_common_attributes(), remove_attribute(), symtab, symtab_node::transparent_alias, TREE_PUBLIC, warning_at(), and symtab_node::weakref.
Referenced by analyze_functions().
|
static |
Process a symver attribute.
References symtab_node::alias, symtab_node::analyzed, copy_node(), symtab_node::create_reference(), symtab_node::decl, DECL_ATTRIBUTES, DECL_COMDAT, DECL_COMMON, DECL_INITIAL, DECL_SOURCE_LOCATION, DECL_STRUCT_FUNCTION, DECL_VISIBILITY, symtab_node::definition, error_at(), symtab_node::get_create(), symtab_node::get_for_asmname(), get_identifier_with_length(), IDENTIFIER_POINTER, inform(), IPA_REF_ALIAS, lookup_attribute(), NULL, NULL_TREE, SET_DECL_ASSEMBLER_NAME, symtab_node::symver, TREE_CHAIN, TREE_CODE, TREE_PUBLIC, TREE_PURPOSE, TREE_STRING_LENGTH, TREE_STRING_POINTER, TREE_VALUE, VISIBILITY_DEFAULT, and symtab_node::weakref.
Referenced by process_common_attributes().
int tp_first_run_node_cmp | ( | const void * | pa, |
const void * | pb ) |
Node comparator that is responsible for the order that corresponds to time when a function was launched for the first time.
References a, b, INT_MAX, and opt_for_fn.
Referenced by expand_all_functions().
|
static |
EDGE is an polymorphic call. Mark all possible targets as reachable and if there is only one target, perform trivial devirtualization. REACHABLE_CALL_TARGETS collects target lists we already walked to avoid duplicate work.
References hash_set< KeyId, Lazy, Traits >::add(), builtin_decl_unreachable(), cgraph_node::create(), dbg_cnt(), dump_enabled_p(), symtab_node::dump_name(), dump_possible_polymorphic_call_targets(), dump_printf_loc(), enqueue_node(), i, cgraph_edge::make_direct(), MSG_OPTIMIZED_LOCATIONS, NULL, possible_polymorphic_call_targets(), print_gimple_stmt(), cgraph_edge::redirect_call_stmt_to_callee(), symtab, TDF_SLIM, TREE_CODE, TREE_TYPE, type_in_anonymous_namespace_p(), and TYPE_METHOD_BASETYPE.
Referenced by analyze_functions(), and symbol_table::remove_unreachable_nodes().
vec<cgraph_node *> cgraph_new_nodes |
Driver of optimization process Copyright (C) 2003-2025 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: - 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 optimizations 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, transactional 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 streaming. 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 multiple 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 functions (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 cgraph_node::add_new_function(), can_remove_node_now_p_1(), cgraphunit_cc_finalize(), and symbol_table::process_new_functions().
|
static |
Referenced by debuginfo_fini(), debuginfo_init(), and debuginfo_start().
|
static |
Referenced by debuginfo_init().
|
static |
Debug dump file, flags, and number.
Referenced by debuginfo_early_init(), debuginfo_fini(), and debuginfo_init().
|
static |
Referenced by debuginfo_early_start(), debuginfo_fini(), and debuginfo_init().
|
static |
Referenced by debuginfo_init().
|
static |
Earlydebug dump file, flags, and number.
Referenced by debuginfo_early_init(), debuginfo_fini(), and debuginfo_init().
|
static |
Discover all functions and variables that are trivially needed, analyze them as well as all functions and variables referred by them
Referenced by analyze_functions(), and cgraphunit_cc_finalize().
|
static |
Referenced by analyze_functions(), and cgraphunit_cc_finalize().
|
static |
Referenced by analyze_functions(), cgraphunit_cc_finalize(), and enqueue_node().
|
static |
Head and terminator of the queue of nodes to be processed while building callgraph.
Referenced by analyze_functions(), and cgraphunit_cc_finalize().