GCC Middle and Back End API Reference
ipa-pure-const.c File Reference

Data Structures

struct  funct_state_d

Typedefs

typedef struct funct_state_dfunct_state

Enumerations

enum  pure_const_state_e { IPA_CONST, IPA_PURE, IPA_NEITHER }

Functions

static bool function_always_visible_to_compiler_p ()
static struct pointer_set_tsuggest_attribute (int option, tree decl, bool known_finite, struct pointer_set_t *warned_about, const char *attrib_name)
static void warn_function_pure ()
static void warn_function_const ()
void warn_function_noreturn ()
static void finish_state ()
static bool has_function_state ()
static funct_state get_function_state ()
static void set_function_state ()
static void check_decl (funct_state local, tree t, bool checking_write, bool ipa)
static void check_op ()
static void state_from_flags (enum pure_const_state_e *state, bool *looping, int flags, bool cannot_lead_to_return)
static void better_state (enum pure_const_state_e *state, bool *looping, enum pure_const_state_e state2, bool looping2)
static void worse_state (enum pure_const_state_e *state, bool *looping, enum pure_const_state_e state2, bool looping2)
static bool special_builtin_state (enum pure_const_state_e *state, bool *looping, tree callee)
static void check_call ()
static bool check_load ()
static bool check_store ()
static bool check_ipa_load ()
static bool check_ipa_store ()
static void check_stmt ()
static funct_state analyze_function ()
static void add_new_function ()
static void duplicate_node_data (struct cgraph_node *src, struct cgraph_node *dst, void *data)
static void remove_node_data ()
static void register_hooks ()
static void pure_const_generate_summary ()
static void pure_const_write_summary ()
static void pure_const_read_summary ()
static bool ignore_edge ()
static bool self_recursive_p ()
static void propagate_pure_const ()
static void propagate_nothrow ()
static unsigned int propagate ()
static bool gate_pure_const ()
ipa_opt_pass_dmake_pass_ipa_pure_const ()
static bool skip_function_for_local_pure_const ()
static unsigned int local_pure_const ()
gimple_opt_passmake_pass_local_pure_const ()

Variables

static struct pointer_set_tvisited_nodes
const char * pure_const_names [3] = {"const", "pure", "neither"}
static struct funct_state_d varying_state = { IPA_NEITHER, IPA_NEITHER, true, true, true }
static vec< funct_statefunct_state_vec
static struct
cgraph_node_hook_list
function_insertion_hook_holder
static struct
cgraph_2node_hook_list
node_duplication_hook_holder
static struct
cgraph_node_hook_list
node_removal_hook_holder

Typedef Documentation

typedef struct funct_state_d* funct_state

Enumeration Type Documentation

Lattice values for const and pure functions.  Everything starts out
   being const, then may drop to pure and then neither depending on
   what is found.   
Enumerator:
IPA_CONST 
IPA_PURE 
IPA_NEITHER 

Function Documentation

static void add_new_function ( )
static
Called when new function is inserted to callgraph late.   

References analyze_function(), AVAIL_OVERWRITABLE, cgraph_function_body_availability(), pointer_set_create(), pointer_set_destroy(), and set_function_state().

Referenced by register_hooks().

static void better_state ( enum pure_const_state_e state,
bool *  looping,
enum pure_const_state_e  state2,
bool  looping2 
)
inlinestatic
Merge STATE and STATE2 and LOOPING and LOOPING2 and store
   into STATE and LOOPING better of the two variants.
   Be sure to merge looping correctly.  IPA_NEITHER functions
   have looping 0 even if they don't have to return.   

References IPA_NEITHER.

Referenced by analyze_function(), and propagate_pure_const().

static void check_call ( )
static
Check the parameters of a function call to CALL_EXPR to see if
   there are any references in the parameters that are not allowed for
   pure or const functions.  Also check to see if this is either an
   indirect call, a call outside the compilation unit, or has special
   attributes that may also effect the purity.  The CALL_EXPR node for
   the entire call expression.   

