GCC Middle and Back End API Reference
ipa-utils.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "predict.h"
#include "alloc-pool.h"
#include "cgraph.h"
#include "lto-streamer.h"
#include "dumpfile.h"
#include "splay-tree.h"
#include "ipa-utils.h"
#include "symbol-summary.h"
#include "tree-vrp.h"
#include "sreal.h"
#include "ipa-cp.h"
#include "ipa-prop.h"
#include "ipa-fnsummary.h"
#include "tree-eh.h"
#include "gimple-iterator.h"
#include "ipa-modref-tree.h"
#include "ipa-modref.h"
#include "tree-ssa-loop-niter.h"
#include "calls.h"
#include "cfgloop.h"
#include "cfganal.h"
Include dependency graph for ipa-utils.cc:

Data Structures

struct  searchc_env
struct  postorder_stack


void ipa_print_order (FILE *out, const char *note, struct cgraph_node **order, int count)
static void searchc (struct searchc_env *env, struct cgraph_node *v, bool(*ignore_edge)(struct cgraph_edge *))
int ipa_reduced_postorder (struct cgraph_node **order, bool reduce, bool(*ignore_edge)(struct cgraph_edge *))
void ipa_free_postorder_info (void)
vec< cgraph_node * > ipa_get_nodes_in_cycle (struct cgraph_node *node)
bool ipa_edge_within_scc (struct cgraph_edge *cs)
int ipa_reverse_postorder (struct cgraph_node **order)
tree get_base_var (tree t)
void scale_ipa_profile_for_fn (struct cgraph_node *node, profile_count orig_count)
void ipa_merge_profiles (struct cgraph_node *dst, struct cgraph_node *src, bool preserve_body)
bool recursive_call_p (tree func, tree dest)
bool stmt_may_terminate_function_p (function *fun, gimple *stmt, bool assume_return_or_eh)
bitmap find_always_executed_bbs (function *fun, bool assume_return_or_eh)

Function Documentation

◆ find_always_executed_bbs()

bitmap find_always_executed_bbs ( function * fun,
bool assume_return_or_eh )
Return bitmap of all basic blocks whose first statements are known to
execute on every invocation of the function.

If assume_return_or_eh we can further assume that the function ends
either by retrn statement or EH (no trapping or infinite loops).
This is useful when sumarizing function in passes like ipa-modref.

Seeing assume_return_or_eh to false is used to prove that given
statmeent will be executed even if the function gets into infinite
loop or trap.   

References hash_set< KeyId, Lazy, Traits >::add(), BITMAP_ALLOC, bitmap_print(), bitmap_set_bit, calculate_dominance_info(), CDI_DOMINATORS, hash_set< KeyId, Lazy, Traits >::contains(), function::decl, dom_info_available_p(), dominated_by_p(), dump_file, dump_flags, ECF_CONST, ECF_LOOPING_CONST_OR_PURE, ECF_PURE, EDGE_COUNT, ENTRY_BLOCK_PTR_FOR_FN, EXIT_BLOCK, EXIT_BLOCK_PTR_FOR_FN, finite_loop_p(), basic_block_def::flags, flags_from_decl_or_type(), FOR_EACH_EDGE, gcc_obstack_init, gsi_end_p(), gsi_next_nondebug(), gsi_start_nondebug_after_labels_bb(), gsi_stmt(), basic_block_def::index, mark_dfs_back_edges(), MAX, MIN, NULL, obstack, basic_block_def::preds, si, single_succ_edge(), stmt_may_terminate_function_p(), basic_block_def::succs, TDF_DETAILS, visited, and worklist.

◆ get_base_var()

tree get_base_var ( tree t)
Given a memory reference T, will return the variable at the bottom
of the access.  Unlike get_base_address, this will recurse through


Referenced by symtab_node::maybe_create_reference(), and record_reference().

◆ ipa_edge_within_scc()

◆ ipa_free_postorder_info()

void ipa_free_postorder_info ( void )
Deallocate all ipa_dfs_info structures pointed to by the aux pointer of call
graph nodes.   

References symtab_node::aux, FOR_EACH_DEFINED_FUNCTION, free(), and NULL.

Referenced by free_toporder_info(), inline_small_functions(), propagate(), propagate_malloc(), propagate_nothrow(), and propagate_pure_const().

◆ ipa_get_nodes_in_cycle()

vec< cgraph_node * > ipa_get_nodes_in_cycle ( struct cgraph_node * node)
Get the set of nodes for the cycle in the reduced call graph starting
from NODE.   

References symtab_node::aux, ipa_dfs_info::next_cycle, and vNULL.

Referenced by propagate(), and propagate_constants_topo().

◆ ipa_merge_profiles()

void ipa_merge_profiles ( struct cgraph_node * dst,
struct cgraph_node * src,
bool preserve_body )
SRC and DST are going to be merged.  Take SRC's profile and merge it into
DST so it is not going to be lost.  Possibly destroy SRC's body on the way
unless PRESERVE_BODY is set.   

