cgraph.h 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188
  1. /* Callgraph handling code.
  2. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  3. Contributed by Jan Hubicka
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_CGRAPH_H
  17. #define GCC_CGRAPH_H
  18. /* Symbol table consists of functions and variables.
  19. TODO: add labels and CONST_DECLs. */
  20. enum symtab_type
  21. {
  22. SYMTAB_SYMBOL,
  23. SYMTAB_FUNCTION,
  24. SYMTAB_VARIABLE
  25. };
  26. /* Section names are stored as reference counted strings in GGC safe hashtable
  27. (to make them survive through PCH). */
  28. struct GTY((for_user)) section_hash_entry_d
  29. {
  30. int ref_count;
  31. char *name; /* As long as this datastructure stays in GGC, we can not put
  32. string at the tail of structure of GGC dies in horrible
  33. way */
  34. };
  35. typedef struct section_hash_entry_d section_hash_entry;
  36. struct section_name_hasher : ggc_hasher<section_hash_entry *>
  37. {
  38. typedef const char *compare_type;
  39. static hashval_t hash (section_hash_entry *);
  40. static bool equal (section_hash_entry *, const char *);
  41. };
  42. enum availability
  43. {
  44. /* Not yet set by cgraph_function_body_availability. */
  45. AVAIL_UNSET,
  46. /* Function body/variable initializer is unknown. */
  47. AVAIL_NOT_AVAILABLE,
  48. /* Function body/variable initializer is known but might be replaced
  49. by a different one from other compilation unit and thus needs to
  50. be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
  51. arbitrary side effects on escaping variables and functions, while
  52. like AVAILABLE it might access static variables. */
  53. AVAIL_INTERPOSABLE,
  54. /* Function body/variable initializer is known and will be used in final
  55. program. */
  56. AVAIL_AVAILABLE,
  57. /* Function body/variable initializer is known and all it's uses are
  58. explicitly visible within current unit (ie it's address is never taken and
  59. it is not exported to other units). Currently used only for functions. */
  60. AVAIL_LOCAL
  61. };
  62. /* Classification of symbols WRT partitioning. */
  63. enum symbol_partitioning_class
  64. {
  65. /* External declarations are ignored by partitioning algorithms and they are
  66. added into the boundary later via compute_ltrans_boundary. */
  67. SYMBOL_EXTERNAL,
  68. /* Partitioned symbols are pur into one of partitions. */
  69. SYMBOL_PARTITION,
  70. /* Duplicated symbols (such as comdat or constant pool references) are
  71. copied into every node needing them via add_symbol_to_partition. */
  72. SYMBOL_DUPLICATE
  73. };
  74. /* Base of all entries in the symbol table.
  75. The symtab_node is inherited by cgraph and varpol nodes. */
  76. class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
  77. chain_next ("%h.next"), chain_prev ("%h.previous")))
  78. symtab_node
  79. {
  80. public:
  81. /* Return name. */
  82. const char *name () const;
  83. /* Return asm name. */
  84. const char * asm_name () const;
  85. /* Add node into symbol table. This function is not used directly, but via
  86. cgraph/varpool node creation routines. */
  87. void register_symbol (void);
  88. /* Remove symbol from symbol table. */
  89. void remove (void);
  90. /* Dump symtab node to F. */
  91. void dump (FILE *f);
  92. /* Dump symtab node to stderr. */
  93. void DEBUG_FUNCTION debug (void);
  94. /* Verify consistency of node. */
  95. void DEBUG_FUNCTION verify (void);
  96. /* Return ipa reference from this symtab_node to
  97. REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
  98. of the use and STMT the statement (if it exists). */
  99. ipa_ref *create_reference (symtab_node *referred_node,
  100. enum ipa_ref_use use_type);
  101. /* Return ipa reference from this symtab_node to
  102. REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
  103. of the use and STMT the statement (if it exists). */
  104. ipa_ref *create_reference (symtab_node *referred_node,
  105. enum ipa_ref_use use_type, gimple stmt);
  106. /* If VAL is a reference to a function or a variable, add a reference from
  107. this symtab_node to the corresponding symbol table node. USE_TYPE specify
  108. type of the use and STMT the statement (if it exists). Return the new
  109. reference or NULL if none was created. */
  110. ipa_ref *maybe_create_reference (tree val, enum ipa_ref_use use_type,
  111. gimple stmt);
  112. /* Clone all references from symtab NODE to this symtab_node. */
  113. void clone_references (symtab_node *node);
  114. /* Remove all stmt references in non-speculative references.
  115. Those are not maintained during inlining & clonning.
  116. The exception are speculative references that are updated along
  117. with callgraph edges associated with them. */
  118. void clone_referring (symtab_node *node);
  119. /* Clone reference REF to this symtab_node and set its stmt to STMT. */
  120. ipa_ref *clone_reference (ipa_ref *ref, gimple stmt);
  121. /* Find the structure describing a reference to REFERRED_NODE
  122. and associated with statement STMT. */
  123. ipa_ref *find_reference (symtab_node *referred_node, gimple stmt,
  124. unsigned int lto_stmt_uid);
  125. /* Remove all references that are associated with statement STMT. */
  126. void remove_stmt_references (gimple stmt);
  127. /* Remove all stmt references in non-speculative references.
  128. Those are not maintained during inlining & clonning.
  129. The exception are speculative references that are updated along
  130. with callgraph edges associated with them. */
  131. void clear_stmts_in_references (void);
  132. /* Remove all references in ref list. */
  133. void remove_all_references (void);
  134. /* Remove all referring items in ref list. */
  135. void remove_all_referring (void);
  136. /* Dump references in ref list to FILE. */
  137. void dump_references (FILE *file);
  138. /* Dump referring in list to FILE. */
  139. void dump_referring (FILE *);
  140. /* Get number of references for this node. */
  141. inline unsigned num_references (void)
  142. {
  143. return ref_list.references ? ref_list.references->length () : 0;
  144. }
  145. /* Iterates I-th reference in the list, REF is also set. */
  146. ipa_ref *iterate_reference (unsigned i, ipa_ref *&ref);
  147. /* Iterates I-th referring item in the list, REF is also set. */
  148. ipa_ref *iterate_referring (unsigned i, ipa_ref *&ref);
  149. /* Iterates I-th referring alias item in the list, REF is also set. */
  150. ipa_ref *iterate_direct_aliases (unsigned i, ipa_ref *&ref);
  151. /* Return true if symtab node and TARGET represents
  152. semantically equivalent symbols. */
  153. bool semantically_equivalent_p (symtab_node *target);
  154. /* Classify symbol symtab node for partitioning. */
  155. enum symbol_partitioning_class get_partitioning_class (void);
  156. /* Return comdat group. */
  157. tree get_comdat_group ()
  158. {
  159. return x_comdat_group;
  160. }
  161. /* Return comdat group as identifier_node. */
  162. tree get_comdat_group_id ()
  163. {
  164. if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
  165. x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
  166. return x_comdat_group;
  167. }
  168. /* Set comdat group. */
  169. void set_comdat_group (tree group)
  170. {
  171. gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
  172. || DECL_P (group));
  173. x_comdat_group = group;
  174. }
  175. /* Return section as string. */
  176. const char * get_section ()
  177. {
  178. if (!x_section)
  179. return NULL;
  180. return x_section->name;
  181. }
  182. /* Remove node from same comdat group. */
  183. void remove_from_same_comdat_group (void);
  184. /* Add this symtab_node to the same comdat group that OLD is in. */
  185. void add_to_same_comdat_group (symtab_node *old_node);
  186. /* Dissolve the same_comdat_group list in which NODE resides. */
  187. void dissolve_same_comdat_group_list (void);
  188. /* Return true when symtab_node is known to be used from other (non-LTO)
  189. object file. Known only when doing LTO via linker plugin. */
  190. bool used_from_object_file_p (void);
  191. /* Walk the alias chain to return the symbol NODE is alias of.
  192. If NODE is not an alias, return NODE.
  193. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  194. symtab_node *ultimate_alias_target (enum availability *avail = NULL);
  195. /* Return next reachable static symbol with initializer after NODE. */
  196. inline symtab_node *next_defined_symbol (void);
  197. /* Add reference recording that symtab node is alias of TARGET.
  198. The function can fail in the case of aliasing cycles; in this case
  199. it returns false. */
  200. bool resolve_alias (symtab_node *target);
  201. /* C++ FE sometimes change linkage flags after producing same
  202. body aliases. */
  203. void fixup_same_cpp_alias_visibility (symtab_node *target);
  204. /* Call callback on symtab node and aliases associated to this node.
  205. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  206. skipped. */
  207. bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
  208. void *data,
  209. bool include_overwrite);
  210. /* If node can not be interposable by static or dynamic linker to point to
  211. different definition, return this symbol. Otherwise look for alias with
  212. such property and if none exists, introduce new one. */
  213. symtab_node *noninterposable_alias (void);
  214. /* Return node that alias is aliasing. */
  215. inline symtab_node *get_alias_target (void);
  216. /* Set section for symbol and its aliases. */
  217. void set_section (const char *section);
  218. /* Set section, do not recurse into aliases.
  219. When one wants to change section of symbol and its aliases,
  220. use set_section. */
  221. void set_section_for_node (const char *section);
  222. /* Set initialization priority to PRIORITY. */
  223. void set_init_priority (priority_type priority);
  224. /* Return the initialization priority. */
  225. priority_type get_init_priority ();
  226. /* Return availability of NODE. */
  227. enum availability get_availability (void);
  228. /* Make DECL local. */
  229. void make_decl_local (void);
  230. /* Return desired alignment of the definition. This is NOT alignment useful
  231. to access THIS, because THIS may be interposable and DECL_ALIGN should
  232. be used instead. It however must be guaranteed when output definition
  233. of THIS. */
  234. unsigned int definition_alignment ();
  235. /* Return true if alignment can be increased. */
  236. bool can_increase_alignment_p ();
  237. /* Increase alignment of symbol to ALIGN. */
  238. void increase_alignment (unsigned int align);
  239. /* Return true if list contains an alias. */
  240. bool has_aliases_p (void);
  241. /* Return true when the symbol is real symbol, i.e. it is not inline clone
  242. or abstract function kept for debug info purposes only. */
  243. bool real_symbol_p (void);
  244. /* Determine if symbol declaration is needed. That is, visible to something
  245. either outside this translation unit, something magic in the system
  246. configury. This function is used just during symbol creation. */
  247. bool needed_p (void);
  248. /* Return true when there are references to the node. */
  249. bool referred_to_p (void);
  250. /* Return true if NODE can be discarded by linker from the binary. */
  251. inline bool
  252. can_be_discarded_p (void)
  253. {
  254. return (DECL_EXTERNAL (decl)
  255. || (get_comdat_group ()
  256. && resolution != LDPR_PREVAILING_DEF
  257. && resolution != LDPR_PREVAILING_DEF_IRONLY
  258. && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
  259. }
  260. /* Return true if NODE is local to a particular COMDAT group, and must not
  261. be named from outside the COMDAT. This is used for C++ decloned
  262. constructors. */
  263. inline bool comdat_local_p (void)
  264. {
  265. return (same_comdat_group && !TREE_PUBLIC (decl));
  266. }
  267. /* Return true if ONE and TWO are part of the same COMDAT group. */
  268. inline bool in_same_comdat_group_p (symtab_node *target);
  269. /* Return true if symbol is known to be nonzero. */
  270. bool nonzero_address ();
  271. /* Return 0 if symbol is known to have different address than S2,
  272. Return 1 if symbol is known to have same address as S2,
  273. return 2 otherwise. */
  274. int equal_address_to (symtab_node *s2);
  275. /* Return true if symbol's address may possibly be compared to other
  276. symbol's address. */
  277. bool address_matters_p ();
  278. /* Return true if NODE's address can be compared. This use properties
  279. of NODE only and does not look if the address is actually taken in
  280. interesting way. For that use ADDRESS_MATTERS_P instead. */
  281. bool address_can_be_compared_p (void);
  282. /* Return symbol table node associated with DECL, if any,
  283. and NULL otherwise. */
  284. static inline symtab_node *get (const_tree decl)
  285. {
  286. #ifdef ENABLE_CHECKING
  287. /* Check that we are called for sane type of object - functions
  288. and static or external variables. */
  289. gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
  290. || (TREE_CODE (decl) == VAR_DECL
  291. && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
  292. || in_lto_p)));
  293. /* Check that the mapping is sane - perhaps this check can go away,
  294. but at the moment frontends tends to corrupt the mapping by calling
  295. memcpy/memset on the tree nodes. */
  296. gcc_checking_assert (!decl->decl_with_vis.symtab_node
  297. || decl->decl_with_vis.symtab_node->decl == decl);
  298. #endif
  299. return decl->decl_with_vis.symtab_node;
  300. }
  301. /* Try to find a symtab node for declaration DECL and if it does not
  302. exist or if it corresponds to an inline clone, create a new one. */
  303. static inline symtab_node * get_create (tree node);
  304. /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
  305. Return NULL if there's no such node. */
  306. static symtab_node *get_for_asmname (const_tree asmname);
  307. /* Dump symbol table to F. */
  308. static void dump_table (FILE *);
  309. /* Dump symbol table to stderr. */
  310. static inline DEBUG_FUNCTION void debug_symtab (void)
  311. {
  312. dump_table (stderr);
  313. }
  314. /* Verify symbol table for internal consistency. */
  315. static DEBUG_FUNCTION void verify_symtab_nodes (void);
  316. /* Type of the symbol. */
  317. ENUM_BITFIELD (symtab_type) type : 8;
  318. /* The symbols resolution. */
  319. ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
  320. /*** Flags representing the symbol type. ***/
  321. /* True when symbol corresponds to a definition in current unit.
  322. set via finalize_function or finalize_decl */
  323. unsigned definition : 1;
  324. /* True when symbol is an alias.
  325. Set by ssemble_alias. */
  326. unsigned alias : 1;
  327. /* True when alias is a weakref. */
  328. unsigned weakref : 1;
  329. /* C++ frontend produce same body aliases and extra name aliases for
  330. virtual functions and vtables that are obviously equivalent.
  331. Those aliases are bit special, especially because C++ frontend
  332. visibility code is so ugly it can not get them right at first time
  333. and their visibility needs to be copied from their "masters" at
  334. the end of parsing. */
  335. unsigned cpp_implicit_alias : 1;
  336. /* Set once the definition was analyzed. The list of references and
  337. other properties are built during analysis. */
  338. unsigned analyzed : 1;
  339. /* Set for write-only variables. */
  340. unsigned writeonly : 1;
  341. /* Visibility of symbol was used for further optimization; do not
  342. permit further changes. */
  343. unsigned refuse_visibility_changes : 1;
  344. /*** Visibility and linkage flags. ***/
  345. /* Set when function is visible by other units. */
  346. unsigned externally_visible : 1;
  347. /* Don't reorder to other symbols having this set. */
  348. unsigned no_reorder : 1;
  349. /* The symbol will be assumed to be used in an invisible way (like
  350. by an toplevel asm statement). */
  351. unsigned force_output : 1;
  352. /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
  353. exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
  354. to static and it does not inhibit optimization. */
  355. unsigned forced_by_abi : 1;
  356. /* True when the name is known to be unique and thus it does not need mangling. */
  357. unsigned unique_name : 1;
  358. /* Specify whether the section was set by user or by
  359. compiler via -ffunction-sections. */
  360. unsigned implicit_section : 1;
  361. /* True when body and other characteristics have been removed by
  362. symtab_remove_unreachable_nodes. */
  363. unsigned body_removed : 1;
  364. /*** WHOPR Partitioning flags.
  365. These flags are used at ltrans stage when only part of the callgraph is
  366. available. ***/
  367. /* Set when variable is used from other LTRANS partition. */
  368. unsigned used_from_other_partition : 1;
  369. /* Set when function is available in the other LTRANS partition.
  370. During WPA output it is used to mark nodes that are present in
  371. multiple partitions. */
  372. unsigned in_other_partition : 1;
  373. /*** other flags. ***/
  374. /* Set when symbol has address taken. */
  375. unsigned address_taken : 1;
  376. /* Set when init priority is set. */
  377. unsigned in_init_priority_hash : 1;
  378. /* Set when symbol needs to be streamed into LTO bytecode for LTO, or in case
  379. of offloading, for separate compilation for a different target. */
  380. unsigned need_lto_streaming : 1;
  381. /* Set when symbol can be streamed into bytecode for offloading. */
  382. unsigned offloadable : 1;
  383. /* Ordering of all symtab entries. */
  384. int order;
  385. /* Declaration representing the symbol. */
  386. tree decl;
  387. /* Linked list of symbol table entries starting with symtab_nodes. */
  388. symtab_node *next;
  389. symtab_node *previous;
  390. /* Linked list of symbols with the same asm name. There may be multiple
  391. entries for single symbol name during LTO, because symbols are renamed
  392. only after partitioning.
  393. Because inline clones are kept in the assembler name has, they also produce
  394. duplicate entries.
  395. There are also several long standing bugs where frontends and builtin
  396. code produce duplicated decls. */
  397. symtab_node *next_sharing_asm_name;
  398. symtab_node *previous_sharing_asm_name;
  399. /* Circular list of nodes in the same comdat group if non-NULL. */
  400. symtab_node *same_comdat_group;
  401. /* Vectors of referring and referenced entities. */
  402. ipa_ref_list ref_list;
  403. /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
  404. depending to what was known to frontend on the creation time.
  405. Once alias is resolved, this pointer become NULL. */
  406. tree alias_target;
  407. /* File stream where this node is being written to. */
  408. struct lto_file_decl_data * lto_file_data;
  409. PTR GTY ((skip)) aux;
  410. /* Comdat group the symbol is in. Can be private if GGC allowed that. */
  411. tree x_comdat_group;
  412. /* Section name. Again can be private, if allowed. */
  413. section_hash_entry *x_section;
  414. protected:
  415. /* Dump base fields of symtab nodes to F. Not to be used directly. */
  416. void dump_base (FILE *);
  417. /* Verify common part of symtab node. */
  418. bool DEBUG_FUNCTION verify_base (void);
  419. /* Remove node from symbol table. This function is not used directly, but via
  420. cgraph/varpool node removal routines. */
  421. void unregister (void);
  422. /* Return the initialization and finalization priority information for
  423. DECL. If there is no previous priority information, a freshly
  424. allocated structure is returned. */
  425. struct symbol_priority_map *priority_info (void);
  426. /* Worker for call_for_symbol_and_aliases_1. */
  427. bool call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *, void *),
  428. void *data,
  429. bool include_overwrite);
  430. private:
  431. /* Worker for set_section. */
  432. static bool set_section (symtab_node *n, void *s);
  433. /* Worker for symtab_resolve_alias. */
  434. static bool set_implicit_section (symtab_node *n, void *);
  435. /* Worker searching noninterposable alias. */
  436. static bool noninterposable_alias (symtab_node *node, void *data);
  437. /* Worker for ultimate_alias_target. */
  438. symtab_node *ultimate_alias_target_1 (enum availability *avail = NULL);
  439. };
  440. /* Walk all aliases for NODE. */
  441. #define FOR_EACH_ALIAS(node, alias) \
  442. for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
  443. /* This is the information that is put into the cgraph local structure
  444. to recover a function. */
  445. struct lto_file_decl_data;
  446. extern const char * const cgraph_availability_names[];
  447. extern const char * const ld_plugin_symbol_resolution_names[];
  448. extern const char * const tls_model_names[];
  449. /* Information about thunk, used only for same body aliases. */
  450. struct GTY(()) cgraph_thunk_info {
  451. /* Information about the thunk. */
  452. HOST_WIDE_INT fixed_offset;
  453. HOST_WIDE_INT virtual_value;
  454. tree alias;
  455. bool this_adjusting;
  456. bool virtual_offset_p;
  457. bool add_pointer_bounds_args;
  458. /* Set to true when alias node is thunk. */
  459. bool thunk_p;
  460. };
  461. /* Information about the function collected locally.
  462. Available after function is analyzed. */
  463. struct GTY(()) cgraph_local_info {
  464. /* Set when function function is visible in current compilation unit only
  465. and its address is never taken. */
  466. unsigned local : 1;
  467. /* False when there is something makes versioning impossible. */
  468. unsigned versionable : 1;
  469. /* False when function calling convention and signature can not be changed.
  470. This is the case when __builtin_apply_args is used. */
  471. unsigned can_change_signature : 1;
  472. /* True when the function has been originally extern inline, but it is
  473. redefined now. */
  474. unsigned redefined_extern_inline : 1;
  475. /* True if the function may enter serial irrevocable mode. */
  476. unsigned tm_may_enter_irr : 1;
  477. };
  478. /* Information about the function that needs to be computed globally
  479. once compilation is finished. Available only with -funit-at-a-time. */
  480. struct GTY(()) cgraph_global_info {
  481. /* For inline clones this points to the function they will be
  482. inlined into. */
  483. cgraph_node *inlined_to;
  484. };
  485. /* Information about the function that is propagated by the RTL backend.
  486. Available only for functions that has been already assembled. */
  487. struct GTY(()) cgraph_rtl_info {
  488. unsigned int preferred_incoming_stack_boundary;
  489. /* Call unsaved hard registers really used by the corresponding
  490. function (including ones used by functions called by the
  491. function). */
  492. HARD_REG_SET function_used_regs;
  493. /* Set if function_used_regs is valid. */
  494. unsigned function_used_regs_valid: 1;
  495. };
  496. /* Represent which DECL tree (or reference to such tree)
  497. will be replaced by another tree while versioning. */
  498. struct GTY(()) ipa_replace_map
  499. {
  500. /* The tree that will be replaced. */
  501. tree old_tree;
  502. /* The new (replacing) tree. */
  503. tree new_tree;
  504. /* Parameter number to replace, when old_tree is NULL. */
  505. int parm_num;
  506. /* True when a substitution should be done, false otherwise. */
  507. bool replace_p;
  508. /* True when we replace a reference to old_tree. */
  509. bool ref_p;
  510. };
  511. struct GTY(()) cgraph_clone_info
  512. {
  513. vec<ipa_replace_map *, va_gc> *tree_map;
  514. bitmap args_to_skip;
  515. bitmap combined_args_to_skip;
  516. };
  517. enum cgraph_simd_clone_arg_type
  518. {
  519. SIMD_CLONE_ARG_TYPE_VECTOR,
  520. SIMD_CLONE_ARG_TYPE_UNIFORM,
  521. SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
  522. SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
  523. SIMD_CLONE_ARG_TYPE_MASK
  524. };
  525. /* Function arguments in the original function of a SIMD clone.
  526. Supplementary data for `struct simd_clone'. */
  527. struct GTY(()) cgraph_simd_clone_arg {
  528. /* Original function argument as it originally existed in
  529. DECL_ARGUMENTS. */
  530. tree orig_arg;
  531. /* orig_arg's function (or for extern functions type from
  532. TYPE_ARG_TYPES). */
  533. tree orig_type;
  534. /* If argument is a vector, this holds the vector version of
  535. orig_arg that after adjusting the argument types will live in
  536. DECL_ARGUMENTS. Otherwise, this is NULL.
  537. This basically holds:
  538. vector(simdlen) __typeof__(orig_arg) new_arg. */
  539. tree vector_arg;
  540. /* vector_arg's type (or for extern functions new vector type. */
  541. tree vector_type;
  542. /* If argument is a vector, this holds the array where the simd
  543. argument is held while executing the simd clone function. This
  544. is a local variable in the cloned function. Its content is
  545. copied from vector_arg upon entry to the clone.
  546. This basically holds:
  547. __typeof__(orig_arg) simd_array[simdlen]. */
  548. tree simd_array;
  549. /* A SIMD clone's argument can be either linear (constant or
  550. variable), uniform, or vector. */
  551. enum cgraph_simd_clone_arg_type arg_type;
  552. /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
  553. the constant linear step, if arg_type is
  554. SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
  555. the uniform argument holding the step, otherwise 0. */
  556. HOST_WIDE_INT linear_step;
  557. /* Variable alignment if available, otherwise 0. */
  558. unsigned int alignment;
  559. };
  560. /* Specific data for a SIMD function clone. */
  561. struct GTY(()) cgraph_simd_clone {
  562. /* Number of words in the SIMD lane associated with this clone. */
  563. unsigned int simdlen;
  564. /* Number of annotated function arguments in `args'. This is
  565. usually the number of named arguments in FNDECL. */
  566. unsigned int nargs;
  567. /* Max hardware vector size in bits for integral vectors. */
  568. unsigned int vecsize_int;
  569. /* Max hardware vector size in bits for floating point vectors. */
  570. unsigned int vecsize_float;
  571. /* The mangling character for a given vector size. This is is used
  572. to determine the ISA mangling bit as specified in the Intel
  573. Vector ABI. */
  574. unsigned char vecsize_mangle;
  575. /* True if this is the masked, in-branch version of the clone,
  576. otherwise false. */
  577. unsigned int inbranch : 1;
  578. /* True if this is a Cilk Plus variant. */
  579. unsigned int cilk_elemental : 1;
  580. /* Doubly linked list of SIMD clones. */
  581. cgraph_node *prev_clone, *next_clone;
  582. /* Original cgraph node the SIMD clones were created for. */
  583. cgraph_node *origin;
  584. /* Annotated function arguments for the original function. */
  585. cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
  586. };
  587. /* Function Multiversioning info. */
  588. struct GTY((for_user)) cgraph_function_version_info {
  589. /* The cgraph_node for which the function version info is stored. */
  590. cgraph_node *this_node;
  591. /* Chains all the semantically identical function versions. The
  592. first function in this chain is the version_info node of the
  593. default function. */
  594. cgraph_function_version_info *prev;
  595. /* If this version node corresponds to a dispatcher for function
  596. versions, this points to the version info node of the default
  597. function, the first node in the chain. */
  598. cgraph_function_version_info *next;
  599. /* If this node corresponds to a function version, this points
  600. to the dispatcher function decl, which is the function that must
  601. be called to execute the right function version at run-time.
  602. If this cgraph node is a dispatcher (if dispatcher_function is
  603. true, in the cgraph_node struct) for function versions, this
  604. points to resolver function, which holds the function body of the
  605. dispatcher. The dispatcher decl is an alias to the resolver
  606. function decl. */
  607. tree dispatcher_resolver;
  608. };
  609. #define DEFCIFCODE(code, type, string) CIF_ ## code,
  610. /* Reasons for inlining failures. */
  611. enum cgraph_inline_failed_t {
  612. #include "cif-code.def"
  613. CIF_N_REASONS
  614. };
  615. enum cgraph_inline_failed_type_t
  616. {
  617. CIF_FINAL_NORMAL = 0,
  618. CIF_FINAL_ERROR
  619. };
  620. struct cgraph_edge;
  621. struct cgraph_edge_hasher : ggc_hasher<cgraph_edge *>
  622. {
  623. typedef gimple compare_type;
  624. static hashval_t hash (cgraph_edge *);
  625. static hashval_t hash (gimple);
  626. static bool equal (cgraph_edge *, gimple);
  627. };
  628. /* The cgraph data structure.
  629. Each function decl has assigned cgraph_node listing callees and callers. */
  630. struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
  631. public:
  632. /* Remove the node from cgraph and all inline clones inlined into it.
  633. Skip however removal of FORBIDDEN_NODE and return true if it needs to be
  634. removed. This allows to call the function from outer loop walking clone
  635. tree. */
  636. bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL);
  637. /* Record all references from cgraph_node that are taken
  638. in statement STMT. */
  639. void record_stmt_references (gimple stmt);
  640. /* Like cgraph_set_call_stmt but walk the clone tree and update all
  641. clones sharing the same function body.
  642. When WHOLE_SPECULATIVE_EDGES is true, all three components of
  643. speculative edge gets updated. Otherwise we update only direct
  644. call. */
  645. void set_call_stmt_including_clones (gimple old_stmt, gcall *new_stmt,
  646. bool update_speculative = true);
  647. /* Walk the alias chain to return the function cgraph_node is alias of.
  648. Walk through thunk, too.
  649. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  650. cgraph_node *function_symbol (enum availability *avail = NULL);
  651. /* Walk the alias chain to return the function cgraph_node is alias of.
  652. Walk through non virtual thunks, too. Thus we return either a function
  653. or a virtual thunk node.
  654. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  655. cgraph_node *function_or_virtual_thunk_symbol
  656. (enum availability *avail = NULL);
  657. /* Create node representing clone of N executed COUNT times. Decrease
  658. the execution counts from original node too.
  659. The new clone will have decl set to DECL that may or may not be the same
  660. as decl of N.
  661. When UPDATE_ORIGINAL is true, the counts are subtracted from the original
  662. function's profile to reflect the fact that part of execution is handled
  663. by node.
  664. When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
  665. the new clone. Otherwise the caller is responsible for doing so later.
  666. If the new node is being inlined into another one, NEW_INLINED_TO should be
  667. the outline function the new one is (even indirectly) inlined to.
  668. All hooks will see this in node's global.inlined_to, when invoked.
  669. Can be NULL if the node is not inlined. */
  670. cgraph_node *create_clone (tree decl, gcov_type count, int freq,
  671. bool update_original,
  672. vec<cgraph_edge *> redirect_callers,
  673. bool call_duplication_hook,
  674. cgraph_node *new_inlined_to,
  675. bitmap args_to_skip);
  676. /* Create callgraph node clone with new declaration. The actual body will
  677. be copied later at compilation stage. */
  678. cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
  679. vec<ipa_replace_map *, va_gc> *tree_map,
  680. bitmap args_to_skip, const char * suffix);
  681. /* cgraph node being removed from symbol table; see if its entry can be
  682. replaced by other inline clone. */
  683. cgraph_node *find_replacement (void);
  684. /* Create a new cgraph node which is the new version of
  685. callgraph node. REDIRECT_CALLERS holds the callers
  686. edges which should be redirected to point to
  687. NEW_VERSION. ALL the callees edges of the node
  688. are cloned to the new version node. Return the new
  689. version node.
  690. If non-NULL BLOCK_TO_COPY determine what basic blocks
  691. was copied to prevent duplications of calls that are dead
  692. in the clone. */
  693. cgraph_node *create_version_clone (tree new_decl,
  694. vec<cgraph_edge *> redirect_callers,
  695. bitmap bbs_to_copy);
  696. /* Perform function versioning.
  697. Function versioning includes copying of the tree and
  698. a callgraph update (creating a new cgraph node and updating
  699. its callees and callers).
  700. REDIRECT_CALLERS varray includes the edges to be redirected
  701. to the new version.
  702. TREE_MAP is a mapping of tree nodes we want to replace with
  703. new ones (according to results of prior analysis).
  704. If non-NULL ARGS_TO_SKIP determine function parameters to remove
  705. from new version.
  706. If SKIP_RETURN is true, the new version will return void.
  707. If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
  708. If non_NULL NEW_ENTRY determine new entry BB of the clone.
  709. Return the new version's cgraph node. */
  710. cgraph_node *create_version_clone_with_body
  711. (vec<cgraph_edge *> redirect_callers,
  712. vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
  713. bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
  714. const char *clone_name);
  715. /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
  716. corresponding to cgraph_node. */
  717. cgraph_function_version_info *insert_new_function_version (void);
  718. /* Get the cgraph_function_version_info node corresponding to node. */
  719. cgraph_function_version_info *function_version (void);
  720. /* Discover all functions and variables that are trivially needed, analyze
  721. them as well as all functions and variables referred by them */
  722. void analyze (void);
  723. /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
  724. aliases DECL with an adjustments made into the first parameter.
  725. See comments in thunk_adjust for detail on the parameters. */
  726. cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
  727. HOST_WIDE_INT fixed_offset,
  728. HOST_WIDE_INT virtual_value,
  729. tree virtual_offset,
  730. tree real_alias);
  731. /* Return node that alias is aliasing. */
  732. inline cgraph_node *get_alias_target (void);
  733. /* Given function symbol, walk the alias chain to return the function node
  734. is alias of. Do not walk through thunks.
  735. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  736. cgraph_node *ultimate_alias_target (availability *availability = NULL);
  737. /* Expand thunk NODE to gimple if possible.
  738. When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
  739. no assembler is produced.
  740. When OUTPUT_ASM_THUNK is true, also produce assembler for
  741. thunks that are not lowered. */
  742. bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk);
  743. /* Call expand_thunk on all callers that are thunks and analyze those
  744. nodes that were expanded. */
  745. void expand_all_artificial_thunks ();
  746. /* Assemble thunks and aliases associated to node. */
  747. void assemble_thunks_and_aliases (void);
  748. /* Expand function specified by node. */
  749. void expand (void);
  750. /* As an GCC extension we allow redefinition of the function. The
  751. semantics when both copies of bodies differ is not well defined.
  752. We replace the old body with new body so in unit at a time mode
  753. we always use new body, while in normal mode we may end up with
  754. old body inlined into some functions and new body expanded and
  755. inlined in others. */
  756. void reset (void);
  757. /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
  758. kind of wrapper method. */
  759. void create_wrapper (cgraph_node *target);
  760. /* Verify cgraph nodes of the cgraph node. */
  761. void DEBUG_FUNCTION verify_node (void);
  762. /* Remove function from symbol table. */
  763. void remove (void);
  764. /* Dump call graph node to file F. */
  765. void dump (FILE *f);
  766. /* Dump call graph node to stderr. */
  767. void DEBUG_FUNCTION debug (void);
  768. /* When doing LTO, read cgraph_node's body from disk if it is not already
  769. present. */
  770. bool get_untransformed_body (void);
  771. /* Prepare function body. When doing LTO, read cgraph_node's body from disk
  772. if it is not already present. When some IPA transformations are scheduled,
  773. apply them. */
  774. bool get_body (void);
  775. /* Release memory used to represent body of function.
  776. Use this only for functions that are released before being translated to
  777. target code (i.e. RTL). Functions that are compiled to RTL and beyond
  778. are free'd in final.c via free_after_compilation(). */
  779. void release_body (bool keep_arguments = false);
  780. /* Return the DECL_STRUCT_FUNCTION of the function. */
  781. struct function *get_fun (void);
  782. /* cgraph_node is no longer nested function; update cgraph accordingly. */
  783. void unnest (void);
  784. /* Bring cgraph node local. */
  785. void make_local (void);
  786. /* Likewise indicate that a node is having address taken. */
  787. void mark_address_taken (void);
  788. /* Set fialization priority to PRIORITY. */
  789. void set_fini_priority (priority_type priority);
  790. /* Return the finalization priority. */
  791. priority_type get_fini_priority (void);
  792. /* Create edge from a given function to CALLEE in the cgraph. */
  793. cgraph_edge *create_edge (cgraph_node *callee,
  794. gcall *call_stmt, gcov_type count,
  795. int freq);
  796. /* Create an indirect edge with a yet-undetermined callee where the call
  797. statement destination is a formal parameter of the caller with index
  798. PARAM_INDEX. */
  799. cgraph_edge *create_indirect_edge (gcall *call_stmt, int ecf_flags,
  800. gcov_type count, int freq,
  801. bool compute_indirect_info = true);
  802. /* Like cgraph_create_edge walk the clone tree and update all clones sharing
  803. same function body. If clones already have edge for OLD_STMT; only
  804. update the edge same way as cgraph_set_call_stmt_including_clones does. */
  805. void create_edge_including_clones (cgraph_node *callee,
  806. gimple old_stmt, gcall *stmt,
  807. gcov_type count,
  808. int freq,
  809. cgraph_inline_failed_t reason);
  810. /* Return the callgraph edge representing the GIMPLE_CALL statement
  811. CALL_STMT. */
  812. cgraph_edge *get_edge (gimple call_stmt);
  813. /* Collect all callers of cgraph_node and its aliases that are known to lead
  814. to NODE (i.e. are not overwritable). */
  815. vec<cgraph_edge *> collect_callers (void);
  816. /* Remove all callers from the node. */
  817. void remove_callers (void);
  818. /* Remove all callees from the node. */
  819. void remove_callees (void);
  820. /* Return function availability. See cgraph.h for description of individual
  821. return values. */
  822. enum availability get_availability (void);
  823. /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
  824. if any to NOTHROW. */
  825. void set_nothrow_flag (bool nothrow);
  826. /* Set TREE_READONLY on cgraph_node's decl and on aliases of the node
  827. if any to READONLY. */
  828. void set_const_flag (bool readonly, bool looping);
  829. /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
  830. if any to PURE. */
  831. void set_pure_flag (bool pure, bool looping);
  832. /* Call callback on function and aliases associated to the function.
  833. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  834. skipped. */
  835. bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
  836. void *),
  837. void *data, bool include_overwritable);
  838. /* Call callback on cgraph_node, thunks and aliases associated to NODE.
  839. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  840. skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
  841. skipped. */
  842. bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
  843. void *data),
  844. void *data,
  845. bool include_overwritable,
  846. bool exclude_virtual_thunks = false);
  847. /* Likewise indicate that a node is needed, i.e. reachable via some
  848. external means. */
  849. inline void mark_force_output (void);
  850. /* Return true when function can be marked local. */
  851. bool local_p (void);
  852. /* Return true if cgraph_node can be made local for API change.
  853. Extern inline functions and C++ COMDAT functions can be made local
  854. at the expense of possible code size growth if function is used in multiple
  855. compilation units. */
  856. bool can_be_local_p (void);
  857. /* Return true when cgraph_node can not return or throw and thus
  858. it is safe to ignore its side effects for IPA analysis. */
  859. bool cannot_return_p (void);
  860. /* Return true when function cgraph_node and all its aliases are only called
  861. directly.
  862. i.e. it is not externally visible, address was not taken and
  863. it is not used in any other non-standard way. */
  864. bool only_called_directly_p (void);
  865. /* Return true when function is only called directly or it has alias.
  866. i.e. it is not externally visible, address was not taken and
  867. it is not used in any other non-standard way. */
  868. inline bool only_called_directly_or_aliased_p (void);
  869. /* Return true when function cgraph_node can be expected to be removed
  870. from program when direct calls in this compilation unit are removed.
  871. As a special case COMDAT functions are
  872. cgraph_can_remove_if_no_direct_calls_p while the are not
  873. cgraph_only_called_directly_p (it is possible they are called from other
  874. unit)
  875. This function behaves as cgraph_only_called_directly_p because eliminating
  876. all uses of COMDAT function does not make it necessarily disappear from
  877. the program unless we are compiling whole program or we do LTO. In this
  878. case we know we win since dynamic linking will not really discard the
  879. linkonce section.
  880. If WILL_INLINE is true, assume that function will be inlined into all the
  881. direct calls. */
  882. bool will_be_removed_from_program_if_no_direct_calls_p
  883. (bool will_inline = false);
  884. /* Return true when function can be removed from callgraph
  885. if all direct calls and references are eliminated. The function does
  886. not take into account comdat groups. */
  887. bool can_remove_if_no_direct_calls_and_refs_p (void);
  888. /* Return true when function cgraph_node and its aliases can be removed from
  889. callgraph if all direct calls are eliminated.
  890. If WILL_INLINE is true, assume that function will be inlined into all the
  891. direct calls. */
  892. bool can_remove_if_no_direct_calls_p (bool will_inline = false);
  893. /* Return true when callgraph node is a function with Gimple body defined
  894. in current unit. Functions can also be define externally or they
  895. can be thunks with no Gimple representation.
  896. Note that at WPA stage, the function body may not be present in memory. */
  897. inline bool has_gimple_body_p (void);
  898. /* Return true if function should be optimized for size. */
  899. bool optimize_for_size_p (void);
  900. /* Dump the callgraph to file F. */
  901. static void dump_cgraph (FILE *f);
  902. /* Dump the call graph to stderr. */
  903. static inline
  904. void debug_cgraph (void)
  905. {
  906. dump_cgraph (stderr);
  907. }
  908. /* Record that DECL1 and DECL2 are semantically identical function
  909. versions. */
  910. static void record_function_versions (tree decl1, tree decl2);
  911. /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
  912. DECL is a duplicate declaration. */
  913. static void delete_function_version (tree decl);
  914. /* Add the function FNDECL to the call graph.
  915. Unlike finalize_function, this function is intended to be used
  916. by middle end and allows insertion of new function at arbitrary point
  917. of compilation. The function can be either in high, low or SSA form
  918. GIMPLE.
  919. The function is assumed to be reachable and have address taken (so no
  920. API breaking optimizations are performed on it).
  921. Main work done by this function is to enqueue the function for later
  922. processing to avoid need the passes to be re-entrant. */
  923. static void add_new_function (tree fndecl, bool lowered);
  924. /* Return callgraph node for given symbol and check it is a function. */
  925. static inline cgraph_node *get (const_tree decl)
  926. {
  927. gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
  928. return dyn_cast <cgraph_node *> (symtab_node::get (decl));
  929. }
  930. /* DECL has been parsed. Take it, queue it, compile it at the whim of the
  931. logic in effect. If NO_COLLECT is true, then our caller cannot stand to
  932. have the garbage collector run at the moment. We would need to either
  933. create a new GC context, or just not compile right now. */
  934. static void finalize_function (tree, bool);
  935. /* Return cgraph node assigned to DECL. Create new one when needed. */
  936. static cgraph_node * create (tree decl);
  937. /* Try to find a call graph node for declaration DECL and if it does not
  938. exist or if it corresponds to an inline clone, create a new one. */
  939. static cgraph_node * get_create (tree);
  940. /* Return local info for the compiled function. */
  941. static cgraph_local_info *local_info (tree decl);
  942. /* Return local info for the compiled function. */
  943. static cgraph_rtl_info *rtl_info (tree);
  944. /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
  945. Return NULL if there's no such node. */
  946. static cgraph_node *get_for_asmname (tree asmname);
  947. /* Attempt to mark ALIAS as an alias to DECL. Return alias node if
  948. successful and NULL otherwise.
  949. Same body aliases are output whenever the body of DECL is output,
  950. and cgraph_node::get (ALIAS) transparently
  951. returns cgraph_node::get (DECL). */
  952. static cgraph_node * create_same_body_alias (tree alias, tree decl);
  953. /* Verify whole cgraph structure. */
  954. static void DEBUG_FUNCTION verify_cgraph_nodes (void);
  955. /* Worker to bring NODE local. */
  956. static bool make_local (cgraph_node *node, void *);
  957. /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
  958. the function body is associated
  959. with (not necessarily cgraph_node (DECL). */
  960. static cgraph_node *create_alias (tree alias, tree target);
  961. /* Return true if NODE has thunk. */
  962. static bool has_thunk_p (cgraph_node *node, void *);
  963. cgraph_edge *callees;
  964. cgraph_edge *callers;
  965. /* List of edges representing indirect calls with a yet undetermined
  966. callee. */
  967. cgraph_edge *indirect_calls;
  968. /* For nested functions points to function the node is nested in. */
  969. cgraph_node *origin;
  970. /* Points to first nested function, if any. */
  971. cgraph_node *nested;
  972. /* Pointer to the next function with same origin, if any. */
  973. cgraph_node *next_nested;
  974. /* Pointer to the next clone. */
  975. cgraph_node *next_sibling_clone;
  976. cgraph_node *prev_sibling_clone;
  977. cgraph_node *clones;
  978. cgraph_node *clone_of;
  979. /* If instrumentation_clone is 1 then instrumented_version points
  980. to the original function used to make instrumented version.
  981. Otherwise points to instrumented version of the function. */
  982. cgraph_node *instrumented_version;
  983. /* If instrumentation_clone is 1 then orig_decl is the original
  984. function declaration. */
  985. tree orig_decl;
  986. /* For functions with many calls sites it holds map from call expression
  987. to the edge to speed up cgraph_edge function. */
  988. hash_table<cgraph_edge_hasher> *GTY(()) call_site_hash;
  989. /* Declaration node used to be clone of. */
  990. tree former_clone_of;
  991. /* If this is a SIMD clone, this points to the SIMD specific
  992. information for it. */
  993. cgraph_simd_clone *simdclone;
  994. /* If this function has SIMD clones, this points to the first clone. */
  995. cgraph_node *simd_clones;
  996. /* Interprocedural passes scheduled to have their transform functions
  997. applied next time we execute local pass on them. We maintain it
  998. per-function in order to allow IPA passes to introduce new functions. */
  999. vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
  1000. cgraph_local_info local;
  1001. cgraph_global_info global;
  1002. cgraph_rtl_info rtl;
  1003. cgraph_clone_info clone;
  1004. cgraph_thunk_info thunk;
  1005. /* Expected number of executions: calculated in profile.c. */
  1006. gcov_type count;
  1007. /* How to scale counts at materialization time; used to merge
  1008. LTO units with different number of profile runs. */
  1009. int count_materialization_scale;
  1010. /* Unique id of the node. */
  1011. int uid;
  1012. /* Summary unique id of the node. */
  1013. int summary_uid;
  1014. /* ID assigned by the profiling. */
  1015. unsigned int profile_id;
  1016. /* Time profiler: first run of function. */
  1017. int tp_first_run;
  1018. /* Set when decl is an abstract function pointed to by the
  1019. ABSTRACT_DECL_ORIGIN of a reachable function. */
  1020. unsigned used_as_abstract_origin : 1;
  1021. /* Set once the function is lowered (i.e. its CFG is built). */
  1022. unsigned lowered : 1;
  1023. /* Set once the function has been instantiated and its callee
  1024. lists created. */
  1025. unsigned process : 1;
  1026. /* How commonly executed the node is. Initialized during branch
  1027. probabilities pass. */
  1028. ENUM_BITFIELD (node_frequency) frequency : 2;
  1029. /* True when function can only be called at startup (from static ctor). */
  1030. unsigned only_called_at_startup : 1;
  1031. /* True when function can only be called at startup (from static dtor). */
  1032. unsigned only_called_at_exit : 1;
  1033. /* True when function is the transactional clone of a function which
  1034. is called only from inside transactions. */
  1035. /* ?? We should be able to remove this. We have enough bits in
  1036. cgraph to calculate it. */
  1037. unsigned tm_clone : 1;
  1038. /* True if this decl is a dispatcher for function versions. */
  1039. unsigned dispatcher_function : 1;
  1040. /* True if this decl calls a COMDAT-local function. This is set up in
  1041. compute_inline_parameters and inline_call. */
  1042. unsigned calls_comdat_local : 1;
  1043. /* True if node has been created by merge operation in IPA-ICF. */
  1044. unsigned icf_merged: 1;
  1045. /* True when function is clone created for Pointer Bounds Checker
  1046. instrumentation. */
  1047. unsigned instrumentation_clone : 1;
  1048. /* True if call to node can't result in a call to free, munmap or
  1049. other operation that could make previously non-trapping memory
  1050. accesses trapping. */
  1051. unsigned nonfreeing_fn : 1;
  1052. /* True if there was multiple COMDAT bodies merged by lto-symtab. */
  1053. unsigned merged : 1;
  1054. /* True if function was created to be executed in parallel. */
  1055. unsigned parallelized_function : 1;
  1056. /* True if function is part split out by ipa-split. */
  1057. unsigned split_part : 1;
  1058. private:
  1059. /* Worker for call_for_symbol_and_aliases. */
  1060. bool call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
  1061. void *),
  1062. void *data, bool include_overwritable);
  1063. };
  1064. /* A cgraph node set is a collection of cgraph nodes. A cgraph node
  1065. can appear in multiple sets. */
  1066. struct cgraph_node_set_def
  1067. {
  1068. hash_map<cgraph_node *, size_t> *map;
  1069. vec<cgraph_node *> nodes;
  1070. };
  1071. typedef cgraph_node_set_def *cgraph_node_set;
  1072. typedef struct varpool_node_set_def *varpool_node_set;
  1073. class varpool_node;
  1074. /* A varpool node set is a collection of varpool nodes. A varpool node
  1075. can appear in multiple sets. */
  1076. struct varpool_node_set_def
  1077. {
  1078. hash_map<varpool_node *, size_t> * map;
  1079. vec<varpool_node *> nodes;
  1080. };
  1081. /* Iterator structure for cgraph node sets. */
  1082. struct cgraph_node_set_iterator
  1083. {
  1084. cgraph_node_set set;
  1085. unsigned index;
  1086. };
  1087. /* Iterator structure for varpool node sets. */
  1088. struct varpool_node_set_iterator
  1089. {
  1090. varpool_node_set set;
  1091. unsigned index;
  1092. };
  1093. /* Context of polymorphic call. It represent information about the type of
  1094. instance that may reach the call. This is used by ipa-devirt walkers of the
  1095. type inheritance graph. */
  1096. class GTY(()) ipa_polymorphic_call_context {
  1097. public:
  1098. /* The called object appears in an object of type OUTER_TYPE
  1099. at offset OFFSET. When information is not 100% reliable, we
  1100. use SPECULATIVE_OUTER_TYPE and SPECULATIVE_OFFSET. */
  1101. HOST_WIDE_INT offset;
  1102. HOST_WIDE_INT speculative_offset;
  1103. tree outer_type;
  1104. tree speculative_outer_type;
  1105. /* True if outer object may be in construction or destruction. */
  1106. unsigned maybe_in_construction : 1;
  1107. /* True if outer object may be of derived type. */
  1108. unsigned maybe_derived_type : 1;
  1109. /* True if speculative outer object may be of derived type. We always
  1110. speculate that construction does not happen. */
  1111. unsigned speculative_maybe_derived_type : 1;
  1112. /* True if the context is invalid and all calls should be redirected
  1113. to BUILTIN_UNREACHABLE. */
  1114. unsigned invalid : 1;
  1115. /* True if the outer type is dynamic. */
  1116. unsigned dynamic : 1;
  1117. /* Build empty "I know nothing" context. */
  1118. ipa_polymorphic_call_context ();
  1119. /* Build polymorphic call context for indirect call E. */
  1120. ipa_polymorphic_call_context (cgraph_edge *e);
  1121. /* Build polymorphic call context for IP invariant CST.
  1122. If specified, OTR_TYPE specify the type of polymorphic call
  1123. that takes CST+OFFSET as a prameter. */
  1124. ipa_polymorphic_call_context (tree cst, tree otr_type = NULL,
  1125. HOST_WIDE_INT offset = 0);
  1126. /* Build context for pointer REF contained in FNDECL at statement STMT.
  1127. if INSTANCE is non-NULL, return pointer to the object described by
  1128. the context. */
  1129. ipa_polymorphic_call_context (tree fndecl, tree ref, gimple stmt,
  1130. tree *instance = NULL);
  1131. /* Look for vtable stores or constructor calls to work out dynamic type
  1132. of memory location. */
  1133. bool get_dynamic_type (tree, tree, tree, gimple);
  1134. /* Make context non-speculative. */
  1135. void clear_speculation ();
  1136. /* Produce context specifying all derrived types of OTR_TYPE. If OTR_TYPE is
  1137. NULL, the context is set to dummy "I know nothing" setting. */
  1138. void clear_outer_type (tree otr_type = NULL);
  1139. /* Walk container types and modify context to point to actual class
  1140. containing OTR_TYPE (if non-NULL) as base class.
  1141. Return true if resulting context is valid.
  1142. When CONSIDER_PLACEMENT_NEW is false, reject contexts that may be made
  1143. valid only via alocation of new polymorphic type inside by means
  1144. of placement new.
  1145. When CONSIDER_BASES is false, only look for actual fields, not base types
  1146. of TYPE. */
  1147. bool restrict_to_inner_class (tree otr_type,
  1148. bool consider_placement_new = true,
  1149. bool consider_bases = true);
  1150. /* Adjust all offsets in contexts by given number of bits. */
  1151. void offset_by (HOST_WIDE_INT);
  1152. /* Use when we can not track dynamic type change. This speculatively assume
  1153. type change is not happening. */
  1154. void possible_dynamic_type_change (bool, tree otr_type = NULL);
  1155. /* Assume that both THIS and a given context is valid and strenghten THIS
  1156. if possible. Return true if any strenghtening was made.
  1157. If actual type the context is being used in is known, OTR_TYPE should be
  1158. set accordingly. This improves quality of combined result. */
  1159. bool combine_with (ipa_polymorphic_call_context, tree otr_type = NULL);
  1160. bool meet_with (ipa_polymorphic_call_context, tree otr_type = NULL);
  1161. /* Return TRUE if context is fully useless. */
  1162. bool useless_p () const;
  1163. /* Return TRUE if this context conveys the same information as X. */
  1164. bool equal_to (const ipa_polymorphic_call_context &x) const;
  1165. /* Dump human readable context to F. If NEWLINE is true, it will be
  1166. terminated by a newline. */
  1167. void dump (FILE *f, bool newline = true) const;
  1168. void DEBUG_FUNCTION debug () const;
  1169. /* LTO streaming. */
  1170. void stream_out (struct output_block *) const;
  1171. void stream_in (struct lto_input_block *, struct data_in *data_in);
  1172. private:
  1173. bool combine_speculation_with (tree, HOST_WIDE_INT, bool, tree);
  1174. bool meet_speculation_with (tree, HOST_WIDE_INT, bool, tree);
  1175. void set_by_decl (tree, HOST_WIDE_INT);
  1176. bool set_by_invariant (tree, tree, HOST_WIDE_INT);
  1177. bool speculation_consistent_p (tree, HOST_WIDE_INT, bool, tree) const;
  1178. void make_speculative (tree otr_type = NULL);
  1179. };
  1180. /* Structure containing additional information about an indirect call. */
  1181. struct GTY(()) cgraph_indirect_call_info
  1182. {
  1183. /* When agg_content is set, an offset where the call pointer is located
  1184. within the aggregate. */
  1185. HOST_WIDE_INT offset;
  1186. /* Context of the polymorphic call; use only when POLYMORPHIC flag is set. */
  1187. ipa_polymorphic_call_context context;
  1188. /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
  1189. HOST_WIDE_INT otr_token;
  1190. /* Type of the object from OBJ_TYPE_REF_OBJECT. */
  1191. tree otr_type;
  1192. /* Index of the parameter that is called. */
  1193. int param_index;
  1194. /* ECF flags determined from the caller. */
  1195. int ecf_flags;
  1196. /* Profile_id of common target obtrained from profile. */
  1197. int common_target_id;
  1198. /* Probability that call will land in function with COMMON_TARGET_ID. */
  1199. int common_target_probability;
  1200. /* Set when the call is a virtual call with the parameter being the
  1201. associated object pointer rather than a simple direct call. */
  1202. unsigned polymorphic : 1;
  1203. /* Set when the call is a call of a pointer loaded from contents of an
  1204. aggregate at offset. */
  1205. unsigned agg_contents : 1;
  1206. /* Set when this is a call through a member pointer. */
  1207. unsigned member_ptr : 1;
  1208. /* When the previous bit is set, this one determines whether the destination
  1209. is loaded from a parameter passed by reference. */
  1210. unsigned by_ref : 1;
  1211. /* For polymorphic calls this specify whether the virtual table pointer
  1212. may have changed in between function entry and the call. */
  1213. unsigned vptr_changed : 1;
  1214. };
  1215. struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"),
  1216. for_user)) cgraph_edge {
  1217. friend class cgraph_node;
  1218. /* Remove the edge in the cgraph. */
  1219. void remove (void);
  1220. /* Change field call_stmt of edge to NEW_STMT.
  1221. If UPDATE_SPECULATIVE and E is any component of speculative
  1222. edge, then update all components. */
  1223. void set_call_stmt (gcall *new_stmt, bool update_speculative = true);
  1224. /* Redirect callee of the edge to N. The function does not update underlying
  1225. call expression. */
  1226. void redirect_callee (cgraph_node *n);
  1227. /* If the edge does not lead to a thunk, simply redirect it to N. Otherwise
  1228. create one or more equivalent thunks for N and redirect E to the first in
  1229. the chain. Note that it is then necessary to call
  1230. n->expand_all_artificial_thunks once all callers are redirected. */
  1231. void redirect_callee_duplicating_thunks (cgraph_node *n);
  1232. /* Make an indirect edge with an unknown callee an ordinary edge leading to
  1233. CALLEE. DELTA is an integer constant that is to be added to the this
  1234. pointer (first parameter) to compensate for skipping
  1235. a thunk adjustment. */
  1236. cgraph_edge *make_direct (cgraph_node *callee);
  1237. /* Turn edge into speculative call calling N2. Update
  1238. the profile so the direct call is taken COUNT times
  1239. with FREQUENCY. */
  1240. cgraph_edge *make_speculative (cgraph_node *n2, gcov_type direct_count,
  1241. int direct_frequency);
  1242. /* Given speculative call edge, return all three components. */
  1243. void speculative_call_info (cgraph_edge *&direct, cgraph_edge *&indirect,
  1244. ipa_ref *&reference);
  1245. /* Speculative call edge turned out to be direct call to CALLE_DECL.
  1246. Remove the speculative call sequence and return edge representing the call.
  1247. It is up to caller to redirect the call as appropriate. */
  1248. cgraph_edge *resolve_speculation (tree callee_decl = NULL);
  1249. /* If necessary, change the function declaration in the call statement
  1250. associated with the edge so that it corresponds to the edge callee. */
  1251. gimple redirect_call_stmt_to_callee (void);
  1252. /* Create clone of edge in the node N represented
  1253. by CALL_EXPR the callgraph. */
  1254. cgraph_edge * clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
  1255. gcov_type count_scale, int freq_scale, bool update_original);
  1256. /* Verify edge count and frequency. */
  1257. bool verify_count_and_frequency ();
  1258. /* Return true when call of edge can not lead to return from caller
  1259. and thus it is safe to ignore its side effects for IPA analysis
  1260. when computing side effects of the caller. */
  1261. bool cannot_lead_to_return_p (void);
  1262. /* Return true when the edge represents a direct recursion. */
  1263. bool recursive_p (void);
  1264. /* Return true if the call can be hot. */
  1265. bool maybe_hot_p (void);
  1266. /* Rebuild cgraph edges for current function node. This needs to be run after
  1267. passes that don't update the cgraph. */
  1268. static unsigned int rebuild_edges (void);
  1269. /* Rebuild cgraph references for current function node. This needs to be run
  1270. after passes that don't update the cgraph. */
  1271. static void rebuild_references (void);
  1272. /* Expected number of executions: calculated in profile.c. */
  1273. gcov_type count;
  1274. cgraph_node *caller;
  1275. cgraph_node *callee;
  1276. cgraph_edge *prev_caller;
  1277. cgraph_edge *next_caller;
  1278. cgraph_edge *prev_callee;
  1279. cgraph_edge *next_callee;
  1280. gcall *call_stmt;
  1281. /* Additional information about an indirect call. Not cleared when an edge
  1282. becomes direct. */
  1283. cgraph_indirect_call_info *indirect_info;
  1284. PTR GTY ((skip (""))) aux;
  1285. /* When equal to CIF_OK, inline this call. Otherwise, points to the
  1286. explanation why function was not inlined. */
  1287. enum cgraph_inline_failed_t inline_failed;
  1288. /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
  1289. when the function is serialized in. */
  1290. unsigned int lto_stmt_uid;
  1291. /* Expected frequency of executions within the function.
  1292. When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
  1293. per function call. The range is 0 to CGRAPH_FREQ_MAX. */
  1294. int frequency;
  1295. /* Unique id of the edge. */
  1296. int uid;
  1297. /* Whether this edge was made direct by indirect inlining. */
  1298. unsigned int indirect_inlining_edge : 1;
  1299. /* Whether this edge describes an indirect call with an undetermined
  1300. callee. */
  1301. unsigned int indirect_unknown_callee : 1;
  1302. /* Whether this edge is still a dangling */
  1303. /* True if the corresponding CALL stmt cannot be inlined. */
  1304. unsigned int call_stmt_cannot_inline_p : 1;
  1305. /* Can this call throw externally? */
  1306. unsigned int can_throw_external : 1;
  1307. /* Edges with SPECULATIVE flag represents indirect calls that was
  1308. speculatively turned into direct (i.e. by profile feedback).
  1309. The final code sequence will have form:
  1310. if (call_target == expected_fn)
  1311. expected_fn ();
  1312. else
  1313. call_target ();
  1314. Every speculative call is represented by three components attached
  1315. to a same call statement:
  1316. 1) a direct call (to expected_fn)
  1317. 2) an indirect call (to call_target)
  1318. 3) a IPA_REF_ADDR refrence to expected_fn.
  1319. Optimizers may later redirect direct call to clone, so 1) and 3)
  1320. do not need to necesarily agree with destination. */
  1321. unsigned int speculative : 1;
  1322. /* Set to true when caller is a constructor or destructor of polymorphic
  1323. type. */
  1324. unsigned in_polymorphic_cdtor : 1;
  1325. private:
  1326. /* Remove the edge from the list of the callers of the callee. */
  1327. void remove_caller (void);
  1328. /* Remove the edge from the list of the callees of the caller. */
  1329. void remove_callee (void);
  1330. /* Set callee N of call graph edge and add it to the corresponding set of
  1331. callers. */
  1332. void set_callee (cgraph_node *n);
  1333. /* Output flags of edge to a file F. */
  1334. void dump_edge_flags (FILE *f);
  1335. /* Verify that call graph edge corresponds to DECL from the associated
  1336. statement. Return true if the verification should fail. */
  1337. bool verify_corresponds_to_fndecl (tree decl);
  1338. };
  1339. #define CGRAPH_FREQ_BASE 1000
  1340. #define CGRAPH_FREQ_MAX 100000
  1341. /* The varpool data structure.
  1342. Each static variable decl has assigned varpool_node. */
  1343. class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
  1344. public:
  1345. /* Dump given varpool node to F. */
  1346. void dump (FILE *f);
  1347. /* Dump given varpool node to stderr. */
  1348. void DEBUG_FUNCTION debug (void);
  1349. /* Remove variable from symbol table. */
  1350. void remove (void);
  1351. /* Remove node initializer when it is no longer needed. */
  1352. void remove_initializer (void);
  1353. void analyze (void);
  1354. /* Return variable availability. */
  1355. availability get_availability (void);
  1356. /* When doing LTO, read variable's constructor from disk if
  1357. it is not already present. */
  1358. tree get_constructor (void);
  1359. /* Return true if variable has constructor that can be used for folding. */
  1360. bool ctor_useable_for_folding_p (void);
  1361. /* For given variable pool node, walk the alias chain to return the function
  1362. the variable is alias of. Do not walk through thunks.
  1363. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  1364. inline varpool_node *ultimate_alias_target
  1365. (availability *availability = NULL);
  1366. /* Return node that alias is aliasing. */
  1367. inline varpool_node *get_alias_target (void);
  1368. /* Output one variable, if necessary. Return whether we output it. */
  1369. bool assemble_decl (void);
  1370. /* For variables in named sections make sure get_variable_section
  1371. is called before we switch to those sections. Then section
  1372. conflicts between read-only and read-only requiring relocations
  1373. sections can be resolved. */
  1374. void finalize_named_section_flags (void);
  1375. /* Call calback on varpool symbol and aliases associated to varpool symbol.
  1376. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  1377. skipped. */
  1378. bool call_for_symbol_and_aliases (bool (*callback) (varpool_node *, void *),
  1379. void *data,
  1380. bool include_overwritable);
  1381. /* Return true when variable should be considered externally visible. */
  1382. bool externally_visible_p (void);
  1383. /* Return true when all references to variable must be visible
  1384. in ipa_ref_list.
  1385. i.e. if the variable is not externally visible or not used in some magic
  1386. way (asm statement or such).
  1387. The magic uses are all summarized in force_output flag. */
  1388. inline bool all_refs_explicit_p ();
  1389. /* Return true when variable can be removed from variable pool
  1390. if all direct calls are eliminated. */
  1391. inline bool can_remove_if_no_refs_p (void);
  1392. /* Add the variable DECL to the varpool.
  1393. Unlike finalize_decl function is intended to be used
  1394. by middle end and allows insertion of new variable at arbitrary point
  1395. of compilation. */
  1396. static void add (tree decl);
  1397. /* Return varpool node for given symbol and check it is a function. */
  1398. static inline varpool_node *get (const_tree decl);
  1399. /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
  1400. the middle end to output the variable to asm file, if needed or externally
  1401. visible. */
  1402. static void finalize_decl (tree decl);
  1403. /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
  1404. Extra name aliases are output whenever DECL is output. */
  1405. static varpool_node * create_extra_name_alias (tree alias, tree decl);
  1406. /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
  1407. Extra name aliases are output whenever DECL is output. */
  1408. static varpool_node * create_alias (tree, tree);
  1409. /* Dump the variable pool to F. */
  1410. static void dump_varpool (FILE *f);
  1411. /* Dump the variable pool to stderr. */
  1412. static void DEBUG_FUNCTION debug_varpool (void);
  1413. /* Allocate new callgraph node and insert it into basic data structures. */
  1414. static varpool_node *create_empty (void);
  1415. /* Return varpool node assigned to DECL. Create new one when needed. */
  1416. static varpool_node *get_create (tree decl);
  1417. /* Given an assembler name, lookup node. */
  1418. static varpool_node *get_for_asmname (tree asmname);
  1419. /* Set when variable is scheduled to be assembled. */
  1420. unsigned output : 1;
  1421. /* Set when variable has statically initialized pointer
  1422. or is a static bounds variable and needs initalization. */
  1423. unsigned need_bounds_init : 1;
  1424. /* Set if the variable is dynamically initialized, except for
  1425. function local statics. */
  1426. unsigned dynamically_initialized : 1;
  1427. ENUM_BITFIELD(tls_model) tls_model : 3;
  1428. /* Set if the variable is known to be used by single function only.
  1429. This is computed by ipa_signle_use pass and used by late optimizations
  1430. in places where optimization would be valid for local static variable
  1431. if we did not do any inter-procedural code movement. */
  1432. unsigned used_by_single_function : 1;
  1433. private:
  1434. /* Assemble thunks and aliases associated to varpool node. */
  1435. void assemble_aliases (void);
  1436. /* Worker for call_for_node_and_aliases. */
  1437. bool call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *, void *),
  1438. void *data,
  1439. bool include_overwritable);
  1440. };
  1441. /* Every top level asm statement is put into a asm_node. */
  1442. struct GTY(()) asm_node {
  1443. /* Next asm node. */
  1444. asm_node *next;
  1445. /* String for this asm node. */
  1446. tree asm_str;
  1447. /* Ordering of all cgraph nodes. */
  1448. int order;
  1449. };
  1450. /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
  1451. template <>
  1452. template <>
  1453. inline bool
  1454. is_a_helper <cgraph_node *>::test (symtab_node *p)
  1455. {
  1456. return p && p->type == SYMTAB_FUNCTION;
  1457. }
  1458. /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
  1459. template <>
  1460. template <>
  1461. inline bool
  1462. is_a_helper <varpool_node *>::test (symtab_node *p)
  1463. {
  1464. return p && p->type == SYMTAB_VARIABLE;
  1465. }
  1466. /* Macros to access the next item in the list of free cgraph nodes and
  1467. edges. */
  1468. #define NEXT_FREE_NODE(NODE) dyn_cast<cgraph_node *> ((NODE)->next)
  1469. #define SET_NEXT_FREE_NODE(NODE,NODE2) ((NODE))->next = NODE2
  1470. #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
  1471. typedef void (*cgraph_edge_hook)(cgraph_edge *, void *);
  1472. typedef void (*cgraph_node_hook)(cgraph_node *, void *);
  1473. typedef void (*varpool_node_hook)(varpool_node *, void *);
  1474. typedef void (*cgraph_2edge_hook)(cgraph_edge *, cgraph_edge *, void *);
  1475. typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, void *);
  1476. struct cgraph_edge_hook_list;
  1477. struct cgraph_node_hook_list;
  1478. struct varpool_node_hook_list;
  1479. struct cgraph_2edge_hook_list;
  1480. struct cgraph_2node_hook_list;
  1481. /* Map from a symbol to initialization/finalization priorities. */
  1482. struct GTY(()) symbol_priority_map {
  1483. priority_type init;
  1484. priority_type fini;
  1485. };
  1486. enum symtab_state
  1487. {
  1488. /* Frontend is parsing and finalizing functions. */
  1489. PARSING,
  1490. /* Callgraph is being constructed. It is safe to add new functions. */
  1491. CONSTRUCTION,
  1492. /* Callgraph is being streamed-in at LTO time. */
  1493. LTO_STREAMING,
  1494. /* Callgraph is built and early IPA passes are being run. */
  1495. IPA,
  1496. /* Callgraph is built and all functions are transformed to SSA form. */
  1497. IPA_SSA,
  1498. /* All inline decisions are done; it is now possible to remove extern inline
  1499. functions and virtual call targets. */
  1500. IPA_SSA_AFTER_INLINING,
  1501. /* Functions are now ordered and being passed to RTL expanders. */
  1502. EXPANSION,
  1503. /* All cgraph expansion is done. */
  1504. FINISHED
  1505. };
  1506. struct asmname_hasher
  1507. {
  1508. typedef symtab_node *value_type;
  1509. typedef const_tree compare_type;
  1510. typedef int store_values_directly;
  1511. static hashval_t hash (symtab_node *n);
  1512. static bool equal (symtab_node *n, const_tree t);
  1513. static void ggc_mx (symtab_node *n);
  1514. static void pch_nx (symtab_node *&);
  1515. static void pch_nx (symtab_node *&, gt_pointer_operator, void *);
  1516. static void remove (symtab_node *) {}
  1517. };
  1518. class GTY((tag ("SYMTAB"))) symbol_table
  1519. {
  1520. public:
  1521. friend class symtab_node;
  1522. friend class cgraph_node;
  1523. friend class cgraph_edge;
  1524. symbol_table (): cgraph_max_summary_uid (1)
  1525. {
  1526. }
  1527. /* Initialize callgraph dump file. */
  1528. void initialize (void);
  1529. /* Register a top-level asm statement ASM_STR. */
  1530. inline asm_node *finalize_toplevel_asm (tree asm_str);
  1531. /* Analyze the whole compilation unit once it is parsed completely. */
  1532. void finalize_compilation_unit (void);
  1533. /* C++ frontend produce same body aliases all over the place, even before PCH
  1534. gets streamed out. It relies on us linking the aliases with their function
  1535. in order to do the fixups, but ipa-ref is not PCH safe. Consequentely we
  1536. first produce aliases without links, but once C++ FE is sure he won't sream
  1537. PCH we build the links via this function. */
  1538. void process_same_body_aliases (void);
  1539. /* Perform simple optimizations based on callgraph. */
  1540. void compile (void);
  1541. /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
  1542. functions into callgraph in a way so they look like ordinary reachable
  1543. functions inserted into callgraph already at construction time. */
  1544. void process_new_functions (void);
  1545. /* Once all functions from compilation unit are in memory, produce all clones
  1546. and update all calls. We might also do this on demand if we don't want to
  1547. bring all functions to memory prior compilation, but current WHOPR
  1548. implementation does that and it is is bit easier to keep everything right
  1549. in this order. */
  1550. void materialize_all_clones (void);
  1551. /* Register a symbol NODE. */
  1552. inline void register_symbol (symtab_node *node);
  1553. inline void
  1554. clear_asm_symbols (void)
  1555. {
  1556. asmnodes = NULL;
  1557. asm_last_node = NULL;
  1558. }
  1559. /* Perform reachability analysis and reclaim all unreachable nodes. */
  1560. bool remove_unreachable_nodes (FILE *file);
  1561. /* Optimization of function bodies might've rendered some variables as
  1562. unnecessary so we want to avoid these from being compiled. Re-do
  1563. reachability starting from variables that are either externally visible
  1564. or was referred from the asm output routines. */
  1565. void remove_unreferenced_decls (void);
  1566. /* Unregister a symbol NODE. */
  1567. inline void unregister (symtab_node *node);
  1568. /* Allocate new callgraph node and insert it into basic data structures. */
  1569. cgraph_node *create_empty (void);
  1570. /* Release a callgraph NODE with UID and put in to the list
  1571. of free nodes. */
  1572. void release_symbol (cgraph_node *node, int uid);
  1573. /* Output all variables enqueued to be assembled. */
  1574. bool output_variables (void);
  1575. /* Weakrefs may be associated to external decls and thus not output
  1576. at expansion time. Emit all necessary aliases. */
  1577. void output_weakrefs (void);
  1578. /* Return first static symbol with definition. */
  1579. inline symtab_node *first_symbol (void);
  1580. /* Return first assembler symbol. */
  1581. inline asm_node *
  1582. first_asm_symbol (void)
  1583. {
  1584. return asmnodes;
  1585. }
  1586. /* Return first static symbol with definition. */
  1587. inline symtab_node *first_defined_symbol (void);
  1588. /* Return first variable. */
  1589. inline varpool_node *first_variable (void);
  1590. /* Return next variable after NODE. */
  1591. inline varpool_node *next_variable (varpool_node *node);
  1592. /* Return first static variable with initializer. */
  1593. inline varpool_node *first_static_initializer (void);
  1594. /* Return next static variable with initializer after NODE. */
  1595. inline varpool_node *next_static_initializer (varpool_node *node);
  1596. /* Return first static variable with definition. */
  1597. inline varpool_node *first_defined_variable (void);
  1598. /* Return next static variable with definition after NODE. */
  1599. inline varpool_node *next_defined_variable (varpool_node *node);
  1600. /* Return first function with body defined. */
  1601. inline cgraph_node *first_defined_function (void);
  1602. /* Return next function with body defined after NODE. */
  1603. inline cgraph_node *next_defined_function (cgraph_node *node);
  1604. /* Return first function. */
  1605. inline cgraph_node *first_function (void);
  1606. /* Return next function. */
  1607. inline cgraph_node *next_function (cgraph_node *node);
  1608. /* Return first function with body defined. */
  1609. cgraph_node *first_function_with_gimple_body (void);
  1610. /* Return next reachable static variable with initializer after NODE. */
  1611. inline cgraph_node *next_function_with_gimple_body (cgraph_node *node);
  1612. /* Register HOOK to be called with DATA on each removed edge. */
  1613. cgraph_edge_hook_list *add_edge_removal_hook (cgraph_edge_hook hook,
  1614. void *data);
  1615. /* Remove ENTRY from the list of hooks called on removing edges. */
  1616. void remove_edge_removal_hook (cgraph_edge_hook_list *entry);
  1617. /* Register HOOK to be called with DATA on each removed node. */
  1618. cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook hook,
  1619. void *data);
  1620. /* Remove ENTRY from the list of hooks called on removing nodes. */
  1621. void remove_cgraph_removal_hook (cgraph_node_hook_list *entry);
  1622. /* Register HOOK to be called with DATA on each removed node. */
  1623. varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook hook,
  1624. void *data);
  1625. /* Remove ENTRY from the list of hooks called on removing nodes. */
  1626. void remove_varpool_removal_hook (varpool_node_hook_list *entry);
  1627. /* Register HOOK to be called with DATA on each inserted node. */
  1628. cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook hook,
  1629. void *data);
  1630. /* Remove ENTRY from the list of hooks called on inserted nodes. */
  1631. void remove_cgraph_insertion_hook (cgraph_node_hook_list *entry);
  1632. /* Register HOOK to be called with DATA on each inserted node. */
  1633. varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook hook,
  1634. void *data);
  1635. /* Remove ENTRY from the list of hooks called on inserted nodes. */
  1636. void remove_varpool_insertion_hook (varpool_node_hook_list *entry);
  1637. /* Register HOOK to be called with DATA on each duplicated edge. */
  1638. cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook hook,
  1639. void *data);
  1640. /* Remove ENTRY from the list of hooks called on duplicating edges. */
  1641. void remove_edge_duplication_hook (cgraph_2edge_hook_list *entry);
  1642. /* Register HOOK to be called with DATA on each duplicated node. */
  1643. cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook hook,
  1644. void *data);
  1645. /* Remove ENTRY from the list of hooks called on duplicating nodes. */
  1646. void remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry);
  1647. /* Call all edge removal hooks. */
  1648. void call_edge_removal_hooks (cgraph_edge *e);
  1649. /* Call all node insertion hooks. */
  1650. void call_cgraph_insertion_hooks (cgraph_node *node);
  1651. /* Call all node removal hooks. */
  1652. void call_cgraph_removal_hooks (cgraph_node *node);
  1653. /* Call all node duplication hooks. */
  1654. void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2);
  1655. /* Call all edge duplication hooks. */
  1656. void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2);
  1657. /* Call all node removal hooks. */
  1658. void call_varpool_removal_hooks (varpool_node *node);
  1659. /* Call all node insertion hooks. */
  1660. void call_varpool_insertion_hooks (varpool_node *node);
  1661. /* Arrange node to be first in its entry of assembler_name_hash. */
  1662. void symtab_prevail_in_asm_name_hash (symtab_node *node);
  1663. /* Initalize asm name hash unless. */
  1664. void symtab_initialize_asm_name_hash (void);
  1665. /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
  1666. void change_decl_assembler_name (tree decl, tree name);
  1667. int cgraph_count;
  1668. int cgraph_max_uid;
  1669. int cgraph_max_summary_uid;
  1670. int edges_count;
  1671. int edges_max_uid;
  1672. symtab_node* GTY(()) nodes;
  1673. asm_node* GTY(()) asmnodes;
  1674. asm_node* GTY(()) asm_last_node;
  1675. cgraph_node* GTY(()) free_nodes;
  1676. /* Head of a linked list of unused (freed) call graph edges.
  1677. Do not GTY((delete)) this list so UIDs gets reliably recycled. */
  1678. cgraph_edge * GTY(()) free_edges;
  1679. /* The order index of the next symtab node to be created. This is
  1680. used so that we can sort the cgraph nodes in order by when we saw
  1681. them, to support -fno-toplevel-reorder. */
  1682. int order;
  1683. /* Set when whole unit has been analyzed so we can access global info. */
  1684. bool global_info_ready;
  1685. /* What state callgraph is in right now. */
  1686. enum symtab_state state;
  1687. /* Set when the cgraph is fully build and the basic flags are computed. */
  1688. bool function_flags_ready;
  1689. bool cpp_implicit_aliases_done;
  1690. /* Hash table used to hold sectoons. */
  1691. hash_table<section_name_hasher> *GTY(()) section_hash;
  1692. /* Hash table used to convert assembler names into nodes. */
  1693. hash_table<asmname_hasher> *assembler_name_hash;
  1694. /* Hash table used to hold init priorities. */
  1695. hash_map<symtab_node *, symbol_priority_map> *init_priority_hash;
  1696. FILE* GTY ((skip)) dump_file;
  1697. private:
  1698. /* Allocate new callgraph node. */
  1699. inline cgraph_node * allocate_cgraph_symbol (void);
  1700. /* Allocate a cgraph_edge structure and fill it with data according to the
  1701. parameters of which only CALLEE can be NULL (when creating an indirect call
  1702. edge). */
  1703. cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee,
  1704. gcall *call_stmt, gcov_type count, int freq,
  1705. bool indir_unknown_callee);
  1706. /* Put the edge onto the free list. */
  1707. void free_edge (cgraph_edge *e);
  1708. /* Insert NODE to assembler name hash. */
  1709. void insert_to_assembler_name_hash (symtab_node *node, bool with_clones);
  1710. /* Remove NODE from assembler name hash. */
  1711. void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones);
  1712. /* Hash asmnames ignoring the user specified marks. */
  1713. static hashval_t decl_assembler_name_hash (const_tree asmname);
  1714. /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
  1715. static bool decl_assembler_name_equal (tree decl, const_tree asmname);
  1716. friend struct asmname_hasher;
  1717. /* List of hooks triggered when an edge is removed. */
  1718. cgraph_edge_hook_list * GTY((skip)) m_first_edge_removal_hook;
  1719. /* List of hooks triggem_red when a cgraph node is removed. */
  1720. cgraph_node_hook_list * GTY((skip)) m_first_cgraph_removal_hook;
  1721. /* List of hooks triggered when an edge is duplicated. */
  1722. cgraph_2edge_hook_list * GTY((skip)) m_first_edge_duplicated_hook;
  1723. /* List of hooks triggered when a node is duplicated. */
  1724. cgraph_2node_hook_list * GTY((skip)) m_first_cgraph_duplicated_hook;
  1725. /* List of hooks triggered when an function is inserted. */
  1726. cgraph_node_hook_list * GTY((skip)) m_first_cgraph_insertion_hook;
  1727. /* List of hooks triggered when an variable is inserted. */
  1728. varpool_node_hook_list * GTY((skip)) m_first_varpool_insertion_hook;
  1729. /* List of hooks triggered when a node is removed. */
  1730. varpool_node_hook_list * GTY((skip)) m_first_varpool_removal_hook;
  1731. };
  1732. extern GTY(()) symbol_table *symtab;
  1733. extern vec<cgraph_node *> cgraph_new_nodes;
  1734. inline hashval_t
  1735. asmname_hasher::hash (symtab_node *n)
  1736. {
  1737. return symbol_table::decl_assembler_name_hash
  1738. (DECL_ASSEMBLER_NAME (n->decl));
  1739. }
  1740. inline bool
  1741. asmname_hasher::equal (symtab_node *n, const_tree t)
  1742. {
  1743. return symbol_table::decl_assembler_name_equal (n->decl, t);
  1744. }
  1745. extern void gt_ggc_mx (symtab_node *&);
  1746. inline void
  1747. asmname_hasher::ggc_mx (symtab_node *n)
  1748. {
  1749. gt_ggc_mx (n);
  1750. }
  1751. extern void gt_pch_nx (symtab_node *&);
  1752. inline void
  1753. asmname_hasher::pch_nx (symtab_node *&n)
  1754. {
  1755. gt_pch_nx (n);
  1756. }
  1757. inline void
  1758. asmname_hasher::pch_nx (symtab_node *&n, gt_pointer_operator op, void *cookie)
  1759. {
  1760. op (&n, cookie);
  1761. }
  1762. /* In cgraph.c */
  1763. void cgraph_c_finalize (void);
  1764. void release_function_body (tree);
  1765. cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
  1766. void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
  1767. bool cgraph_function_possibly_inlined_p (tree);
  1768. const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
  1769. cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
  1770. extern bool gimple_check_call_matching_types (gimple, tree, bool);
  1771. /* In cgraphunit.c */
  1772. void cgraphunit_c_finalize (void);
  1773. /* Initialize datastructures so DECL is a function in lowered gimple form.
  1774. IN_SSA is true if the gimple is in SSA. */
  1775. basic_block init_lowered_empty_function (tree, bool, gcov_type);
  1776. /* In cgraphclones.c */
  1777. tree clone_function_name_1 (const char *, const char *);
  1778. tree clone_function_name (tree decl, const char *);
  1779. void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
  1780. bool, bitmap, bool, bitmap, basic_block);
  1781. /* In cgraphbuild.c */
  1782. int compute_call_stmt_bb_frequency (tree, basic_block bb);
  1783. void record_references_in_initializer (tree, bool);
  1784. /* In ipa.c */
  1785. void cgraph_build_static_cdtor (char which, tree body, int priority);
  1786. bool ipa_discover_readonly_nonaddressable_vars (void);
  1787. /* In varpool.c */
  1788. tree ctor_for_folding (tree);
  1789. /* In tree-chkp.c */
  1790. extern bool chkp_function_instrumented_p (tree fndecl);
  1791. /* Return true when the symbol is real symbol, i.e. it is not inline clone
  1792. or abstract function kept for debug info purposes only. */
  1793. inline bool
  1794. symtab_node::real_symbol_p (void)
  1795. {
  1796. cgraph_node *cnode;
  1797. if (DECL_ABSTRACT_P (decl))
  1798. return false;
  1799. if (!is_a <cgraph_node *> (this))
  1800. return true;
  1801. cnode = dyn_cast <cgraph_node *> (this);
  1802. if (cnode->global.inlined_to)
  1803. return false;
  1804. return true;
  1805. }
  1806. /* Return true if DECL should have entry in symbol table if used.
  1807. Those are functions and static & external veriables*/
  1808. static inline bool
  1809. decl_in_symtab_p (const_tree decl)
  1810. {
  1811. return (TREE_CODE (decl) == FUNCTION_DECL
  1812. || (TREE_CODE (decl) == VAR_DECL
  1813. && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
  1814. }
  1815. inline bool
  1816. symtab_node::in_same_comdat_group_p (symtab_node *target)
  1817. {
  1818. symtab_node *source = this;
  1819. if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
  1820. {
  1821. if (cn->global.inlined_to)
  1822. source = cn->global.inlined_to;
  1823. }
  1824. if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
  1825. {
  1826. if (cn->global.inlined_to)
  1827. target = cn->global.inlined_to;
  1828. }
  1829. return source->get_comdat_group () == target->get_comdat_group ();
  1830. }
  1831. /* Return node that alias is aliasing. */
  1832. inline symtab_node *
  1833. symtab_node::get_alias_target (void)
  1834. {
  1835. ipa_ref *ref = NULL;
  1836. iterate_reference (0, ref);
  1837. if (ref->use == IPA_REF_CHKP)
  1838. iterate_reference (1, ref);
  1839. gcc_checking_assert (ref->use == IPA_REF_ALIAS);
  1840. return ref->referred;
  1841. }
  1842. /* Return next reachable static symbol with initializer after the node. */
  1843. inline symtab_node *
  1844. symtab_node::next_defined_symbol (void)
  1845. {
  1846. symtab_node *node1 = next;
  1847. for (; node1; node1 = node1->next)
  1848. if (node1->definition)
  1849. return node1;
  1850. return NULL;
  1851. }
  1852. /* Iterates I-th reference in the list, REF is also set. */
  1853. inline ipa_ref *
  1854. symtab_node::iterate_reference (unsigned i, ipa_ref *&ref)
  1855. {
  1856. vec_safe_iterate (ref_list.references, i, &ref);
  1857. return ref;
  1858. }
  1859. /* Iterates I-th referring item in the list, REF is also set. */
  1860. inline ipa_ref *
  1861. symtab_node::iterate_referring (unsigned i, ipa_ref *&ref)
  1862. {
  1863. ref_list.referring.iterate (i, &ref);
  1864. return ref;
  1865. }
  1866. /* Iterates I-th referring alias item in the list, REF is also set. */
  1867. inline ipa_ref *
  1868. symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref)
  1869. {
  1870. ref_list.referring.iterate (i, &ref);
  1871. if (ref && ref->use != IPA_REF_ALIAS)
  1872. return NULL;
  1873. return ref;
  1874. }
  1875. /* Return true if list contains an alias. */
  1876. inline bool
  1877. symtab_node::has_aliases_p (void)
  1878. {
  1879. ipa_ref *ref = NULL;
  1880. return (iterate_direct_aliases (0, ref) != NULL);
  1881. }
  1882. /* Return true when RESOLUTION indicate that linker will use
  1883. the symbol from non-LTO object files. */
  1884. inline bool
  1885. resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
  1886. {
  1887. return (resolution == LDPR_PREVAILING_DEF
  1888. || resolution == LDPR_PREEMPTED_REG
  1889. || resolution == LDPR_RESOLVED_EXEC
  1890. || resolution == LDPR_RESOLVED_DYN);
  1891. }
  1892. /* Return true when symtab_node is known to be used from other (non-LTO)
  1893. object file. Known only when doing LTO via linker plugin. */
  1894. inline bool
  1895. symtab_node::used_from_object_file_p (void)
  1896. {
  1897. if (!TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
  1898. return false;
  1899. if (resolution_used_from_other_file_p (resolution))
  1900. return true;
  1901. return false;
  1902. }
  1903. /* Return varpool node for given symbol and check it is a function. */
  1904. inline varpool_node *
  1905. varpool_node::get (const_tree decl)
  1906. {
  1907. gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
  1908. return dyn_cast<varpool_node *> (symtab_node::get (decl));
  1909. }
  1910. /* Register a symbol NODE. */
  1911. inline void
  1912. symbol_table::register_symbol (symtab_node *node)
  1913. {
  1914. node->next = nodes;
  1915. node->previous = NULL;
  1916. if (nodes)
  1917. nodes->previous = node;
  1918. nodes = node;
  1919. node->order = order++;
  1920. }
  1921. /* Register a top-level asm statement ASM_STR. */
  1922. asm_node *
  1923. symbol_table::finalize_toplevel_asm (tree asm_str)
  1924. {
  1925. asm_node *node;
  1926. node = ggc_cleared_alloc<asm_node> ();
  1927. node->asm_str = asm_str;
  1928. node->order = order++;
  1929. node->next = NULL;
  1930. if (asmnodes == NULL)
  1931. asmnodes = node;
  1932. else
  1933. asm_last_node->next = node;
  1934. asm_last_node = node;
  1935. return node;
  1936. }
  1937. /* Unregister a symbol NODE. */
  1938. inline void
  1939. symbol_table::unregister (symtab_node *node)
  1940. {
  1941. if (node->previous)
  1942. node->previous->next = node->next;
  1943. else
  1944. nodes = node->next;
  1945. if (node->next)
  1946. node->next->previous = node->previous;
  1947. node->next = NULL;
  1948. node->previous = NULL;
  1949. }
  1950. /* Release a callgraph NODE with UID and put in to the list of free nodes. */
  1951. inline void
  1952. symbol_table::release_symbol (cgraph_node *node, int uid)
  1953. {
  1954. cgraph_count--;
  1955. /* Clear out the node to NULL all pointers and add the node to the free
  1956. list. */
  1957. memset (node, 0, sizeof (*node));
  1958. node->type = SYMTAB_FUNCTION;
  1959. node->uid = uid;
  1960. SET_NEXT_FREE_NODE (node, free_nodes);
  1961. free_nodes = node;
  1962. }
  1963. /* Allocate new callgraph node. */
  1964. inline cgraph_node *
  1965. symbol_table::allocate_cgraph_symbol (void)
  1966. {
  1967. cgraph_node *node;
  1968. if (free_nodes)
  1969. {
  1970. node = free_nodes;
  1971. free_nodes = NEXT_FREE_NODE (node);
  1972. }
  1973. else
  1974. {
  1975. node = ggc_cleared_alloc<cgraph_node> ();
  1976. node->uid = cgraph_max_uid++;
  1977. }
  1978. node->summary_uid = cgraph_max_summary_uid++;
  1979. return node;
  1980. }
  1981. /* Return first static symbol with definition. */
  1982. inline symtab_node *
  1983. symbol_table::first_symbol (void)
  1984. {
  1985. return nodes;
  1986. }
  1987. /* Walk all symbols. */
  1988. #define FOR_EACH_SYMBOL(node) \
  1989. for ((node) = symtab->first_symbol (); (node); (node) = (node)->next)
  1990. /* Return first static symbol with definition. */
  1991. inline symtab_node *
  1992. symbol_table::first_defined_symbol (void)
  1993. {
  1994. symtab_node *node;
  1995. for (node = nodes; node; node = node->next)
  1996. if (node->definition)
  1997. return node;
  1998. return NULL;
  1999. }
  2000. /* Walk all symbols with definitions in current unit. */
  2001. #define FOR_EACH_DEFINED_SYMBOL(node) \
  2002. for ((node) = symtab->first_defined_symbol (); (node); \
  2003. (node) = node->next_defined_symbol ())
  2004. /* Return first variable. */
  2005. inline varpool_node *
  2006. symbol_table::first_variable (void)
  2007. {
  2008. symtab_node *node;
  2009. for (node = nodes; node; node = node->next)
  2010. if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
  2011. return vnode;
  2012. return NULL;
  2013. }
  2014. /* Return next variable after NODE. */
  2015. inline varpool_node *
  2016. symbol_table::next_variable (varpool_node *node)
  2017. {
  2018. symtab_node *node1 = node->next;
  2019. for (; node1; node1 = node1->next)
  2020. if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
  2021. return vnode1;
  2022. return NULL;
  2023. }
  2024. /* Walk all variables. */
  2025. #define FOR_EACH_VARIABLE(node) \
  2026. for ((node) = symtab->first_variable (); \
  2027. (node); \
  2028. (node) = symtab->next_variable ((node)))
  2029. /* Return first static variable with initializer. */
  2030. inline varpool_node *
  2031. symbol_table::first_static_initializer (void)
  2032. {
  2033. symtab_node *node;
  2034. for (node = nodes; node; node = node->next)
  2035. {
  2036. varpool_node *vnode = dyn_cast <varpool_node *> (node);
  2037. if (vnode && DECL_INITIAL (node->decl))
  2038. return vnode;
  2039. }
  2040. return NULL;
  2041. }
  2042. /* Return next static variable with initializer after NODE. */
  2043. inline varpool_node *
  2044. symbol_table::next_static_initializer (varpool_node *node)
  2045. {
  2046. symtab_node *node1 = node->next;
  2047. for (; node1; node1 = node1->next)
  2048. {
  2049. varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
  2050. if (vnode1 && DECL_INITIAL (node1->decl))
  2051. return vnode1;
  2052. }
  2053. return NULL;
  2054. }
  2055. /* Walk all static variables with initializer set. */
  2056. #define FOR_EACH_STATIC_INITIALIZER(node) \
  2057. for ((node) = symtab->first_static_initializer (); (node); \
  2058. (node) = symtab->next_static_initializer (node))
  2059. /* Return first static variable with definition. */
  2060. inline varpool_node *
  2061. symbol_table::first_defined_variable (void)
  2062. {
  2063. symtab_node *node;
  2064. for (node = nodes; node; node = node->next)
  2065. {
  2066. varpool_node *vnode = dyn_cast <varpool_node *> (node);
  2067. if (vnode && vnode->definition)
  2068. return vnode;
  2069. }
  2070. return NULL;
  2071. }
  2072. /* Return next static variable with definition after NODE. */
  2073. inline varpool_node *
  2074. symbol_table::next_defined_variable (varpool_node *node)
  2075. {
  2076. symtab_node *node1 = node->next;
  2077. for (; node1; node1 = node1->next)
  2078. {
  2079. varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
  2080. if (vnode1 && vnode1->definition)
  2081. return vnode1;
  2082. }
  2083. return NULL;
  2084. }
  2085. /* Walk all variables with definitions in current unit. */
  2086. #define FOR_EACH_DEFINED_VARIABLE(node) \
  2087. for ((node) = symtab->first_defined_variable (); (node); \
  2088. (node) = symtab->next_defined_variable (node))
  2089. /* Return first function with body defined. */
  2090. inline cgraph_node *
  2091. symbol_table::first_defined_function (void)
  2092. {
  2093. symtab_node *node;
  2094. for (node = nodes; node; node = node->next)
  2095. {
  2096. cgraph_node *cn = dyn_cast <cgraph_node *> (node);
  2097. if (cn && cn->definition)
  2098. return cn;
  2099. }
  2100. return NULL;
  2101. }
  2102. /* Return next function with body defined after NODE. */
  2103. inline cgraph_node *
  2104. symbol_table::next_defined_function (cgraph_node *node)
  2105. {
  2106. symtab_node *node1 = node->next;
  2107. for (; node1; node1 = node1->next)
  2108. {
  2109. cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
  2110. if (cn1 && cn1->definition)
  2111. return cn1;
  2112. }
  2113. return NULL;
  2114. }
  2115. /* Walk all functions with body defined. */
  2116. #define FOR_EACH_DEFINED_FUNCTION(node) \
  2117. for ((node) = symtab->first_defined_function (); (node); \
  2118. (node) = symtab->next_defined_function ((node)))
  2119. /* Return first function. */
  2120. inline cgraph_node *
  2121. symbol_table::first_function (void)
  2122. {
  2123. symtab_node *node;
  2124. for (node = nodes; node; node = node->next)
  2125. if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
  2126. return cn;
  2127. return NULL;
  2128. }
  2129. /* Return next function. */
  2130. inline cgraph_node *
  2131. symbol_table::next_function (cgraph_node *node)
  2132. {
  2133. symtab_node *node1 = node->next;
  2134. for (; node1; node1 = node1->next)
  2135. if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
  2136. return cn1;
  2137. return NULL;
  2138. }
  2139. /* Return first function with body defined. */
  2140. inline cgraph_node *
  2141. symbol_table::first_function_with_gimple_body (void)
  2142. {
  2143. symtab_node *node;
  2144. for (node = nodes; node; node = node->next)
  2145. {
  2146. cgraph_node *cn = dyn_cast <cgraph_node *> (node);
  2147. if (cn && cn->has_gimple_body_p ())
  2148. return cn;
  2149. }
  2150. return NULL;
  2151. }
  2152. /* Return next reachable static variable with initializer after NODE. */
  2153. inline cgraph_node *
  2154. symbol_table::next_function_with_gimple_body (cgraph_node *node)
  2155. {
  2156. symtab_node *node1 = node->next;
  2157. for (; node1; node1 = node1->next)
  2158. {
  2159. cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
  2160. if (cn1 && cn1->has_gimple_body_p ())
  2161. return cn1;
  2162. }
  2163. return NULL;
  2164. }
  2165. /* Walk all functions. */
  2166. #define FOR_EACH_FUNCTION(node) \
  2167. for ((node) = symtab->first_function (); (node); \
  2168. (node) = symtab->next_function ((node)))
  2169. /* Return true when callgraph node is a function with Gimple body defined
  2170. in current unit. Functions can also be define externally or they
  2171. can be thunks with no Gimple representation.
  2172. Note that at WPA stage, the function body may not be present in memory. */
  2173. inline bool
  2174. cgraph_node::has_gimple_body_p (void)
  2175. {
  2176. return definition && !thunk.thunk_p && !alias;
  2177. }
  2178. /* Walk all functions with body defined. */
  2179. #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
  2180. for ((node) = symtab->first_function_with_gimple_body (); (node); \
  2181. (node) = symtab->next_function_with_gimple_body (node))
  2182. /* Uniquize all constants that appear in memory.
  2183. Each constant in memory thus far output is recorded
  2184. in `const_desc_table'. */
  2185. struct GTY((for_user)) constant_descriptor_tree {
  2186. /* A MEM for the constant. */
  2187. rtx rtl;
  2188. /* The value of the constant. */
  2189. tree value;
  2190. /* Hash of value. Computing the hash from value each time
  2191. hashfn is called can't work properly, as that means recursive
  2192. use of the hash table during hash table expansion. */
  2193. hashval_t hash;
  2194. };
  2195. /* Return true when function is only called directly or it has alias.
  2196. i.e. it is not externally visible, address was not taken and
  2197. it is not used in any other non-standard way. */
  2198. inline bool
  2199. cgraph_node::only_called_directly_or_aliased_p (void)
  2200. {
  2201. gcc_assert (!global.inlined_to);
  2202. return (!force_output && !address_taken
  2203. && !used_from_other_partition
  2204. && !DECL_VIRTUAL_P (decl)
  2205. && !DECL_STATIC_CONSTRUCTOR (decl)
  2206. && !DECL_STATIC_DESTRUCTOR (decl)
  2207. && !used_from_object_file_p ()
  2208. && !externally_visible);
  2209. }
  2210. /* Return true when function can be removed from callgraph
  2211. if all direct calls are eliminated. */
  2212. inline bool
  2213. cgraph_node::can_remove_if_no_direct_calls_and_refs_p (void)
  2214. {
  2215. gcc_checking_assert (!global.inlined_to);
  2216. /* Instrumentation clones should not be removed before
  2217. instrumentation happens. New callers may appear after
  2218. instrumentation. */
  2219. if (instrumentation_clone
  2220. && !chkp_function_instrumented_p (decl))
  2221. return false;
  2222. /* Extern inlines can always go, we will use the external definition. */
  2223. if (DECL_EXTERNAL (decl))
  2224. return true;
  2225. /* When function is needed, we can not remove it. */
  2226. if (force_output || used_from_other_partition)
  2227. return false;
  2228. if (DECL_STATIC_CONSTRUCTOR (decl)
  2229. || DECL_STATIC_DESTRUCTOR (decl))
  2230. return false;
  2231. /* Only COMDAT functions can be removed if externally visible. */
  2232. if (externally_visible
  2233. && (!DECL_COMDAT (decl)
  2234. || forced_by_abi
  2235. || used_from_object_file_p ()))
  2236. return false;
  2237. return true;
  2238. }
  2239. /* Return true when variable can be removed from variable pool
  2240. if all direct calls are eliminated. */
  2241. inline bool
  2242. varpool_node::can_remove_if_no_refs_p (void)
  2243. {
  2244. if (DECL_EXTERNAL (decl))
  2245. return true;
  2246. return (!force_output && !used_from_other_partition
  2247. && ((DECL_COMDAT (decl)
  2248. && !forced_by_abi
  2249. && !used_from_object_file_p ())
  2250. || !externally_visible
  2251. || DECL_HAS_VALUE_EXPR_P (decl)));
  2252. }
  2253. /* Return true when all references to variable must be visible in ipa_ref_list.
  2254. i.e. if the variable is not externally visible or not used in some magic
  2255. way (asm statement or such).
  2256. The magic uses are all summarized in force_output flag. */
  2257. inline bool
  2258. varpool_node::all_refs_explicit_p ()
  2259. {
  2260. return (definition
  2261. && !externally_visible
  2262. && !used_from_other_partition
  2263. && !force_output);
  2264. }
  2265. struct tree_descriptor_hasher : ggc_hasher<constant_descriptor_tree *>
  2266. {
  2267. static hashval_t hash (constant_descriptor_tree *);
  2268. static bool equal (constant_descriptor_tree *, constant_descriptor_tree *);
  2269. };
  2270. /* Constant pool accessor function. */
  2271. hash_table<tree_descriptor_hasher> *constant_pool_htab (void);
  2272. /* Return node that alias is aliasing. */
  2273. inline cgraph_node *
  2274. cgraph_node::get_alias_target (void)
  2275. {
  2276. return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
  2277. }
  2278. /* Return node that alias is aliasing. */
  2279. inline varpool_node *
  2280. varpool_node::get_alias_target (void)
  2281. {
  2282. return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
  2283. }
  2284. /* Walk the alias chain to return the symbol NODE is alias of.
  2285. If NODE is not an alias, return NODE.
  2286. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  2287. inline symtab_node *
  2288. symtab_node::ultimate_alias_target (enum availability *availability)
  2289. {
  2290. if (!alias)
  2291. {
  2292. if (availability)
  2293. *availability = get_availability ();
  2294. return this;
  2295. }
  2296. return ultimate_alias_target_1 (availability);
  2297. }
  2298. /* Given function symbol, walk the alias chain to return the function node
  2299. is alias of. Do not walk through thunks.
  2300. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  2301. inline cgraph_node *
  2302. cgraph_node::ultimate_alias_target (enum availability *availability)
  2303. {
  2304. cgraph_node *n = dyn_cast <cgraph_node *>
  2305. (symtab_node::ultimate_alias_target (availability));
  2306. if (!n && availability)
  2307. *availability = AVAIL_NOT_AVAILABLE;
  2308. return n;
  2309. }
  2310. /* For given variable pool node, walk the alias chain to return the function
  2311. the variable is alias of. Do not walk through thunks.
  2312. When AVAILABILITY is non-NULL, get minimal availability in the chain. */
  2313. inline varpool_node *
  2314. varpool_node::ultimate_alias_target (availability *availability)
  2315. {
  2316. varpool_node *n = dyn_cast <varpool_node *>
  2317. (symtab_node::ultimate_alias_target (availability));
  2318. if (!n && availability)
  2319. *availability = AVAIL_NOT_AVAILABLE;
  2320. return n;
  2321. }
  2322. /* Set callee N of call graph edge and add it to the corresponding set of
  2323. callers. */
  2324. inline void
  2325. cgraph_edge::set_callee (cgraph_node *n)
  2326. {
  2327. prev_caller = NULL;
  2328. if (n->callers)
  2329. n->callers->prev_caller = this;
  2330. next_caller = n->callers;
  2331. n->callers = this;
  2332. callee = n;
  2333. }
  2334. /* Redirect callee of the edge to N. The function does not update underlying
  2335. call expression. */
  2336. inline void
  2337. cgraph_edge::redirect_callee (cgraph_node *n)
  2338. {
  2339. /* Remove from callers list of the current callee. */
  2340. remove_callee ();
  2341. /* Insert to callers list of the new callee. */
  2342. set_callee (n);
  2343. }
  2344. /* Return true when the edge represents a direct recursion. */
  2345. inline bool
  2346. cgraph_edge::recursive_p (void)
  2347. {
  2348. cgraph_node *c = callee->ultimate_alias_target ();
  2349. if (caller->global.inlined_to)
  2350. return caller->global.inlined_to->decl == c->decl;
  2351. else
  2352. return caller->decl == c->decl;
  2353. }
  2354. /* Remove the edge from the list of the callers of the callee. */
  2355. inline void
  2356. cgraph_edge::remove_callee (void)
  2357. {
  2358. gcc_assert (!indirect_unknown_callee);
  2359. if (prev_caller)
  2360. prev_caller->next_caller = next_caller;
  2361. if (next_caller)
  2362. next_caller->prev_caller = prev_caller;
  2363. if (!prev_caller)
  2364. callee->callers = next_caller;
  2365. }
  2366. /* Return true if the TM_CLONE bit is set for a given FNDECL. */
  2367. static inline bool
  2368. decl_is_tm_clone (const_tree fndecl)
  2369. {
  2370. cgraph_node *n = cgraph_node::get (fndecl);
  2371. if (n)
  2372. return n->tm_clone;
  2373. return false;
  2374. }
  2375. /* Likewise indicate that a node is needed, i.e. reachable via some
  2376. external means. */
  2377. inline void
  2378. cgraph_node::mark_force_output (void)
  2379. {
  2380. force_output = 1;
  2381. gcc_checking_assert (!global.inlined_to);
  2382. }
  2383. /* Return true if function should be optimized for size. */
  2384. inline bool
  2385. cgraph_node::optimize_for_size_p (void)
  2386. {
  2387. if (opt_for_fn (decl, optimize_size))
  2388. return true;
  2389. if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
  2390. return true;
  2391. else
  2392. return false;
  2393. }
  2394. /* Return symtab_node for NODE or create one if it is not present
  2395. in symtab. */
  2396. inline symtab_node *
  2397. symtab_node::get_create (tree node)
  2398. {
  2399. if (TREE_CODE (node) == VAR_DECL)
  2400. return varpool_node::get_create (node);
  2401. else
  2402. return cgraph_node::get_create (node);
  2403. }
  2404. /* Return availability of NODE. */
  2405. inline enum availability
  2406. symtab_node::get_availability (void)
  2407. {
  2408. if (is_a <cgraph_node *> (this))
  2409. return dyn_cast <cgraph_node *> (this)->get_availability ();
  2410. else
  2411. return dyn_cast <varpool_node *> (this)->get_availability ();;
  2412. }
  2413. /* Call calback on symtab node and aliases associated to this node.
  2414. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  2415. skipped. */
  2416. inline bool
  2417. symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
  2418. void *),
  2419. void *data,
  2420. bool include_overwritable)
  2421. {
  2422. if (callback (this, data))
  2423. return true;
  2424. if (has_aliases_p ())
  2425. return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
  2426. return false;
  2427. }
  2428. /* Call callback on function and aliases associated to the function.
  2429. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  2430. skipped. */
  2431. inline bool
  2432. cgraph_node::call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
  2433. void *),
  2434. void *data,
  2435. bool include_overwritable)
  2436. {
  2437. if (callback (this, data))
  2438. return true;
  2439. if (has_aliases_p ())
  2440. return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
  2441. return false;
  2442. }
  2443. /* Call calback on varpool symbol and aliases associated to varpool symbol.
  2444. When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
  2445. skipped. */
  2446. inline bool
  2447. varpool_node::call_for_symbol_and_aliases (bool (*callback) (varpool_node *,
  2448. void *),
  2449. void *data,
  2450. bool include_overwritable)
  2451. {
  2452. if (callback (this, data))
  2453. return true;
  2454. if (has_aliases_p ())
  2455. return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
  2456. return false;
  2457. }
  2458. /* Return true if NODE's address can be compared. */
  2459. inline bool
  2460. symtab_node::address_can_be_compared_p ()
  2461. {
  2462. /* Address of virtual tables and functions is never compared. */
  2463. if (DECL_VIRTUAL_P (decl))
  2464. return false;
  2465. /* Address of C++ cdtors is never compared. */
  2466. if (is_a <cgraph_node *> (this)
  2467. && (DECL_CXX_CONSTRUCTOR_P (decl)
  2468. || DECL_CXX_DESTRUCTOR_P (decl)))
  2469. return false;
  2470. /* Constant pool symbols addresses are never compared.
  2471. flag_merge_constants permits us to assume the same on readonly vars. */
  2472. if (is_a <varpool_node *> (this)
  2473. && (DECL_IN_CONSTANT_POOL (decl)
  2474. || (flag_merge_constants >= 2
  2475. && TREE_READONLY (decl) && !TREE_THIS_VOLATILE (decl))))
  2476. return false;
  2477. return true;
  2478. }
  2479. /* Return true if refernece may be used in address compare. */
  2480. inline bool
  2481. ipa_ref::address_matters_p ()
  2482. {
  2483. if (use != IPA_REF_ADDR)
  2484. return false;
  2485. /* Addresses taken from virtual tables are never compared. */
  2486. if (is_a <varpool_node *> (referring)
  2487. && DECL_VIRTUAL_P (referring->decl))
  2488. return false;
  2489. return referred->address_can_be_compared_p ();
  2490. }
  2491. /* Build polymorphic call context for indirect call E. */
  2492. inline
  2493. ipa_polymorphic_call_context::ipa_polymorphic_call_context (cgraph_edge *e)
  2494. {
  2495. gcc_checking_assert (e->indirect_info->polymorphic);
  2496. *this = e->indirect_info->context;
  2497. }
  2498. /* Build empty "I know nothing" context. */
  2499. inline
  2500. ipa_polymorphic_call_context::ipa_polymorphic_call_context ()
  2501. {
  2502. clear_speculation ();
  2503. clear_outer_type ();
  2504. invalid = false;
  2505. }
  2506. /* Make context non-speculative. */
  2507. inline void
  2508. ipa_polymorphic_call_context::clear_speculation ()
  2509. {
  2510. speculative_outer_type = NULL;
  2511. speculative_offset = 0;
  2512. speculative_maybe_derived_type = false;
  2513. }
  2514. /* Produce context specifying all derrived types of OTR_TYPE. If OTR_TYPE is
  2515. NULL, the context is set to dummy "I know nothing" setting. */
  2516. inline void
  2517. ipa_polymorphic_call_context::clear_outer_type (tree otr_type)
  2518. {
  2519. outer_type = otr_type ? TYPE_MAIN_VARIANT (otr_type) : NULL;
  2520. offset = 0;
  2521. maybe_derived_type = true;
  2522. maybe_in_construction = true;
  2523. dynamic = true;
  2524. }
  2525. /* Adjust all offsets in contexts by OFF bits. */
  2526. inline void
  2527. ipa_polymorphic_call_context::offset_by (HOST_WIDE_INT off)
  2528. {
  2529. if (outer_type)
  2530. offset += off;
  2531. if (speculative_outer_type)
  2532. speculative_offset += off;
  2533. }
  2534. /* Return TRUE if context is fully useless. */
  2535. inline bool
  2536. ipa_polymorphic_call_context::useless_p () const
  2537. {
  2538. return (!outer_type && !speculative_outer_type);
  2539. }
  2540. /* Return true if NODE is local. Instrumentation clones are counted as local
  2541. only when original function is local. */
  2542. static inline bool
  2543. cgraph_local_p (cgraph_node *node)
  2544. {
  2545. if (!node->instrumentation_clone || !node->instrumented_version)
  2546. return node->local.local;
  2547. return node->local.local && node->instrumented_version->local.local;
  2548. }
  2549. /* When using fprintf (or similar), problems can arise with
  2550. transient generated strings. Many string-generation APIs
  2551. only support one result being alive at once (e.g. by
  2552. returning a pointer to a statically-allocated buffer).
  2553. If there is more than one generated string within one
  2554. fprintf call: the first string gets evicted or overwritten
  2555. by the second, before fprintf is fully evaluated.
  2556. See e.g. PR/53136.
  2557. This function provides a workaround for this, by providing
  2558. a simple way to create copies of these transient strings,
  2559. without the need to have explicit cleanup:
  2560. fprintf (dumpfile, "string 1: %s string 2:%s\n",
  2561. xstrdup_for_dump (EXPR_1),
  2562. xstrdup_for_dump (EXPR_2));
  2563. This is actually a simple wrapper around ggc_strdup, but
  2564. the name documents the intent. We require that no GC can occur
  2565. within the fprintf call. */
  2566. static inline const char *
  2567. xstrdup_for_dump (const char *transient_str)
  2568. {
  2569. return ggc_strdup (transient_str);
  2570. }
  2571. #endif /* GCC_CGRAPH_H */