xref: /dflybsd-src/contrib/gcc-8.0/gcc/ipa-ref.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* IPA reference lists.
2*38fd1498Szrj    Copyright (C) 2010-2018 Free Software Foundation, Inc.
3*38fd1498Szrj    Contributed by Jan Hubicka
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
8*38fd1498Szrj the terms of the GNU General Public License as published by the Free
9*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
10*38fd1498Szrj version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*38fd1498Szrj for more details.
16*38fd1498Szrj 
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
20*38fd1498Szrj 
21*38fd1498Szrj #ifndef GCC_IPA_REF_H
22*38fd1498Szrj #define GCC_IPA_REF_H
23*38fd1498Szrj 
24*38fd1498Szrj struct cgraph_node;
25*38fd1498Szrj class varpool_node;
26*38fd1498Szrj class symtab_node;
27*38fd1498Szrj 
28*38fd1498Szrj 
29*38fd1498Szrj /* How the reference is done.  */
30*38fd1498Szrj enum GTY(()) ipa_ref_use
31*38fd1498Szrj {
32*38fd1498Szrj   IPA_REF_LOAD,
33*38fd1498Szrj   IPA_REF_STORE,
34*38fd1498Szrj   IPA_REF_ADDR,
35*38fd1498Szrj   IPA_REF_ALIAS,
36*38fd1498Szrj   IPA_REF_CHKP
37*38fd1498Szrj };
38*38fd1498Szrj 
39*38fd1498Szrj /* Record of reference in callgraph or varpool.  */
40*38fd1498Szrj struct GTY(()) ipa_ref
41*38fd1498Szrj {
42*38fd1498Szrj public:
43*38fd1498Szrj   /* Remove reference.  */
44*38fd1498Szrj   void remove_reference ();
45*38fd1498Szrj 
46*38fd1498Szrj   /* Return true when execution of reference can lead to return from
47*38fd1498Szrj      function.  */
48*38fd1498Szrj   bool cannot_lead_to_return ();
49*38fd1498Szrj 
50*38fd1498Szrj   /* Return true if refernece may be used in address compare.  */
51*38fd1498Szrj   bool address_matters_p ();
52*38fd1498Szrj 
53*38fd1498Szrj   /* Return reference list this reference is in.  */
54*38fd1498Szrj   struct ipa_ref_list * referring_ref_list (void);
55*38fd1498Szrj 
56*38fd1498Szrj   /* Return reference list this reference is in.  */
57*38fd1498Szrj   struct ipa_ref_list * referred_ref_list (void);
58*38fd1498Szrj 
59*38fd1498Szrj   symtab_node *referring;
60*38fd1498Szrj   symtab_node *referred;
61*38fd1498Szrj   gimple *stmt;
62*38fd1498Szrj   unsigned int lto_stmt_uid;
63*38fd1498Szrj   unsigned int referred_index;
64*38fd1498Szrj   ENUM_BITFIELD (ipa_ref_use) use:3;
65*38fd1498Szrj   unsigned int speculative:1;
66*38fd1498Szrj };
67*38fd1498Szrj 
68*38fd1498Szrj typedef struct ipa_ref ipa_ref_t;
69*38fd1498Szrj typedef struct ipa_ref *ipa_ref_ptr;
70*38fd1498Szrj 
71*38fd1498Szrj 
72*38fd1498Szrj /* List of references.  This is stored in both callgraph and varpool nodes.  */
73*38fd1498Szrj struct GTY(()) ipa_ref_list
74*38fd1498Szrj {
75*38fd1498Szrj public:
76*38fd1498Szrj   /* Return first reference in list or NULL if empty.  */
first_referenceipa_ref_list77*38fd1498Szrj   struct ipa_ref *first_reference (void)
78*38fd1498Szrj   {
79*38fd1498Szrj     if (!vec_safe_length (references))
80*38fd1498Szrj       return NULL;
81*38fd1498Szrj     return &(*references)[0];
82*38fd1498Szrj   }
83*38fd1498Szrj 
84*38fd1498Szrj   /* Return first referring ref in list or NULL if empty.  */
first_referringipa_ref_list85*38fd1498Szrj   struct ipa_ref *first_referring (void)
86*38fd1498Szrj   {
87*38fd1498Szrj     if (!referring.length ())
88*38fd1498Szrj       return NULL;
89*38fd1498Szrj     return referring[0];
90*38fd1498Szrj   }
91*38fd1498Szrj 
92*38fd1498Szrj   /* Return first referring alias.  */
first_aliasipa_ref_list93*38fd1498Szrj   struct ipa_ref *first_alias (void)
94*38fd1498Szrj   {
95*38fd1498Szrj     struct ipa_ref *r = first_referring ();
96*38fd1498Szrj 
97*38fd1498Szrj     return r && r->use == IPA_REF_ALIAS ? r : NULL;
98*38fd1498Szrj   }
99*38fd1498Szrj 
100*38fd1498Szrj   /* Return last referring alias.  */
last_aliasipa_ref_list101*38fd1498Szrj   struct ipa_ref *last_alias (void)
102*38fd1498Szrj   {
103*38fd1498Szrj     unsigned int i = 0;
104*38fd1498Szrj 
105*38fd1498Szrj     for(i = 0; i < referring.length (); i++)
106*38fd1498Szrj       if (referring[i]->use != IPA_REF_ALIAS)
107*38fd1498Szrj 	break;
108*38fd1498Szrj 
109*38fd1498Szrj     return i == 0 ? NULL : referring[i - 1];
110*38fd1498Szrj   }
111*38fd1498Szrj 
112*38fd1498Szrj   /* Return true if the symbol has an alias.  */
has_aliases_pipa_ref_list113*38fd1498Szrj   bool inline has_aliases_p (void)
114*38fd1498Szrj   {
115*38fd1498Szrj     return first_alias ();
116*38fd1498Szrj   }
117*38fd1498Szrj 
118*38fd1498Szrj   /* Clear reference list.  */
clearipa_ref_list119*38fd1498Szrj   void clear (void)
120*38fd1498Szrj   {
121*38fd1498Szrj     referring.create (0);
122*38fd1498Szrj     references = NULL;
123*38fd1498Szrj   }
124*38fd1498Szrj 
125*38fd1498Szrj   /* Return number of references.  */
nreferencesipa_ref_list126*38fd1498Szrj   unsigned int nreferences (void)
127*38fd1498Szrj   {
128*38fd1498Szrj     return vec_safe_length (references);
129*38fd1498Szrj   }
130*38fd1498Szrj 
131*38fd1498Szrj   /* Store actual references in references vector.  */
132*38fd1498Szrj   vec<ipa_ref_t, va_gc> *references;
133*38fd1498Szrj   /* Referring is vector of pointers to references.  It must not live in GGC space
134*38fd1498Szrj      or GGC will try to mark middle of references vectors.  */
135*38fd1498Szrj   vec<ipa_ref_ptr>  GTY((skip)) referring;
136*38fd1498Szrj };
137*38fd1498Szrj 
138*38fd1498Szrj #endif /* GCC_IPA_REF_H */
139