GCC Middle and Back End API Reference
ipa-reference.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "gimple.h"
#include "tree-inline.h"
#include "tree-pass.h"
#include "pointer-set.h"
#include "splay-tree.h"
#include "ggc.h"
#include "ipa-utils.h"
#include "ipa-reference.h"
#include "flags.h"
#include "diagnostic.h"
#include "data-streamer.h"
#include "lto-streamer.h"
Include dependency graph for ipa-reference.c:

Data Structures

struct  ipa_reference_local_vars_info_d
struct  ipa_reference_global_vars_info_d
struct  ipa_reference_optimization_summary_d
struct  ipa_reference_vars_info_d

Typedefs

typedef struct
ipa_reference_local_vars_info_d
ipa_reference_local_vars_info_t
typedef struct
ipa_reference_global_vars_info_d
ipa_reference_global_vars_info_t
typedef struct
ipa_reference_optimization_summary_d
ipa_reference_optimization_summary_t
typedef struct
ipa_reference_vars_info_d
ipa_reference_vars_info_t

Functions

static void remove_node_data (struct cgraph_node *node, void *data)
static void duplicate_node_data (struct cgraph_node *src, struct cgraph_node *dst, void *data)
static ipa_reference_vars_info_t get_reference_vars_info ()
static
ipa_reference_optimization_summary_t 
get_reference_optimization_summary ()
static void set_reference_vars_info (struct cgraph_node *node, ipa_reference_vars_info_t info)
static void set_reference_optimization_summary (struct cgraph_node *node, ipa_reference_optimization_summary_t info)
bitmap ipa_reference_get_not_read_global ()
bitmap ipa_reference_get_not_written_global ()
static void add_static_var ()
static bool is_proper_for_analysis ()
static const char * get_static_name ()
static void dump_static_vars_set_to_file ()
static bool union_static_var_sets ()
static bool intersect_static_var_sets ()
static bitmap copy_static_var_set ()
static void propagate_bits ()
static void ipa_init ()
static
ipa_reference_local_vars_info_t 
init_function_info ()
static void analyze_function ()
static void remove_node_data ()
static void generate_summary ()
static void read_write_all_from_decl (struct cgraph_node *node, bool &read_all, bool &write_all)
static void get_read_write_all_from_node (struct cgraph_node *node, bool &read_all, bool &write_all)
static unsigned int propagate ()
static bool write_node_summary_p (struct cgraph_node *node, lto_symtab_encoder_t encoder, bitmap ltrans_statics)
static void stream_out_bitmap (struct lto_simple_output_block *ob, bitmap bits, bitmap ltrans_statics, int ltrans_statics_bitcount)
static void ipa_reference_write_optimization_summary ()
static void ipa_reference_read_optimization_summary ()
static bool gate_reference ()
ipa_opt_pass_dmake_pass_ipa_reference ()

Variables

static splay_tree reference_vars_to_consider
static bitmap all_module_statics
static bitmap_obstack local_info_obstack
static bitmap_obstack optimization_summary_obstack
static struct
cgraph_2node_hook_list
node_duplication_hook_holder
static struct
cgraph_node_hook_list
node_removal_hook_holder
static vec
< ipa_reference_vars_info_t
ipa_reference_vars_vector
static vec
< ipa_reference_optimization_summary_t
ipa_reference_opt_sum_vector

Typedef Documentation


Function Documentation

static void add_static_var ( )
inlinestatic

Add VAR to all_module_statics and the two reference_vars_to_consider* sets.

static void analyze_function ( )
static
static bitmap copy_static_var_set ( )
static

Return a copy of SET on the bitmap obstack containing SET. But if SET is NULL or the maximum set, return that instead.

Referenced by analyze_function().

static void dump_static_vars_set_to_file ( )
static

Dump a set of static vars to FILE.

References all_module_statics, and BITMAP_FREE.

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 analyze_function(), dump_file, EXECUTE_IF_SET_IN_BITMAP, FOR_EACH_DEFINED_FUNCTION, get_static_name(), and ipa_init().

static bool gate_reference ( )
static

Don't bother doing anything if the program has errors.

static void generate_summary ( )
static

Analyze each function in the cgraph to see which global or statics are read or written.

Process all of the functions next.

References dump_file, and get_static_name().

