ipa-prop.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. /* Interprocedural analyses.
  2. Copyright (C) 2005-2020 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_LOAD_AGG is a compound pass-through jump function, in which primary
  32. operation on formal parameter is memory dereference that loads a value from
  33. a part of an aggregate, which is represented or pointed to by the formal
  34. parameter. Moreover, an additional unary/binary operation can be applied on
  35. the loaded value, and final result is passed as actual argument of callee
  36. (e.g. *(param_1(D) + 4) op 24 ). It is meant to describe usage of aggregate
  37. parameter or by-reference parameter referenced in argument passing, commonly
  38. found in C++ and Fortran.
  39. IPA_JF_ANCESTOR is a special pass-through jump function, which means that
  40. the result is an address of a part of the object pointed to by the formal
  41. parameter to which the function refers. It is mainly intended to represent
  42. getting addresses of ancestor fields in C++
  43. (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is
  44. NULL, ancestor jump function must behave like a simple pass-through.
  45. Other pass-through functions can either simply pass on an unchanged formal
  46. parameter or can apply one simple binary operation to it (such jump
  47. functions are called polynomial).
  48. Jump functions are computed in ipa-prop.c by function
  49. update_call_notes_after_inlining. Some information can be lost and jump
  50. functions degraded accordingly when inlining, see
  51. update_call_notes_after_inlining in the same file. */
  52. enum jump_func_type
  53. {
  54. IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */
  55. IPA_JF_CONST, /* represented by field costant */
  56. IPA_JF_PASS_THROUGH, /* represented by field pass_through */
  57. IPA_JF_LOAD_AGG, /* represented by field load_agg */
  58. IPA_JF_ANCESTOR /* represented by field ancestor */
  59. };
  60. struct ipa_cst_ref_desc;
  61. /* Structure holding data required to describe a constant jump function. */
  62. struct GTY(()) ipa_constant_data
  63. {
  64. /* THe value of the constant. */
  65. tree value;
  66. /* Pointer to the structure that describes the reference. */
  67. struct ipa_cst_ref_desc GTY((skip)) *rdesc;
  68. };
  69. /* Structure holding data required to describe a pass-through jump function. */
  70. struct GTY(()) ipa_pass_through_data
  71. {
  72. /* If an operation is to be performed on the original parameter, this is the
  73. second (constant) operand. */
  74. tree operand;
  75. /* Number of the caller's formal parameter being passed. */
  76. int formal_id;
  77. /* Operation that is performed on the argument before it is passed on.
  78. NOP_EXPR means no operation. Otherwise oper must be a simple binary
  79. arithmetic operation where the caller's parameter is the first operand and
  80. operand field from this structure is the second one. */
  81. enum tree_code operation;
  82. /* When the passed value is a pointer, it is set to true only when we are
  83. certain that no write to the object it points to has occurred since the
  84. caller functions started execution, except for changes noted in the
  85. aggregate part of the jump function (see description of
  86. ipa_agg_jump_function). The flag is used only when the operation is
  87. NOP_EXPR. */
  88. unsigned agg_preserved : 1;
  89. };
  90. /* Structure holding data required to describe a load-value-from-aggregate
  91. jump function. */
  92. struct GTY(()) ipa_load_agg_data
  93. {
  94. /* Inherit from pass through jump function, describing unary/binary
  95. operation on the value loaded from aggregate that is represented or
  96. pointed to by the formal parameter, specified by formal_id in this
  97. pass_through jump function data structure. */
  98. struct ipa_pass_through_data pass_through;
  99. /* Type of the value loaded from the aggregate. */
  100. tree type;
  101. /* Offset at which the value is located within the aggregate. */
  102. HOST_WIDE_INT offset;
  103. /* True if loaded by reference (the aggregate is pointed to by the formal
  104. parameter) or false if loaded by value (the aggregate is represented
  105. by the formal parameter). */
  106. bool by_ref;
  107. };
  108. /* Structure holding data required to describe an ancestor pass-through
  109. jump function. */
  110. struct GTY(()) ipa_ancestor_jf_data
  111. {
  112. /* Offset of the field representing the ancestor. */
  113. HOST_WIDE_INT offset;
  114. /* Number of the caller's formal parameter being passed. */
  115. int formal_id;
  116. /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */
  117. unsigned agg_preserved : 1;
  118. };
  119. /* A jump function for an aggregate part at a given offset, which describes how
  120. it content value is generated. All unlisted positions are assumed to have a
  121. value defined in an unknown way. */
  122. struct GTY(()) ipa_agg_jf_item
  123. {
  124. /* The offset for the aggregate part. */
  125. HOST_WIDE_INT offset;
  126. /* Data type of the aggregate part. */
  127. tree type;
  128. /* Jump function type. */
  129. enum jump_func_type jftype;
  130. /* Represents a value of jump function. constant represents the actual constant
  131. in constant jump function content. pass_through is used only in simple pass
  132. through jump function context. load_agg is for load-value-from-aggregate
  133. jump function context. */
  134. union jump_func_agg_value
  135. {
  136. tree GTY ((tag ("IPA_JF_CONST"))) constant;
  137. struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
  138. struct ipa_load_agg_data GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg;
  139. } GTY ((desc ("%1.jftype"))) value;
  140. };
  141. /* Jump functions describing a set of aggregate contents. */
  142. struct GTY(()) ipa_agg_jump_function
  143. {
  144. /* Description of the individual jump function item. */
  145. vec<ipa_agg_jf_item, va_gc> *items;
  146. /* True if the data was passed by reference (as opposed to by value). */
  147. bool by_ref;
  148. };
  149. /* An element in an aggregate part describing a known value at a given offset.
  150. All unlisted positions are assumed to be unknown and all listed values must
  151. fulfill is_gimple_ip_invariant. */
  152. struct ipa_agg_value
  153. {
  154. /* The offset at which the known value is located within the aggregate. */
  155. HOST_WIDE_INT offset;
  156. /* The known constant. */
  157. tree value;
  158. /* Return true if OTHER describes same agg value. */
  159. bool equal_to (const ipa_agg_value &other);
  160. };
  161. /* Structure describing a set of known offset/value for aggregate. */
  162. struct ipa_agg_value_set
  163. {
  164. /* Description of the individual item. */
  165. vec<ipa_agg_value> items;
  166. /* True if the data was passed by reference (as opposed to by value). */
  167. bool by_ref;
  168. /* Return true if OTHER describes same agg values. */
  169. bool equal_to (const ipa_agg_value_set &other)
  170. {
  171. if (by_ref != other.by_ref)
  172. return false;
  173. if (items.length () != other.items.length ())
  174. return false;
  175. for (unsigned int i = 0; i < items.length (); i++)
  176. if (!items[i].equal_to (other.items[i]))
  177. return false;
  178. return true;
  179. }
  180. /* Return true if there is any value for aggregate. */
  181. bool is_empty () const
  182. {
  183. return items.is_empty ();
  184. }
  185. ipa_agg_value_set copy () const
  186. {
  187. ipa_agg_value_set new_copy;
  188. new_copy.items = items.copy ();
  189. new_copy.by_ref = by_ref;
  190. return new_copy;
  191. }
  192. void release ()
  193. {
  194. items.release ();
  195. }
  196. };
  197. /* Return copy of a vec<ipa_agg_value_set>. */
  198. static inline vec<ipa_agg_value_set>
  199. ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs)
  200. {
  201. vec<ipa_agg_value_set> aggs_copy = vNULL;
  202. if (!aggs.is_empty ())
  203. {
  204. ipa_agg_value_set *agg;
  205. int i;
  206. aggs_copy.reserve_exact (aggs.length ());
  207. FOR_EACH_VEC_ELT (aggs, i, agg)
  208. aggs_copy.quick_push (agg->copy ());
  209. }
  210. return aggs_copy;
  211. }
  212. /* For vec<ipa_agg_value_set>, DO NOT call release(), use below function
  213. instead. Because ipa_agg_value_set contains a field of vector type, we
  214. should release this child vector in each element before reclaiming the
  215. whole vector. */
  216. static inline void
  217. ipa_release_agg_values (vec<ipa_agg_value_set> &aggs,
  218. bool release_vector = true)
  219. {
  220. ipa_agg_value_set *agg;
  221. int i;
  222. FOR_EACH_VEC_ELT (aggs, i, agg)
  223. agg->release ();
  224. if (release_vector)
  225. aggs.release ();
  226. }
  227. /* Information about zero/non-zero bits. */
  228. class GTY(()) ipa_bits
  229. {
  230. public:
  231. /* The propagated value. */
  232. widest_int value;
  233. /* Mask corresponding to the value.
  234. Similar to ccp_lattice_t, if xth bit of mask is 0,
  235. implies xth bit of value is constant. */
  236. widest_int mask;
  237. };
  238. /* Info about value ranges. */
  239. class GTY(()) ipa_vr
  240. {
  241. public:
  242. /* The data fields below are valid only if known is true. */
  243. bool known;
  244. enum value_range_kind type;
  245. wide_int min;
  246. wide_int max;
  247. bool nonzero_p (tree) const;
  248. };
  249. /* A jump function for a callsite represents the values passed as actual
  250. arguments of the callsite. See enum jump_func_type for the various
  251. types of jump functions supported. */
  252. struct GTY (()) ipa_jump_func
  253. {
  254. /* Aggregate jump function description. See struct ipa_agg_jump_function
  255. and its description. */
  256. struct ipa_agg_jump_function agg;
  257. /* Information about zero/non-zero bits. The pointed to structure is shared
  258. betweed different jump functions. Use ipa_set_jfunc_bits to set this
  259. field. */
  260. class ipa_bits *bits;
  261. /* Information about value range, containing valid data only when vr_known is
  262. true. The pointed to structure is shared betweed different jump
  263. functions. Use ipa_set_jfunc_vr to set this field. */
  264. class value_range *m_vr;
  265. enum jump_func_type type;
  266. /* Represents a value of a jump function. pass_through is used only in jump
  267. function context. constant represents the actual constant in constant jump
  268. functions and member_cst holds constant c++ member functions. */
  269. union jump_func_value
  270. {
  271. struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant;
  272. struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through;
  273. struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor;
  274. } GTY ((desc ("%1.type"))) value;
  275. };
  276. /* Return the constant stored in a constant jump functin JFUNC. */
  277. static inline tree
  278. ipa_get_jf_constant (struct ipa_jump_func *jfunc)
  279. {
  280. gcc_checking_assert (jfunc->type == IPA_JF_CONST);
  281. return jfunc->value.constant.value;
  282. }
  283. static inline struct ipa_cst_ref_desc *
  284. ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc)
  285. {
  286. gcc_checking_assert (jfunc->type == IPA_JF_CONST);
  287. return jfunc->value.constant.rdesc;
  288. }
  289. /* Return the operand of a pass through jmp function JFUNC. */
  290. static inline tree
  291. ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc)
  292. {
  293. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  294. return jfunc->value.pass_through.operand;
  295. }
  296. /* Return the number of the caller's formal parameter that a pass through jump
  297. function JFUNC refers to. */
  298. static inline int
  299. ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc)
  300. {
  301. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  302. return jfunc->value.pass_through.formal_id;
  303. }
  304. /* Return operation of a pass through jump function JFUNC. */
  305. static inline enum tree_code
  306. ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc)
  307. {
  308. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  309. return jfunc->value.pass_through.operation;
  310. }
  311. /* Return the agg_preserved flag of a pass through jump function JFUNC. */
  312. static inline bool
  313. ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc)
  314. {
  315. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  316. return jfunc->value.pass_through.agg_preserved;
  317. }
  318. /* Return true if pass through jump function JFUNC preserves type
  319. information. */
  320. static inline bool
  321. ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc)
  322. {
  323. gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH);
  324. return jfunc->value.pass_through.agg_preserved;
  325. }
  326. /* Return the offset of an ancestor jump function JFUNC. */
  327. static inline HOST_WIDE_INT
  328. ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc)
  329. {
  330. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  331. return jfunc->value.ancestor.offset;
  332. }
  333. /* Return the number of the caller's formal parameter that an ancestor jump
  334. function JFUNC refers to. */
  335. static inline int
  336. ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc)
  337. {
  338. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  339. return jfunc->value.ancestor.formal_id;
  340. }
  341. /* Return the agg_preserved flag of an ancestor jump function JFUNC. */
  342. static inline bool
  343. ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc)
  344. {
  345. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  346. return jfunc->value.ancestor.agg_preserved;
  347. }
  348. /* Return true if ancestor jump function JFUNC presrves type information. */
  349. static inline bool
  350. ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc)
  351. {
  352. gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR);
  353. return jfunc->value.ancestor.agg_preserved;
  354. }
  355. /* Summary describing a single formal parameter. */
  356. struct GTY(()) ipa_param_descriptor
  357. {
  358. /* In analysis and modification phase, this is the PARAM_DECL of this
  359. parameter, in IPA LTO phase, this is the type of the described
  360. parameter or NULL if not known. Do not read this field directly but
  361. through ipa_get_param and ipa_get_type as appropriate. */
  362. tree decl_or_type;
  363. /* If all uses of the parameter are described by ipa-prop structures, this
  364. says how many there are. If any use could not be described by means of
  365. ipa-prop structures, this is IPA_UNDESCRIBED_USE. */
  366. int controlled_uses;
  367. unsigned int move_cost : 28;
  368. /* The parameter is used. */
  369. unsigned used : 1;
  370. unsigned used_by_ipa_predicates : 1;
  371. unsigned used_by_indirect_call : 1;
  372. unsigned used_by_polymorphic_call : 1;
  373. };
  374. /* ipa_node_params stores information related to formal parameters of functions
  375. and some other information for interprocedural passes that operate on
  376. parameters (such as ipa-cp). */
  377. class GTY((for_user)) ipa_node_params
  378. {
  379. public:
  380. /* Default constructor. */
  381. ipa_node_params ();
  382. /* Default destructor. */
  383. ~ipa_node_params ();
  384. /* Information about individual formal parameters that are gathered when
  385. summaries are generated. */
  386. vec<ipa_param_descriptor, va_gc> *descriptors;
  387. /* Pointer to an array of structures describing individual formal
  388. parameters. */
  389. class ipcp_param_lattices * GTY((skip)) lattices;
  390. /* Only for versioned nodes this field would not be NULL,
  391. it points to the node that IPA cp cloned from. */
  392. struct cgraph_node * GTY((skip)) ipcp_orig_node;
  393. /* If this node is an ipa-cp clone, these are the known constants that
  394. describe what it has been specialized for. */
  395. vec<tree> GTY((skip)) known_csts;
  396. /* If this node is an ipa-cp clone, these are the known polymorphic contexts
  397. that describe what it has been specialized for. */
  398. vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts;
  399. /* Whether the param uses analysis and jump function computation has already
  400. been performed. */
  401. unsigned analysis_done : 1;
  402. /* Whether the function is enqueued in ipa-cp propagation stack. */
  403. unsigned node_enqueued : 1;
  404. /* Whether we should create a specialized version based on values that are
  405. known to be constant in all contexts. */
  406. unsigned do_clone_for_all_contexts : 1;
  407. /* Set if this is an IPA-CP clone for all contexts. */
  408. unsigned is_all_contexts_clone : 1;
  409. /* Node has been completely replaced by clones and will be removed after
  410. ipa-cp is finished. */
  411. unsigned node_dead : 1;
  412. /* Node is involved in a recursion, potentionally indirect. */
  413. unsigned node_within_scc : 1;
  414. /* Node contains only direct recursion. */
  415. unsigned node_is_self_scc : 1;
  416. /* Node is calling a private function called only once. */
  417. unsigned node_calling_single_call : 1;
  418. /* False when there is something makes versioning impossible. */
  419. unsigned versionable : 1;
  420. };
  421. inline
  422. ipa_node_params::ipa_node_params ()
  423. : descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL),
  424. known_csts (vNULL), known_contexts (vNULL), analysis_done (0),
  425. node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0),
  426. node_dead (0), node_within_scc (0), node_calling_single_call (0),
  427. versionable (0)
  428. {
  429. }
  430. inline
  431. ipa_node_params::~ipa_node_params ()
  432. {
  433. free (lattices);
  434. known_csts.release ();
  435. known_contexts.release ();
  436. }
  437. /* Intermediate information that we get from alias analysis about a particular
  438. parameter in a particular basic_block. When a parameter or the memory it
  439. references is marked modified, we use that information in all dominated
  440. blocks without consulting alias analysis oracle. */
  441. struct ipa_param_aa_status
  442. {
  443. /* Set when this structure contains meaningful information. If not, the
  444. structure describing a dominating BB should be used instead. */
  445. bool valid;
  446. /* Whether we have seen something which might have modified the data in
  447. question. PARM is for the parameter itself, REF is for data it points to
  448. but using the alias type of individual accesses and PT is the same thing
  449. but for computing aggregate pass-through functions using a very inclusive
  450. ao_ref. */
  451. bool parm_modified, ref_modified, pt_modified;
  452. };
  453. /* Information related to a given BB that used only when looking at function
  454. body. */
  455. struct ipa_bb_info
  456. {
  457. /* Call graph edges going out of this BB. */
  458. vec<cgraph_edge *> cg_edges;
  459. /* Alias analysis statuses of each formal parameter at this bb. */
  460. vec<ipa_param_aa_status> param_aa_statuses;
  461. };
  462. /* Structure with global information that is only used when looking at function
  463. body. */
  464. struct ipa_func_body_info
  465. {
  466. /* The node that is being analyzed. */
  467. cgraph_node *node;
  468. /* Its info. */
  469. class ipa_node_params *info;
  470. /* Information about individual BBs. */
  471. vec<ipa_bb_info> bb_infos;
  472. /* Number of parameters. */
  473. int param_count;
  474. /* Number of statements we are still allowed to walked by when analyzing this
  475. function. */
  476. unsigned int aa_walk_budget;
  477. };
  478. /* ipa_node_params access functions. Please use these to access fields that
  479. are or will be shared among various passes. */
  480. /* Return the number of formal parameters. */
  481. static inline int
  482. ipa_get_param_count (class ipa_node_params *info)
  483. {
  484. return vec_safe_length (info->descriptors);
  485. }
  486. /* Return the declaration of Ith formal parameter of the function corresponding
  487. to INFO. Note there is no setter function as this array is built just once
  488. using ipa_initialize_node_params. This function should not be called in
  489. WPA. */
  490. static inline tree
  491. ipa_get_param (class ipa_node_params *info, int i)
  492. {
  493. gcc_checking_assert (info->descriptors);
  494. tree t = (*info->descriptors)[i].decl_or_type;
  495. gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
  496. return t;
  497. }
  498. /* Return the type of Ith formal parameter of the function corresponding
  499. to INFO if it is known or NULL if not. */
  500. static inline tree
  501. ipa_get_type (class ipa_node_params *info, int i)
  502. {
  503. if (vec_safe_length (info->descriptors) <= (unsigned) i)
  504. return NULL;
  505. tree t = (*info->descriptors)[i].decl_or_type;
  506. if (!t)
  507. return NULL;
  508. if (TYPE_P (t))
  509. return t;
  510. gcc_checking_assert (TREE_CODE (t) == PARM_DECL);
  511. return TREE_TYPE (t);
  512. }
  513. /* Return the move cost of Ith formal parameter of the function corresponding
  514. to INFO. */
  515. static inline int
  516. ipa_get_param_move_cost (class ipa_node_params *info, int i)
  517. {
  518. gcc_checking_assert (info->descriptors);
  519. return (*info->descriptors)[i].move_cost;
  520. }
  521. /* Set the used flag corresponding to the Ith formal parameter of the function
  522. associated with INFO to VAL. */
  523. static inline void
  524. ipa_set_param_used (class ipa_node_params *info, int i, bool val)
  525. {
  526. gcc_checking_assert (info->descriptors);
  527. (*info->descriptors)[i].used = val;
  528. }
  529. /* Set the used_by_ipa_predicates flag corresponding to the Ith formal
  530. parameter of the function associated with INFO to VAL. */
  531. static inline void
  532. ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val)
  533. {
  534. gcc_checking_assert (info->descriptors);
  535. (*info->descriptors)[i].used_by_ipa_predicates = val;
  536. }
  537. /* Set the used_by_indirect_call flag corresponding to the Ith formal
  538. parameter of the function associated with INFO to VAL. */
  539. static inline void
  540. ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val)
  541. {
  542. gcc_checking_assert (info->descriptors);
  543. (*info->descriptors)[i].used_by_indirect_call = val;
  544. }
  545. /* Set the .used_by_polymorphic_call flag corresponding to the Ith formal
  546. parameter of the function associated with INFO to VAL. */
  547. static inline void
  548. ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val)
  549. {
  550. gcc_checking_assert (info->descriptors);
  551. (*info->descriptors)[i].used_by_polymorphic_call = val;
  552. }
  553. /* Return how many uses described by ipa-prop a parameter has or
  554. IPA_UNDESCRIBED_USE if there is a use that is not described by these
  555. structures. */
  556. static inline int
  557. ipa_get_controlled_uses (class ipa_node_params *info, int i)
  558. {
  559. /* FIXME: introducing speculation causes out of bounds access here. */
  560. if (vec_safe_length (info->descriptors) > (unsigned)i)
  561. return (*info->descriptors)[i].controlled_uses;
  562. return IPA_UNDESCRIBED_USE;
  563. }
  564. /* Set the controlled counter of a given parameter. */
  565. static inline void
  566. ipa_set_controlled_uses (class ipa_node_params *info, int i, int val)
  567. {
  568. gcc_checking_assert (info->descriptors);
  569. (*info->descriptors)[i].controlled_uses = val;
  570. }
  571. /* Return the used flag corresponding to the Ith formal parameter of the
  572. function associated with INFO. */
  573. static inline bool
  574. ipa_is_param_used (class ipa_node_params *info, int i)
  575. {
  576. gcc_checking_assert (info->descriptors);
  577. return (*info->descriptors)[i].used;
  578. }
  579. /* Return the used_by_ipa_predicates flag corresponding to the Ith formal
  580. parameter of the function associated with INFO. */
  581. static inline bool
  582. ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i)
  583. {
  584. gcc_checking_assert (info->descriptors);
  585. return (*info->descriptors)[i].used_by_ipa_predicates;
  586. }
  587. /* Return the used_by_indirect_call flag corresponding to the Ith formal
  588. parameter of the function associated with INFO. */
  589. static inline bool
  590. ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i)
  591. {
  592. gcc_checking_assert (info->descriptors);
  593. return (*info->descriptors)[i].used_by_indirect_call;
  594. }
  595. /* Return the used_by_polymorphic_call flag corresponding to the Ith formal
  596. parameter of the function associated with INFO. */
  597. static inline bool
  598. ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i)
  599. {
  600. gcc_checking_assert (info->descriptors);
  601. return (*info->descriptors)[i].used_by_polymorphic_call;
  602. }
  603. /* Information about replacements done in aggregates for a given node (each
  604. node has its linked list). */
  605. struct GTY(()) ipa_agg_replacement_value
  606. {
  607. /* Next item in the linked list. */
  608. struct ipa_agg_replacement_value *next;
  609. /* Offset within the aggregate. */
  610. HOST_WIDE_INT offset;
  611. /* The constant value. */
  612. tree value;
  613. /* The parameter index. */
  614. int index;
  615. /* Whether the value was passed by reference. */
  616. bool by_ref;
  617. };
  618. /* Structure holding information for the transformation phase of IPA-CP. */
  619. struct GTY(()) ipcp_transformation
  620. {
  621. /* Linked list of known aggregate values. */
  622. ipa_agg_replacement_value *agg_values;
  623. /* Known bits information. */
  624. vec<ipa_bits *, va_gc> *bits;
  625. /* Value range information. */
  626. vec<ipa_vr, va_gc> *m_vr;
  627. /* Default constructor. */
  628. ipcp_transformation ()
  629. : agg_values (NULL), bits (NULL), m_vr (NULL)
  630. { }
  631. /* Default destructor. */
  632. ~ipcp_transformation ()
  633. {
  634. ipa_agg_replacement_value *agg = agg_values;
  635. while (agg)
  636. {
  637. ipa_agg_replacement_value *next = agg->next;
  638. ggc_free (agg);
  639. agg = next;
  640. }
  641. vec_free (bits);
  642. vec_free (m_vr);
  643. }
  644. };
  645. void ipa_set_node_agg_value_chain (struct cgraph_node *node,
  646. struct ipa_agg_replacement_value *aggvals);
  647. void ipcp_transformation_initialize (void);
  648. void ipcp_free_transformation_sum (void);
  649. /* ipa_edge_args stores information related to a callsite and particularly its
  650. arguments. It can be accessed by the IPA_EDGE_REF macro. */
  651. class GTY((for_user)) ipa_edge_args
  652. {
  653. public:
  654. /* Default constructor. */
  655. ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL)
  656. {}
  657. /* Destructor. */
  658. ~ipa_edge_args ()
  659. {
  660. vec_free (jump_functions);
  661. vec_free (polymorphic_call_contexts);
  662. }
  663. /* Vectors of the callsite's jump function and polymorphic context
  664. information of each parameter. */
  665. vec<ipa_jump_func, va_gc> *jump_functions;
  666. vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts;
  667. };
  668. /* ipa_edge_args access functions. Please use these to access fields that
  669. are or will be shared among various passes. */
  670. /* Return the number of actual arguments. */
  671. static inline int
  672. ipa_get_cs_argument_count (class ipa_edge_args *args)
  673. {
  674. return vec_safe_length (args->jump_functions);
  675. }
  676. /* Returns a pointer to the jump function for the ith argument. Please note
  677. there is no setter function as jump functions are all set up in
  678. ipa_compute_jump_functions. */
  679. static inline struct ipa_jump_func *
  680. ipa_get_ith_jump_func (class ipa_edge_args *args, int i)
  681. {
  682. return &(*args->jump_functions)[i];
  683. }
  684. /* Returns a pointer to the polymorphic call context for the ith argument.
  685. NULL if contexts are not computed. */
  686. static inline class ipa_polymorphic_call_context *
  687. ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i)
  688. {
  689. if (!args->polymorphic_call_contexts)
  690. return NULL;
  691. return &(*args->polymorphic_call_contexts)[i];
  692. }
  693. /* Function summary for ipa_node_params. */
  694. class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *>
  695. {
  696. public:
  697. ipa_node_params_t (symbol_table *table, bool ggc):
  698. function_summary<ipa_node_params *> (table, ggc) { }
  699. /* Hook that is called by summary when a node is duplicated. */
  700. virtual void duplicate (cgraph_node *node,
  701. cgraph_node *node2,
  702. ipa_node_params *data,
  703. ipa_node_params *data2);
  704. };
  705. /* Summary to manange ipa_edge_args structures. */
  706. class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *>
  707. {
  708. public:
  709. ipa_edge_args_sum_t (symbol_table *table, bool ggc)
  710. : call_summary<ipa_edge_args *> (table, ggc) { }
  711. void remove (cgraph_edge *edge)
  712. {
  713. call_summary <ipa_edge_args *>::remove (edge);
  714. }
  715. /* Hook that is called by summary when an edge is removed. */
  716. virtual void remove (cgraph_edge *cs, ipa_edge_args *args);
  717. /* Hook that is called by summary when an edge is duplicated. */
  718. virtual void duplicate (cgraph_edge *src,
  719. cgraph_edge *dst,
  720. ipa_edge_args *old_args,
  721. ipa_edge_args *new_args);
  722. };
  723. /* Function summary where the parameter infos are actually stored. */
  724. extern GTY(()) ipa_node_params_t * ipa_node_params_sum;
  725. /* Call summary to store information about edges such as jump functions. */
  726. extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum;
  727. /* Function summary for IPA-CP transformation. */
  728. class ipcp_transformation_t
  729. : public function_summary<ipcp_transformation *>
  730. {
  731. public:
  732. ipcp_transformation_t (symbol_table *table, bool ggc):
  733. function_summary<ipcp_transformation *> (table, ggc) {}
  734. ~ipcp_transformation_t () {}
  735. static ipcp_transformation_t *create_ggc (symbol_table *symtab)
  736. {
  737. ipcp_transformation_t *summary
  738. = new (ggc_alloc_no_dtor <ipcp_transformation_t> ())
  739. ipcp_transformation_t (symtab, true);
  740. return summary;
  741. }
  742. /* Hook that is called by summary when a node is duplicated. */
  743. virtual void duplicate (cgraph_node *node,
  744. cgraph_node *node2,
  745. ipcp_transformation *data,
  746. ipcp_transformation *data2);
  747. };
  748. /* Function summary where the IPA CP transformations are actually stored. */
  749. extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum;
  750. /* Return the associated parameter/argument info corresponding to the given
  751. node/edge. */
  752. #define IPA_NODE_REF(NODE) (ipa_node_params_sum->get (NODE))
  753. #define IPA_NODE_REF_GET_CREATE(NODE) (ipa_node_params_sum->get_create (NODE))
  754. #define IPA_EDGE_REF(EDGE) (ipa_edge_args_sum->get (EDGE))
  755. #define IPA_EDGE_REF_GET_CREATE(EDGE) (ipa_edge_args_sum->get_create (EDGE))
  756. /* This macro checks validity of index returned by
  757. ipa_get_param_decl_index function. */
  758. #define IS_VALID_JUMP_FUNC_INDEX(I) ((I) != -1)
  759. /* Creating and freeing ipa_node_params and ipa_edge_args. */
  760. void ipa_create_all_node_params (void);
  761. void ipa_create_all_edge_args (void);
  762. void ipa_check_create_edge_args (void);
  763. void ipa_free_all_node_params (void);
  764. void ipa_free_all_edge_args (void);
  765. void ipa_free_all_structures_after_ipa_cp (void);
  766. void ipa_free_all_structures_after_iinln (void);
  767. void ipa_register_cgraph_hooks (void);
  768. int count_formal_params (tree fndecl);
  769. /* This function ensures the array of node param infos is big enough to
  770. accommodate a structure for all nodes and reallocates it if not. */
  771. static inline void
  772. ipa_check_create_node_params (void)
  773. {
  774. if (!ipa_node_params_sum)
  775. ipa_node_params_sum
  776. = (new (ggc_alloc_no_dtor <ipa_node_params_t> ())
  777. ipa_node_params_t (symtab, true));
  778. }
  779. /* Returns true if edge summary contains a record for EDGE. The main purpose
  780. of this function is that debug dumping function can check info availability
  781. without causing allocations. */
  782. static inline bool
  783. ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge)
  784. {
  785. return ipa_edge_args_sum->exists (edge);
  786. }
  787. static inline ipcp_transformation *
  788. ipcp_get_transformation_summary (cgraph_node *node)
  789. {
  790. if (ipcp_transformation_sum == NULL)
  791. return NULL;
  792. return ipcp_transformation_sum->get (node);
  793. }
  794. /* Return the aggregate replacements for NODE, if there are any. */
  795. static inline struct ipa_agg_replacement_value *
  796. ipa_get_agg_replacements_for_node (cgraph_node *node)
  797. {
  798. ipcp_transformation *ts = ipcp_get_transformation_summary (node);
  799. return ts ? ts->agg_values : NULL;
  800. }
  801. /* Function formal parameters related computations. */
  802. void ipa_initialize_node_params (struct cgraph_node *node);
  803. bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
  804. vec<cgraph_edge *> *new_edges);
  805. /* Indirect edge and binfo processing. */
  806. tree ipa_get_indirect_edge_target (struct cgraph_edge *ie,
  807. vec<tree>,
  808. vec<ipa_polymorphic_call_context>,
  809. vec<ipa_agg_value_set>,
  810. bool *);
  811. struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree,
  812. bool speculative = false);
  813. tree ipa_impossible_devirt_target (struct cgraph_edge *, tree);
  814. ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value,
  815. const widest_int &mask);
  816. /* Functions related to both. */
  817. void ipa_analyze_node (struct cgraph_node *);
  818. /* Aggregate jump function related functions. */
  819. tree ipa_find_agg_cst_for_param (struct ipa_agg_value_set *agg, tree scalar,
  820. HOST_WIDE_INT offset, bool by_ref,
  821. bool *from_global_constant = NULL);
  822. bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
  823. vec<ipa_param_descriptor, va_gc> *descriptors,
  824. gimple *stmt, tree op, int *index_p,
  825. HOST_WIDE_INT *offset_p, poly_int64 *size_p,
  826. bool *by_ref, bool *guaranteed_unmodified = NULL);
  827. /* Debugging interface. */
  828. void ipa_print_node_params (FILE *, struct cgraph_node *node);
  829. void ipa_print_all_params (FILE *);
  830. void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node);
  831. void ipa_print_all_jump_functions (FILE * f);
  832. void ipcp_verify_propagated_values (void);
  833. template <typename value>
  834. class ipcp_value;
  835. extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool;
  836. extern object_allocator<ipcp_value<ipa_polymorphic_call_context> >
  837. ipcp_poly_ctx_values_pool;
  838. template <typename valtype>
  839. struct ipcp_value_source;
  840. extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool;
  841. struct ipcp_agg_lattice;
  842. extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool;
  843. void ipa_dump_agg_replacement_values (FILE *f,
  844. struct ipa_agg_replacement_value *av);
  845. void ipa_prop_write_jump_functions (void);
  846. void ipa_prop_read_jump_functions (void);
  847. void ipcp_write_transformation_summaries (void);
  848. void ipcp_read_transformation_summaries (void);
  849. int ipa_get_param_decl_index (class ipa_node_params *, tree);
  850. tree ipa_value_from_jfunc (class ipa_node_params *info,
  851. struct ipa_jump_func *jfunc, tree type);
  852. unsigned int ipcp_transform_function (struct cgraph_node *node);
  853. ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *,
  854. cgraph_edge *,
  855. int,
  856. ipa_jump_func *);
  857. value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *,
  858. ipa_jump_func *, tree);
  859. ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *,
  860. cgraph_node *,
  861. ipa_agg_jump_function *);
  862. void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
  863. void ipa_release_body_info (struct ipa_func_body_info *);
  864. tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
  865. bool ipcp_get_parm_bits (tree, tree *, widest_int *);
  866. /* From tree-sra.c: */
  867. tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree,
  868. gimple_stmt_iterator *, bool);
  869. /* In ipa-cp.c */
  870. void ipa_cp_c_finalize (void);
  871. #endif /* IPA_PROP_H */