1 /* Interprocedural reference lists. 2 Copyright (C) 2010-2015 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 "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" 48 49 /* Remove reference. */ 50 51 void 52 ipa_ref::remove_reference () 53 { 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; 58 59 gcc_assert (list->referring[referred_index] == this); 60 61 last = list->referring.last (); 62 if (this != last) 63 { 64 if (use == IPA_REF_ALIAS) 65 { 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 (); 70 71 if (last_alias && referred_index < last_alias->referred_index 72 && last_alias != last) 73 { 74 unsigned last_alias_index = last_alias->referred_index; 75 76 list->referring[referred_index] = last_alias; 77 list->referring[referred_index]->referred_index = referred_index; 78 79 /* New position for replacement is previous index 80 of the last_alias. */ 81 referred_index = last_alias_index; 82 } 83 } 84 85 list->referring[referred_index] = list->referring.last (); 86 list->referring[referred_index]->referred_index= referred_index; 87 } 88 list->referring.pop (); 89 90 last = &list2->references->last (); 91 92 struct ipa_ref *ref = this; 93 94 if (ref != last) 95 { 96 *ref = *last; 97 ref->referred_ref_list ()->referring[referred_index] = ref; 98 } 99 list2->references->pop (); 100 gcc_assert (list2->references == old_references); 101 } 102 103 /* Return true when execution of reference can lead to return from 104 function. */ 105 106 bool 107 ipa_ref::cannot_lead_to_return () 108 { 109 return dyn_cast <cgraph_node *> (referring)->cannot_return_p (); 110 } 111 112 /* Return reference list this reference is in. */ 113 114 struct ipa_ref_list * 115 ipa_ref::referring_ref_list (void) 116 { 117 return &referring->ref_list; 118 } 119 120 /* Return reference list this reference is in. */ 121 122 struct ipa_ref_list * 123 ipa_ref::referred_ref_list (void) 124 { 125 return &referred->ref_list; 126 } 127