static void get_read_write_all_from_node ( struct cgraph_node node,
bool read_all,
bool write_all 
)
static

Set READ_ALL/WRITE_ALL based on decl flags of NODE or any member in the cycle of NODE.

When function is overwritable, we can not assume anything.

static ipa_reference_optimization_summary_t get_reference_optimization_summary ( )
inlinestatic

Return the ipa_reference_vars structure starting from the cgraph NODE.

Referenced by analyze_function(), ipa_reference_get_not_read_global(), and set_reference_optimization_summary().

static ipa_reference_vars_info_t get_reference_vars_info ( )
inlinestatic

Return the ipa_reference_vars structure starting from the cgraph NODE.

Referenced by remove_node_data().

static const char* get_static_name ( )
static

Lookup the tree node for the static variable that has UID and convert the name to a string for debugging.

Referenced by duplicate_node_data(), generate_summary(), and remove_node_data().

static ipa_reference_local_vars_info_t init_function_info ( )
static

Set up the persistent info for FN.

Add the info to the tree's annotation.

static bool intersect_static_var_sets ( )
static

Compute X &= Y, taking into account the possibility that X may become the maximum set.

As with union_static_var_sets, reducing to the maximum set as early as possible is an overall win.

static void ipa_init ( )
static

The init routine for analyzing global static variable usage. See comments at top for description.

Referenced by duplicate_node_data().

bitmap ipa_reference_get_not_read_global ( )

Return a bitmap indexed by DECL_UID for the static variables that are not read during the execution of the function FN. Returns NULL if no data is available.

References all_module_statics, symtab_node_base::decl, ECF_LEAF, flags_from_decl_or_type(), get_reference_optimization_summary(), NULL, and ipa_reference_optimization_summary_d::statics_not_written.

bitmap ipa_reference_get_not_written_global ( )

Return a bitmap indexed by DECL_UID for the static variables that are not written during the execution of the function FN. Note that variables written may or may not be read during the function call. Returns NULL if no data is available.

References bitmap_set_bit, DECL_UID, dump_file, gcc_assert, reference_vars_to_consider, and TREE_CODE.

static void ipa_reference_read_optimization_summary ( )
static

Deserialize the ipa info for lto.

             Set the statics not read.   
             Set the statics not written.   
       Fatal error here.  We do not want to support compiling ltrans units with
       different version of compiler or different flags than the WPA unit, so
       this should never happen.   
static void ipa_reference_write_optimization_summary ( )
static

Serialize the ipa info for lto.

See what variables we are interested in.

 Process all of the functions.   
static bool is_proper_for_analysis ( )
inlinestatic

Return true if the variable T is the right kind of static variable to perform compilation unit scope escape analysis.

 If the variable has the "used" attribute, treat it as if it had a
 been touched by the devil.   
 Do not want to do anything with volatile except mark any
 function that uses one to be not const or pure.   
 We do not need to analyze readonly vars, we already know they do not
 alias.   
 This is a variable we care about.  Check if we have seen it
 before, and if not add it the set of variables we care about.   
ipa_opt_pass_d* make_pass_ipa_reference ( )
static unsigned int propagate ( )
static

Produce the global information by preforming a transitive closure on the local information that was produced by ipa_analyze_function.

 Now we know what vars are really statics; prune out those that aren't.   
 Forget info we collected "just for fun" on variables that turned out to be
 non-local.   
 Propagate the local information through the call graph to produce
 the global information.  All the nodes within a cycle will have
 the same info so we collapse cycles first.  Then we can do the
 propagation in one pass from the leaves to the roots.   
     If any node in a cycle is read_all or write_all, they all are.   
     Initialized the bitmaps global sets for the reduced node.   
     Merge the sets of this cycle with all sets of callees reached
     from this cycle.   
     All nodes within a cycle have the same global info bitmaps.   
 Cleanup.  
         Create the complimentary sets.   
static void propagate_bits ( )
static

Compute the union all of the statics read and written by every callee of X into X_GLOBAL->statics_read and X_GLOBAL->statics_written. X_GLOBAL is actually the set representing the cycle containing X. If the read and written sets of X_GLOBAL has been reduced to the maximum set, we don't have to look at the remaining callees.

     Only look into nodes we can propagate something.   
             Calls in the current cycle do not have their global set
             computed yet (but everything else does because we're
             visiting nodes in topological order).   
             If the function is const, it reads no memory even if it
             seems so to local analysis.   
             If the function is pure, it has no stores even if it
             seems so to local analysis.  If we cannot return from
             the function, we can safely ignore the call.   