References BUILT_IN_NORMAL, funct_state_d::can_throw, function::can_throw_non_call_exceptions, cfun, current_function_decl, dump_file, dump_flags, gimple_call_flags(), gimple_call_fndecl(), gimple_num_ops(), gimple_op(), IPA_NEITHER, lookup_stmt_eh_lp(), funct_state_d::looping, funct_state_d::pure_const_state, setjmp_call_p(), special_builtin_state(), state_from_flags(), stmt_can_throw_external(), stmt_could_throw_p(), tree_could_throw_p(), and worse_state().

Referenced by check_stmt().

static void check_decl ( funct_state  local,
tree  t,
bool  checking_write,
bool  ipa 
)
inlinestatic
Check to see if the use (or definition when CHECKING_WRITE is true)
   variable T is legal in a function that is either pure or const.   

References dump_file, IPA_CONST, IPA_NEITHER, IPA_PURE, and funct_state_d::pure_const_state.

Referenced by check_ipa_load(), check_ipa_store(), check_load(), and check_store().

static bool check_ipa_load ( )
static
Wrapper around check_decl for loads in ipa mode.   

References check_decl(), and check_op().

Referenced by check_stmt().

static bool check_ipa_store ( )
static
Wrapper around check_decl for stores in ipa mode.   

References check_decl(), and check_op().

Referenced by check_stmt().

static bool check_load ( )
static
Wrapper around check_decl for loads in local more.   

References check_decl(), and check_op().

Referenced by check_stmt().

static void check_op ( )
inlinestatic
Check to see if the use (or definition when CHECKING_WRITE is true)
   variable T is legal in a function that is either pure or const.   

References dump_file, get_base_address(), IPA_CONST, IPA_NEITHER, IPA_PURE, ptr_deref_may_alias_global_p(), and funct_state_d::pure_const_state.

Referenced by check_ipa_load(), check_ipa_store(), check_load(), and check_store().

static bool check_store ( )
static
Wrapper around check_decl for stores in local more.   

References check_decl(), and check_op().

Referenced by check_stmt().

static void duplicate_node_data ( struct cgraph_node src,
struct cgraph_node dst,
void *  data 
)
static
Called when new clone is inserted to callgraph late.   

References get_function_state(), has_function_state(), memcpy(), and set_function_state().

Referenced by register_hooks().

static void finish_state ( )
static
Init the function state.   

Referenced by propagate().

static bool function_always_visible_to_compiler_p ( )
static
Try to guess if function body will always be visible to compiler
   when compiling the call and whether compiler will be able
   to propagate the information by itself.   

Referenced by suggest_attribute().

static bool gate_pure_const ( )
static

References seen_error().

static funct_state get_function_state ( )
inlinestatic
static bool has_function_state ( )
inlinestatic
Return true if we have a function state for NODE.   

References cgraph_node::uid.

Referenced by duplicate_node_data(), propagate(), pure_const_write_summary(), and remove_node_data().

static bool ignore_edge ( )
static
static unsigned int local_pure_const ( )
static
ipa_opt_pass_d* make_pass_ipa_pure_const ( )
gimple_opt_pass* make_pass_local_pure_const ( )
static unsigned int propagate ( )
static
Produce the global information by preforming a transitive closure
   on the local information that was produced by generate_summary.   

References cgraph_remove_function_insertion_hook(), cgraph_remove_node_duplication_hook(), cgraph_remove_node_removal_hook(), finish_state(), free(), get_function_state(), has_function_state(), propagate_nothrow(), and propagate_pure_const().

Referenced by propagate_pseudo_copies().

static void pure_const_generate_summary ( )
static
Analyze each function in the cgraph to see if it is locally PURE or
   CONST.   

References analyze_function(), AVAIL_OVERWRITABLE, cgraph_function_body_availability(), pointer_set_create(), pointer_set_destroy(), register_hooks(), and set_function_state().

static void remove_node_data ( )
static
Called when new clone is inserted to callgraph late.   

References free(), get_function_state(), has_function_state(), set_function_state(), and varying_state.

Referenced by ipa_init(), ipa_reference_read_optimization_summary(), and register_hooks().

static bool self_recursive_p ( )
static
Return true if NODE is self recursive function.
   ??? self recursive and indirectly recursive funcions should
   be the same, so this function seems unnecessary.   

References cgraph_edge::callee, cgraph_node::callees, cgraph_function_node(), and cgraph_edge::next_callee.

Referenced by propagate_pure_const().

