1*e4b17023SJohn Marino /* IPA reference lists.
2*e4b17023SJohn Marino Copyright (C) 2010
3*e4b17023SJohn Marino Free Software Foundation, Inc.
4*e4b17023SJohn Marino Contributed by Jan Hubicka
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino /* Return callgraph node REF is refering. */
23*e4b17023SJohn Marino static inline struct cgraph_node *
ipa_ref_node(struct ipa_ref * ref)24*e4b17023SJohn Marino ipa_ref_node (struct ipa_ref *ref)
25*e4b17023SJohn Marino {
26*e4b17023SJohn Marino gcc_assert (ref->refered_type == IPA_REF_CGRAPH);
27*e4b17023SJohn Marino return ref->refered.cgraph_node;
28*e4b17023SJohn Marino }
29*e4b17023SJohn Marino
30*e4b17023SJohn Marino /* Return varpool node REF is refering. */
31*e4b17023SJohn Marino
32*e4b17023SJohn Marino static inline struct varpool_node *
ipa_ref_varpool_node(struct ipa_ref * ref)33*e4b17023SJohn Marino ipa_ref_varpool_node (struct ipa_ref *ref)
34*e4b17023SJohn Marino {
35*e4b17023SJohn Marino gcc_assert (ref->refered_type == IPA_REF_VARPOOL);
36*e4b17023SJohn Marino return ref->refered.varpool_node;
37*e4b17023SJohn Marino }
38*e4b17023SJohn Marino
39*e4b17023SJohn Marino /* Return cgraph node REF is in. */
40*e4b17023SJohn Marino
41*e4b17023SJohn Marino static inline struct cgraph_node *
ipa_ref_refering_node(struct ipa_ref * ref)42*e4b17023SJohn Marino ipa_ref_refering_node (struct ipa_ref *ref)
43*e4b17023SJohn Marino {
44*e4b17023SJohn Marino gcc_assert (ref->refering_type == IPA_REF_CGRAPH);
45*e4b17023SJohn Marino return ref->refering.cgraph_node;
46*e4b17023SJohn Marino }
47*e4b17023SJohn Marino
48*e4b17023SJohn Marino /* Return varpool node REF is in. */
49*e4b17023SJohn Marino
50*e4b17023SJohn Marino static inline struct varpool_node *
ipa_ref_refering_varpool_node(struct ipa_ref * ref)51*e4b17023SJohn Marino ipa_ref_refering_varpool_node (struct ipa_ref *ref)
52*e4b17023SJohn Marino {
53*e4b17023SJohn Marino gcc_assert (ref->refering_type == IPA_REF_VARPOOL);
54*e4b17023SJohn Marino return ref->refering.varpool_node;
55*e4b17023SJohn Marino }
56*e4b17023SJohn Marino
57*e4b17023SJohn Marino /* Return reference list REF is in. */
58*e4b17023SJohn Marino
59*e4b17023SJohn Marino static inline struct ipa_ref_list *
ipa_ref_refering_ref_list(struct ipa_ref * ref)60*e4b17023SJohn Marino ipa_ref_refering_ref_list (struct ipa_ref *ref)
61*e4b17023SJohn Marino {
62*e4b17023SJohn Marino if (ref->refering_type == IPA_REF_CGRAPH)
63*e4b17023SJohn Marino return &ipa_ref_refering_node (ref)->ref_list;
64*e4b17023SJohn Marino else
65*e4b17023SJohn Marino return &ipa_ref_refering_varpool_node (ref)->ref_list;
66*e4b17023SJohn Marino }
67*e4b17023SJohn Marino
68*e4b17023SJohn Marino /* Return reference list REF is in. */
69*e4b17023SJohn Marino
70*e4b17023SJohn Marino static inline struct ipa_ref_list *
ipa_ref_refered_ref_list(struct ipa_ref * ref)71*e4b17023SJohn Marino ipa_ref_refered_ref_list (struct ipa_ref *ref)
72*e4b17023SJohn Marino {
73*e4b17023SJohn Marino if (ref->refered_type == IPA_REF_CGRAPH)
74*e4b17023SJohn Marino return &ipa_ref_node (ref)->ref_list;
75*e4b17023SJohn Marino else
76*e4b17023SJohn Marino return &ipa_ref_varpool_node (ref)->ref_list;
77*e4b17023SJohn Marino }
78*e4b17023SJohn Marino
79*e4b17023SJohn Marino /* Return first reference in LIST or NULL if empty. */
80*e4b17023SJohn Marino
81*e4b17023SJohn Marino static inline struct ipa_ref *
ipa_ref_list_first_reference(struct ipa_ref_list * list)82*e4b17023SJohn Marino ipa_ref_list_first_reference (struct ipa_ref_list *list)
83*e4b17023SJohn Marino {
84*e4b17023SJohn Marino if (!VEC_length (ipa_ref_t, list->references))
85*e4b17023SJohn Marino return NULL;
86*e4b17023SJohn Marino return VEC_index (ipa_ref_t, list->references, 0);
87*e4b17023SJohn Marino }
88*e4b17023SJohn Marino
89*e4b17023SJohn Marino /* Return first refering ref in LIST or NULL if empty. */
90*e4b17023SJohn Marino
91*e4b17023SJohn Marino static inline struct ipa_ref *
ipa_ref_list_first_refering(struct ipa_ref_list * list)92*e4b17023SJohn Marino ipa_ref_list_first_refering (struct ipa_ref_list *list)
93*e4b17023SJohn Marino {
94*e4b17023SJohn Marino if (!VEC_length (ipa_ref_ptr, list->refering))
95*e4b17023SJohn Marino return NULL;
96*e4b17023SJohn Marino return VEC_index (ipa_ref_ptr, list->refering, 0);
97*e4b17023SJohn Marino }
98*e4b17023SJohn Marino
99*e4b17023SJohn Marino /* Clear reference list. */
100*e4b17023SJohn Marino
101*e4b17023SJohn Marino static inline void
ipa_empty_ref_list(struct ipa_ref_list * list)102*e4b17023SJohn Marino ipa_empty_ref_list (struct ipa_ref_list *list)
103*e4b17023SJohn Marino {
104*e4b17023SJohn Marino list->refering = NULL;
105*e4b17023SJohn Marino list->references = NULL;
106*e4b17023SJohn Marino }
107*e4b17023SJohn Marino
108*e4b17023SJohn Marino /* Clear reference list. */
109*e4b17023SJohn Marino
110*e4b17023SJohn Marino static inline unsigned int
ipa_ref_list_nreferences(struct ipa_ref_list * list)111*e4b17023SJohn Marino ipa_ref_list_nreferences (struct ipa_ref_list *list)
112*e4b17023SJohn Marino {
113*e4b17023SJohn Marino return VEC_length (ipa_ref_t, list->references);
114*e4b17023SJohn Marino }
115*e4b17023SJohn Marino
116*e4b17023SJohn Marino #define ipa_ref_list_reference_iterate(L,I,P) \
117*e4b17023SJohn Marino VEC_iterate(ipa_ref_t, (L)->references, (I), (P))
118*e4b17023SJohn Marino #define ipa_ref_list_refering_iterate(L,I,P) \
119*e4b17023SJohn Marino VEC_iterate(ipa_ref_ptr, (L)->refering, (I), (P))
120