References symtab_node::alias, profile_count::apply_scale(), BASIC_BLOCK_FOR_FN, cgraph_edge::call_stmt, cgraph_node::callees, hash_table< Descriptor, Lazy, Allocator >::clear_slot(), compute_fn_summary(), compute_function_frequency(), copy_node(), basic_block_def::count, cgraph_edge::count, cgraph_node::count, symtab_node::decl, DECL_ARGUMENTS, DECL_INITIAL, DECL_RESULT, DECL_STRUCT_FUNCTION, symtab_node::definition, profile_count::dump(), symbol_table::dump_file, symtab_node::dump_name(), dyn_cast(), EDGE_COUNT, EDGE_SUCC, ENTRY_BLOCK_PTR_FOR_FN, hash_table< Descriptor, Lazy, Allocator >::find_slot(), cgraph_edge::first_speculative_call_target(), lto_in_decl_state::fn_decl, FOR_ALL_BB_FN, cgraph_node::frequency, lto_file_decl_data::function_decl_states, gcc_assert, cgraph_node::get_untransformed_body(), gimple_bb(), i, basic_block_def::index, cgraph_node::indirect_calls, profile_count::initialized_p(), profile_count::ipa(), last_basic_block_for_fn, symtab_node::lto_file_data, cgraph_edge::make_speculative(), n_basic_blocks_for_fn, cgraph_edge::next_callee, cgraph_edge::next_speculative_call_target(), profile_count::nonzero_p(), NULL, pop_cfun(), profile_count::probability_in(), cgraph_node::profile_id, push_cfun(), cgraph_edge::redirect_callee(), cgraph_node::release_body(), cgraph_edge::resolve_speculation(), scale_ipa_profile_for_fn(), cgraph_edge::speculative, cgraph_edge::speculative_call_for_target(), basic_block_def::succs, symtab, cgraph_node::thunk, cgraph_node::tp_first_run, update_max_bb_count(), and profile_count::zero().

Referenced by ipa_icf::sem_function::merge().

◆ ipa_print_order()

void ipa_print_order ( FILE * out,
const char * note,
struct cgraph_node ** order,
int count )
Utilities for ipa analysis.
   Copyright (C) 2005-2024 Free Software Foundation, Inc.
   Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>

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

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
Debugging function for postorder and inorder code. NOTE is a string
that is printed before the nodes are printed.  ORDER is an array of
cgraph_nodes that has COUNT useful nodes in it.   

References count, and i.

Referenced by propagate(), propagate_nothrow(), and propagate_pure_const().

◆ ipa_reduced_postorder()

int ipa_reduced_postorder ( struct cgraph_node ** order,
bool reduce,
bool(* ignore_edge )(struct cgraph_edge *) )
Topsort the call graph by caller relation.  Put the result in ORDER.

The REDUCE flag is true if you want the cycles reduced to single nodes.
You can use ipa_get_nodes_in_cycle to obtain a vector containing all real
call graph nodes in a reduced node.

Set ALLOW_OVERWRITABLE if nodes with such availability should be included.
IGNORE_EDGE, if non-NULL is a hook that may make some edges insignificant
for the topological sort.    

References symtab_node::aux, AVAIL_INTERPOSABLE, symbol_table::cgraph_count, env, FOR_EACH_DEFINED_FUNCTION, free(), cgraph_node::get_availability(), cgraph_node::get_uid(), ipa_dfs_info::new_node, ipa_dfs_info::next_cycle, NULL, ipa_dfs_info::on_stack, searchc_env::reduce, searchc_env::result, searchc(), and symtab.

Referenced by build_toporder_info(), inline_small_functions(), propagate(), propagate_nothrow(), and propagate_pure_const().

◆ ipa_reverse_postorder()

◆ recursive_call_p()

◆ scale_ipa_profile_for_fn()

void scale_ipa_profile_for_fn ( struct cgraph_node * node,
profile_count orig_count )

◆ searchc()

static void searchc ( struct searchc_env * env,
struct cgraph_node * v,
bool(* ignore_edge )(struct cgraph_edge *) )
This is an implementation of Tarjan's strongly connected region
finder as reprinted in Aho Hopcraft and Ullman's The Design and
Analysis of Computer Programs (1975) pages 192-193.  This version
has been customized for cgraph_nodes.  The env parameter is because
it is recursive and there are no nested functions here.  This
function should only be called from itself or
ipa_reduced_postorder.  ENV is a stack env and would be
unnecessary if C had nested functions.  V is the node to start
searching from.   

References symtab_node::aux, AVAIL_INTERPOSABLE, cgraph_node::callees, ipa_dfs_info::dfn_number, env, cgraph_node::get_uid(), last, ipa_dfs_info::low_link, ipa_dfs_info::new_node, ipa_dfs_info::next_cycle, NULL, ipa_dfs_info::on_stack, ipa_dfs_info::scc_no, searchc(), and cgraph_node::ultimate_alias_target().

Referenced by ipa_reduced_postorder(), and searchc().

◆ stmt_may_terminate_function_p()

bool stmt_may_terminate_function_p ( function * fun,
gimple * stmt,
bool assume_return_or_eh )
Return true if stmt may terminate execution of function.
If assume_return_or_eh we can further assume that the function ends
either by retrn statement or EH (no trapping or infinite loops).   

References dyn_cast(), ECF_CONST, ECF_LOOPING_CONST_OR_PURE, ECF_PURE, get_modref_function_summary(), gimple_asm_volatile_p(), gimple_call_flags(), gimple_could_trap_p(), NULL, modref_summary::side_effects, and stmt_can_throw_external().

Referenced by find_always_executed_bbs().