ipa-cp.c (ipcp_cloning_candidate_p): Use opt_for_fn.
[gcc.git] / gcc / ipa-ref.c
1 /* Interprocedural reference lists.
2 Copyright (C) 2010-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "ggc.h"
26 #include "target.h"
27 #include "hash-map.h"
28 #include "is-a.h"
29 #include "plugin-api.h"
30 #include "vec.h"
31 #include "hashtab.h"
32 #include "hash-set.h"
33 #include "machmode.h"
34 #include "tm.h"
35 #include "hard-reg-set.h"
36 #include "input.h"
37 #include "function.h"
38 #include "ipa-ref.h"
39 #include "cgraph.h"
40 #include "ipa-utils.h"
41
42 /* Remove reference. */
43
44 void
45 ipa_ref::remove_reference ()
46 {
47 struct ipa_ref_list *list = referred_ref_list ();
48 struct ipa_ref_list *list2 = referring_ref_list ();
49 vec<ipa_ref_t, va_gc> *old_references = list2->references;
50 struct ipa_ref *last;
51
52 gcc_assert (list->referring[referred_index] == this);
53
54 last = list->referring.last ();
55 if (this != last)
56 {
57 if (use == IPA_REF_ALIAS)
58 {
59 /* If deleted item is IPA_REF_ALIAS, we have to move last
60 item of IPA_REF_LIST type to the deleted position. After that
61 we replace last node with deletion slot. */
62 struct ipa_ref *last_alias = list->last_alias ();
63
64 if (last_alias && referred_index < last_alias->referred_index
65 && last_alias != last)
66 {
67 unsigned last_alias_index = last_alias->referred_index;
68
69 list->referring[referred_index] = last_alias;
70 list->referring[referred_index]->referred_index = referred_index;
71
72 /* New position for replacement is previous index
73 of the last_alias. */
74 referred_index = last_alias_index;
75 }
76 }
77
78 list->referring[referred_index] = list->referring.last ();
79 list->referring[referred_index]->referred_index= referred_index;
80 }
81 list->referring.pop ();
82
83 last = &list2->references->last ();
84
85 struct ipa_ref *ref = this;
86
87 if (ref != last)
88 {
89 *ref = *last;
90 ref->referred_ref_list ()->referring[referred_index] = ref;
91 }
92 list2->references->pop ();
93 gcc_assert (list2->references == old_references);
94 }
95
96 /* Return true when execution of reference can lead to return from
97 function. */
98
99 bool
100 ipa_ref::cannot_lead_to_return ()
101 {
102 return dyn_cast <cgraph_node *> (referring)->cannot_return_p ();
103 }
104
105 /* Return reference list this reference is in. */
106
107 struct ipa_ref_list *
108 ipa_ref::referring_ref_list (void)
109 {
110 return &referring->ref_list;
111 }
112
113 /* Return reference list this reference is in. */
114
115 struct ipa_ref_list *
116 ipa_ref::referred_ref_list (void)
117 {
118 return &referred->ref_list;
119 }