1 /* Interprocedural reference lists.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
29 static const char *ipa_ref_use_name
[] = {"read","write","addr","alias"};
31 /* Return ipa reference from REFERING_NODE or REFERING_VARPOOL_NODE
32 to REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
33 of the use and STMT the statement (if it exists). */
36 ipa_record_reference (symtab_node referring_node
,
37 symtab_node referred_node
,
38 enum ipa_ref_use use_type
, gimple stmt
)
41 struct ipa_ref_list
*list
, *list2
;
42 ipa_ref_t
*old_references
;
44 gcc_checking_assert (!stmt
|| is_a
<cgraph_node
> (referring_node
));
45 gcc_checking_assert (use_type
!= IPA_REF_ALIAS
|| !stmt
);
47 list
= &referring_node
->symbol
.ref_list
;
48 old_references
= vec_safe_address (list
->references
);
49 vec_safe_grow (list
->references
, vec_safe_length (list
->references
) + 1);
50 ref
= &list
->references
->last ();
52 list2
= &referred_node
->symbol
.ref_list
;
53 list2
->referring
.safe_push (ref
);
54 ref
->referred_index
= list2
->referring
.length () - 1;
55 ref
->referring
= referring_node
;
56 ref
->referred
= referred_node
;
60 /* If vector was moved in memory, update pointers. */
61 if (old_references
!= list
->references
->address ())
64 for (i
= 0; ipa_ref_list_reference_iterate (list
, i
, ref
); i
++)
65 ipa_ref_referred_ref_list (ref
)->referring
[ref
->referred_index
] = ref
;
70 /* Remove reference REF. */
73 ipa_remove_reference (struct ipa_ref
*ref
)
75 struct ipa_ref_list
*list
= ipa_ref_referred_ref_list (ref
);
76 struct ipa_ref_list
*list2
= ipa_ref_referring_ref_list (ref
);
77 vec
<ipa_ref_t
, va_gc
> *old_references
= list2
->references
;
80 gcc_assert (list
->referring
[ref
->referred_index
] == ref
);
81 last
= list
->referring
.last ();
84 list
->referring
[ref
->referred_index
] = list
->referring
.last ();
85 list
->referring
[ref
->referred_index
]->referred_index
86 = ref
->referred_index
;
88 list
->referring
.pop ();
90 last
= &list2
->references
->last ();
94 ipa_ref_referred_ref_list (ref
)->referring
[ref
->referred_index
] = ref
;
96 list2
->references
->pop ();
97 gcc_assert (list2
->references
== old_references
);
100 /* Remove all references in ref list LIST. */
103 ipa_remove_all_references (struct ipa_ref_list
*list
)
105 while (vec_safe_length (list
->references
))
106 ipa_remove_reference (&list
->references
->last ());
107 vec_free (list
->references
);
110 /* Remove all references in ref list LIST. */
113 ipa_remove_all_referring (struct ipa_ref_list
*list
)
115 while (list
->referring
.length ())
116 ipa_remove_reference (list
->referring
.last ());
117 list
->referring
.release ();
120 /* Dump references in LIST to FILE. */
123 ipa_dump_references (FILE * file
, struct ipa_ref_list
*list
)
127 for (i
= 0; ipa_ref_list_reference_iterate (list
, i
, ref
); i
++)
129 fprintf (file
, "%s/%i (%s)",
130 symtab_node_asm_name (ref
->referred
),
131 ref
->referred
->symbol
.order
,
132 ipa_ref_use_name
[ref
->use
]);
134 fprintf (file
, "\n");
137 /* Dump referring in LIST to FILE. */
140 ipa_dump_referring (FILE * file
, struct ipa_ref_list
*list
)
144 for (i
= 0; ipa_ref_list_referring_iterate (list
, i
, ref
); i
++)
146 fprintf (file
, "%s/%i (%s)",
147 symtab_node_asm_name (ref
->referring
),
148 ref
->referring
->symbol
.order
,
149 ipa_ref_use_name
[ref
->use
]);
151 fprintf (file
, "\n");
154 /* Clone all references from SRC to DEST_NODE or DEST_VARPOOL_NODE. */
157 ipa_clone_references (symtab_node dest_node
,
158 struct ipa_ref_list
*src
)
162 for (i
= 0; ipa_ref_list_reference_iterate (src
, i
, ref
); i
++)
163 ipa_record_reference (dest_node
,
165 ref
->use
, ref
->stmt
);
168 /* Clone all referring from SRC to DEST_NODE or DEST_VARPOOL_NODE. */
171 ipa_clone_referring (symtab_node dest_node
,
172 struct ipa_ref_list
*src
)
176 for (i
= 0; ipa_ref_list_referring_iterate (src
, i
, ref
); i
++)
177 ipa_record_reference (ref
->referring
,
179 ref
->use
, ref
->stmt
);
182 /* Return true when execution of REF can lead to return from
185 ipa_ref_cannot_lead_to_return (struct ipa_ref
*ref
)
187 return cgraph_node_cannot_return (ipa_ref_referring_node (ref
));
190 /* Return true if list contains an alias. */
192 ipa_ref_has_aliases_p (struct ipa_ref_list
*ref_list
)
196 for (i
= 0; ipa_ref_list_referring_iterate (ref_list
, i
, ref
); i
++)
197 if (ref
->use
== IPA_REF_ALIAS
)