static void set_function_state ( )
inlinestatic
static bool skip_function_for_local_pure_const ( )
static
Return true if function should be skipped for local pure const analysis.   

References AVAIL_OVERWRITABLE, cgraph_function_body_availability(), dump_file, and function_called_by_processed_nodes_p().

Referenced by local_pure_const().

static bool special_builtin_state ( enum pure_const_state_e state,
bool *  looping,
tree  callee 
)
static
Recognize special cases of builtins that are by themselves not pure or const
   but function using them is.   

References BUILT_IN_NORMAL, and IPA_CONST.

Referenced by check_call(), and propagate_pure_const().

static void state_from_flags ( enum pure_const_state_e state,
bool *  looping,
int  flags,
bool  cannot_lead_to_return 
)
static
compute state based on ECF FLAGS and store to STATE and LOOPING.   

References dump_file, dump_flags, IPA_CONST, IPA_NEITHER, and IPA_PURE.

Referenced by analyze_function(), check_call(), and propagate_pure_const().

static struct pointer_set_t* suggest_attribute ( int  option,
tree  decl,
bool  known_finite,
struct pointer_set_t warned_about,
const char *  attrib_name 
)
staticread
Emit suggestion about attribute ATTRIB_NAME for DECL.  KNOWN_FINITE
   is true if the function is known to be finite.  The diagnostic is
   controlled by OPTION.  WARNED_ABOUT is a pointer_set unique for
   OPTION, this function may initialize it and it is always returned
   by the function.   

References function_always_visible_to_compiler_p(), option_enabled(), pointer_set_contains(), pointer_set_create(), pointer_set_insert(), and warning_at().

Referenced by warn_function_const(), warn_function_noreturn(), and warn_function_pure().

static void warn_function_const ( )
static
Emit suggestion about __attribute_((const)) for DECL.  KNOWN_FINITE
   is true if the function is known to be finite.   

References suggest_attribute().

Referenced by local_pure_const(), and propagate_pure_const().

void warn_function_noreturn ( )
static void warn_function_pure ( )
static
Emit suggestion about __attribute_((pure)) for DECL.  KNOWN_FINITE
   is true if the function is known to be finite.   

References suggest_attribute().

Referenced by local_pure_const(), and propagate_pure_const().

static void worse_state ( enum pure_const_state_e state,
bool *  looping,
enum pure_const_state_e  state2,
bool  looping2 
)
inlinestatic
Merge STATE and STATE2 and LOOPING and LOOPING2 and store
   into STATE and LOOPING worse of the two variants.   

Referenced by check_call(), and propagate_pure_const().


Variable Documentation

vec<funct_state> funct_state_vec
static
The storage of the funct_state is abstracted because there is the
   possibility that it may be desirable to move this to the cgraph
   local info.   
Array, indexed by cgraph node uid, of function states.   
struct cgraph_node_hook_list* function_insertion_hook_holder
static
Holders of ipa cgraph hooks:  
struct cgraph_2node_hook_list* node_duplication_hook_holder
static
struct cgraph_node_hook_list* node_removal_hook_holder
static
const char* pure_const_names[3] = {"const", "pure", "neither"}
struct funct_state_d varying_state = { IPA_NEITHER, IPA_NEITHER, true, true, true }
static
State used when we know nothing about function.   

Referenced by get_function_state(), and remove_node_data().

struct pointer_set_t* visited_nodes
static
@verbatim Callgraph based analysis of static variables.

Copyright (C) 2004-2013 Free Software Foundation, Inc. Contributed by Kenneth Zadeck zadec.nosp@m.k@na.nosp@m.tural.nosp@m.brid.nosp@m.ge.co.nosp@m.m

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 file marks functions as being either const (TREE_READONLY) or
   pure (DECL_PURE_P).  It can also set a variant of these that
   are allowed to loop indefinitely (DECL_LOOPING_CONST_PURE_P).

   This must be run after inlining decisions have been made since
   otherwise, the local sets will not contain information that is
   consistent with post inlined state.  The global sets are not prone
   to this problem since they are by definition transitive.   
The code in this module is called by the ipa pass manager. It
   should be one of the later passes since it's information is used by
   the rest of the compilation.  

Referenced by build_cgraph_edges(), inline_forbidden_p(), and record_references_in_initializer().