static void read_write_all_from_decl ( struct cgraph_node node,
bool read_all,
bool write_all 
)
static

Set READ_ALL/WRITE_ALL based on decl flags of NODE.

TODO: To be able to produce sane results, we should also handle common builtins, in particular throw.

References AVAIL_OVERWRITABLE, cgraph_edge::callee, cgraph_function_node(), and gcc_checking_assert.

static void remove_node_data ( struct cgraph_node node,
void *  data 
)
static

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 gathers information about how variables whose scope is confined to the compilation unit are used.

The transitive call site specific clobber effects are computed for the variables whose scope is contained within this compilation unit.

First each function and static variable initialization is analyzed to determine which local static variables are either read, written, or have their address taken. Any local static that has its address taken is removed from consideration. Once the local read and writes are determined, a transitive closure of this information is performed over the call graph to determine the worst case set of side effects of each call. In later parts of the compiler, these local and global sets are examined to make the call clobbering less traumatic, promote some statics to registers, and improve aliasing information.

static void set_reference_optimization_summary ( struct cgraph_node node,
ipa_reference_optimization_summary_t  info 
)
inlinestatic
static void set_reference_vars_info ( struct cgraph_node node,
ipa_reference_vars_info_t  info 
)
inlinestatic

Return the ipa_reference_vars structure starting from the cgraph NODE.

static void stream_out_bitmap ( struct lto_simple_output_block ob,
bitmap  bits,
bitmap  ltrans_statics,
int  ltrans_statics_bitcount 
)
static

Stream out BITS&LTRANS_STATICS as list of decls to OB. LTRANS_STATICS_BITCOUNT specify number of bits in LTRANS_STATICS or -1. When it is positive, just output -1 when BITS&LTRANS_STATICS == BITS&LTRANS_STATICS.

static bool union_static_var_sets ( )
static

Compute X |= Y, taking into account the possibility that either X or Y is already the maximum set. Return true if X is the maximum set after taking the union with Y.

The union may have reduced X to the maximum set. In that case, we want to make that visible explicitly. Even though bitmap_equal_p can be very expensive, it turns out to be an overall win to check this here for an LTO bootstrap of GCC itself. Liberally extrapoliate that result to be applicable to all cases.

References all_module_statics, bitmap_and_into(), bitmap_equal_p(), and BITMAP_FREE.

static bool write_node_summary_p ( struct cgraph_node node,
lto_symtab_encoder_t  encoder,
bitmap  ltrans_statics 
)
static

Return true if we need to write summary of NODE.

 See if we have (non-empty) info.   
 See if we want to encode it.
 Encode also referenced functions since constant folding might turn it into
 a direct call.

 In future we might also want to include summaries of functions references
 by initializers of constant variables references in current unit.   
 See if the info has non-empty intersections with vars we want to encode.   

References lto_simple_output_block::decl_state, lto_output_var_decl_index(), lto_simple_output_block::main_stream, and reference_vars_to_consider.


Variable Documentation

bitmap all_module_statics
static

Set of all interesting module statics. A bit is set for every module static we are considering. This is added to the local info when asm code is found that clobbers all memory.

Referenced by dump_static_vars_set_to_file(), ipa_reference_get_not_read_global(), set_reference_optimization_summary(), and union_static_var_sets().

vec<ipa_reference_optimization_summary_t> ipa_reference_opt_sum_vector
static
vec<ipa_reference_vars_info_t> ipa_reference_vars_vector
static

Vector where the reference var infos are actually stored. Indexed by UID of call graph nodes.

bitmap_obstack local_info_obstack
static

Obstack holding bitmaps of local analysis (live from analysis to propagation)

struct cgraph_2node_hook_list* node_duplication_hook_holder
static

Holders of ipa cgraph hooks:

struct cgraph_node_hook_list* node_removal_hook_holder
static
bitmap_obstack optimization_summary_obstack
static

Obstack holding global analysis live forever.

splay_tree reference_vars_to_consider
static

This splay tree contains all of the static variables that are being considered by the compilation level alias analysis.

Referenced by ipa_reference_get_not_written_global(), and write_node_summary_p().