2015-06-11 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / ipa-ref.c
blob139733182a15dfc948a984b8008fc909094bb419
1 /* Interprocedural reference lists.
2 Copyright (C) 2010-2015 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
10 version.
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
15 for more details.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "input.h"
25 #include "alias.h"
26 #include "symtab.h"
27 #include "options.h"
28 #include "tree.h"
29 #include "fold-const.h"
30 #include "target.h"
31 #include "is-a.h"
32 #include "plugin-api.h"
33 #include "tm.h"
34 #include "hard-reg-set.h"
35 #include "input.h"
36 #include "function.h"
37 #include "ipa-ref.h"
38 #include "cgraph.h"
39 #include "ipa-utils.h"
41 /* Remove reference. */
43 void
44 ipa_ref::remove_reference ()
46 struct ipa_ref_list *list = referred_ref_list ();
47 struct ipa_ref_list *list2 = referring_ref_list ();
48 vec<ipa_ref_t, va_gc> *old_references = list2->references;
49 struct ipa_ref *last;
51 gcc_assert (list->referring[referred_index] == this);
53 last = list->referring.last ();
54 if (this != last)
56 if (use == IPA_REF_ALIAS)
58 /* If deleted item is IPA_REF_ALIAS, we have to move last
59 item of IPA_REF_LIST type to the deleted position. After that
60 we replace last node with deletion slot. */
61 struct ipa_ref *last_alias = list->last_alias ();
63 if (last_alias && referred_index < last_alias->referred_index
64 && last_alias != last)
66 unsigned last_alias_index = last_alias->referred_index;
68 list->referring[referred_index] = last_alias;
69 list->referring[referred_index]->referred_index = referred_index;
71 /* New position for replacement is previous index
72 of the last_alias. */
73 referred_index = last_alias_index;
77 list->referring[referred_index] = list->referring.last ();
78 list->referring[referred_index]->referred_index= referred_index;
80 list->referring.pop ();
82 last = &list2->references->last ();
84 struct ipa_ref *ref = this;
86 if (ref != last)
88 *ref = *last;
89 ref->referred_ref_list ()->referring[referred_index] = ref;
91 list2->references->pop ();
92 gcc_assert (list2->references == old_references);
95 /* Return true when execution of reference can lead to return from
96 function. */
98 bool
99 ipa_ref::cannot_lead_to_return ()
101 return dyn_cast <cgraph_node *> (referring)->cannot_return_p ();
104 /* Return reference list this reference is in. */
106 struct ipa_ref_list *
107 ipa_ref::referring_ref_list (void)
109 return &referring->ref_list;
112 /* Return reference list this reference is in. */
114 struct ipa_ref_list *
115 ipa_ref::referred_ref_list (void)
117 return &referred->ref_list;