ipa-prop.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /* Interprocedural analyses.
  2. Copyright (C) 2005-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef IPA_PROP_H
  16. #define IPA_PROP_H
  17. /* The following definitions and interfaces are used by
  18. interprocedural analyses or parameters. */
  19. #define IPA_UNDESCRIBED_USE -1
  20. /* ipa-prop.c stuff (ipa-cp, indirect inlining): */
  21. /* A jump function for a callsite represents the values passed as actual
  22. arguments of the callsite. They were originally proposed in a paper called
  23. "Interprocedural Constant Propagation", by David Callahan, Keith D Cooper,
  24. Ken Kennedy, Linda Torczon in Comp86, pg 152-161. There are three main
  25. types of values :
  26. Pass-through - the caller's formal parameter is passed as an actual
  27. argument, possibly one simple operation performed on it.
  28. Constant - a constant (is_gimple_ip_invariant)is passed as an actual
  29. argument.
  30. Unknown - neither of the above.
  31. IPA_JF_ANCESTOR is a special pass-through jump function, which means that
  32. the result is an address of a part of the object pointed to by the formal
  33. parameter to which the function refers. It is mainly intended to represent
  34. getting addresses of ancestor fields in C++
  35. (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is
  36. NULL, ancestor jump function must behave like a simple pass-through.
  37. Other pass-through functions can either simply pass on an unchanged formal
  38. parameter or can apply one simple binary operation to it (such jump
  39. functions are called polynomial).
  40. Jump functions are computed in ipa-prop.c by function
  41. update_call_notes_after_inlining. Some information can be lost and jump
  42. functions degraded accordingly when inlining, see
  43. update_call_notes_after_inlining in the same file. */
  44. enum jump_func_type
  45. {
  46. IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
  47. IPA_JF_CONST, /* represented by field costant */
  48. IPA_JF_PASS_THROUGH, /* represented by field pass_through */
  49. IPA_JF_ANCESTOR /* represented by field ancestor */
  50. };
  51. struct ipa_cst_ref_desc;
  52. /* Structure holding data required to describe a constant jump function. */
  53. struct GTY(()) ipa_constant_data
  54. {
  55. /* THe value of the constant. */
  56. tree value;
  57. /* Pointer to the structure that describes the reference. */
  58. struct ipa_cst_ref_desc GTY((skip)) *rdesc;
  59. };
  60. /* Structure holding data required to describe a pass-through jump function. */
  61. struct GTY(()) ipa_pass_through_data
  62. {
  63. /* If an operation is to be performed on the original parameter, this is the
  64. second (constant) operand. */
  65. tree operand;
  66. /* Number of the caller's formal parameter being passed. */
  67. int formal_id;
  68. /* Operation that is performed on the argument before it is passed on.
  69. NOP_EXPR means no operation. Otherwise oper must be a simple binary
  70. arithmetic operation where the caller's parameter is the first operand and
  71. operand field from this structure is the second one. */
  72. enum tree_code operation;
  73. /* When the passed value is a pointer, it is set to true only when we are
  74. certain that no write to the object it points to has occurred since the
  75. caller functions started execution, except for changes noted in the
  76. aggregate part of the jump function (see description of
  77. ipa_agg_jump_function). The flag is used only when the operation is
  78. NOP_EXPR. */
  79. unsigned agg_preserved : 1;
  80. };
  81. /* Structure holding data required to describe an ancestor pass-through
  82. jump function. */
  83. struct GTY(()) ipa_ancestor_jf_data
  84. {
  85. /* Offset of the field representing the ancestor. */
  86. HOST_WIDE_INT offset;
  87. /* Number of the caller's formal parameter being passed. */
  88. int formal_id;
  89. /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */
  90. unsigned agg_preserved : 1;
  91. };
  92. /* An element in an aggegate part of a jump function describing a known value
  93. at a given offset. When it is part of a pass-through jump function with
  94. agg_preserved set or an ancestor jump function with agg_preserved set, all
  95. unlisted positions are assumed to be preserved but the value can be a type
  96. node, which means that the particular piece (starting at offset and having
  97. the size of the type) is clobbered with an unknown value. When
  98. agg_preserved is false or the type of the containing jump function is
  99. different, all unlisted parts are assumed to be unknown and all values must
  100. fulfill is_gimple_ip_invariant. */
  101. struct GTY(()) ipa_agg_jf_item
  102. {
  103. /* The offset at which the known value is located within the aggregate. */
  104. HOST_WIDE_INT offset;
  105. /* The known constant or type if this is a clobber. */
  106. tree value;
  107. };
  108. /* Aggregate jump function - i.e. description of contents of aggregates passed
  109. either by reference or value. */
  110. struct GTY(()) ipa_agg_jump_function
  111. {
  112. /* Description of the individual items. */
  113. vec<ipa_agg_jf_item, va_gc> *items;
  114. /* True if the data was passed by reference (as opposed to by value). */
  115. bool by_ref;
  116. };
  117. typedef struct ipa_agg_jump_function *ipa_agg_jump_function_p;
  118. /* Information about zero/non-zero bits. */
  119. struct GTY(()) ipa_bits
  120. {
  121. /* The propagated value. */
  122. widest_int value;
  123. /* Mask corresponding to the value.
  124. Similar to ccp_lattice_t, if xth bit of mask is 0,
  125. implies xth bit of value is constant. */
  126. widest_int mask;
  127. };
  128. /* Info about value ranges. */
  129. struct GTY(()) ipa_vr
  130. {
  131. /* The data fields below are valid only if known is true. */
  132. bool known;
  133. enum value_range_kind type;
  134. wide_int min;
  135. wide_int max;
  136. };
  137. /* A jump function for a callsite represents the values passed as actual
  138. arguments of the callsite. See enum jump_func_type for the various
  139. types of jump functions supported. */
  140. struct GTY (()) ipa_jump_func
  141. {
  142. /* Aggregate contants description. See struct ipa_agg_jump_function and its
  143. description. */
  144. struct ipa_agg_jump_function agg;
  145. /* Information about zero/non-zero bits. The pointed to structure is shared
  146. betweed different jump functions. Use ipa_set_jfunc_bits to set this
  147. field. */
  148. struct ipa_bits *bits;
  149. /* Information about value range, containing valid data only when vr_known is
  150. true. The pointed to structure is shared betweed different jump
  151. functions. Use ipa_set_jfunc_vr to set this field. */
  152. struct value_range_base *m_vr;
  153. enum jump_func_type type;
  154. /* Represents a value of a jump function. pass_through is used only in jump
  155. function context. constant represents the actual constant in constant jump
  156. functions and member_cst holds constant c++ member functions. */
  157. union jump_func_value
  158. {
  159. struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
  160. struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
  161. struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
  162. } GTY ((desc ("%1.type"))) value;
  163. };
  164. /* Return the constant stored in a constant jump functin JFUNC. */
  165. static inline tree
  166. ipa_get_jf_constant (struct ipa_jump_func *jfunc)
  167. {
  168. gcc_checking_assert (jfunc->type == IPA_JF_CONST);
  169. return jfunc->value.constant.value;
  170. }
  171. static inline struct ipa_cst_ref_desc *
  172. ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
  173. {
  174. gcc_checking_assert (jfunc->type == IPA_JF_CONST);
  175. return jfunc->value.constant.rdesc;
  176. }
  177. /* Return the operand of a pass through jmp function JFUNC. */
  178. static inline tree
  179. ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
  180. {
  181. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  182. return jfunc->value.pass_through.operand;
  183. }
  184. /* Return the number of the caller's formal parameter that a pass through jump
  185. function JFUNC refers to. */
  186. static inline int
  187. ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
  188. {
  189. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  190. return jfunc->value.pass_through.formal_id;
  191. }
  192. /* Return operation of a pass through jump function JFUNC. */
  193. static inline enum tree_code
  194. ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
  195. {
  196. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  197. return jfunc->value.pass_through.operation;
  198. }
  199. /* Return the agg_preserved flag of a pass through jump function JFUNC. */
  200. static inline bool
  201. ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
  202. {
  203. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  204. return jfunc->value.pass_through.agg_preserved;
  205. }
  206. /* Return true if pass through jump function JFUNC preserves type
  207. information. */
  208. static inline bool
  209. ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
  210. {
  211. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  212. return jfunc->value.pass_through.agg_preserved;
  213. }
  214. /* Return the offset of an ancestor jump function JFUNC. */
  215. static inline HOST_WIDE_INT
  216. ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
  217. {
  218. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  219. return jfunc->value.ancestor.offset;
  220. }
  221. /* Return the number of the caller's formal parameter that an ancestor jump
  222. function JFUNC refers to. */
  223. static inline int
  224. ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
  225. {
  226. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  227. return jfunc->value.ancestor.formal_id;
  228. }
  229. /* Return the agg_preserved flag of an ancestor jump function JFUNC. */
  230. static inline bool
  231. ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
  232. {
  233. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  234. return jfunc->value.ancestor.agg_preserved;
  235. }
  236. /* Return true if ancestor jump function JFUNC presrves type information. */
  237. static inline bool
  238. ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
  239. {
  240. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  241. return jfunc->value.ancestor.agg_preserved;
  242. }
  243. /* Summary describing a single formal parameter. */
  244. struct GTY(()) ipa_param_descriptor
  245. {
  246. /* In analysis and modification phase, this is the PARAM_DECL of this
  247. parameter, in IPA LTO phase, this is the type of the the described
  248. parameter or NULL if not known. Do not read this field directly but
  249. through ipa_get_param and ipa_get_type as appropriate. */
  250. tree decl_or_type;
  251. /* If all uses of the parameter are described by ipa-prop structures, this
  252. says how many there are. If any use could not be described by means of
  253. ipa-prop structures, this is IPA_UNDESCRIBED_USE. */
  254. int controlled_uses;
  255. unsigned int move_cost : 31;
  256. /* The parameter is used. */
  257. unsigned used : 1;
  258. };
  259. /* ipa_node_params stores information related to formal parameters of functions
  260. and some other information for interprocedural passes that operate on
  261. parameters (such as ipa-cp). */
  262. struct GTY((for_user)) ipa_node_params
  263. {
  264. /* Default constructor. */
  265. ipa_node_params ();
  266. /* Default destructor. */
  267. ~ipa_node_params ();
  268. /* Information about individual formal parameters that are gathered when
  269. summaries are generated. */
  270. vec<ipa_param_descriptor, va_gc> *descriptors;
  271. /* Pointer to an array of structures describing individual formal
  272. parameters. */
  273. struct ipcp_param_lattices * GTY((skip)) lattices;
  274. /* Only for versioned nodes this field would not be NULL,
  275. it points to the node that IPA cp cloned from. */
  276. struct cgraph_node * GTY((skip)) ipcp_orig_node;
  277. /* If this node is an ipa-cp clone, these are the known constants that
  278. describe what it has been specialized for. */
  279. vec<tree> GTY((skip)) known_csts;
  280. /* If this node is an ipa-cp clone, these are the known polymorphic contexts
  281. that describe what it has been specialized for. */
  282. vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
  283. /* Whether the param uses analysis and jump function computation has already
  284. been performed. */
  285. unsigned analysis_done : 1;
  286. /* Whether the function is enqueued in ipa-cp propagation stack. */
  287. unsigned node_enqueued : 1;
  288. /* Whether we should create a specialized version based on values that are
  289. known to be constant in all contexts. */
  290. unsigned do_clone_for_all_contexts : 1;
  291. /* Set if this is an IPA-CP clone for all contexts. */
  292. unsigned is_all_contexts_clone : 1;
  293. /* Node has been completely replaced by clones and will be removed after
  294. ipa-cp is finished. */
  295. unsigned node_dead : 1;
  296. /* Node is involved in a recursion, potentionally indirect. */
  297. unsigned node_within_scc : 1;
  298. /* Node is calling a private function called only once. */
  299. unsigned node_calling_single_call : 1;
  300. /* False when there is something makes versioning impossible. */
  301. unsigned versionable : 1;
  302. };
  303. inline
  304. ipa_node_params::ipa_node_params ()
  305. : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
  306. known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
  307. node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
  308. node_dead (0), node_within_scc (0), node_calling_single_call (0),
  309. versionable (0)
  310. {
  311. }
  312. inline
  313. ipa_node_params::~ipa_node_params ()
  314. {
  315. free (lattices);
  316. known_csts.release ();
  317. known_contexts.release ();
  318. }
  319. /* Intermediate information that we get from alias analysis about a particular
  320. parameter in a particular basic_block. When a parameter or the memory it
  321. references is marked modified, we use that information in all dominated
  322. blocks without consulting alias analysis oracle. */
  323. struct ipa_param_aa_status
  324. {
  325. /* Set when this structure contains meaningful information. If not, the
  326. structure describing a dominating BB should be used instead. */
  327. bool valid;
  328. /* Whether we have seen something which might have modified the data in
  329. question. PARM is for the parameter itself, REF is for data it points to
  330. but using the alias type of individual accesses and PT is the same thing
  331. but for computing aggregate pass-through functions using a very inclusive
  332. ao_ref. */
  333. bool parm_modified, ref_modified, pt_modified;
  334. };
  335. /* Information related to a given BB that used only when looking at function
  336. body. */
  337. struct ipa_bb_info
  338. {
  339. /* Call graph edges going out of this BB. */
  340. vec<cgraph_edge *> cg_edges;
  341. /* Alias analysis statuses of each formal parameter at this bb. */
  342. vec<ipa_param_aa_status> param_aa_statuses;
  343. };
  344. /* Structure with global information that is only used when looking at function
  345. body. */
  346. struct ipa_func_body_info
  347. {
  348. /* The node that is being analyzed. */
  349. cgraph_node *node;
  350. /* Its info. */
  351. struct ipa_node_params *info;
  352. /* Information about individual BBs. */
  353. vec<ipa_bb_info> bb_infos;
  354. /* Number of parameters. */
  355. int param_count;
  356. /* Number of statements we are still allowed to walked by when analyzing this
  357. function. */
  358. unsigned int aa_walk_budget;
  359. };
  360. /* ipa_node_params access functions. Please use these to access fields that
  361. are or will be shared among various passes. */
  362. /* Return the number of formal parameters. */
  363. static inline int
  364. ipa_get_param_count (struct ipa_node_params *info)
  365. {
  366. return vec_safe_length (info->descriptors);
  367. }
  368. /* Return the declaration of Ith formal parameter of the function corresponding
  369. to INFO. Note there is no setter function as this array is built just once
  370. using ipa_initialize_node_params. This function should not be called in
  371. WPA. */
  372. static inline tree
  373. ipa_get_param (struct ipa_node_params *info, int i)
  374. {
  375. gcc_checking_assert (info->descriptors);
  376. gcc_checking_assert (!flag_wpa);
  377. tree t = (*info->descriptors)[i].decl_or_type;
  378. gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
  379. return t;
  380. }
  381. /* Return the type of Ith formal parameter of the function corresponding
  382. to INFO if it is known or NULL if not. */
  383. static inline tree
  384. ipa_get_type (struct ipa_node_params *info, int i)
  385. {
  386. if (vec_safe_length (info->descriptors) <= (unsigned) i)
  387. return NULL;
  388. tree t = (*info->descriptors)[i].decl_or_type;
  389. if (!t)
  390. return NULL;
  391. if (TYPE_P (t))
  392. return t;
  393. gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
  394. return TREE_TYPE (t);
  395. }
  396. /* Return the move cost of Ith formal parameter of the function corresponding
  397. to INFO. */
  398. static inline int
  399. ipa_get_param_move_cost (struct ipa_node_params *info, int i)
  400. {
  401. gcc_checking_assert (info->descriptors);
  402. return (*info->descriptors)[i].move_cost;
  403. }
  404. /* Set the used flag corresponding to the Ith formal parameter of the function
  405. associated with INFO to VAL. */
  406. static inline void
  407. ipa_set_param_used (struct ipa_node_params *info, int i, bool val)
  408. {
  409. gcc_checking_assert (info->descriptors);
  410. (*info->descriptors)[i].used = val;
  411. }
  412. /* Return how many uses described by ipa-prop a parameter has or
  413. IPA_UNDESCRIBED_USE if there is a use that is not described by these
  414. structures. */
  415. static inline int
  416. ipa_get_controlled_uses (struct ipa_node_params *info, int i)
  417. {
  418. /* FIXME: introducing speculation causes out of bounds access here. */
  419. if (vec_safe_length (info->descriptors) > (unsigned)i)
  420. return (*info->descriptors)[i].controlled_uses;
  421. return IPA_UNDESCRIBED_USE;
  422. }
  423. /* Set the controlled counter of a given parameter. */
  424. static inline void
  425. ipa_set_controlled_uses (struct ipa_node_params *info, int i, int val)
  426. {
  427. gcc_checking_assert (info->descriptors);
  428. (*info->descriptors)[i].controlled_uses = val;
  429. }
  430. /* Return the used flag corresponding to the Ith formal parameter of the
  431. function associated with INFO. */
  432. static inline bool
  433. ipa_is_param_used (struct ipa_node_params *info, int i)
  434. {
  435. gcc_checking_assert (info->descriptors);
  436. return (*info->descriptors)[i].used;
  437. }
  438. /* Information about replacements done in aggregates for a given node (each
  439. node has its linked list). */
  440. struct GTY(()) ipa_agg_replacement_value
  441. {
  442. /* Next item in the linked list. */
  443. struct ipa_agg_replacement_value *next;
  444. /* Offset within the aggregate. */
  445. HOST_WIDE_INT offset;
  446. /* The constant value. */
  447. tree value;
  448. /* The paramter index. */
  449. int index;
  450. /* Whether the value was passed by reference. */
  451. bool by_ref;
  452. };
  453. /* Structure holding information for the transformation phase of IPA-CP. */
  454. struct GTY(()) ipcp_transformation
  455. {
  456. /* Linked list of known aggregate values. */
  457. ipa_agg_replacement_value *agg_values;
  458. /* Known bits information. */
  459. vec<ipa_bits *, va_gc> *bits;
  460. /* Value range information. */
  461. vec<ipa_vr, va_gc> *m_vr;
  462. };
  463. void ipa_set_node_agg_value_chain (struct cgraph_node *node,
  464. struct ipa_agg_replacement_value *aggvals);
  465. void ipcp_transformation_initialize (void);
  466. void ipcp_free_transformation_sum (void);
  467. /* ipa_edge_args stores information related to a callsite and particularly its
  468. arguments. It can be accessed by the IPA_EDGE_REF macro. */
  469. class GTY((for_user)) ipa_edge_args
  470. {
  471. public:
  472. /* Default constructor. */
  473. ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
  474. {}
  475. /* Destructor. */
  476. ~ipa_edge_args ()
  477. {
  478. vec_free (jump_functions);
  479. vec_free (polymorphic_call_contexts);
  480. }
  481. /* Vectors of the callsite's jump function and polymorphic context
  482. information of each parameter. */
  483. vec<ipa_jump_func, va_gc> *jump_functions;
  484. vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
  485. };
  486. /* ipa_edge_args access functions. Please use these to access fields that
  487. are or will be shared among various passes. */
  488. /* Return the number of actual arguments. */
  489. static inline int
  490. ipa_get_cs_argument_count (struct ipa_edge_args *args)
  491. {
  492. return vec_safe_length (args->jump_functions);
  493. }
  494. /* Returns a pointer to the jump function for the ith argument. Please note
  495. there is no setter function as jump functions are all set up in
  496. ipa_compute_jump_functions. */
  497. static inline struct ipa_jump_func *
  498. ipa_get_ith_jump_func (struct ipa_edge_args *args, int i)
  499. {
  500. return &(*args->jump_functions)[i];
  501. }
  502. /* Returns a pointer to the polymorphic call context for the ith argument.
  503. NULL if contexts are not computed. */
  504. static inline struct ipa_polymorphic_call_context *
  505. ipa_get_ith_polymorhic_call_context (struct ipa_edge_args *args, int i)
  506. {
  507. if (!args->polymorphic_call_contexts)
  508. return NULL;
  509. return &(*args->polymorphic_call_contexts)[i];
  510. }
  511. /* Function summary for ipa_node_params. */
  512. class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
  513. {
  514. public:
  515. ipa_node_params_t (symbol_table *table, bool ggc):
  516. function_summary<ipa_node_params *> (table, ggc) { }
  517. /* Hook that is called by summary when a node is duplicated. */
  518. virtual void duplicate (cgraph_node *node,
  519. cgraph_node *node2,
  520. ipa_node_params *data,
  521. ipa_node_params *data2);
  522. };
  523. /* Summary to manange ipa_edge_args structures. */
  524. class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
  525. {
  526. public:
  527. ipa_edge_args_sum_t (symbol_table *table, bool ggc)
  528. : call_summary<ipa_edge_args *> (table, ggc) { }
  529. /* Hook that is called by summary when an edge is duplicated. */
  530. virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
  531. /* Hook that is called by summary when an edge is duplicated. */
  532. virtual void duplicate (cgraph_edge *src,
  533. cgraph_edge *dst,
  534. ipa_edge_args *old_args,
  535. ipa_edge_args *new_args);
  536. };
  537. /* Function summary where the parameter infos are actually stored. */
  538. extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
  539. /* Call summary to store information about edges such as jump functions. */
  540. extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
  541. /* Function summary for IPA-CP transformation. */
  542. class ipcp_transformation_t
  543. : public function_summary<ipcp_transformation *>
  544. {
  545. public:
  546. ipcp_transformation_t (symbol_table *table, bool ggc):
  547. function_summary<ipcp_transformation *> (table, ggc) {}
  548. ~ipcp_transformation_t () {}
  549. static ipcp_transformation_t *create_ggc (symbol_table *symtab)
  550. {
  551. ipcp_transformation_t *summary
  552. = new (ggc_cleared_alloc <ipcp_transformation_t> ())
  553. ipcp_transformation_t (symtab, true);
  554. return summary;
  555. }
  556. };
  557. /* Function summary where the IPA CP transformations are actually stored. */
  558. extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
  559. /* Return the associated parameter/argument info corresponding to the given
  560. node/edge. */
  561. #define IPA_NODE_REF(NODE) (ipa_node_params_sum->get_create (NODE))
  562. #define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get_create (EDGE))
  563. /* This macro checks validity of index returned by
  564. ipa_get_param_decl_index function. */
  565. #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
  566. /* Creating and freeing ipa_node_params and ipa_edge_args. */
  567. void ipa_create_all_node_params (void);
  568. void ipa_create_all_edge_args (void);
  569. void ipa_check_create_edge_args (void);
  570. void ipa_free_all_node_params (void);
  571. void ipa_free_all_edge_args (void);
  572. void ipa_free_all_structures_after_ipa_cp (void);
  573. void ipa_free_all_structures_after_iinln (void);
  574. void ipa_register_cgraph_hooks (void);
  575. int count_formal_params (tree fndecl);
  576. /* This function ensures the array of node param infos is big enough to
  577. accommodate a structure for all nodes and reallocates it if not. */
  578. static inline void
  579. ipa_check_create_node_params (void)
  580. {
  581. if (!ipa_node_params_sum)
  582. ipa_node_params_sum
  583. = (new (ggc_cleared_alloc <ipa_node_params_t> ())
  584. ipa_node_params_t (symtab, true));
  585. }
  586. /* Returns true if edge summary contains a record for EDGE. The main purpose
  587. of this function is that debug dumping function can check info availability
  588. without causing allocations. */
  589. static inline bool
  590. ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
  591. {
  592. return ipa_edge_args_sum->exists (edge);
  593. }
  594. static inline ipcp_transformation *
  595. ipcp_get_transformation_summary (cgraph_node *node)
  596. {
  597. if (ipcp_transformation_sum == NULL)
  598. return NULL;
  599. return ipcp_transformation_sum->get (node);
  600. }
  601. /* Return the aggregate replacements for NODE, if there are any. */
  602. static inline struct ipa_agg_replacement_value *
  603. ipa_get_agg_replacements_for_node (cgraph_node *node)
  604. {
  605. ipcp_transformation *ts = ipcp_get_transformation_summary (node);
  606. return ts ? ts->agg_values : NULL;
  607. }
  608. /* Function formal parameters related computations. */
  609. void ipa_initialize_node_params (struct cgraph_node *node);
  610. bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
  611. vec<cgraph_edge *> *new_edges);
  612. /* Indirect edge and binfo processing. */
  613. tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
  614. vec<tree> ,
  615. vec<ipa_polymorphic_call_context>,
  616. vec<ipa_agg_jump_function_p>,
  617. bool *);
  618. struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
  619. bool speculative = false);
  620. tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
  621. ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
  622. const widest_int &mask);
  623. /* Functions related to both. */
  624. void ipa_analyze_node (struct cgraph_node *);
  625. /* Aggregate jump function related functions. */
  626. tree ipa_find_agg_cst_for_param (struct ipa_agg_jump_function *agg, tree scalar,
  627. HOST_WIDE_INT offset, bool by_ref,
  628. bool *from_global_constant = NULL);
  629. bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
  630. vec<ipa_param_descriptor, va_gc> *descriptors,
  631. gimple *stmt, tree op, int *index_p,
  632. HOST_WIDE_INT *offset_p, HOST_WIDE_INT *size_p,
  633. bool *by_ref, bool *guaranteed_unmodified = NULL);
  634. /* Debugging interface. */
  635. void ipa_print_node_params (FILE *, struct cgraph_node *node);
  636. void ipa_print_all_params (FILE *);
  637. void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
  638. void ipa_print_all_jump_functions (FILE * f);
  639. void ipcp_verify_propagated_values (void);
  640. template <typename value>
  641. class ipcp_value;
  642. extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
  643. extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
  644. ipcp_poly_ctx_values_pool;
  645. template <typename valtype>
  646. class ipcp_value_source;
  647. extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
  648. class ipcp_agg_lattice;
  649. extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
  650. void ipa_dump_agg_replacement_values (FILE *f,
  651. struct ipa_agg_replacement_value *av);
  652. void ipa_prop_write_jump_functions (void);
  653. void ipa_prop_read_jump_functions (void);
  654. void ipcp_write_transformation_summaries (void);
  655. void ipcp_read_transformation_summaries (void);
  656. int ipa_get_param_decl_index (struct ipa_node_params *, tree);
  657. tree ipa_value_from_jfunc (struct ipa_node_params *info,
  658. struct ipa_jump_func *jfunc, tree type);
  659. unsigned int ipcp_transform_function (struct cgraph_node *node);
  660. ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
  661. cgraph_edge *,
  662. int,
  663. ipa_jump_func *);
  664. void ipa_dump_param (FILE *, struct ipa_node_params *info, int i);
  665. void ipa_release_body_info (struct ipa_func_body_info *);
  666. tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
  667. /* From tree-sra.c: */
  668. tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
  669. gimple_stmt_iterator *, bool);
  670. /* In ipa-cp.c */
  671. void ipa_cp_c_finalize (void);
  672. #endif /* IPA_PROP_H */