re PR lto/45375 ([meta-bug] Issues with building Mozilla (i.e. Firefox) with LTO)
[official-gcc.git] / gcc / ipa-ref.c
blob91c2f89af25271ef94183d69f5b79224a393f88f
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 "hash-set.h"
25 #include "machmode.h"
26 #include "vec.h"
27 #include "double-int.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "symtab.h"
31 #include "options.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "fold-const.h"
36 #include "ggc.h"
37 #include "target.h"
38 #include "hash-map.h"
39 #include "is-a.h"
40 #include "plugin-api.h"
41 #include "tm.h"
42 #include "hard-reg-set.h"
43 #include "input.h"
44 #include "function.h"
45 #include "ipa-ref.h"
46 #include "cgraph.h"
47 #include "ipa-utils.h"
49 /* Remove reference. */
51 void
52 ipa_ref::remove_reference ()
54 struct ipa_ref_list *list = referred_ref_list ();
55 struct ipa_ref_list *list2 = referring_ref_list ();
56 vec<ipa_ref_t, va_gc> *old_references = list2->references;
57 struct ipa_ref *last;
59 gcc_assert (list->referring[referred_index] == this);
61 last = list->referring.last ();
62 if (this != last)
64 if (use == IPA_REF_ALIAS)
66 /* If deleted item is IPA_REF_ALIAS, we have to move last
67 item of IPA_REF_LIST type to the deleted position. After that
68 we replace last node with deletion slot. */
69 struct ipa_ref *last_alias = list->last_alias ();
71 if (last_alias && referred_index < last_alias->referred_index
72 && last_alias != last)
74 unsigned last_alias_index = last_alias->referred_index;
76 list->referring[referred_index] = last_alias;
77 list->referring[referred_index]->referred_index = referred_index;
79 /* New position for replacement is previous index
80 of the last_alias. */
81 referred_index = last_alias_index;
85 list->referring[referred_index] = list->referring.last ();
86 list->referring[referred_index]->referred_index= referred_index;
88 list->referring.pop ();
90 last = &list2->references->last ();
92 struct ipa_ref *ref = this;
94 if (ref != last)
96 *ref = *last;
97 ref->referred_ref_list ()->referring[referred_index] = ref;
99 list2->references->pop ();
100 gcc_assert (list2->references == old_references);
103 /* Return true when execution of reference can lead to return from
104 function. */
106 bool
107 ipa_ref::cannot_lead_to_return ()
109 return dyn_cast <cgraph_node *> (referring)->cannot_return_p ();
112 /* Return reference list this reference is in. */
114 struct ipa_ref_list *
115 ipa_ref::referring_ref_list (void)
117 return &referring->ref_list;
120 /* Return reference list this reference is in. */
122 struct ipa_ref_list *
123 ipa_ref::referred_ref_list (void)
125 return &referred->ref_list;