cgraph.h 115 KB

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