1/* Interprocedural analyses. 2 Copyright (C) 2005-2022 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 3, or (at your option) any later 9version. 10 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16You should have received a copy of the GNU General Public License 17along with GCC; see the file COPYING3. If not see 18<http://www.gnu.org/licenses/>. */ 19 20#ifndef IPA_PROP_H 21#define IPA_PROP_H 22 23/* The following definitions and interfaces are used by 24 interprocedural analyses or parameters. */ 25 26#define IPA_UNDESCRIBED_USE -1 27 28/* ipa-prop.cc stuff (ipa-cp, indirect inlining): */ 29 30/* A jump function for a callsite represents the values passed as actual 31 arguments of the callsite. They were originally proposed in a paper called 32 "Interprocedural Constant Propagation", by David Callahan, Keith D Cooper, 33 Ken Kennedy, Linda Torczon in Comp86, pg 152-161. There are three main 34 types of values : 35 36 Pass-through - the caller's formal parameter is passed as an actual 37 argument, possibly one simple operation performed on it. 38 Constant - a constant (is_gimple_ip_invariant)is passed as an actual 39 argument. 40 Unknown - neither of the above. 41 42 IPA_JF_LOAD_AGG is a compound pass-through jump function, in which primary 43 operation on formal parameter is memory dereference that loads a value from 44 a part of an aggregate, which is represented or pointed to by the formal 45 parameter. Moreover, an additional unary/binary operation can be applied on 46 the loaded value, and final result is passed as actual argument of callee 47 (e.g. *(param_1(D) + 4) op 24 ). It is meant to describe usage of aggregate 48 parameter or by-reference parameter referenced in argument passing, commonly 49 found in C++ and Fortran. 50 51 IPA_JF_ANCESTOR is a special pass-through jump function, which means that 52 the result is an address of a part of the object pointed to by the formal 53 parameter to which the function refers. It is mainly intended to represent 54 getting addresses of ancestor fields in C++ 55 (e.g. &this_1(D)->D.1766.D.1756). Note that if the original pointer is 56 NULL, ancestor jump function must behave like a simple pass-through. 57 58 Other pass-through functions can either simply pass on an unchanged formal 59 parameter or can apply one simple binary operation to it (such jump 60 functions are called polynomial). 61 62 Jump functions are computed in ipa-prop.cc by function 63 update_call_notes_after_inlining. Some information can be lost and jump 64 functions degraded accordingly when inlining, see 65 update_call_notes_after_inlining in the same file. */ 66 67enum jump_func_type 68{ 69 IPA_JF_UNKNOWN = 0, /* newly allocated and zeroed jump functions default */ 70 IPA_JF_CONST, /* represented by field costant */ 71 IPA_JF_PASS_THROUGH, /* represented by field pass_through */ 72 IPA_JF_LOAD_AGG, /* represented by field load_agg */ 73 IPA_JF_ANCESTOR /* represented by field ancestor */ 74}; 75 76struct ipa_cst_ref_desc; 77 78/* Structure holding data required to describe a constant jump function. */ 79struct GTY(()) ipa_constant_data 80{ 81 /* THe value of the constant. */ 82 tree value; 83 /* Pointer to the structure that describes the reference. */ 84 struct ipa_cst_ref_desc GTY((skip)) *rdesc; 85}; 86 87/* Structure holding data required to describe a pass-through jump function. */ 88 89struct GTY(()) ipa_pass_through_data 90{ 91 /* If an operation is to be performed on the original parameter, this is the 92 second (constant) operand. */ 93 tree operand; 94 /* Number of the caller's formal parameter being passed. */ 95 int formal_id; 96 /* Operation that is performed on the argument before it is passed on. 97 Special values which have other meaning than in normal contexts: 98 - NOP_EXPR means no operation, not even type conversion. 99 - ASSERT_EXPR means that only the value in operand is allowed to pass 100 through (without any change), for all other values the result is 101 unknown. 102 Otherwise operation must be a simple binary or unary arithmetic operation 103 where the caller's parameter is the first operand and (for binary 104 operations) the operand field from this structure is the second one. */ 105 enum tree_code operation; 106 /* When the passed value is a pointer, it is set to true only when we are 107 certain that no write to the object it points to has occurred since the 108 caller functions started execution, except for changes noted in the 109 aggregate part of the jump function (see description of 110 ipa_agg_jump_function). The flag is used only when the operation is 111 NOP_EXPR. */ 112 unsigned agg_preserved : 1; 113 /* Set when the edge has already been used to decrement an appropriate 114 reference description counter and should not be decremented again. */ 115 unsigned refdesc_decremented : 1; 116}; 117 118/* Structure holding data required to describe a load-value-from-aggregate 119 jump function. */ 120 121struct GTY(()) ipa_load_agg_data 122{ 123 /* Inherit from pass through jump function, describing unary/binary 124 operation on the value loaded from aggregate that is represented or 125 pointed to by the formal parameter, specified by formal_id in this 126 pass_through jump function data structure. */ 127 struct ipa_pass_through_data pass_through; 128 /* Type of the value loaded from the aggregate. */ 129 tree type; 130 /* Offset at which the value is located within the aggregate. */ 131 HOST_WIDE_INT offset; 132 /* True if loaded by reference (the aggregate is pointed to by the formal 133 parameter) or false if loaded by value (the aggregate is represented 134 by the formal parameter). */ 135 bool by_ref; 136}; 137 138/* Structure holding data required to describe an ancestor pass-through 139 jump function. */ 140 141struct GTY(()) ipa_ancestor_jf_data 142{ 143 /* Offset of the field representing the ancestor. */ 144 HOST_WIDE_INT offset; 145 /* Number of the caller's formal parameter being passed. */ 146 int formal_id; 147 /* Flag with the same meaning like agg_preserve in ipa_pass_through_data. */ 148 unsigned agg_preserved : 1; 149 /* When set, the operation should not have any effect on NULL pointers. */ 150 unsigned keep_null : 1; 151}; 152 153/* A jump function for an aggregate part at a given offset, which describes how 154 it content value is generated. All unlisted positions are assumed to have a 155 value defined in an unknown way. */ 156 157struct GTY(()) ipa_agg_jf_item 158{ 159 /* The offset for the aggregate part. */ 160 HOST_WIDE_INT offset; 161 162 /* Data type of the aggregate part. */ 163 tree type; 164 165 /* Jump function type. */ 166 enum jump_func_type jftype; 167 168 /* Represents a value of jump function. constant represents the actual constant 169 in constant jump function content. pass_through is used only in simple pass 170 through jump function context. load_agg is for load-value-from-aggregate 171 jump function context. */ 172 union jump_func_agg_value 173 { 174 tree GTY ((tag ("IPA_JF_CONST"))) constant; 175 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through; 176 struct ipa_load_agg_data GTY ((tag ("IPA_JF_LOAD_AGG"))) load_agg; 177 } GTY ((desc ("%1.jftype"))) value; 178}; 179 180/* Jump functions describing a set of aggregate contents. */ 181 182struct GTY(()) ipa_agg_jump_function 183{ 184 /* Description of the individual jump function item. */ 185 vec<ipa_agg_jf_item, va_gc> *items; 186 /* True if the data was passed by reference (as opposed to by value). */ 187 bool by_ref; 188}; 189 190/* An element in an aggregate part describing a known value at a given offset. 191 All unlisted positions are assumed to be unknown and all listed values must 192 fulfill is_gimple_ip_invariant. */ 193 194struct ipa_agg_value 195{ 196 /* The offset at which the known value is located within the aggregate. */ 197 HOST_WIDE_INT offset; 198 199 /* The known constant. */ 200 tree value; 201 202 /* Return true if OTHER describes same agg value. */ 203 bool equal_to (const ipa_agg_value &other); 204}; 205 206/* Structure describing a set of known offset/value for aggregate. */ 207 208struct ipa_agg_value_set 209{ 210 /* Description of the individual item. */ 211 vec<ipa_agg_value> items; 212 /* True if the data was passed by reference (as opposed to by value). */ 213 bool by_ref; 214 215 /* Return true if OTHER describes same agg values. */ 216 bool equal_to (const ipa_agg_value_set &other) 217 { 218 if (by_ref != other.by_ref) 219 return false; 220 if (items.length () != other.items.length ()) 221 return false; 222 for (unsigned int i = 0; i < items.length (); i++) 223 if (!items[i].equal_to (other.items[i])) 224 return false; 225 return true; 226 } 227 228 /* Return true if there is any value for aggregate. */ 229 bool is_empty () const 230 { 231 return items.is_empty (); 232 } 233 234 ipa_agg_value_set copy () const 235 { 236 ipa_agg_value_set new_copy; 237 238 new_copy.items = items.copy (); 239 new_copy.by_ref = by_ref; 240 241 return new_copy; 242 } 243 244 void release () 245 { 246 items.release (); 247 } 248}; 249 250/* Return copy of a vec<ipa_agg_value_set>. */ 251 252static inline vec<ipa_agg_value_set> 253ipa_copy_agg_values (const vec<ipa_agg_value_set> &aggs) 254{ 255 vec<ipa_agg_value_set> aggs_copy = vNULL; 256 257 if (!aggs.is_empty ()) 258 { 259 ipa_agg_value_set *agg; 260 int i; 261 262 aggs_copy.reserve_exact (aggs.length ()); 263 264 FOR_EACH_VEC_ELT (aggs, i, agg) 265 aggs_copy.quick_push (agg->copy ()); 266 } 267 268 return aggs_copy; 269} 270 271/* For vec<ipa_agg_value_set>, DO NOT call release(), use below function 272 instead. Because ipa_agg_value_set contains a field of vector type, we 273 should release this child vector in each element before reclaiming the 274 whole vector. */ 275 276static inline void 277ipa_release_agg_values (vec<ipa_agg_value_set> &aggs, 278 bool release_vector = true) 279{ 280 ipa_agg_value_set *agg; 281 int i; 282 283 FOR_EACH_VEC_ELT (aggs, i, agg) 284 agg->release (); 285 if (release_vector) 286 aggs.release (); 287} 288 289/* Information about zero/non-zero bits. */ 290class GTY(()) ipa_bits 291{ 292public: 293 /* The propagated value. */ 294 widest_int value; 295 /* Mask corresponding to the value. 296 Similar to ccp_lattice_t, if xth bit of mask is 0, 297 implies xth bit of value is constant. */ 298 widest_int mask; 299}; 300 301/* Info about value ranges. */ 302 303class GTY(()) ipa_vr 304{ 305public: 306 /* The data fields below are valid only if known is true. */ 307 bool known; 308 enum value_range_kind type; 309 wide_int min; 310 wide_int max; 311 bool nonzero_p (tree) const; 312}; 313 314/* A jump function for a callsite represents the values passed as actual 315 arguments of the callsite. See enum jump_func_type for the various 316 types of jump functions supported. */ 317struct GTY (()) ipa_jump_func 318{ 319 /* Aggregate jump function description. See struct ipa_agg_jump_function 320 and its description. */ 321 struct ipa_agg_jump_function agg; 322 323 /* Information about zero/non-zero bits. The pointed to structure is shared 324 betweed different jump functions. Use ipa_set_jfunc_bits to set this 325 field. */ 326 class ipa_bits *bits; 327 328 /* Information about value range, containing valid data only when vr_known is 329 true. The pointed to structure is shared betweed different jump 330 functions. Use ipa_set_jfunc_vr to set this field. */ 331 value_range *m_vr; 332 333 enum jump_func_type type; 334 /* Represents a value of a jump function. pass_through is used only in jump 335 function context. constant represents the actual constant in constant jump 336 functions and member_cst holds constant c++ member functions. */ 337 union jump_func_value 338 { 339 struct ipa_constant_data GTY ((tag ("IPA_JF_CONST"))) constant; 340 struct ipa_pass_through_data GTY ((tag ("IPA_JF_PASS_THROUGH"))) pass_through; 341 struct ipa_ancestor_jf_data GTY ((tag ("IPA_JF_ANCESTOR"))) ancestor; 342 } GTY ((desc ("%1.type"))) value; 343}; 344 345 346/* Return the constant stored in a constant jump functin JFUNC. */ 347 348static inline tree 349ipa_get_jf_constant (struct ipa_jump_func *jfunc) 350{ 351 gcc_checking_assert (jfunc->type == IPA_JF_CONST); 352 return jfunc->value.constant.value; 353} 354 355static inline struct ipa_cst_ref_desc * 356ipa_get_jf_constant_rdesc (struct ipa_jump_func *jfunc) 357{ 358 gcc_checking_assert (jfunc->type == IPA_JF_CONST); 359 return jfunc->value.constant.rdesc; 360} 361 362/* Make JFUNC not participate in any further reference counting. */ 363 364inline void 365ipa_zap_jf_refdesc (ipa_jump_func *jfunc) 366{ 367 gcc_checking_assert (jfunc->type == IPA_JF_CONST); 368 jfunc->value.constant.rdesc = NULL; 369} 370 371/* Return the operand of a pass through jmp function JFUNC. */ 372 373static inline tree 374ipa_get_jf_pass_through_operand (struct ipa_jump_func *jfunc) 375{ 376 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 377 return jfunc->value.pass_through.operand; 378} 379 380/* Return the number of the caller's formal parameter that a pass through jump 381 function JFUNC refers to. */ 382 383static inline int 384ipa_get_jf_pass_through_formal_id (struct ipa_jump_func *jfunc) 385{ 386 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 387 return jfunc->value.pass_through.formal_id; 388} 389 390/* Return operation of a pass through jump function JFUNC. */ 391 392static inline enum tree_code 393ipa_get_jf_pass_through_operation (struct ipa_jump_func *jfunc) 394{ 395 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 396 return jfunc->value.pass_through.operation; 397} 398 399/* Return the agg_preserved flag of a pass through jump function JFUNC. */ 400 401static inline bool 402ipa_get_jf_pass_through_agg_preserved (struct ipa_jump_func *jfunc) 403{ 404 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 405 return jfunc->value.pass_through.agg_preserved; 406} 407 408/* Return the refdesc_decremented flag of a pass through jump function 409 JFUNC. */ 410 411inline bool 412ipa_get_jf_pass_through_refdesc_decremented (struct ipa_jump_func *jfunc) 413{ 414 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 415 return jfunc->value.pass_through.refdesc_decremented; 416} 417 418/* Set the refdesc_decremented flag of a pass through jump function JFUNC to 419 VALUE. */ 420 421inline void 422ipa_set_jf_pass_through_refdesc_decremented (ipa_jump_func *jfunc, bool value) 423{ 424 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 425 jfunc->value.pass_through.refdesc_decremented = value; 426} 427 428/* Return true if pass through jump function JFUNC preserves type 429 information. */ 430 431static inline bool 432ipa_get_jf_pass_through_type_preserved (struct ipa_jump_func *jfunc) 433{ 434 gcc_checking_assert (jfunc->type == IPA_JF_PASS_THROUGH); 435 return jfunc->value.pass_through.agg_preserved; 436} 437 438/* Return the offset of an ancestor jump function JFUNC. */ 439 440static inline HOST_WIDE_INT 441ipa_get_jf_ancestor_offset (struct ipa_jump_func *jfunc) 442{ 443 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); 444 return jfunc->value.ancestor.offset; 445} 446 447/* Return the number of the caller's formal parameter that an ancestor jump 448 function JFUNC refers to. */ 449 450static inline int 451ipa_get_jf_ancestor_formal_id (struct ipa_jump_func *jfunc) 452{ 453 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); 454 return jfunc->value.ancestor.formal_id; 455} 456 457/* Return the agg_preserved flag of an ancestor jump function JFUNC. */ 458 459static inline bool 460ipa_get_jf_ancestor_agg_preserved (struct ipa_jump_func *jfunc) 461{ 462 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); 463 return jfunc->value.ancestor.agg_preserved; 464} 465 466/* Return true if ancestor jump function JFUNC presrves type information. */ 467 468static inline bool 469ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc) 470{ 471 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); 472 return jfunc->value.ancestor.agg_preserved; 473} 474 475/* Return if jfunc represents an operation whether we first check the formal 476 parameter for non-NULLness unless it does not matter because the offset is 477 zero anyway. */ 478 479static inline bool 480ipa_get_jf_ancestor_keep_null (struct ipa_jump_func *jfunc) 481{ 482 gcc_checking_assert (jfunc->type == IPA_JF_ANCESTOR); 483 return jfunc->value.ancestor.keep_null; 484} 485 486/* Class for allocating a bundle of various potentially known properties about 487 actual arguments of a particular call on stack for the usual case and on 488 heap only if there are unusually many arguments. The data is deallocated 489 when the instance of this class goes out of scope or is otherwise 490 destructed. */ 491 492class ipa_auto_call_arg_values 493{ 494public: 495 ~ipa_auto_call_arg_values (); 496 497 /* If m_known_vals (vector of known "scalar" values) is sufficiantly long, 498 return its element at INDEX, otherwise return NULL. */ 499 tree safe_sval_at (int index) 500 { 501 /* TODO: Assert non-negative index here and test. */ 502 if ((unsigned) index < m_known_vals.length ()) 503 return m_known_vals[index]; 504 return NULL; 505 } 506 507 /* If m_known_aggs is sufficiantly long, return the pointer rto its element 508 at INDEX, otherwise return NULL. */ 509 ipa_agg_value_set *safe_aggval_at (int index) 510 { 511 /* TODO: Assert non-negative index here and test. */ 512 if ((unsigned) index < m_known_aggs.length ()) 513 return &m_known_aggs[index]; 514 return NULL; 515 } 516 517 /* Vector describing known values of parameters. */ 518 auto_vec<tree, 32> m_known_vals; 519 520 /* Vector describing known polymorphic call contexts. */ 521 auto_vec<ipa_polymorphic_call_context, 32> m_known_contexts; 522 523 /* Vector describing known aggregate values. */ 524 auto_vec<ipa_agg_value_set, 32> m_known_aggs; 525 526 /* Vector describing known value ranges of arguments. */ 527 auto_vec<value_range, 32> m_known_value_ranges; 528}; 529 530/* Class bundling the various potentially known properties about actual 531 arguments of a particular call. This variant does not deallocate the 532 bundled data in any way. */ 533 534class ipa_call_arg_values 535{ 536public: 537 /* Default constructor, setting the vectors to empty ones. */ 538 ipa_call_arg_values () 539 {} 540 541 /* Construct this general variant of the bundle from the variant which uses 542 auto_vecs to hold the vectors. This means that vectors of objects 543 constructed with this constructor should not be changed because if they 544 get reallocated, the member vectors and the underlying auto_vecs would get 545 out of sync. */ 546 ipa_call_arg_values (ipa_auto_call_arg_values *aavals) 547 : m_known_vals (aavals->m_known_vals.to_vec_legacy ()), 548 m_known_contexts (aavals->m_known_contexts.to_vec_legacy ()), 549 m_known_aggs (aavals->m_known_aggs.to_vec_legacy ()), 550 m_known_value_ranges (aavals->m_known_value_ranges.to_vec_legacy ()) 551 {} 552 553 /* If m_known_vals (vector of known "scalar" values) is sufficiantly long, 554 return its element at INDEX, otherwise return NULL. */ 555 tree safe_sval_at (int index) 556 { 557 /* TODO: Assert non-negative index here and test. */ 558 if ((unsigned) index < m_known_vals.length ()) 559 return m_known_vals[index]; 560 return NULL; 561 } 562 563 /* If m_known_aggs is sufficiantly long, return the pointer rto its element 564 at INDEX, otherwise return NULL. */ 565 ipa_agg_value_set *safe_aggval_at (int index) 566 { 567 /* TODO: Assert non-negative index here and test. */ 568 if ((unsigned) index < m_known_aggs.length ()) 569 return &m_known_aggs[index]; 570 return NULL; 571 } 572 573 /* Vector describing known values of parameters. */ 574 vec<tree> m_known_vals = vNULL; 575 576 /* Vector describing known polymorphic call contexts. */ 577 vec<ipa_polymorphic_call_context> m_known_contexts = vNULL; 578 579 /* Vector describing known aggregate values. */ 580 vec<ipa_agg_value_set> m_known_aggs = vNULL; 581 582 /* Vector describing known value ranges of arguments. */ 583 vec<value_range> m_known_value_ranges = vNULL; 584}; 585 586 587/* Summary describing a single formal parameter. */ 588 589struct GTY(()) ipa_param_descriptor 590{ 591 /* In analysis and modification phase, this is the PARAM_DECL of this 592 parameter, in IPA LTO phase, this is the type of the described 593 parameter or NULL if not known. Do not read this field directly but 594 through ipa_get_param and ipa_get_type as appropriate. */ 595 tree decl_or_type; 596 /* If all uses of the parameter are described by ipa-prop structures, this 597 says how many there are. If any use could not be described by means of 598 ipa-prop structures (which include flag dereferenced below), this is 599 IPA_UNDESCRIBED_USE. */ 600 int controlled_uses; 601 unsigned int move_cost : 27; 602 /* The parameter is used. */ 603 unsigned used : 1; 604 unsigned used_by_ipa_predicates : 1; 605 unsigned used_by_indirect_call : 1; 606 unsigned used_by_polymorphic_call : 1; 607 /* Set to true when in addition to being used in call statements, the 608 parameter has also been used for loads (but not for writes, does not 609 escape, etc.). This allows us to identify parameters p which are only 610 used as *p, and so when we propagate a constant to them, we can generate a 611 LOAD and not ADDR reference to them. */ 612 unsigned load_dereferenced : 1; 613}; 614 615/* ipa_node_params stores information related to formal parameters of functions 616 and some other information for interprocedural passes that operate on 617 parameters (such as ipa-cp). */ 618 619class GTY((for_user)) ipa_node_params 620{ 621public: 622 /* Default constructor. */ 623 ipa_node_params (); 624 625 /* Default destructor. */ 626 ~ipa_node_params (); 627 628 /* Information about individual formal parameters that are gathered when 629 summaries are generated. */ 630 vec<ipa_param_descriptor, va_gc> *descriptors; 631 /* Pointer to an array of structures describing individual formal 632 parameters. */ 633 class ipcp_param_lattices * GTY((skip)) lattices; 634 /* Only for versioned nodes this field would not be NULL, 635 it points to the node that IPA cp cloned from. */ 636 struct cgraph_node * GTY((skip)) ipcp_orig_node; 637 /* If this node is an ipa-cp clone, these are the known constants that 638 describe what it has been specialized for. */ 639 vec<tree> GTY((skip)) known_csts; 640 /* If this node is an ipa-cp clone, these are the known polymorphic contexts 641 that describe what it has been specialized for. */ 642 vec<ipa_polymorphic_call_context> GTY((skip)) known_contexts; 643 /* Whether the param uses analysis and jump function computation has already 644 been performed. */ 645 unsigned analysis_done : 1; 646 /* Whether the function is enqueued in ipa-cp propagation stack. */ 647 unsigned node_enqueued : 1; 648 /* Whether we should create a specialized version based on values that are 649 known to be constant in all contexts. */ 650 unsigned do_clone_for_all_contexts : 1; 651 /* Set if this is an IPA-CP clone for all contexts. */ 652 unsigned is_all_contexts_clone : 1; 653 /* Node has been completely replaced by clones and will be removed after 654 ipa-cp is finished. */ 655 unsigned node_dead : 1; 656 /* Node is involved in a recursion, potentionally indirect. */ 657 unsigned node_within_scc : 1; 658 /* Node contains only direct recursion. */ 659 unsigned node_is_self_scc : 1; 660 /* Node is calling a private function called only once. */ 661 unsigned node_calling_single_call : 1; 662 /* False when there is something makes versioning impossible. */ 663 unsigned versionable : 1; 664}; 665 666inline 667ipa_node_params::ipa_node_params () 668: descriptors (NULL), lattices (NULL), ipcp_orig_node (NULL), 669 known_csts (vNULL), known_contexts (vNULL), analysis_done (0), 670 node_enqueued (0), do_clone_for_all_contexts (0), is_all_contexts_clone (0), 671 node_dead (0), node_within_scc (0), node_is_self_scc (0), 672 node_calling_single_call (0), versionable (0) 673{ 674} 675 676inline 677ipa_node_params::~ipa_node_params () 678{ 679 free (lattices); 680 vec_free (descriptors); 681 known_csts.release (); 682 known_contexts.release (); 683} 684 685/* Intermediate information that we get from alias analysis about a particular 686 parameter in a particular basic_block. When a parameter or the memory it 687 references is marked modified, we use that information in all dominated 688 blocks without consulting alias analysis oracle. */ 689 690struct ipa_param_aa_status 691{ 692 /* Set when this structure contains meaningful information. If not, the 693 structure describing a dominating BB should be used instead. */ 694 bool valid; 695 696 /* Whether we have seen something which might have modified the data in 697 question. PARM is for the parameter itself, REF is for data it points to 698 but using the alias type of individual accesses and PT is the same thing 699 but for computing aggregate pass-through functions using a very inclusive 700 ao_ref. */ 701 bool parm_modified, ref_modified, pt_modified; 702}; 703 704/* Information related to a given BB that used only when looking at function 705 body. */ 706 707struct ipa_bb_info 708{ 709 /* Call graph edges going out of this BB. */ 710 vec<cgraph_edge *> cg_edges; 711 /* Alias analysis statuses of each formal parameter at this bb. */ 712 vec<ipa_param_aa_status> param_aa_statuses; 713}; 714 715/* Structure with global information that is only used when looking at function 716 body. */ 717 718struct ipa_func_body_info 719{ 720 /* The node that is being analyzed. */ 721 cgraph_node *node; 722 723 /* Its info. */ 724 class ipa_node_params *info; 725 726 /* Information about individual BBs. */ 727 vec<ipa_bb_info> bb_infos; 728 729 /* Number of parameters. */ 730 int param_count; 731 732 /* Number of statements we are still allowed to walked by when analyzing this 733 function. */ 734 unsigned int aa_walk_budget; 735}; 736 737/* ipa_node_params access functions. Please use these to access fields that 738 are or will be shared among various passes. */ 739 740/* Return the number of formal parameters. */ 741 742static inline int 743ipa_get_param_count (class ipa_node_params *info) 744{ 745 return vec_safe_length (info->descriptors); 746} 747 748/* Return the parameter declaration in DESCRIPTORS at index I and assert it is 749 indeed a PARM_DECL. */ 750 751static inline tree 752ipa_get_param (const vec<ipa_param_descriptor, va_gc> &descriptors, int i) 753{ 754 tree t = descriptors[i].decl_or_type; 755 gcc_checking_assert (TREE_CODE (t) == PARM_DECL); 756 return t; 757} 758 759/* Return the declaration of Ith formal parameter of the function corresponding 760 to INFO. Note there is no setter function as this array is built just once 761 using ipa_initialize_node_params. This function should not be called in 762 WPA. */ 763 764static inline tree 765ipa_get_param (class ipa_node_params *info, int i) 766{ 767 gcc_checking_assert (info->descriptors); 768 return ipa_get_param (*info->descriptors, i); 769} 770 771/* Return the type of Ith formal parameter of the function corresponding 772 to INFO if it is known or NULL if not. */ 773 774static inline tree 775ipa_get_type (class ipa_node_params *info, int i) 776{ 777 if (vec_safe_length (info->descriptors) <= (unsigned) i) 778 return NULL; 779 tree t = (*info->descriptors)[i].decl_or_type; 780 if (!t) 781 return NULL; 782 if (TYPE_P (t)) 783 return t; 784 gcc_checking_assert (TREE_CODE (t) == PARM_DECL); 785 return TREE_TYPE (t); 786} 787 788/* Return the move cost of Ith formal parameter of the function corresponding 789 to INFO. */ 790 791static inline int 792ipa_get_param_move_cost (class ipa_node_params *info, int i) 793{ 794 gcc_checking_assert (info->descriptors); 795 return (*info->descriptors)[i].move_cost; 796} 797 798/* Set the used flag corresponding to the Ith formal parameter of the function 799 associated with INFO to VAL. */ 800 801static inline void 802ipa_set_param_used (class ipa_node_params *info, int i, bool val) 803{ 804 gcc_checking_assert (info->descriptors); 805 (*info->descriptors)[i].used = val; 806} 807 808/* Set the used_by_ipa_predicates flag corresponding to the Ith formal 809 parameter of the function associated with INFO to VAL. */ 810 811static inline void 812ipa_set_param_used_by_ipa_predicates (class ipa_node_params *info, int i, bool val) 813{ 814 gcc_checking_assert (info->descriptors); 815 (*info->descriptors)[i].used_by_ipa_predicates = val; 816} 817 818/* Set the used_by_indirect_call flag corresponding to the Ith formal 819 parameter of the function associated with INFO to VAL. */ 820 821static inline void 822ipa_set_param_used_by_indirect_call (class ipa_node_params *info, int i, bool val) 823{ 824 gcc_checking_assert (info->descriptors); 825 (*info->descriptors)[i].used_by_indirect_call = val; 826} 827 828/* Set the .used_by_polymorphic_call flag corresponding to the Ith formal 829 parameter of the function associated with INFO to VAL. */ 830 831static inline void 832ipa_set_param_used_by_polymorphic_call (class ipa_node_params *info, int i, bool val) 833{ 834 gcc_checking_assert (info->descriptors); 835 (*info->descriptors)[i].used_by_polymorphic_call = val; 836} 837 838/* Return how many uses described by ipa-prop a parameter has or 839 IPA_UNDESCRIBED_USE if there is a use that is not described by these 840 structures. */ 841static inline int 842ipa_get_controlled_uses (class ipa_node_params *info, int i) 843{ 844 /* FIXME: introducing speculation causes out of bounds access here. */ 845 if (vec_safe_length (info->descriptors) > (unsigned)i) 846 return (*info->descriptors)[i].controlled_uses; 847 return IPA_UNDESCRIBED_USE; 848} 849 850/* Set the controlled counter of a given parameter. */ 851 852static inline void 853ipa_set_controlled_uses (class ipa_node_params *info, int i, int val) 854{ 855 gcc_checking_assert (info->descriptors); 856 (*info->descriptors)[i].controlled_uses = val; 857} 858 859/* Assuming a parameter does not have IPA_UNDESCRIBED_USE controlled uses, 860 return flag which indicates it has been dereferenced but only in a load. */ 861static inline int 862ipa_get_param_load_dereferenced (class ipa_node_params *info, int i) 863{ 864 gcc_assert (ipa_get_controlled_uses (info, i) != IPA_UNDESCRIBED_USE); 865 return (*info->descriptors)[i].load_dereferenced; 866} 867 868/* Set the load_dereferenced flag of a given parameter. */ 869 870static inline void 871ipa_set_param_load_dereferenced (class ipa_node_params *info, int i, bool val) 872{ 873 gcc_checking_assert (info->descriptors); 874 (*info->descriptors)[i].load_dereferenced = val; 875} 876 877/* Return the used flag corresponding to the Ith formal parameter of the 878 function associated with INFO. */ 879 880static inline bool 881ipa_is_param_used (class ipa_node_params *info, int i) 882{ 883 gcc_checking_assert (info->descriptors); 884 return (*info->descriptors)[i].used; 885} 886 887/* Return the used_by_ipa_predicates flag corresponding to the Ith formal 888 parameter of the function associated with INFO. */ 889 890static inline bool 891ipa_is_param_used_by_ipa_predicates (class ipa_node_params *info, int i) 892{ 893 gcc_checking_assert (info->descriptors); 894 return (*info->descriptors)[i].used_by_ipa_predicates; 895} 896 897/* Return the used_by_indirect_call flag corresponding to the Ith formal 898 parameter of the function associated with INFO. */ 899 900static inline bool 901ipa_is_param_used_by_indirect_call (class ipa_node_params *info, int i) 902{ 903 gcc_checking_assert (info->descriptors); 904 return (*info->descriptors)[i].used_by_indirect_call; 905} 906 907/* Return the used_by_polymorphic_call flag corresponding to the Ith formal 908 parameter of the function associated with INFO. */ 909 910static inline bool 911ipa_is_param_used_by_polymorphic_call (class ipa_node_params *info, int i) 912{ 913 gcc_checking_assert (info->descriptors); 914 return (*info->descriptors)[i].used_by_polymorphic_call; 915} 916 917/* Information about replacements done in aggregates for a given node (each 918 node has its linked list). */ 919struct GTY(()) ipa_agg_replacement_value 920{ 921 /* Next item in the linked list. */ 922 struct ipa_agg_replacement_value *next; 923 /* Offset within the aggregate. */ 924 HOST_WIDE_INT offset; 925 /* The constant value. */ 926 tree value; 927 /* The parameter index. */ 928 int index; 929 /* Whether the value was passed by reference. */ 930 bool by_ref; 931}; 932 933/* Structure holding information for the transformation phase of IPA-CP. */ 934 935struct GTY(()) ipcp_transformation 936{ 937 /* Linked list of known aggregate values. */ 938 ipa_agg_replacement_value *agg_values; 939 /* Known bits information. */ 940 vec<ipa_bits *, va_gc> *bits; 941 /* Value range information. */ 942 vec<ipa_vr, va_gc> *m_vr; 943 944 /* Default constructor. */ 945 ipcp_transformation () 946 : agg_values (NULL), bits (NULL), m_vr (NULL) 947 { } 948 949 /* Default destructor. */ 950 ~ipcp_transformation () 951 { 952 ipa_agg_replacement_value *agg = agg_values; 953 while (agg) 954 { 955 ipa_agg_replacement_value *next = agg->next; 956 ggc_free (agg); 957 agg = next; 958 } 959 vec_free (bits); 960 vec_free (m_vr); 961 } 962}; 963 964void ipa_set_node_agg_value_chain (struct cgraph_node *node, 965 struct ipa_agg_replacement_value *aggvals); 966void ipcp_transformation_initialize (void); 967void ipcp_free_transformation_sum (void); 968 969/* ipa_edge_args stores information related to a callsite and particularly its 970 arguments. It can be accessed by the IPA_EDGE_REF macro. */ 971 972class GTY((for_user)) ipa_edge_args 973{ 974 public: 975 976 /* Default constructor. */ 977 ipa_edge_args () : jump_functions (NULL), polymorphic_call_contexts (NULL) 978 {} 979 980 /* Destructor. */ 981 ~ipa_edge_args () 982 { 983 unsigned int i; 984 ipa_jump_func *jf; 985 FOR_EACH_VEC_SAFE_ELT (jump_functions, i, jf) 986 vec_free (jf->agg.items); 987 vec_free (jump_functions); 988 vec_free (polymorphic_call_contexts); 989 } 990 991 /* Vectors of the callsite's jump function and polymorphic context 992 information of each parameter. */ 993 vec<ipa_jump_func, va_gc> *jump_functions; 994 vec<ipa_polymorphic_call_context, va_gc> *polymorphic_call_contexts; 995}; 996 997/* ipa_edge_args access functions. Please use these to access fields that 998 are or will be shared among various passes. */ 999 1000/* Return the number of actual arguments. */ 1001 1002static inline int 1003ipa_get_cs_argument_count (class ipa_edge_args *args) 1004{ 1005 return vec_safe_length (args->jump_functions); 1006} 1007 1008/* Returns a pointer to the jump function for the ith argument. Please note 1009 there is no setter function as jump functions are all set up in 1010 ipa_compute_jump_functions. */ 1011 1012static inline struct ipa_jump_func * 1013ipa_get_ith_jump_func (class ipa_edge_args *args, int i) 1014{ 1015 return &(*args->jump_functions)[i]; 1016} 1017 1018/* Returns a pointer to the polymorphic call context for the ith argument. 1019 NULL if contexts are not computed. */ 1020static inline class ipa_polymorphic_call_context * 1021ipa_get_ith_polymorhic_call_context (class ipa_edge_args *args, int i) 1022{ 1023 if (!args->polymorphic_call_contexts) 1024 return NULL; 1025 return &(*args->polymorphic_call_contexts)[i]; 1026} 1027 1028/* Function summary for ipa_node_params. */ 1029class GTY((user)) ipa_node_params_t: public function_summary <ipa_node_params *> 1030{ 1031public: 1032 ipa_node_params_t (symbol_table *table, bool ggc): 1033 function_summary<ipa_node_params *> (table, ggc) 1034 { 1035 disable_insertion_hook (); 1036 } 1037 1038 /* Hook that is called by summary when a node is duplicated. */ 1039 virtual void duplicate (cgraph_node *node, 1040 cgraph_node *node2, 1041 ipa_node_params *data, 1042 ipa_node_params *data2); 1043}; 1044 1045/* Summary to manange ipa_edge_args structures. */ 1046 1047class GTY((user)) ipa_edge_args_sum_t : public call_summary <ipa_edge_args *> 1048{ 1049 public: 1050 ipa_edge_args_sum_t (symbol_table *table, bool ggc) 1051 : call_summary<ipa_edge_args *> (table, ggc) { } 1052 1053 void remove (cgraph_edge *edge) 1054 { 1055 call_summary <ipa_edge_args *>::remove (edge); 1056 } 1057 1058 /* Hook that is called by summary when an edge is removed. */ 1059 virtual void remove (cgraph_edge *cs, ipa_edge_args *args); 1060 /* Hook that is called by summary when an edge is duplicated. */ 1061 virtual void duplicate (cgraph_edge *src, 1062 cgraph_edge *dst, 1063 ipa_edge_args *old_args, 1064 ipa_edge_args *new_args); 1065}; 1066 1067/* Function summary where the parameter infos are actually stored. */ 1068extern GTY(()) ipa_node_params_t * ipa_node_params_sum; 1069/* Call summary to store information about edges such as jump functions. */ 1070extern GTY(()) ipa_edge_args_sum_t *ipa_edge_args_sum; 1071 1072/* Function summary for IPA-CP transformation. */ 1073class ipcp_transformation_t 1074: public function_summary<ipcp_transformation *> 1075{ 1076public: 1077 ipcp_transformation_t (symbol_table *table, bool ggc): 1078 function_summary<ipcp_transformation *> (table, ggc) {} 1079 1080 ~ipcp_transformation_t () {} 1081 1082 static ipcp_transformation_t *create_ggc (symbol_table *symtab) 1083 { 1084 ipcp_transformation_t *summary 1085 = new (ggc_alloc_no_dtor <ipcp_transformation_t> ()) 1086 ipcp_transformation_t (symtab, true); 1087 return summary; 1088 } 1089 /* Hook that is called by summary when a node is duplicated. */ 1090 virtual void duplicate (cgraph_node *node, 1091 cgraph_node *node2, 1092 ipcp_transformation *data, 1093 ipcp_transformation *data2); 1094}; 1095 1096/* Function summary where the IPA CP transformations are actually stored. */ 1097extern GTY(()) function_summary <ipcp_transformation *> *ipcp_transformation_sum; 1098 1099/* Creating and freeing ipa_node_params and ipa_edge_args. */ 1100void ipa_create_all_node_params (void); 1101void ipa_create_all_edge_args (void); 1102void ipa_check_create_edge_args (void); 1103void ipa_free_all_node_params (void); 1104void ipa_free_all_edge_args (void); 1105void ipa_free_all_structures_after_ipa_cp (void); 1106void ipa_free_all_structures_after_iinln (void); 1107 1108void ipa_register_cgraph_hooks (void); 1109int count_formal_params (tree fndecl); 1110 1111/* This function ensures the array of node param infos is big enough to 1112 accommodate a structure for all nodes and reallocates it if not. */ 1113 1114static inline void 1115ipa_check_create_node_params (void) 1116{ 1117 if (!ipa_node_params_sum) 1118 ipa_node_params_sum 1119 = (new (ggc_alloc_no_dtor <ipa_node_params_t> ()) 1120 ipa_node_params_t (symtab, true)); 1121} 1122 1123/* Returns true if edge summary contains a record for EDGE. The main purpose 1124 of this function is that debug dumping function can check info availability 1125 without causing allocations. */ 1126 1127static inline bool 1128ipa_edge_args_info_available_for_edge_p (struct cgraph_edge *edge) 1129{ 1130 return ipa_edge_args_sum->exists (edge); 1131} 1132 1133static inline ipcp_transformation * 1134ipcp_get_transformation_summary (cgraph_node *node) 1135{ 1136 if (ipcp_transformation_sum == NULL) 1137 return NULL; 1138 1139 return ipcp_transformation_sum->get (node); 1140} 1141 1142/* Return the aggregate replacements for NODE, if there are any. */ 1143 1144static inline struct ipa_agg_replacement_value * 1145ipa_get_agg_replacements_for_node (cgraph_node *node) 1146{ 1147 ipcp_transformation *ts = ipcp_get_transformation_summary (node); 1148 return ts ? ts->agg_values : NULL; 1149} 1150 1151/* Function formal parameters related computations. */ 1152void ipa_initialize_node_params (struct cgraph_node *node); 1153bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, 1154 vec<cgraph_edge *> *new_edges); 1155 1156/* Indirect edge processing and target discovery. */ 1157tree ipa_get_indirect_edge_target (struct cgraph_edge *ie, 1158 ipa_call_arg_values *avals, 1159 bool *speculative); 1160tree ipa_get_indirect_edge_target (struct cgraph_edge *ie, 1161 ipa_auto_call_arg_values *avals, 1162 bool *speculative); 1163struct cgraph_edge *ipa_make_edge_direct_to_target (struct cgraph_edge *, tree, 1164 bool speculative = false); 1165tree ipa_impossible_devirt_target (struct cgraph_edge *, tree); 1166ipa_bits *ipa_get_ipa_bits_for_value (const widest_int &value, 1167 const widest_int &mask); 1168 1169 1170/* Functions related to both. */ 1171void ipa_analyze_node (struct cgraph_node *); 1172 1173/* Aggregate jump function related functions. */ 1174tree ipa_find_agg_cst_for_param (const ipa_agg_value_set *agg, tree scalar, 1175 HOST_WIDE_INT offset, bool by_ref, 1176 bool *from_global_constant = NULL); 1177bool ipa_load_from_parm_agg (struct ipa_func_body_info *fbi, 1178 vec<ipa_param_descriptor, va_gc> *descriptors, 1179 gimple *stmt, tree op, int *index_p, 1180 HOST_WIDE_INT *offset_p, poly_int64 *size_p, 1181 bool *by_ref, bool *guaranteed_unmodified = NULL); 1182 1183/* Debugging interface. */ 1184void ipa_print_node_params (FILE *, struct cgraph_node *node); 1185void ipa_print_all_params (FILE *); 1186void ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node); 1187void ipa_print_all_jump_functions (FILE * f); 1188void ipcp_verify_propagated_values (void); 1189 1190template <typename value> 1191class ipcp_value; 1192 1193extern object_allocator<ipcp_value<tree> > ipcp_cst_values_pool; 1194extern object_allocator<ipcp_value<ipa_polymorphic_call_context> > 1195 ipcp_poly_ctx_values_pool; 1196 1197template <typename valtype> 1198struct ipcp_value_source; 1199 1200extern object_allocator<ipcp_value_source<tree> > ipcp_sources_pool; 1201 1202struct ipcp_agg_lattice; 1203 1204extern object_allocator<ipcp_agg_lattice> ipcp_agg_lattice_pool; 1205 1206void ipa_dump_agg_replacement_values (FILE *f, 1207 struct ipa_agg_replacement_value *av); 1208void ipa_prop_write_jump_functions (void); 1209void ipa_prop_read_jump_functions (void); 1210void ipcp_write_transformation_summaries (void); 1211void ipcp_read_transformation_summaries (void); 1212int ipa_get_param_decl_index (class ipa_node_params *, tree); 1213tree ipa_value_from_jfunc (class ipa_node_params *info, 1214 struct ipa_jump_func *jfunc, tree type); 1215unsigned int ipcp_transform_function (struct cgraph_node *node); 1216ipa_polymorphic_call_context ipa_context_from_jfunc (ipa_node_params *, 1217 cgraph_edge *, 1218 int, 1219 ipa_jump_func *); 1220value_range ipa_value_range_from_jfunc (ipa_node_params *, cgraph_edge *, 1221 ipa_jump_func *, tree); 1222ipa_agg_value_set ipa_agg_value_set_from_jfunc (ipa_node_params *, 1223 cgraph_node *, 1224 ipa_agg_jump_function *); 1225void ipa_dump_param (FILE *, class ipa_node_params *info, int i); 1226void ipa_release_body_info (struct ipa_func_body_info *); 1227tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); 1228bool ipcp_get_parm_bits (tree, tree *, widest_int *); 1229bool unadjusted_ptr_and_unit_offset (tree op, tree *ret, 1230 poly_int64 *offset_ret); 1231 1232/* From tree-sra.cc: */ 1233tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, 1234 gimple_stmt_iterator *, bool); 1235 1236/* In ipa-cp.cc */ 1237void ipa_cp_cc_finalize (void); 1238 1239#endif /* IPA_PROP_H */ 1240