cgraph.h 113 KB

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