[i386][obvious] Use std::swap instead of manually swapping in a couple of places
[official-gcc.git] / gcc / ipa-ref.c
blob3e34017c886e4ffa1b1080b080f09886fb7797e9
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 "alias.h"
25 #include "symtab.h"
26 #include "options.h"
27 #include "tree.h"
28 #include "fold-const.h"
29 #include "target.h"
30 #include "plugin-api.h"
31 #include "tm.h"
32 #include "hard-reg-set.h"
33 #include "function.h"
34 #include "ipa-ref.h"
35 #include "cgraph.h"
36 #include "ipa-utils.h"
38 /* Remove reference. */
40 void
41 ipa_ref::remove_reference ()
43 struct ipa_ref_list *list = referred_ref_list ();
44 struct ipa_ref_list *list2 = referring_ref_list ();
45 vec<ipa_ref_t, va_gc> *old_references = list2->references;
46 struct ipa_ref *last;
48 gcc_assert (list->referring[referred_index] == this);
50 last = list->referring.last ();
51 if (this != last)
53 if (use == IPA_REF_ALIAS)
55 /* If deleted item is IPA_REF_ALIAS, we have to move last
56 item of IPA_REF_LIST type to the deleted position. After that
57 we replace last node with deletion slot. */
58 struct ipa_ref *last_alias = list->last_alias ();
60 if (last_alias && referred_index < last_alias->referred_index
61 && last_alias != last)
63 unsigned last_alias_index = last_alias->referred_index;
65 list->referring[referred_index] = last_alias;
66 list->referring[referred_index]->referred_index = referred_index;
68 /* New position for replacement is previous index
69 of the last_alias. */
70 referred_index = last_alias_index;
74 list->referring[referred_index] = list->referring.last ();
75 list->referring[referred_index]->referred_index= referred_index;
77 list->referring.pop ();
79 last = &list2->references->last ();
81 struct ipa_ref *ref = this;
83 if (ref != last)
85 *ref = *last;
86 ref->referred_ref_list ()->referring[referred_index] = ref;
88 list2->references->pop ();
89 gcc_assert (list2->references == old_references);
92 /* Return true when execution of reference can lead to return from
93 function. */
95 bool
96 ipa_ref::cannot_lead_to_return ()
98 return dyn_cast <cgraph_node *> (referring)->cannot_return_p ();
101 /* Return reference list this reference is in. */
103 struct ipa_ref_list *
104 ipa_ref::referring_ref_list (void)
106 return &referring->ref_list;
109 /* Return reference list this reference is in. */
111 struct ipa_ref_list *
112 ipa_ref::referred_ref_list (void)
114 return &referred->ref_list;