1169689Skan/* Interprocedural analyses. 2169689Skan Copyright (C) 2005 Free Software Foundation, Inc. 3169689Skan 4169689SkanThis file is part of GCC. 5169689Skan 6169689SkanGCC is free software; you can redistribute it and/or modify it under 7169689Skanthe terms of the GNU General Public License as published by the Free 8169689SkanSoftware Foundation; either version 2, or (at your option) any later 9169689Skanversion. 10169689Skan 11169689SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 12169689SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 13169689SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14169689Skanfor more details. 15169689Skan 16169689SkanYou should have received a copy of the GNU General Public License 17169689Skanalong with GCC; see the file COPYING. If not, write to the Free 18169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 19169689Skan02110-1301, USA. */ 20169689Skan 21169689Skan#ifndef IPA_PROP_H 22169689Skan#define IPA_PROP_H 23169689Skan 24169689Skan#include "tree.h" 25169689Skan 26169689Skan/* The following definitions and interfaces are used by 27169689Skan interprocedural analyses. */ 28169689Skan 29169689Skan/* A jump function for a callsite represents the values passed as actual 30169689Skan arguments of the callsite. There are three main types of values : 31169689Skan Formal - the caller's formal parameter is passed as an actual argument. 32169689Skan Constant - a constant is passed as a an actual argument. 33169689Skan Unknown - neither of the above. 34169689Skan Integer and real constants are represented as CONST_IPATYPE and Fortran 35169689Skan constants are represented as CONST_IPATYPE_REF. */ 36169689Skanenum jump_func_type 37169689Skan{ 38169689Skan UNKNOWN_IPATYPE, 39169689Skan CONST_IPATYPE, 40169689Skan CONST_IPATYPE_REF, 41169689Skan FORMAL_IPATYPE 42169689Skan}; 43169689Skan 44169689Skan/* All formal parameters in the program have a cval computed by 45169689Skan the interprocedural stage of IPCP. 46169689Skan There are three main values of cval : 47169689Skan TOP - unknown. 48169689Skan BOTTOM - non constant. 49169689Skan CONSTANT_TYPE - constant value. 50169689Skan Cval of formal f will have a constant value if all callsites to this 51169689Skan function have the same constant value passed to f. 52169689Skan Integer and real constants are represented as CONST_IPATYPE and Fortran 53169689Skan constants are represented as CONST_IPATYPE_REF. */ 54169689Skanenum cvalue_type 55169689Skan{ 56169689Skan BOTTOM, 57169689Skan CONST_VALUE, 58169689Skan CONST_VALUE_REF, 59169689Skan TOP 60169689Skan}; 61169689Skan 62169689Skan/* Represents the value of either jump function or cval. 63169689Skan value represents a constant. 64169689Skan formal_id is used only in jump function context and represents 65169689Skan pass-through parameter (the formal of caller is passed 66169689Skan as argument). */ 67169689Skanunion parameter_info 68169689Skan{ 69169689Skan unsigned int formal_id; 70169689Skan tree value; 71169689Skan}; 72169689Skan 73169689Skan/* A jump function for a callsite represents the values passed as actual 74169689Skan arguments of the callsite. See enum jump_func_type for the various 75169689Skan types of jump functions supported. */ 76169689Skanstruct ipa_jump_func 77169689Skan{ 78169689Skan enum jump_func_type type; 79169689Skan union parameter_info info_type; 80169689Skan}; 81169689Skan 82169689Skan/* All formal parameters in the program have a cval computed by 83169689Skan the interprocedural stage of IPCP. See enum cvalue_type for 84169689Skan the various types of cvals supported */ 85169689Skanstruct ipcp_formal 86169689Skan{ 87169689Skan enum cvalue_type cval_type; 88169689Skan union parameter_info cvalue; 89169689Skan}; 90169689Skan 91169689Skan/* Represent which DECL tree (or reference to such tree) 92169689Skan will be replaced by another tree while versioning. */ 93169689Skanstruct ipa_replace_map 94169689Skan{ 95169689Skan /* The tree that will be replaced. */ 96169689Skan tree old_tree; 97169689Skan /* The new (replacing) tree. */ 98169689Skan tree new_tree; 99169689Skan /* True when a substitution should be done, false otherwise. */ 100169689Skan bool replace_p; 101169689Skan /* True when we replace a reference to old_tree. */ 102169689Skan bool ref_p; 103169689Skan}; 104169689Skan 105169689Skan/* Return the field in cgraph_node/cgraph_edge struct that points 106169689Skan to ipa_node/ipa_edge struct. */ 107169689Skan#define IPA_NODE_REF(MT) ((struct ipa_node *)(MT)->aux) 108169689Skan#define IPA_EDGE_REF(EDGE) ((struct ipa_edge *)(EDGE)->aux) 109169689Skan 110169689Skan/* ipa_node stores information related to a method and 111169689Skan its formal parameters. It is pointed to by a field in the 112169689Skan method's corresponding cgraph_node. 113169689Skan 114169689Skan ipa_edge stores information related to a callsite and 115169689Skan its arguments. It is pointed to by a field in the 116169689Skan callsite's corresponding cgraph_edge. */ 117169689Skanstruct ipa_node 118169689Skan{ 119169689Skan /* Number of formal parameters of this method. When set to 0, 120169689Skan this method's parameters would not be analyzed by the different 121169689Skan stages of IPA CP. */ 122169689Skan int ipa_arg_num; 123169689Skan /* Array of cvals. */ 124169689Skan struct ipcp_formal *ipcp_cval; 125169689Skan /* Mapping each parameter to its PARM_DECL tree. */ 126169689Skan tree *ipa_param_tree; 127169689Skan /* Indicating which parameter is modified in its method. */ 128169689Skan bool *ipa_mod; 129169689Skan /* Only for versioned nodes this field would not be NULL, 130169689Skan it points to the node that IPA cp cloned from. */ 131169689Skan struct cgraph_node *ipcp_orig_node; 132169689Skan /* Meaningful only for original methods. Expresses the 133169689Skan ratio between the direct calls and sum of all invocations of 134169689Skan this function (given by profiling info). It is used to calculate 135169689Skan the profiling information of the original function and the versioned 136169689Skan one. */ 137169689Skan gcov_type count_scale; 138169689Skan}; 139169689Skan 140169689Skanstruct ipa_edge 141169689Skan{ 142169689Skan /* Number of actual arguments in this callsite. When set to 0, 143169689Skan this callsite's parameters would not be analyzed by the different 144169689Skan stages of IPA CP. */ 145169689Skan int ipa_param_num; 146169689Skan /* Array of the callsite's jump function of each parameter. */ 147169689Skan struct ipa_jump_func *ipa_param_map; 148169689Skan}; 149169689Skan 150169689Skan/* A methodlist element (referred to also as methodlist node). It is used 151169689Skan to create a temporary worklist used in 152169689Skan the propagation stage of IPCP. (can be used for more IPA 153169689Skan optimizations) */ 154169689Skanstruct ipa_methodlist 155169689Skan{ 156169689Skan struct cgraph_node *method_p; 157169689Skan struct ipa_methodlist *next_method; 158169689Skan}; 159169689Skan 160169689Skan/* A pointer to a methodlist element. */ 161169689Skantypedef struct ipa_methodlist *ipa_methodlist_p; 162169689Skan 163169689Skan/* ipa_methodlist interface. */ 164169689Skanipa_methodlist_p ipa_methodlist_init (void); 165169689Skanbool ipa_methodlist_not_empty (ipa_methodlist_p); 166169689Skanvoid ipa_add_method (ipa_methodlist_p *, struct cgraph_node *); 167169689Skanstruct cgraph_node *ipa_remove_method (ipa_methodlist_p *); 168169689Skan 169169689Skan/* ipa_callsite interface. */ 170169689Skanint ipa_callsite_param_count (struct cgraph_edge *); 171169689Skanvoid ipa_callsite_param_count_set (struct cgraph_edge *, int); 172169689Skanstruct ipa_jump_func *ipa_callsite_param (struct cgraph_edge *, int); 173169689Skanstruct cgraph_node *ipa_callsite_callee (struct cgraph_edge *); 174169689Skanvoid ipa_callsite_compute_param (struct cgraph_edge *); 175169689Skanvoid ipa_callsite_compute_count (struct cgraph_edge *); 176169689Skan 177169689Skan/* ipa_method interface. */ 178169689Skanint ipa_method_formal_count (struct cgraph_node *); 179169689Skanvoid ipa_method_formal_count_set (struct cgraph_node *, int); 180169689Skantree ipa_method_get_tree (struct cgraph_node *, int); 181169689Skanvoid ipa_method_compute_tree_map (struct cgraph_node *); 182169689Skanvoid ipa_method_formal_compute_count (struct cgraph_node *); 183169689Skanvoid ipa_method_compute_modify (struct cgraph_node *); 184169689Skan 185169689Skan/* jump function interface. */ 186169689Skanenum jump_func_type get_type (struct ipa_jump_func *); 187169689Skanunion parameter_info *ipa_jf_get_info_type (struct ipa_jump_func *); 188169689Skan 189169689Skan/* ipa_node and ipa_edge interfaces. */ 190169689Skanvoid ipa_node_create (struct cgraph_node *); 191169689Skanvoid ipa_free (void); 192169689Skanvoid ipa_nodes_create (void); 193169689Skanvoid ipa_edges_create (void); 194169689Skanvoid ipa_edges_free (void); 195169689Skanvoid ipa_nodes_free (void); 196169689Skan 197169689Skan 198169689Skan/* Debugging interface. */ 199169689Skanvoid ipa_method_tree_print (FILE *); 200169689Skanvoid ipa_method_modify_print (FILE *); 201169689Skan 202169689Skanunsigned int ipcp_driver (void); 203169689Skan 204169689Skan#endif /* IPA_PROP_H */ 205