toplev.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  1. /* Top level of GCC compilers (cc1, cc1plus, etc.)
  2. Copyright (C) 1987-2021 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This is the top level of cc1/c++.
  16. It parses command args, opens files, invokes the various passes
  17. in the proper order, and counts the time used by each.
  18. Error messages and low-level interface to malloc also handled here. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "coretypes.h"
  22. #include "backend.h"
  23. #include "target.h"
  24. #include "rtl.h"
  25. #include "tree.h"
  26. #include "gimple.h"
  27. #include "alloc-pool.h"
  28. #include "timevar.h"
  29. #include "memmodel.h"
  30. #include "tm_p.h"
  31. #include "optabs-libfuncs.h"
  32. #include "insn-config.h"
  33. #include "ira.h"
  34. #include "recog.h"
  35. #include "cgraph.h"
  36. #include "coverage.h"
  37. #include "diagnostic.h"
  38. #include "varasm.h"
  39. #include "tree-inline.h"
  40. #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
  41. #include "version.h"
  42. #include "flags.h"
  43. #include "insn-attr.h"
  44. #include "output.h"
  45. #include "toplev.h"
  46. #include "expr.h"
  47. #include "intl.h"
  48. #include "tree-diagnostic.h"
  49. #include "reload.h"
  50. #include "lra.h"
  51. #include "dwarf2asm.h"
  52. #include "debug.h"
  53. #include "common/common-target.h"
  54. #include "langhooks.h"
  55. #include "cfgloop.h" /* for init_set_costs */
  56. #include "hosthooks.h"
  57. #include "opts.h"
  58. #include "opts-diagnostic.h"
  59. #include "stringpool.h"
  60. #include "attribs.h"
  61. #include "asan.h"
  62. #include "tsan.h"
  63. #include "plugin.h"
  64. #include "context.h"
  65. #include "pass_manager.h"
  66. #include "auto-profile.h"
  67. #include "dwarf2out.h"
  68. #include "ipa-reference.h"
  69. #include "symbol-summary.h"
  70. #include "tree-vrp.h"
  71. #include "ipa-prop.h"
  72. #include "gcse.h"
  73. #include "omp-offload.h"
  74. #include "edit-context.h"
  75. #include "tree-pass.h"
  76. #include "dumpfile.h"
  77. #include "ipa-fnsummary.h"
  78. #include "dump-context.h"
  79. #include "print-tree.h"
  80. #include "optinfo-emit-json.h"
  81. #include "ipa-modref-tree.h"
  82. #include "ipa-modref.h"
  83. #include "dbgcnt.h"
  84. #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
  85. #include "dbxout.h"
  86. #endif
  87. #ifdef XCOFF_DEBUGGING_INFO
  88. #include "xcoffout.h" /* Needed for external data declarations. */
  89. #endif
  90. #include "selftest.h"
  91. #ifdef HAVE_isl
  92. #include <isl/version.h>
  93. #endif
  94. static void general_init (const char *, bool);
  95. static void do_compile ();
  96. static void process_options (void);
  97. static void backend_init (void);
  98. static int lang_dependent_init (const char *);
  99. static void init_asm_output (const char *);
  100. static void finalize (bool);
  101. static void crash_signal (int) ATTRIBUTE_NORETURN;
  102. static void compile_file (void);
  103. /* True if we don't need a backend (e.g. preprocessing only). */
  104. static bool no_backend;
  105. /* Decoded options, and number of such options. */
  106. struct cl_decoded_option *save_decoded_options;
  107. unsigned int save_decoded_options_count;
  108. /* Used to enable -fvar-tracking, -fweb and -frename-registers according
  109. to optimize in process_options (). */
  110. #define AUTODETECT_VALUE 2
  111. /* Debug hooks - dependent upon command line options. */
  112. const struct gcc_debug_hooks *debug_hooks;
  113. /* The FUNCTION_DECL for the function currently being compiled,
  114. or 0 if between functions. */
  115. tree current_function_decl;
  116. /* Set to the FUNC_BEGIN label of the current function, or NULL
  117. if none. */
  118. const char * current_function_func_begin_label;
  119. /* A random sequence of characters, unless overridden by user. */
  120. static const char *flag_random_seed;
  121. /* A local time stamp derived from the time of compilation. It will be
  122. zero if the system cannot provide a time. It will be -1u, if the
  123. user has specified a particular random seed. */
  124. unsigned local_tick;
  125. /* Random number for this compilation */
  126. HOST_WIDE_INT random_seed;
  127. /* -f flags. */
  128. /* When non-NULL, indicates that whenever space is allocated on the
  129. stack, the resulting stack pointer must not pass this
  130. address---that is, for stacks that grow downward, the stack pointer
  131. must always be greater than or equal to this address; for stacks
  132. that grow upward, the stack pointer must be less than this address.
  133. At present, the rtx may be either a REG or a SYMBOL_REF, although
  134. the support provided depends on the backend. */
  135. rtx stack_limit_rtx;
  136. class target_flag_state default_target_flag_state;
  137. #if SWITCHABLE_TARGET
  138. class target_flag_state *this_target_flag_state = &default_target_flag_state;
  139. #else
  140. #define this_target_flag_state (&default_target_flag_state)
  141. #endif
  142. /* The user symbol prefix after having resolved same. */
  143. const char *user_label_prefix;
  144. /* Output files for assembler code (real compiler output)
  145. and debugging dumps. */
  146. FILE *asm_out_file;
  147. FILE *aux_info_file;
  148. FILE *callgraph_info_file = NULL;
  149. /*
  150. * added
  151. */
  152. #include "sfg.c"
  153. FILE *svg_callgraph_info_file = NULL;
  154. FILE *gv_callgraph_info_file = NULL;
  155. #include "splay-tree.h"
  156. /* edge info */
  157. struct svg_callgraph_edge
  158. {
  159. int fn; /* id of from node */
  160. int tn; /* id of to node */
  161. };
  162. /* node id to node text */
  163. static splay_tree svg_callgraph_tree_nodes = NULL;
  164. /* nodes count */
  165. static int svg_callgraph_tree_nodes_count = 0;
  166. /* helper to delete the (char *)value string which was strdup()'ed */
  167. static void svg_callgraph_tree_nodes_delete_value (splay_tree_value val)
  168. {
  169. if (val) {
  170. free ((void *) val);
  171. }
  172. return;
  173. }
  174. /* node id to node text */
  175. static splay_tree svg_callgraph_tree_edges = NULL;
  176. /* edge counter */
  177. static int svg_callgraph_tree_edges_count = 0;
  178. /* helper to delete the (char *)value string which was strdup()'ed */
  179. static void svg_callgraph_tree_edges_delete_value (splay_tree_value val)
  180. {
  181. if (val) {
  182. free ((void *) val);
  183. }
  184. return;
  185. }
  186. /*
  187. * end added
  188. */
  189. static bitmap callgraph_info_external_printed;
  190. FILE *stack_usage_file = NULL;
  191. /* The current working directory of a translation. It's generally the
  192. directory from which compilation was initiated, but a preprocessed
  193. file may specify the original directory in which it was
  194. created. */
  195. static const char *src_pwd;
  196. /* Initialize src_pwd with the given string, and return true. If it
  197. was already initialized, return false. As a special case, it may
  198. be called with a NULL argument to test whether src_pwd has NOT been
  199. initialized yet. */
  200. bool
  201. set_src_pwd (const char *pwd)
  202. {
  203. if (src_pwd)
  204. {
  205. if (strcmp (src_pwd, pwd) == 0)
  206. return true;
  207. else
  208. return false;
  209. }
  210. src_pwd = xstrdup (pwd);
  211. return true;
  212. }
  213. /* Return the directory from which the translation unit was initiated,
  214. in case set_src_pwd() was not called before to assign it a
  215. different value. */
  216. const char *
  217. get_src_pwd (void)
  218. {
  219. if (! src_pwd)
  220. {
  221. src_pwd = getpwd ();
  222. if (!src_pwd)
  223. src_pwd = ".";
  224. }
  225. return src_pwd;
  226. }
  227. /* Called when the start of a function definition is parsed,
  228. this function prints on stderr the name of the function. */
  229. void
  230. announce_function (tree decl)
  231. {
  232. if (!quiet_flag)
  233. {
  234. if (rtl_dump_and_exit)
  235. fprintf (stderr, "%s ",
  236. identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
  237. else
  238. fprintf (stderr, " %s",
  239. identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
  240. fflush (stderr);
  241. pp_needs_newline (global_dc->printer) = true;
  242. diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
  243. }
  244. }
  245. /* Initialize local_tick with the time of day, or -1 if
  246. flag_random_seed is set. */
  247. static void
  248. init_local_tick (void)
  249. {
  250. if (!flag_random_seed)
  251. {
  252. #ifdef HAVE_GETTIMEOFDAY
  253. {
  254. struct timeval tv;
  255. gettimeofday (&tv, NULL);
  256. local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
  257. }
  258. #else
  259. {
  260. time_t now = time (NULL);
  261. if (now != (time_t)-1)
  262. local_tick = (unsigned) now;
  263. }
  264. #endif
  265. }
  266. else
  267. local_tick = -1;
  268. }
  269. /* Obtain the random_seed. Unless NOINIT, initialize it if
  270. it's not provided in the command line. */
  271. HOST_WIDE_INT
  272. get_random_seed (bool noinit)
  273. {
  274. if (!random_seed && !noinit)
  275. {
  276. int fd = open ("/dev/urandom", O_RDONLY);
  277. if (fd >= 0)
  278. {
  279. if (read (fd, &random_seed, sizeof (random_seed))
  280. != sizeof (random_seed))
  281. random_seed = 0;
  282. close (fd);
  283. }
  284. if (!random_seed)
  285. random_seed = local_tick ^ getpid ();
  286. }
  287. return random_seed;
  288. }
  289. /* Set flag_random_seed to VAL, and if non-null, reinitialize random_seed. */
  290. void
  291. set_random_seed (const char *val)
  292. {
  293. flag_random_seed = val;
  294. if (flag_random_seed)
  295. {
  296. char *endp;
  297. /* When the driver passed in a hex number don't crc it again */
  298. random_seed = strtoul (flag_random_seed, &endp, 0);
  299. if (!(endp > flag_random_seed && *endp == 0))
  300. random_seed = crc32_string (0, flag_random_seed);
  301. }
  302. }
  303. /* Handler for fatal signals, such as SIGSEGV. These are transformed
  304. into ICE messages, which is much more user friendly. In case the
  305. error printer crashes, reset the signal to prevent infinite recursion. */
  306. static void
  307. crash_signal (int signo)
  308. {
  309. signal (signo, SIG_DFL);
  310. /* If we crashed while processing an ASM statement, then be a little more
  311. graceful. It's most likely the user's fault. */
  312. if (this_is_asm_operands)
  313. {
  314. output_operand_lossage ("unrecoverable error");
  315. exit (FATAL_EXIT_CODE);
  316. }
  317. internal_error ("%s", strsignal (signo));
  318. }
  319. /* A subroutine of wrapup_global_declarations. We've come to the end of
  320. the compilation unit. All deferred variables should be undeferred,
  321. and all incomplete decls should be finalized. */
  322. void
  323. wrapup_global_declaration_1 (tree decl)
  324. {
  325. /* We're not deferring this any longer. Assignment is conditional to
  326. avoid needlessly dirtying PCH pages. */
  327. if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
  328. && DECL_DEFER_OUTPUT (decl) != 0)
  329. DECL_DEFER_OUTPUT (decl) = 0;
  330. if (VAR_P (decl) && DECL_SIZE (decl) == 0)
  331. lang_hooks.finish_incomplete_decl (decl);
  332. }
  333. /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
  334. needs to be output. Return true if it is output. */
  335. bool
  336. wrapup_global_declaration_2 (tree decl)
  337. {
  338. if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
  339. || (VAR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)))
  340. return false;
  341. /* Don't write out static consts, unless we still need them.
  342. We also keep static consts if not optimizing (for debugging),
  343. unless the user specified -fno-keep-static-consts.
  344. ??? They might be better written into the debug information.
  345. This is possible when using DWARF.
  346. A language processor that wants static constants to be always
  347. written out (even if it is not used) is responsible for
  348. calling rest_of_decl_compilation itself. E.g. the C front-end
  349. calls rest_of_decl_compilation from finish_decl.
  350. One motivation for this is that is conventional in some
  351. environments to write things like:
  352. static const char rcsid[] = "... version string ...";
  353. intending to force the string to be in the executable.
  354. A language processor that would prefer to have unneeded
  355. static constants "optimized away" would just defer writing
  356. them out until here. E.g. C++ does this, because static
  357. constants are often defined in header files.
  358. ??? A tempting alternative (for both C and C++) would be
  359. to force a constant to be written if and only if it is
  360. defined in a main file, as opposed to an include file. */
  361. if (VAR_P (decl) && TREE_STATIC (decl))
  362. {
  363. varpool_node *node;
  364. bool needed = true;
  365. node = varpool_node::get (decl);
  366. if (!node && flag_ltrans)
  367. needed = false;
  368. else if (node && node->definition)
  369. needed = false;
  370. else if (node && node->alias)
  371. needed = false;
  372. else if (!symtab->global_info_ready
  373. && (TREE_USED (decl)
  374. || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
  375. /* needed */;
  376. else if (node && node->analyzed)
  377. /* needed */;
  378. else if (DECL_COMDAT (decl))
  379. needed = false;
  380. else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
  381. && (optimize || !flag_keep_static_consts
  382. || DECL_ARTIFICIAL (decl)))
  383. needed = false;
  384. if (needed)
  385. {
  386. rest_of_decl_compilation (decl, 1, 1);
  387. return true;
  388. }
  389. }
  390. return false;
  391. }
  392. /* Do any final processing required for the declarations in VEC, of
  393. which there are LEN. We write out inline functions and variables
  394. that have been deferred until this point, but which are required.
  395. Returns nonzero if anything was put out. */
  396. bool
  397. wrapup_global_declarations (tree *vec, int len)
  398. {
  399. bool reconsider, output_something = false;
  400. int i;
  401. for (i = 0; i < len; i++)
  402. wrapup_global_declaration_1 (vec[i]);
  403. /* Now emit any global variables or functions that we have been
  404. putting off. We need to loop in case one of the things emitted
  405. here references another one which comes earlier in the list. */
  406. do
  407. {
  408. reconsider = false;
  409. for (i = 0; i < len; i++)
  410. reconsider |= wrapup_global_declaration_2 (vec[i]);
  411. if (reconsider)
  412. output_something = true;
  413. }
  414. while (reconsider);
  415. return output_something;
  416. }
  417. /* Compile an entire translation unit. Write a file of assembly
  418. output and various debugging dumps. */
  419. static void
  420. compile_file (void)
  421. {
  422. timevar_start (TV_PHASE_PARSING);
  423. timevar_push (TV_PARSE_GLOBAL);
  424. /* Parse entire file and generate initial debug information. */
  425. lang_hooks.parse_file ();
  426. timevar_pop (TV_PARSE_GLOBAL);
  427. timevar_stop (TV_PHASE_PARSING);
  428. if (flag_dump_locations)
  429. dump_location_info (stderr);
  430. /* Compilation is now finished except for writing
  431. what's left of the symbol table output. */
  432. if (flag_syntax_only || flag_wpa)
  433. return;
  434. /* Reset maximum_field_alignment, it can be adjusted by #pragma pack
  435. and this shouldn't influence any types built by the middle-end
  436. from now on (like gcov_info_type). */
  437. maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
  438. ggc_protect_identifiers = false;
  439. /* Run the actual compilation process. */
  440. if (!in_lto_p)
  441. {
  442. timevar_start (TV_PHASE_OPT_GEN);
  443. symtab->finalize_compilation_unit ();
  444. timevar_stop (TV_PHASE_OPT_GEN);
  445. }
  446. /* Perform any post compilation-proper parser cleanups and
  447. processing. This is currently only needed for the C++ parser,
  448. which can be hopefully cleaned up so this hook is no longer
  449. necessary. */
  450. if (lang_hooks.decls.post_compilation_parsing_cleanups)
  451. lang_hooks.decls.post_compilation_parsing_cleanups ();
  452. dump_context::get ().finish_any_json_writer ();
  453. if (seen_error ())
  454. return;
  455. timevar_start (TV_PHASE_LATE_ASM);
  456. /* Compilation unit is finalized. When producing non-fat LTO object, we are
  457. basically finished. */
  458. if ((in_lto_p && flag_incremental_link != INCREMENTAL_LINK_LTO)
  459. || !flag_lto || flag_fat_lto_objects)
  460. {
  461. /* File-scope initialization for AddressSanitizer. */
  462. if (flag_sanitize & SANITIZE_ADDRESS)
  463. asan_finish_file ();
  464. if (flag_sanitize & SANITIZE_THREAD)
  465. tsan_finish_file ();
  466. if (gate_hwasan ())
  467. hwasan_finish_file ();
  468. omp_finish_file ();
  469. output_shared_constant_pool ();
  470. output_object_blocks ();
  471. finish_tm_clone_pairs ();
  472. /* Write out any pending weak symbol declarations. */
  473. weak_finish ();
  474. /* This must be at the end before unwind and debug info.
  475. Some target ports emit PIC setup thunks here. */
  476. targetm.asm_out.code_end ();
  477. /* Do dbx symbols. */
  478. timevar_push (TV_SYMOUT);
  479. #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
  480. dwarf2out_frame_finish ();
  481. #endif
  482. debuginfo_start ();
  483. (*debug_hooks->finish) (main_input_filename);
  484. debuginfo_stop ();
  485. timevar_pop (TV_SYMOUT);
  486. /* Output some stuff at end of file if nec. */
  487. dw2_output_indirect_constants ();
  488. /* Flush any pending external directives. */
  489. process_pending_assemble_externals ();
  490. }
  491. /* Let linker plugin know that this is a slim object and must be LTOed
  492. even when user did not ask for it. */
  493. if (flag_generate_lto && !flag_fat_lto_objects)
  494. {
  495. #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
  496. ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
  497. HOST_WIDE_INT_1U, 8);
  498. #elif defined ASM_OUTPUT_ALIGNED_COMMON
  499. ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
  500. HOST_WIDE_INT_1U, 8);
  501. #else
  502. ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
  503. HOST_WIDE_INT_1U,
  504. HOST_WIDE_INT_1U);
  505. #endif
  506. }
  507. /* Attach a special .ident directive to the end of the file to identify
  508. the version of GCC which compiled this code. The format of the .ident
  509. string is patterned after the ones produced by native SVR4 compilers. */
  510. if (!flag_no_ident)
  511. {
  512. const char *pkg_version = "(GNU) ";
  513. char *ident_str;
  514. if (strcmp ("(GCC) ", pkgversion_string))
  515. pkg_version = pkgversion_string;
  516. ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
  517. targetm.asm_out.output_ident (ident_str);
  518. }
  519. /* Auto profile finalization. */
  520. if (flag_auto_profile)
  521. end_auto_profile ();
  522. /* Invoke registered plugin callbacks. */
  523. invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
  524. /* This must be at the end. Some target ports emit end of file directives
  525. into the assembly file here, and hence we cannot output anything to the
  526. assembly file after this point. */
  527. targetm.asm_out.file_end ();
  528. timevar_stop (TV_PHASE_LATE_ASM);
  529. }
  530. /* Print version information to FILE.
  531. Each line begins with INDENT (for the case where FILE is the
  532. assembler output file).
  533. If SHOW_GLOBAL_STATE is true (for cc1 etc), we are within the compiler
  534. proper and can print pertinent state (e.g. params and plugins).
  535. If SHOW_GLOBAL_STATE is false (for use by libgccjit), we are outside the
  536. compiler, and we don't hold the mutex on the compiler's global state:
  537. we can't print params and plugins, since they might not be initialized,
  538. or might be being manipulated by a compile running in another
  539. thread. */
  540. void
  541. print_version (FILE *file, const char *indent, bool show_global_state)
  542. {
  543. static const char fmt1[] =
  544. #ifdef __GNUC__
  545. N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
  546. #else
  547. N_("%s%s%s %sversion %s (%s) compiled by CC, ")
  548. #endif
  549. ;
  550. static const char fmt2[] =
  551. N_("GMP version %s, MPFR version %s, MPC version %s, isl version %s\n");
  552. static const char fmt3[] =
  553. N_("%s%swarning: %s header version %s differs from library version %s.\n");
  554. static const char fmt4[] =
  555. N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
  556. #ifndef __VERSION__
  557. #define __VERSION__ "[?]"
  558. #endif
  559. fprintf (file,
  560. file == stderr ? _(fmt1) : fmt1,
  561. indent, *indent != 0 ? " " : "",
  562. lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
  563. indent, __VERSION__);
  564. /* We need to stringify the GMP macro values. Ugh, gmp_version has
  565. two string formats, "i.j.k" and "i.j" when k is zero. As of
  566. gmp-4.3.0, GMP always uses the 3 number format. */
  567. #define GCC_GMP_STRINGIFY_VERSION3(X) #X
  568. #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3 (X)
  569. #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
  570. #define GCC_GMP_VERSION \
  571. GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
  572. #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
  573. #define GCC_GMP_STRINGIFY_VERSION \
  574. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
  575. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR)
  576. #else
  577. #define GCC_GMP_STRINGIFY_VERSION \
  578. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
  579. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR) "." \
  580. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_PATCHLEVEL)
  581. #endif
  582. fprintf (file,
  583. file == stderr ? _(fmt2) : fmt2,
  584. GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING,
  585. #ifndef HAVE_isl
  586. "none"
  587. #else
  588. isl_version ()
  589. #endif
  590. );
  591. if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
  592. fprintf (file,
  593. file == stderr ? _(fmt3) : fmt3,
  594. indent, *indent != 0 ? " " : "",
  595. "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
  596. if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
  597. fprintf (file,
  598. file == stderr ? _(fmt3) : fmt3,
  599. indent, *indent != 0 ? " " : "",
  600. "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
  601. if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
  602. fprintf (file,
  603. file == stderr ? _(fmt3) : fmt3,
  604. indent, *indent != 0 ? " " : "",
  605. "MPC", MPC_VERSION_STRING, mpc_get_version ());
  606. if (show_global_state)
  607. {
  608. fprintf (file,
  609. file == stderr ? _(fmt4) : fmt4,
  610. indent, *indent != 0 ? " " : "",
  611. param_ggc_min_expand, param_ggc_min_heapsize);
  612. print_plugins_versions (file, indent);
  613. }
  614. }
  615. /* Open assembly code output file. Do this even if -fsyntax-only is
  616. on, because then the driver will have provided the name of a
  617. temporary file or bit bucket for us. NAME is the file specified on
  618. the command line, possibly NULL. */
  619. static void
  620. init_asm_output (const char *name)
  621. {
  622. if (name == NULL && asm_file_name == 0)
  623. asm_out_file = stdout;
  624. else
  625. {
  626. if (asm_file_name == 0)
  627. {
  628. int len = strlen (dump_base_name);
  629. char *dumpname = XNEWVEC (char, len + 6);
  630. memcpy (dumpname, dump_base_name, len + 1);
  631. strip_off_ending (dumpname, len);
  632. strcat (dumpname, ".s");
  633. asm_file_name = dumpname;
  634. }
  635. if (!strcmp (asm_file_name, "-"))
  636. asm_out_file = stdout;
  637. else if (!canonical_filename_eq (asm_file_name, name)
  638. || !strcmp (asm_file_name, HOST_BIT_BUCKET))
  639. asm_out_file = fopen (asm_file_name, "w");
  640. else
  641. /* Use UNKOWN_LOCATION to prevent gcc from printing the first
  642. line in the current file. */
  643. fatal_error (UNKNOWN_LOCATION,
  644. "input file %qs is the same as output file",
  645. asm_file_name);
  646. if (asm_out_file == 0)
  647. fatal_error (UNKNOWN_LOCATION,
  648. "cannot open %qs for writing: %m", asm_file_name);
  649. }
  650. if (!flag_syntax_only)
  651. {
  652. targetm.asm_out.file_start ();
  653. if (flag_record_gcc_switches)
  654. {
  655. if (targetm.asm_out.record_gcc_switches)
  656. {
  657. const char *str
  658. = gen_producer_string (lang_hooks.name,
  659. save_decoded_options,
  660. save_decoded_options_count);
  661. targetm.asm_out.record_gcc_switches (str);
  662. }
  663. else
  664. inform (UNKNOWN_LOCATION,
  665. "%<-frecord-gcc-switches%> is not supported by "
  666. "the current target");
  667. }
  668. if (flag_verbose_asm)
  669. {
  670. print_version (asm_out_file, ASM_COMMENT_START, true);
  671. fputs (ASM_COMMENT_START, asm_out_file);
  672. fputs (" options passed: ", asm_out_file);
  673. char *cmdline = gen_command_line_string (save_decoded_options,
  674. save_decoded_options_count);
  675. fputs (cmdline, asm_out_file);
  676. free (cmdline);
  677. fputc ('\n', asm_out_file);
  678. }
  679. }
  680. }
  681. /* A helper function; used as the reallocator function for cpp's line
  682. table. */
  683. static void *
  684. realloc_for_line_map (void *ptr, size_t len)
  685. {
  686. return ggc_realloc (ptr, len);
  687. }
  688. /* A helper function: used as the allocator function for
  689. identifier_to_locale. */
  690. static void *
  691. alloc_for_identifier_to_locale (size_t len)
  692. {
  693. return ggc_alloc_atomic (len);
  694. }
  695. /* Output stack usage information. */
  696. static void
  697. output_stack_usage_1 (FILE *cf)
  698. {
  699. static bool warning_issued = false;
  700. enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
  701. const char *stack_usage_kind_str[] = {
  702. "static",
  703. "dynamic",
  704. "dynamic,bounded"
  705. };
  706. HOST_WIDE_INT stack_usage = current_function_static_stack_size;
  707. enum stack_usage_kind_type stack_usage_kind;
  708. if (stack_usage < 0)
  709. {
  710. if (!warning_issued)
  711. {
  712. warning (0, "stack usage computation not supported for this target");
  713. warning_issued = true;
  714. }
  715. return;
  716. }
  717. stack_usage_kind = STATIC;
  718. /* Add the maximum amount of space pushed onto the stack. */
  719. if (maybe_ne (current_function_pushed_stack_size, 0))
  720. {
  721. HOST_WIDE_INT extra;
  722. if (current_function_pushed_stack_size.is_constant (&extra))
  723. {
  724. stack_usage += extra;
  725. stack_usage_kind = DYNAMIC_BOUNDED;
  726. }
  727. else
  728. {
  729. extra = constant_lower_bound (current_function_pushed_stack_size);
  730. stack_usage += extra;
  731. stack_usage_kind = DYNAMIC;
  732. }
  733. }
  734. /* Now on to the tricky part: dynamic stack allocation. */
  735. if (current_function_allocates_dynamic_stack_space)
  736. {
  737. if (stack_usage_kind != DYNAMIC)
  738. {
  739. if (current_function_has_unbounded_dynamic_stack_size)
  740. stack_usage_kind = DYNAMIC;
  741. else
  742. stack_usage_kind = DYNAMIC_BOUNDED;
  743. }
  744. /* Add the size even in the unbounded case, this can't hurt. */
  745. stack_usage += current_function_dynamic_stack_size;
  746. }
  747. if (cf && flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE)
  748. fprintf (cf, "\\n" HOST_WIDE_INT_PRINT_DEC " bytes (%s)",
  749. stack_usage,
  750. stack_usage_kind_str[stack_usage_kind]);
  751. if (stack_usage_file)
  752. {
  753. print_decl_identifier (stack_usage_file, current_function_decl,
  754. PRINT_DECL_ORIGIN | PRINT_DECL_NAME);
  755. fprintf (stack_usage_file, "\t" HOST_WIDE_INT_PRINT_DEC"\t%s\n",
  756. stack_usage, stack_usage_kind_str[stack_usage_kind]);
  757. }
  758. if (warn_stack_usage >= 0 && warn_stack_usage < HOST_WIDE_INT_MAX)
  759. {
  760. const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
  761. if (stack_usage_kind == DYNAMIC)
  762. warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
  763. else if (stack_usage > warn_stack_usage)
  764. {
  765. if (stack_usage_kind == DYNAMIC_BOUNDED)
  766. warning_at (loc,
  767. OPT_Wstack_usage_, "stack usage might be %wu bytes",
  768. stack_usage);
  769. else
  770. warning_at (loc, OPT_Wstack_usage_, "stack usage is %wu bytes",
  771. stack_usage);
  772. }
  773. }
  774. }
  775. /* Dump placeholder node for indirect calls in VCG format. */
  776. #define INDIRECT_CALL_NAME "__indirect_call"
  777. static void
  778. dump_final_node_vcg_start (FILE *f, tree decl)
  779. {
  780. fputs ("node: { title: \"", f);
  781. if (decl) {
  782. print_decl_identifier (f, decl, PRINT_DECL_UNIQUE_NAME);
  783. } else {
  784. fputs (INDIRECT_CALL_NAME, f);
  785. }
  786. fputs ("\" label: \"", f);
  787. if (decl)
  788. {
  789. print_decl_identifier (f, decl, PRINT_DECL_NAME);
  790. fputs ("\\n", f);
  791. print_decl_identifier (f, decl, PRINT_DECL_ORIGIN);
  792. }
  793. else {
  794. fputs ("Indirect Call Placeholder", f);
  795. }
  796. /*
  797. * added
  798. */
  799. {
  800. const char *name = NULL;
  801. const char *name2 = NULL;
  802. int nodeid = 0;
  803. splay_tree_node spn = NULL;
  804. /* get uniq node name */
  805. if (decl) {
  806. name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
  807. if (!TREE_PUBLIC (decl)
  808. || (DECL_WEAK (decl) && !DECL_EXTERNAL (decl))) {
  809. /* The symbol has internal or weak linkage so its assembler name
  810. is not necessarily unique among the compilation units of the
  811. program. We therefore have to further mangle it. But we can't
  812. simply use DECL_SOURCE_FILE because it contains the name of the
  813. file the symbol originates from so, e.g. for function templates
  814. in C++ where the templates are defined in a header file, we can
  815. have symbols with the same assembler name and DECL_SOURCE_FILE.
  816. That's why we use the name of the top-level source file of the
  817. compilation unit. ??? Unnecessary for Ada. */
  818. name = ACONCAT ((main_input_filename, ":", name, NULL));
  819. }
  820. nodeid = DECL_UID (decl);
  821. if (0) printf("--> node \"%s\" has id %d\n",name,nodeid);
  822. name2 = xstrdup (name);
  823. spn = splay_tree_insert (svg_callgraph_tree_nodes, (splay_tree_key) nodeid, (splay_tree_value) name2);
  824. if (spn) {
  825. svg_callgraph_tree_nodes_count++;
  826. }
  827. } else {
  828. /* node has no decl, it is indirect call name and skipped */
  829. }
  830. /*
  831. * end added
  832. */
  833. }
  834. return;
  835. }
  836. /* Dump final cgraph edge in VCG format. */
  837. static void
  838. dump_final_callee_vcg (FILE *f, location_t location, tree callee)
  839. {
  840. if ((!callee || DECL_EXTERNAL (callee))
  841. && bitmap_set_bit (callgraph_info_external_printed,
  842. callee ? DECL_UID (callee) + 1 : 0))
  843. {
  844. dump_final_node_vcg_start (f, callee);
  845. fputs ("\" shape : ellipse }\n", f);
  846. }
  847. fputs ("edge: { sourcename: \"", f);
  848. print_decl_identifier (f, current_function_decl, PRINT_DECL_UNIQUE_NAME);
  849. fputs ("\" targetname: \"", f);
  850. if (callee)
  851. print_decl_identifier (f, callee, PRINT_DECL_UNIQUE_NAME);
  852. else
  853. fputs (INDIRECT_CALL_NAME, f);
  854. if (LOCATION_LOCUS (location) != UNKNOWN_LOCATION)
  855. {
  856. expanded_location loc;
  857. fputs ("\" label: \"", f);
  858. loc = expand_location (location);
  859. fprintf (f, "%s:%d:%d", loc.file, loc.line, loc.column);
  860. }
  861. fputs ("\" }\n", f);
  862. /*
  863. * added
  864. */
  865. {
  866. struct svg_callgraph_edge *newedge = NULL;
  867. int fid = 0;
  868. int tid = 0;
  869. splay_tree_node spn = NULL;
  870. if (callee) {
  871. /* add edge to splay tree starting with edge number 1 */
  872. // newedge = (struct svg_callgraph_edge *) xmalloc (sizeof (struct svg_callgraph_edge));
  873. newedge = (struct svg_callgraph_edge *) XCNEW (struct svg_callgraph_edge);
  874. if (newedge) {
  875. fid = DECL_UID (current_function_decl);
  876. tid = DECL_UID (callee);
  877. if (0) printf("--> edge %d to %d\n", fid, tid );
  878. svg_callgraph_tree_edges_count++;
  879. newedge->fn = (int) fid;
  880. newedge->tn = (int) tid;
  881. spn = splay_tree_insert (svg_callgraph_tree_edges, (splay_tree_key) svg_callgraph_tree_edges_count, (splay_tree_value) newedge);
  882. if (spn) {
  883. }
  884. newedge = NULL;
  885. }
  886. } else {
  887. /* indirect routines are omitted */
  888. }
  889. }
  890. /*
  891. * end added
  892. */
  893. return;
  894. }
  895. /* Dump final cgraph node in VCG format. */
  896. static void
  897. dump_final_node_vcg (FILE *f)
  898. {
  899. dump_final_node_vcg_start (f, current_function_decl);
  900. if (flag_stack_usage_info
  901. || (flag_callgraph_info & CALLGRAPH_INFO_STACK_USAGE))
  902. output_stack_usage_1 (f);
  903. if (flag_callgraph_info & CALLGRAPH_INFO_DYNAMIC_ALLOC)
  904. {
  905. fprintf (f, "\\n%u dynamic objects", vec_safe_length (cfun->su->dallocs));
  906. unsigned i;
  907. callinfo_dalloc *cda;
  908. FOR_EACH_VEC_SAFE_ELT (cfun->su->dallocs, i, cda)
  909. {
  910. expanded_location loc = expand_location (cda->location);
  911. fprintf (f, "\\n %s", cda->name);
  912. fprintf (f, " %s:%d:%d", loc.file, loc.line, loc.column);
  913. }
  914. vec_free (cfun->su->dallocs);
  915. cfun->su->dallocs = NULL;
  916. }
  917. fputs ("\" }\n", f);
  918. unsigned i;
  919. callinfo_callee *c;
  920. FOR_EACH_VEC_SAFE_ELT (cfun->su->callees, i, c)
  921. dump_final_callee_vcg (f, c->location, c->decl);
  922. vec_free (cfun->su->callees);
  923. cfun->su->callees = NULL;
  924. }
  925. /* Output stack usage and callgraph info, as requested. */
  926. void
  927. output_stack_usage (void)
  928. {
  929. if (flag_callgraph_info)
  930. dump_final_node_vcg (callgraph_info_file);
  931. else
  932. output_stack_usage_1 (NULL);
  933. }
  934. /* Open an auxiliary output file. */
  935. static FILE *
  936. open_auxiliary_file (const char *ext)
  937. {
  938. char *filename;
  939. FILE *file;
  940. filename = concat (aux_base_name, ".", ext, NULL);
  941. file = fopen (filename, "w");
  942. if (!file)
  943. fatal_error (input_location, "cannot open %s for writing: %m", filename);
  944. free (filename);
  945. return file;
  946. }
  947. /* Alternative diagnostics callback for reentered ICE reporting. */
  948. static void
  949. internal_error_reentered (diagnostic_context *, const char *, va_list *)
  950. {
  951. /* Flush the dump file if emergency_dump_function itself caused an ICE. */
  952. if (dump_file)
  953. fflush (dump_file);
  954. }
  955. /* Auxiliary callback for the diagnostics code. */
  956. static void
  957. internal_error_function (diagnostic_context *, const char *, va_list *)
  958. {
  959. global_dc->internal_error = internal_error_reentered;
  960. warn_if_plugins ();
  961. emergency_dump_function ();
  962. }
  963. /* Initialization of the front end environment, before command line
  964. options are parsed. Signal handlers, internationalization etc.
  965. ARGV0 is main's argv[0]. */
  966. static void
  967. general_init (const char *argv0, bool init_signals)
  968. {
  969. const char *p;
  970. p = argv0 + strlen (argv0);
  971. while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
  972. --p;
  973. progname = p;
  974. xmalloc_set_program_name (progname);
  975. hex_init ();
  976. /* Unlock the stdio streams. */
  977. unlock_std_streams ();
  978. gcc_init_libintl ();
  979. identifier_to_locale_alloc = alloc_for_identifier_to_locale;
  980. identifier_to_locale_free = ggc_free;
  981. /* Initialize the diagnostics reporting machinery, so option parsing
  982. can give warnings and errors. */
  983. diagnostic_initialize (global_dc, N_OPTS);
  984. global_dc->lang_mask = lang_hooks.option_lang_mask ();
  985. /* Set a default printer. Language specific initializations will
  986. override it later. */
  987. tree_diagnostics_defaults (global_dc);
  988. global_dc->show_caret
  989. = global_options_init.x_flag_diagnostics_show_caret;
  990. global_dc->show_labels_p
  991. = global_options_init.x_flag_diagnostics_show_labels;
  992. global_dc->show_line_numbers_p
  993. = global_options_init.x_flag_diagnostics_show_line_numbers;
  994. global_dc->show_cwe
  995. = global_options_init.x_flag_diagnostics_show_cwe;
  996. global_dc->path_format
  997. = (enum diagnostic_path_format)global_options_init.x_flag_diagnostics_path_format;
  998. global_dc->show_path_depths
  999. = global_options_init.x_flag_diagnostics_show_path_depths;
  1000. global_dc->show_option_requested
  1001. = global_options_init.x_flag_diagnostics_show_option;
  1002. global_dc->min_margin_width
  1003. = global_options_init.x_diagnostics_minimum_margin_width;
  1004. global_dc->show_column
  1005. = global_options_init.x_flag_show_column;
  1006. global_dc->internal_error = internal_error_function;
  1007. global_dc->option_enabled = option_enabled;
  1008. global_dc->option_state = &global_options;
  1009. global_dc->option_name = option_name;
  1010. global_dc->get_option_url = get_option_url;
  1011. if (init_signals)
  1012. {
  1013. /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
  1014. #ifdef SIGSEGV
  1015. signal (SIGSEGV, crash_signal);
  1016. #endif
  1017. #ifdef SIGILL
  1018. signal (SIGILL, crash_signal);
  1019. #endif
  1020. #ifdef SIGBUS
  1021. signal (SIGBUS, crash_signal);
  1022. #endif
  1023. #ifdef SIGABRT
  1024. signal (SIGABRT, crash_signal);
  1025. #endif
  1026. #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
  1027. signal (SIGIOT, crash_signal);
  1028. #endif
  1029. #ifdef SIGFPE
  1030. signal (SIGFPE, crash_signal);
  1031. #endif
  1032. /* Other host-specific signal setup. */
  1033. (*host_hooks.extra_signals)();
  1034. }
  1035. /* Initialize the garbage-collector, string pools and tree type hash
  1036. table. */
  1037. init_ggc ();
  1038. init_stringpool ();
  1039. input_location = UNKNOWN_LOCATION;
  1040. line_table = ggc_alloc<line_maps> ();
  1041. linemap_init (line_table, BUILTINS_LOCATION);
  1042. line_table->reallocator = realloc_for_line_map;
  1043. line_table->round_alloc_size = ggc_round_alloc_size;
  1044. line_table->default_range_bits = 5;
  1045. init_ttree ();
  1046. /* Initialize register usage now so switches may override. */
  1047. init_reg_sets ();
  1048. /* Create the singleton holder for global state. This creates the
  1049. dump manager. */
  1050. g = new gcc::context ();
  1051. /* Allow languages and middle-end to register their dumps before the
  1052. optimization passes. */
  1053. g->get_dumps ()->register_dumps ();
  1054. /* Create the passes. */
  1055. g->set_passes (new gcc::pass_manager (g));
  1056. symtab = new (ggc_alloc <symbol_table> ()) symbol_table ();
  1057. statistics_early_init ();
  1058. debuginfo_early_init ();
  1059. }
  1060. /* Return true if the current target supports -fsection-anchors. */
  1061. static bool
  1062. target_supports_section_anchors_p (void)
  1063. {
  1064. if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
  1065. return false;
  1066. if (targetm.asm_out.output_anchor == NULL)
  1067. return false;
  1068. return true;
  1069. }
  1070. /* Parse "N[:M][:...]" into struct align_flags A.
  1071. VALUES contains parsed values (in reverse order), all processed
  1072. values are popped. */
  1073. static void
  1074. read_log_maxskip (auto_vec<unsigned> &values, align_flags_tuple *a)
  1075. {
  1076. unsigned n = values.pop ();
  1077. if (n != 0)
  1078. a->log = floor_log2 (n * 2 - 1);
  1079. if (values.is_empty ())
  1080. a->maxskip = n ? n - 1 : 0;
  1081. else
  1082. {
  1083. unsigned m = values.pop ();
  1084. /* -falign-foo=N:M means M-1 max bytes of padding, not M. */
  1085. if (m > 0)
  1086. m--;
  1087. a->maxskip = m;
  1088. }
  1089. /* Normalize the tuple. */
  1090. a->normalize ();
  1091. }
  1092. /* Parse "N[:M[:N2[:M2]]]" string FLAG into a pair of struct align_flags. */
  1093. static void
  1094. parse_N_M (const char *flag, align_flags &a)
  1095. {
  1096. if (flag)
  1097. {
  1098. static hash_map <nofree_string_hash, align_flags> cache;
  1099. align_flags *entry = cache.get (flag);
  1100. if (entry)
  1101. {
  1102. a = *entry;
  1103. return;
  1104. }
  1105. auto_vec<unsigned> result_values;
  1106. bool r = parse_and_check_align_values (flag, NULL, result_values, false,
  1107. UNKNOWN_LOCATION);
  1108. if (!r)
  1109. return;
  1110. /* Reverse values for easier manipulation. */
  1111. result_values.reverse ();
  1112. read_log_maxskip (result_values, &a.levels[0]);
  1113. if (!result_values.is_empty ())
  1114. read_log_maxskip (result_values, &a.levels[1]);
  1115. #ifdef SUBALIGN_LOG
  1116. else
  1117. {
  1118. /* N2[:M2] is not specified. This arch has a default for N2.
  1119. Before -falign-foo=N:M:N2:M2 was introduced, x86 had a tweak.
  1120. -falign-functions=N with N > 8 was adding secondary alignment.
  1121. -falign-functions=10 was emitting this before every function:
  1122. .p2align 4,,9
  1123. .p2align 3
  1124. Now this behavior (and more) can be explicitly requested:
  1125. -falign-functions=16:10:8
  1126. Retain old behavior if N2 is missing: */
  1127. int align = 1 << a.levels[0].log;
  1128. int subalign = 1 << SUBALIGN_LOG;
  1129. if (a.levels[0].log > SUBALIGN_LOG
  1130. && a.levels[0].maxskip >= subalign - 1)
  1131. {
  1132. /* Set N2 unless subalign can never have any effect. */
  1133. if (align > a.levels[0].maxskip + 1)
  1134. {
  1135. a.levels[1].log = SUBALIGN_LOG;
  1136. a.levels[1].normalize ();
  1137. }
  1138. }
  1139. }
  1140. #endif
  1141. /* Cache seen value. */
  1142. cache.put (flag, a);
  1143. }
  1144. }
  1145. /* Process -falign-foo=N[:M[:N2[:M2]]] options. */
  1146. void
  1147. parse_alignment_opts (void)
  1148. {
  1149. parse_N_M (str_align_loops, align_loops);
  1150. parse_N_M (str_align_jumps, align_jumps);
  1151. parse_N_M (str_align_labels, align_labels);
  1152. parse_N_M (str_align_functions, align_functions);
  1153. }
  1154. /* Process the options that have been parsed. */
  1155. static void
  1156. process_options (void)
  1157. {
  1158. /* Just in case lang_hooks.post_options ends up calling a debug_hook.
  1159. This can happen with incorrect pre-processed input. */
  1160. debug_hooks = &do_nothing_debug_hooks;
  1161. maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
  1162. /* Allow the front end to perform consistency checks and do further
  1163. initialization based on the command line options. This hook also
  1164. sets the original filename if appropriate (e.g. foo.i -> foo.c)
  1165. so we can correctly initialize debug output. */
  1166. no_backend = lang_hooks.post_options (&main_input_filename);
  1167. /* Some machines may reject certain combinations of options. */
  1168. location_t saved_location = input_location;
  1169. input_location = UNKNOWN_LOCATION;
  1170. targetm.target_option.override ();
  1171. input_location = saved_location;
  1172. if (flag_diagnostics_generate_patch)
  1173. global_dc->edit_context_ptr = new edit_context ();
  1174. /* Avoid any informative notes in the second run of -fcompare-debug. */
  1175. if (flag_compare_debug)
  1176. diagnostic_inhibit_notes (global_dc);
  1177. if (flag_section_anchors && !target_supports_section_anchors_p ())
  1178. {
  1179. warning_at (UNKNOWN_LOCATION, OPT_fsection_anchors,
  1180. "this target does not support %qs",
  1181. "-fsection-anchors");
  1182. flag_section_anchors = 0;
  1183. }
  1184. if (flag_short_enums == 2)
  1185. flag_short_enums = targetm.default_short_enums ();
  1186. /* Set aux_base_name if not already set. */
  1187. if (aux_base_name)
  1188. ;
  1189. else if (dump_base_name)
  1190. {
  1191. const char *name = dump_base_name;
  1192. int nlen, len;
  1193. if (dump_base_ext && (len = strlen (dump_base_ext))
  1194. && (nlen = strlen (name)) && nlen > len
  1195. && strcmp (name + nlen - len, dump_base_ext) == 0)
  1196. {
  1197. char *p = xstrndup (name, nlen - len);
  1198. name = p;
  1199. }
  1200. aux_base_name = name;
  1201. }
  1202. else
  1203. aux_base_name = "gccaux";
  1204. #ifndef HAVE_isl
  1205. if (flag_graphite
  1206. || flag_loop_nest_optimize
  1207. || flag_graphite_identity
  1208. || flag_loop_parallelize_all)
  1209. sorry ("Graphite loop optimizations cannot be used (isl is not available) "
  1210. "(%<-fgraphite%>, %<-fgraphite-identity%>, "
  1211. "%<-floop-nest-optimize%>, %<-floop-parallelize-all%>)");
  1212. #endif
  1213. if (flag_cf_protection != CF_NONE
  1214. && !(flag_cf_protection & CF_SET))
  1215. {
  1216. if (flag_cf_protection == CF_FULL)
  1217. {
  1218. error_at (UNKNOWN_LOCATION,
  1219. "%<-fcf-protection=full%> is not supported for this "
  1220. "target");
  1221. flag_cf_protection = CF_NONE;
  1222. }
  1223. if (flag_cf_protection == CF_BRANCH)
  1224. {
  1225. error_at (UNKNOWN_LOCATION,
  1226. "%<-fcf-protection=branch%> is not supported for this "
  1227. "target");
  1228. flag_cf_protection = CF_NONE;
  1229. }
  1230. if (flag_cf_protection == CF_RETURN)
  1231. {
  1232. error_at (UNKNOWN_LOCATION,
  1233. "%<-fcf-protection=return%> is not supported for this "
  1234. "target");
  1235. flag_cf_protection = CF_NONE;
  1236. }
  1237. }
  1238. /* One region RA really helps to decrease the code size. */
  1239. if (flag_ira_region == IRA_REGION_AUTODETECT)
  1240. flag_ira_region
  1241. = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
  1242. if (!abi_version_at_least (2))
  1243. {
  1244. /* -fabi-version=1 support was removed after GCC 4.9. */
  1245. error_at (UNKNOWN_LOCATION,
  1246. "%<-fabi-version=1%> is no longer supported");
  1247. flag_abi_version = 2;
  1248. }
  1249. /* web and rename-registers help when run after loop unrolling. */
  1250. if (flag_web == AUTODETECT_VALUE)
  1251. flag_web = flag_unroll_loops;
  1252. if (flag_rename_registers == AUTODETECT_VALUE)
  1253. flag_rename_registers = flag_unroll_loops;
  1254. if (flag_non_call_exceptions)
  1255. flag_asynchronous_unwind_tables = 1;
  1256. if (flag_asynchronous_unwind_tables)
  1257. flag_unwind_tables = 1;
  1258. if (flag_value_profile_transformations)
  1259. flag_profile_values = 1;
  1260. /* Warn about options that are not supported on this machine. */
  1261. #ifndef INSN_SCHEDULING
  1262. if (flag_schedule_insns || flag_schedule_insns_after_reload)
  1263. warning_at (UNKNOWN_LOCATION, 0,
  1264. "instruction scheduling not supported on this target machine");
  1265. #endif
  1266. if (!DELAY_SLOTS && flag_delayed_branch)
  1267. warning_at (UNKNOWN_LOCATION, 0,
  1268. "this target machine does not have delayed branches");
  1269. user_label_prefix = USER_LABEL_PREFIX;
  1270. if (flag_leading_underscore != -1)
  1271. {
  1272. /* If the default prefix is more complicated than "" or "_",
  1273. issue a warning and ignore this option. */
  1274. if (user_label_prefix[0] == 0 ||
  1275. (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
  1276. {
  1277. user_label_prefix = flag_leading_underscore ? "_" : "";
  1278. }
  1279. else
  1280. warning_at (UNKNOWN_LOCATION, 0,
  1281. "%<-f%sleading-underscore%> not supported on this "
  1282. "target machine", flag_leading_underscore ? "" : "no-");
  1283. }
  1284. /* If we are in verbose mode, write out the version and maybe all the
  1285. option flags in use. */
  1286. if (version_flag)
  1287. {
  1288. print_version (stderr, "", true);
  1289. if (!quiet_flag)
  1290. {
  1291. fputs ("options passed: ", stderr);
  1292. char *cmdline = gen_command_line_string (save_decoded_options,
  1293. save_decoded_options_count);
  1294. fputs (cmdline, stderr);
  1295. free (cmdline);
  1296. fputc ('\n', stderr);
  1297. }
  1298. }
  1299. if (flag_syntax_only)
  1300. {
  1301. write_symbols = NO_DEBUG;
  1302. profile_flag = 0;
  1303. }
  1304. if (flag_gtoggle)
  1305. {
  1306. if (debug_info_level == DINFO_LEVEL_NONE)
  1307. {
  1308. debug_info_level = DINFO_LEVEL_NORMAL;
  1309. if (write_symbols == NO_DEBUG)
  1310. write_symbols = PREFERRED_DEBUGGING_TYPE;
  1311. }
  1312. else
  1313. debug_info_level = DINFO_LEVEL_NONE;
  1314. }
  1315. if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
  1316. {
  1317. FILE *final_output = fopen (flag_dump_final_insns, "w");
  1318. if (!final_output)
  1319. {
  1320. error_at (UNKNOWN_LOCATION,
  1321. "could not open final insn dump file %qs: %m",
  1322. flag_dump_final_insns);
  1323. flag_dump_final_insns = NULL;
  1324. }
  1325. else if (fclose (final_output))
  1326. {
  1327. error_at (UNKNOWN_LOCATION,
  1328. "could not close zeroed insn dump file %qs: %m",
  1329. flag_dump_final_insns);
  1330. flag_dump_final_insns = NULL;
  1331. }
  1332. }
  1333. /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
  1334. level is 0. */
  1335. if (debug_info_level == DINFO_LEVEL_NONE)
  1336. write_symbols = NO_DEBUG;
  1337. if (write_symbols == NO_DEBUG)
  1338. ;
  1339. #if defined(DBX_DEBUGGING_INFO)
  1340. else if (write_symbols == DBX_DEBUG)
  1341. debug_hooks = &dbx_debug_hooks;
  1342. #endif
  1343. #if defined(XCOFF_DEBUGGING_INFO)
  1344. else if (write_symbols == XCOFF_DEBUG)
  1345. debug_hooks = &xcoff_debug_hooks;
  1346. #endif
  1347. #ifdef DWARF2_DEBUGGING_INFO
  1348. else if (write_symbols == DWARF2_DEBUG)
  1349. debug_hooks = &dwarf2_debug_hooks;
  1350. #endif
  1351. #ifdef VMS_DEBUGGING_INFO
  1352. else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
  1353. debug_hooks = &vmsdbg_debug_hooks;
  1354. #endif
  1355. #ifdef DWARF2_LINENO_DEBUGGING_INFO
  1356. else if (write_symbols == DWARF2_DEBUG)
  1357. debug_hooks = &dwarf2_lineno_debug_hooks;
  1358. #endif
  1359. else
  1360. error_at (UNKNOWN_LOCATION,
  1361. "target system does not support the %qs debug format",
  1362. debug_type_names[write_symbols]);
  1363. /* We know which debug output will be used so we can set flag_var_tracking
  1364. and flag_var_tracking_uninit if the user has not specified them. */
  1365. if (debug_info_level < DINFO_LEVEL_NORMAL
  1366. || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
  1367. {
  1368. if (flag_var_tracking == 1
  1369. || flag_var_tracking_uninit == 1)
  1370. {
  1371. if (debug_info_level < DINFO_LEVEL_NORMAL)
  1372. warning_at (UNKNOWN_LOCATION, 0,
  1373. "variable tracking requested, but useless unless "
  1374. "producing debug info");
  1375. else
  1376. warning_at (UNKNOWN_LOCATION, 0,
  1377. "variable tracking requested, but not supported "
  1378. "by this debug format");
  1379. }
  1380. flag_var_tracking = 0;
  1381. flag_var_tracking_uninit = 0;
  1382. }
  1383. /* The debug hooks are used to implement -fdump-go-spec because it
  1384. gives a simple and stable API for all the information we need to
  1385. dump. */
  1386. if (flag_dump_go_spec != NULL)
  1387. debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
  1388. /* If the user specifically requested variable tracking with tagging
  1389. uninitialized variables, we need to turn on variable tracking.
  1390. (We already determined above that variable tracking is feasible.) */
  1391. if (flag_var_tracking_uninit == 1)
  1392. flag_var_tracking = 1;
  1393. if (flag_var_tracking == AUTODETECT_VALUE)
  1394. flag_var_tracking = optimize >= 1;
  1395. if (flag_var_tracking_uninit == AUTODETECT_VALUE)
  1396. flag_var_tracking_uninit = flag_var_tracking;
  1397. if (flag_var_tracking_assignments == AUTODETECT_VALUE)
  1398. flag_var_tracking_assignments
  1399. = (flag_var_tracking
  1400. && !(flag_selective_scheduling || flag_selective_scheduling2));
  1401. if (flag_var_tracking_assignments_toggle)
  1402. flag_var_tracking_assignments = !flag_var_tracking_assignments;
  1403. if (flag_var_tracking_assignments && !flag_var_tracking)
  1404. flag_var_tracking = flag_var_tracking_assignments = -1;
  1405. if (flag_var_tracking_assignments
  1406. && (flag_selective_scheduling || flag_selective_scheduling2))
  1407. warning_at (UNKNOWN_LOCATION, 0,
  1408. "var-tracking-assignments changes selective scheduling");
  1409. if (debug_nonbind_markers_p == AUTODETECT_VALUE)
  1410. debug_nonbind_markers_p
  1411. = (optimize
  1412. && debug_info_level >= DINFO_LEVEL_NORMAL
  1413. && (write_symbols == DWARF2_DEBUG
  1414. || write_symbols == VMS_AND_DWARF2_DEBUG)
  1415. && !(flag_selective_scheduling || flag_selective_scheduling2));
  1416. if (dwarf2out_as_loc_support == AUTODETECT_VALUE)
  1417. dwarf2out_as_loc_support
  1418. = dwarf2out_default_as_loc_support ();
  1419. if (dwarf2out_as_locview_support == AUTODETECT_VALUE)
  1420. dwarf2out_as_locview_support
  1421. = dwarf2out_default_as_locview_support ();
  1422. if (debug_variable_location_views == AUTODETECT_VALUE)
  1423. {
  1424. debug_variable_location_views
  1425. = (flag_var_tracking
  1426. && debug_info_level >= DINFO_LEVEL_NORMAL
  1427. && (write_symbols == DWARF2_DEBUG
  1428. || write_symbols == VMS_AND_DWARF2_DEBUG)
  1429. && !dwarf_strict
  1430. && dwarf2out_as_loc_support
  1431. && dwarf2out_as_locview_support);
  1432. }
  1433. else if (debug_variable_location_views == -1 && dwarf_version != 5)
  1434. {
  1435. warning_at (UNKNOWN_LOCATION, 0,
  1436. "without %<-gdwarf-5%>, "
  1437. "%<-gvariable-location-views=incompat5%> "
  1438. "is equivalent to %<-gvariable-location-views%>");
  1439. debug_variable_location_views = 1;
  1440. }
  1441. if (debug_internal_reset_location_views == 2)
  1442. {
  1443. debug_internal_reset_location_views
  1444. = (debug_variable_location_views
  1445. && targetm.reset_location_view);
  1446. }
  1447. else if (debug_internal_reset_location_views
  1448. && !debug_variable_location_views)
  1449. {
  1450. warning_at (UNKNOWN_LOCATION, 0,
  1451. "%<-ginternal-reset-location-views%> is forced disabled "
  1452. "without %<-gvariable-location-views%>");
  1453. debug_internal_reset_location_views = 0;
  1454. }
  1455. if (debug_inline_points == AUTODETECT_VALUE)
  1456. debug_inline_points = debug_variable_location_views;
  1457. else if (debug_inline_points && !debug_nonbind_markers_p)
  1458. {
  1459. warning_at (UNKNOWN_LOCATION, 0,
  1460. "%<-ginline-points%> is forced disabled without "
  1461. "%<-gstatement-frontiers%>");
  1462. debug_inline_points = 0;
  1463. }
  1464. if (flag_tree_cselim == AUTODETECT_VALUE)
  1465. {
  1466. if (HAVE_conditional_move)
  1467. flag_tree_cselim = 1;
  1468. else
  1469. flag_tree_cselim = 0;
  1470. }
  1471. /* If auxiliary info generation is desired, open the output file.
  1472. This goes in the same directory as the source file--unlike
  1473. all the other output files. */
  1474. if (flag_gen_aux_info)
  1475. {
  1476. aux_info_file = fopen (aux_info_file_name, "w");
  1477. if (aux_info_file == 0)
  1478. fatal_error (UNKNOWN_LOCATION,
  1479. "cannot open %s: %m", aux_info_file_name);
  1480. }
  1481. if (!targetm_common.have_named_sections)
  1482. {
  1483. if (flag_function_sections)
  1484. {
  1485. warning_at (UNKNOWN_LOCATION, 0,
  1486. "%<-ffunction-sections%> not supported for this target");
  1487. flag_function_sections = 0;
  1488. }
  1489. if (flag_data_sections)
  1490. {
  1491. warning_at (UNKNOWN_LOCATION, 0,
  1492. "%<-fdata-sections%> not supported for this target");
  1493. flag_data_sections = 0;
  1494. }
  1495. }
  1496. if (flag_prefetch_loop_arrays > 0 && !targetm.code_for_prefetch)
  1497. {
  1498. warning_at (UNKNOWN_LOCATION, 0,
  1499. "%<-fprefetch-loop-arrays%> not supported for this target");
  1500. flag_prefetch_loop_arrays = 0;
  1501. }
  1502. else if (flag_prefetch_loop_arrays > 0 && !targetm.have_prefetch ())
  1503. {
  1504. warning_at (UNKNOWN_LOCATION, 0,
  1505. "%<-fprefetch-loop-arrays%> not supported for this target "
  1506. "(try %<-march%> switches)");
  1507. flag_prefetch_loop_arrays = 0;
  1508. }
  1509. /* This combination of options isn't handled for i386 targets and doesn't
  1510. make much sense anyway, so don't allow it. */
  1511. if (flag_prefetch_loop_arrays > 0 && optimize_size)
  1512. {
  1513. warning_at (UNKNOWN_LOCATION, 0,
  1514. "%<-fprefetch-loop-arrays%> is not supported with %<-Os%>");
  1515. flag_prefetch_loop_arrays = 0;
  1516. }
  1517. /* The presence of IEEE signaling NaNs, implies all math can trap. */
  1518. if (flag_signaling_nans)
  1519. flag_trapping_math = 1;
  1520. /* We cannot reassociate if we want traps or signed zeros. */
  1521. if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
  1522. {
  1523. warning_at (UNKNOWN_LOCATION, 0,
  1524. "%<-fassociative-math%> disabled; other options take "
  1525. "precedence");
  1526. flag_associative_math = 0;
  1527. }
  1528. /* -fstack-clash-protection is not currently supported on targets
  1529. where the stack grows up. */
  1530. if (flag_stack_clash_protection && !STACK_GROWS_DOWNWARD)
  1531. {
  1532. warning_at (UNKNOWN_LOCATION, 0,
  1533. "%<-fstack-clash-protection%> is not supported on targets "
  1534. "where the stack grows from lower to higher addresses");
  1535. flag_stack_clash_protection = 0;
  1536. }
  1537. /* We cannot support -fstack-check= and -fstack-clash-protection at
  1538. the same time. */
  1539. if (flag_stack_check != NO_STACK_CHECK && flag_stack_clash_protection)
  1540. {
  1541. warning_at (UNKNOWN_LOCATION, 0,
  1542. "%<-fstack-check=%> and %<-fstack-clash_protection%> are "
  1543. "mutually exclusive; disabling %<-fstack-check=%>");
  1544. flag_stack_check = NO_STACK_CHECK;
  1545. }
  1546. /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
  1547. if (flag_cx_limited_range)
  1548. flag_complex_method = 0;
  1549. /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
  1550. if (flag_cx_fortran_rules)
  1551. flag_complex_method = 1;
  1552. /* Targets must be able to place spill slots at lower addresses. If the
  1553. target already uses a soft frame pointer, the transition is trivial. */
  1554. if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
  1555. {
  1556. warning_at (UNKNOWN_LOCATION, 0,
  1557. "%<-fstack-protector%> not supported for this target");
  1558. flag_stack_protect = 0;
  1559. }
  1560. if (!flag_stack_protect)
  1561. warn_stack_protect = 0;
  1562. /* Address Sanitizer needs porting to each target architecture. */
  1563. if ((flag_sanitize & SANITIZE_ADDRESS)
  1564. && !FRAME_GROWS_DOWNWARD)
  1565. {
  1566. warning_at (UNKNOWN_LOCATION, 0,
  1567. "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
  1568. "are not supported for this target");
  1569. flag_sanitize &= ~SANITIZE_ADDRESS;
  1570. }
  1571. if ((flag_sanitize & SANITIZE_USER_ADDRESS)
  1572. && ((targetm.asan_shadow_offset == NULL)
  1573. || (targetm.asan_shadow_offset () == 0)))
  1574. {
  1575. warning_at (UNKNOWN_LOCATION, 0,
  1576. "%<-fsanitize=address%> not supported for this target");
  1577. flag_sanitize &= ~SANITIZE_ADDRESS;
  1578. }
  1579. if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
  1580. && (targetm.asan_shadow_offset == NULL
  1581. && !asan_shadow_offset_set_p ()))
  1582. {
  1583. warning_at (UNKNOWN_LOCATION, 0,
  1584. "%<-fsanitize=kernel-address%> with stack protection "
  1585. "is not supported without %<-fasan-shadow-offset=%> "
  1586. "for this target");
  1587. flag_sanitize &= ~SANITIZE_ADDRESS;
  1588. }
  1589. /* HWAsan requires top byte ignore feature in the backend. */
  1590. if (flag_sanitize & SANITIZE_HWADDRESS
  1591. && ! targetm.memtag.can_tag_addresses ())
  1592. {
  1593. warning_at (UNKNOWN_LOCATION, 0, "%qs is not supported for this target",
  1594. "-fsanitize=hwaddress");
  1595. flag_sanitize &= ~SANITIZE_HWADDRESS;
  1596. }
  1597. HOST_WIDE_INT patch_area_size, patch_area_start;
  1598. parse_and_check_patch_area (flag_patchable_function_entry, false,
  1599. &patch_area_size, &patch_area_start);
  1600. /* Do not use IPA optimizations for register allocation if profiler is active
  1601. or patchable function entries are inserted for run-time instrumentation
  1602. or port does not emit prologue and epilogue as RTL. */
  1603. if (profile_flag || patch_area_size
  1604. || !targetm.have_prologue () || !targetm.have_epilogue ())
  1605. flag_ipa_ra = 0;
  1606. /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
  1607. have not been set. */
  1608. if (!global_options_set.x_warnings_are_errors
  1609. && warn_coverage_mismatch
  1610. && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
  1611. DK_UNSPECIFIED))
  1612. diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
  1613. DK_ERROR, UNKNOWN_LOCATION);
  1614. /* Save the current optimization options. */
  1615. optimization_default_node
  1616. = build_optimization_node (&global_options, &global_options_set);
  1617. optimization_current_node = optimization_default_node;
  1618. if (flag_checking >= 2)
  1619. hash_table_sanitize_eq_limit
  1620. = param_hash_table_verification_limit;
  1621. if (flag_large_source_files)
  1622. line_table->default_range_bits = 0;
  1623. /* Please don't change global_options after this point, those changes won't
  1624. be reflected in optimization_{default,current}_node. */
  1625. }
  1626. /* This function can be called multiple times to reinitialize the compiler
  1627. back end when register classes or instruction sets have changed,
  1628. before each function. */
  1629. static void
  1630. backend_init_target (void)
  1631. {
  1632. /* This depends on stack_pointer_rtx. */
  1633. init_fake_stack_mems ();
  1634. /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
  1635. mode-dependent. */
  1636. init_alias_target ();
  1637. /* Depends on HARD_FRAME_POINTER_REGNUM. */
  1638. if (!ira_use_lra_p)
  1639. init_reload ();
  1640. /* Depends on the enabled attribute. */
  1641. recog_init ();
  1642. /* The following initialization functions need to generate rtl, so
  1643. provide a dummy function context for them. */
  1644. init_dummy_function_start ();
  1645. /* rtx_cost is mode-dependent, so cached values need to be recomputed
  1646. on a mode change. */
  1647. init_expmed ();
  1648. init_lower_subreg ();
  1649. init_set_costs ();
  1650. init_expr_target ();
  1651. ira_init ();
  1652. /* We may need to recompute regno_save_code[] and regno_restore_code[]
  1653. after a mode change as well. */
  1654. caller_save_initialized_p = false;
  1655. expand_dummy_function_end ();
  1656. }
  1657. /* Initialize the compiler back end. This function is called only once,
  1658. when starting the compiler. */
  1659. static void
  1660. backend_init (void)
  1661. {
  1662. init_emit_once ();
  1663. init_rtlanal ();
  1664. init_inline_once ();
  1665. init_varasm_once ();
  1666. save_register_info ();
  1667. /* Middle end needs this initialization for default mem attributes
  1668. used by early calls to make_decl_rtl. */
  1669. init_emit_regs ();
  1670. /* Middle end needs this initialization for mode tables used to assign
  1671. modes to vector variables. */
  1672. init_regs ();
  1673. }
  1674. /* Initialize things that are both lang-dependent and target-dependent.
  1675. This function can be called more than once if target parameters change. */
  1676. static void
  1677. lang_dependent_init_target (void)
  1678. {
  1679. /* This creates various _DECL nodes, so needs to be called after the
  1680. front end is initialized. It also depends on the HAVE_xxx macros
  1681. generated from the target machine description. */
  1682. init_optabs ();
  1683. gcc_assert (!this_target_rtl->target_specific_initialized);
  1684. }
  1685. /* Perform initializations that are lang-dependent or target-dependent.
  1686. but matters only for late optimizations and RTL generation. */
  1687. static int rtl_initialized;
  1688. void
  1689. initialize_rtl (void)
  1690. {
  1691. auto_timevar tv (g_timer, TV_INITIALIZE_RTL);
  1692. /* Initialization done just once per compilation, but delayed
  1693. till code generation. */
  1694. if (!rtl_initialized)
  1695. ira_init_once ();
  1696. rtl_initialized = true;
  1697. /* Target specific RTL backend initialization. */
  1698. if (!this_target_rtl->target_specific_initialized)
  1699. {
  1700. backend_init_target ();
  1701. this_target_rtl->target_specific_initialized = true;
  1702. }
  1703. }
  1704. /* Language-dependent initialization. Returns nonzero on success. */
  1705. static int
  1706. lang_dependent_init (const char *name)
  1707. {
  1708. location_t save_loc = input_location;
  1709. if (!dump_base_name)
  1710. {
  1711. dump_base_name = name && name[0] ? name : "gccdump";
  1712. /* We do not want to derive a non-empty dumpbase-ext from an
  1713. explicit -dumpbase argument, only from a defaulted
  1714. dumpbase. */
  1715. if (!dump_base_ext)
  1716. {
  1717. const char *base = lbasename (dump_base_name);
  1718. const char *ext = strrchr (base, '.');
  1719. if (ext)
  1720. dump_base_ext = ext;
  1721. }
  1722. }
  1723. /* Other front-end initialization. */
  1724. input_location = BUILTINS_LOCATION;
  1725. if (lang_hooks.init () == 0)
  1726. return 0;
  1727. input_location = save_loc;
  1728. if (!flag_wpa)
  1729. {
  1730. init_asm_output (name);
  1731. if (!flag_generate_lto && !flag_compare_debug)
  1732. {
  1733. /* If stack usage information is desired, open the output file. */
  1734. if (flag_stack_usage)
  1735. stack_usage_file = open_auxiliary_file ("su");
  1736. /* If call graph information is desired, open the output file. */
  1737. if (flag_callgraph_info)
  1738. {
  1739. callgraph_info_file = open_auxiliary_file ("ci");
  1740. /* Write the file header. */
  1741. fprintf (callgraph_info_file,
  1742. "graph: { title: \"%s\"\n", main_input_filename);
  1743. bitmap_obstack_initialize (NULL);
  1744. callgraph_info_external_printed = BITMAP_ALLOC (NULL);
  1745. /*
  1746. * added
  1747. */
  1748. {
  1749. svg_callgraph_info_file = open_auxiliary_file ("callgraph-info.svg");
  1750. svg_callgraph_tree_nodes = splay_tree_new (splay_tree_compare_ints, NULL, svg_callgraph_tree_nodes_delete_value);
  1751. svg_callgraph_tree_edges = splay_tree_new (splay_tree_compare_ints, NULL, svg_callgraph_tree_edges_delete_value);
  1752. gv_callgraph_info_file = open_auxiliary_file ("callgraph-info.gv");
  1753. }
  1754. /*
  1755. * end added
  1756. */
  1757. }
  1758. }
  1759. else
  1760. flag_stack_usage = flag_callgraph_info = false;
  1761. }
  1762. /* This creates various _DECL nodes, so needs to be called after the
  1763. front end is initialized. */
  1764. init_eh ();
  1765. /* Do the target-specific parts of the initialization. */
  1766. lang_dependent_init_target ();
  1767. if (!flag_wpa)
  1768. {
  1769. /* If dbx symbol table desired, initialize writing it and output the
  1770. predefined types. */
  1771. timevar_push (TV_SYMOUT);
  1772. /* Now we have the correct original filename, we can initialize
  1773. debug output. */
  1774. (*debug_hooks->init) (name);
  1775. timevar_pop (TV_SYMOUT);
  1776. }
  1777. return 1;
  1778. }
  1779. /* Reinitialize everything when target parameters, such as register usage,
  1780. have changed. */
  1781. void
  1782. target_reinit (void)
  1783. {
  1784. struct rtl_data saved_x_rtl;
  1785. rtx *saved_regno_reg_rtx;
  1786. tree saved_optimization_current_node;
  1787. struct target_optabs *saved_this_fn_optabs;
  1788. /* Temporarily switch to the default optimization node, so that
  1789. *this_target_optabs is set to the default, not reflecting
  1790. whatever a previous function used for the optimize
  1791. attribute. */
  1792. saved_optimization_current_node = optimization_current_node;
  1793. saved_this_fn_optabs = this_fn_optabs;
  1794. if (saved_optimization_current_node != optimization_default_node)
  1795. {
  1796. optimization_current_node = optimization_default_node;
  1797. cl_optimization_restore
  1798. (&global_options, &global_options_set,
  1799. TREE_OPTIMIZATION (optimization_default_node));
  1800. }
  1801. this_fn_optabs = this_target_optabs;
  1802. /* Save *crtl and regno_reg_rtx around the reinitialization
  1803. to allow target_reinit being called even after prepare_function_start. */
  1804. saved_regno_reg_rtx = regno_reg_rtx;
  1805. if (saved_regno_reg_rtx)
  1806. {
  1807. saved_x_rtl = *crtl;
  1808. memset (crtl, '\0', sizeof (*crtl));
  1809. regno_reg_rtx = NULL;
  1810. }
  1811. this_target_rtl->target_specific_initialized = false;
  1812. /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
  1813. to initialize reg_raw_mode[]. */
  1814. init_emit_regs ();
  1815. /* This invokes target hooks to set fixed_reg[] etc, which is
  1816. mode-dependent. */
  1817. init_regs ();
  1818. /* Reinitialize lang-dependent parts. */
  1819. lang_dependent_init_target ();
  1820. /* Restore the original optimization node. */
  1821. if (saved_optimization_current_node != optimization_default_node)
  1822. {
  1823. optimization_current_node = saved_optimization_current_node;
  1824. cl_optimization_restore (&global_options, &global_options_set,
  1825. TREE_OPTIMIZATION (optimization_current_node));
  1826. }
  1827. this_fn_optabs = saved_this_fn_optabs;
  1828. /* Restore regno_reg_rtx at the end, as free_after_compilation from
  1829. expand_dummy_function_end clears it. */
  1830. if (saved_regno_reg_rtx)
  1831. {
  1832. *crtl = saved_x_rtl;
  1833. regno_reg_rtx = saved_regno_reg_rtx;
  1834. saved_regno_reg_rtx = NULL;
  1835. }
  1836. }
  1837. void
  1838. dump_memory_report (const char *header)
  1839. {
  1840. /* Print significant header. */
  1841. fputc ('\n', stderr);
  1842. for (unsigned i = 0; i < 80; i++)
  1843. fputc ('#', stderr);
  1844. fprintf (stderr, "\n# %-77s#\n", header);
  1845. for (unsigned i = 0; i < 80; i++)
  1846. fputc ('#', stderr);
  1847. fputs ("\n\n", stderr);
  1848. dump_line_table_statistics ();
  1849. ggc_print_statistics ();
  1850. stringpool_statistics ();
  1851. dump_tree_statistics ();
  1852. dump_gimple_statistics ();
  1853. dump_rtx_statistics ();
  1854. dump_alloc_pool_statistics ();
  1855. dump_bitmap_statistics ();
  1856. dump_hash_table_loc_statistics ();
  1857. dump_vec_loc_statistics ();
  1858. dump_ggc_loc_statistics ();
  1859. dump_alias_stats (stderr);
  1860. dump_pta_stats (stderr);
  1861. }
  1862. /* Clean up: close opened files, etc. */
  1863. static void
  1864. finalize (bool no_backend)
  1865. {
  1866. /* Close the dump files. */
  1867. if (flag_gen_aux_info)
  1868. {
  1869. fclose (aux_info_file);
  1870. aux_info_file = NULL;
  1871. if (seen_error ())
  1872. unlink (aux_info_file_name);
  1873. }
  1874. /* Close non-debugging input and output files. Take special care to note
  1875. whether fclose returns an error, since the pages might still be on the
  1876. buffer chain while the file is open. */
  1877. if (asm_out_file)
  1878. {
  1879. if (ferror (asm_out_file) != 0)
  1880. fatal_error (input_location, "error writing to %s: %m", asm_file_name);
  1881. if (fclose (asm_out_file) != 0)
  1882. fatal_error (input_location, "error closing %s: %m", asm_file_name);
  1883. asm_out_file = NULL;
  1884. }
  1885. if (stack_usage_file)
  1886. {
  1887. fclose (stack_usage_file);
  1888. stack_usage_file = NULL;
  1889. }
  1890. if (callgraph_info_file)
  1891. {
  1892. fputs ("}\n", callgraph_info_file);
  1893. fclose (callgraph_info_file);
  1894. callgraph_info_file = NULL;
  1895. BITMAP_FREE (callgraph_info_external_printed);
  1896. bitmap_obstack_release (NULL);
  1897. /*
  1898. * added
  1899. */
  1900. {
  1901. int i = 0;
  1902. int len = 0;
  1903. int status = 0;
  1904. int sfgmaxx = 0;
  1905. int sfgmaxy = 0;
  1906. int nmin = 0;
  1907. int nmax = 0;
  1908. int nxpos = 0;
  1909. int nypos = 0;
  1910. int nxsize = 0;
  1911. int nysize = 0;
  1912. char *ntext = NULL;
  1913. int ef = 0;
  1914. int et = 0;
  1915. int eftype = 0;
  1916. int ettype = 0;
  1917. int efposx = 0;
  1918. int etposx = 0;
  1919. int efposy = 0;
  1920. int etposy = 0;
  1921. int svgxoff = 0;
  1922. int svgyoff = 0;
  1923. splay_tree_node spn = (splay_tree_node)0;
  1924. splay_tree_key spnkey = (splay_tree_key)0;
  1925. splay_tree_value spnvalue = (splay_tree_value)0;
  1926. struct svg_callgraph_edge *callgraph_info_sce = (struct svg_callgraph_edge *)0;
  1927. if (svg_callgraph_info_file) {
  1928. if (svg_callgraph_tree_nodes_count) {
  1929. /* init to start */
  1930. status = sfg_init();
  1931. if (status < 0) { /* error */
  1932. }
  1933. spn = splay_tree_min (svg_callgraph_tree_nodes);
  1934. while (spn)
  1935. {
  1936. spnkey = spn->key;
  1937. spnvalue = spn->value;
  1938. len = (int) strlen ((char *) spnvalue);
  1939. status = sfg_addnode((int)spnkey, (len*9), 15);
  1940. spn = splay_tree_successor (svg_callgraph_tree_nodes, (splay_tree_key)spnkey);
  1941. }
  1942. if (svg_callgraph_tree_edges_count) {
  1943. for (i = 0 ; i < (svg_callgraph_tree_edges_count + 1) ; i++)
  1944. {
  1945. spn = splay_tree_lookup (svg_callgraph_tree_edges, (splay_tree_key) i);
  1946. if (spn) {
  1947. callgraph_info_sce = (struct svg_callgraph_edge *) spn->value;
  1948. status = sfg_addedge((int)spn->key, /* from */ callgraph_info_sce->fn, /* to */ callgraph_info_sce->tn, 0, 0);
  1949. }
  1950. }
  1951. }
  1952. /* set min (x,y) spacing of nodes */
  1953. status = sfg_xspacing(5);
  1954. if (status < 0) { /* error */
  1955. }
  1956. status = sfg_yspacing(15);
  1957. if (status < 0) { /* error */
  1958. }
  1959. /* run layout */
  1960. status = sfg_layout();
  1961. if (status < 0) { /* error */
  1962. }
  1963. /* head of svg */
  1964. sfgmaxx = sfg_maxx();
  1965. if (sfgmaxx < 5) {
  1966. sfgmaxx = 5;
  1967. }
  1968. sfgmaxy = sfg_maxy();
  1969. if (sfgmaxy < 5) {
  1970. sfgmaxy = 5;
  1971. }
  1972. svgxoff = 25;
  1973. svgyoff = 25;
  1974. sfgmaxx += (2 * svgxoff);
  1975. sfgmaxy += (2 * svgyoff);
  1976. fprintf(svg_callgraph_info_file, "<svg width=\"%d\" height=\"%d\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\">\n", sfgmaxx + 1, sfgmaxy + 5);
  1977. fprintf(svg_callgraph_info_file, "%s\n", " <g>");
  1978. fprintf(svg_callgraph_info_file, "%s\n", " <title>callgraph-info</title>");
  1979. fprintf(svg_callgraph_info_file, "%s\n", " <style>");
  1980. fprintf(svg_callgraph_info_file, "%s\n", " .small { font: italic 15px sans-serif; }");
  1981. fprintf(svg_callgraph_info_file, "%s\n", " </style>");
  1982. nmin = sfg_nodemin ();
  1983. nmax = sfg_nodemax ();
  1984. if (nmin > 0 && nmax > 0) { }
  1985. if (svg_callgraph_tree_nodes_count) {
  1986. /* draw edges */
  1987. if (svg_callgraph_tree_edges_count) {
  1988. for (i = 1 ; i < (svg_callgraph_tree_edges_count + 1) ; i++)
  1989. {
  1990. spn = splay_tree_lookup (svg_callgraph_tree_edges, (splay_tree_key) i);
  1991. if (spn) {
  1992. callgraph_info_sce = (struct svg_callgraph_edge *) spn->value;
  1993. ef = callgraph_info_sce->fn;
  1994. et = callgraph_info_sce->tn;
  1995. eftype = sfg_nodetype (ef);
  1996. ettype = sfg_nodetype (et);
  1997. if(eftype > 0 && ettype > 0) {
  1998. efposx = sfg_nodexpos (ef);
  1999. efposy = sfg_nodeypos (ef);
  2000. etposx = sfg_nodexpos (et);
  2001. etposy = sfg_nodeypos (et);
  2002. if (eftype == 1) {
  2003. efposx += (sfg_nodexsize (ef) / 2);
  2004. efposy += (sfg_nodeysize (ef) / 2);
  2005. }
  2006. if (ettype == 1) {
  2007. etposx += (sfg_nodexsize (et) / 2);
  2008. etposy += (sfg_nodeysize (et) / 2);
  2009. }
  2010. fprintf(svg_callgraph_info_file, " <line id=\"edge_%d\" y2=\"%d\" x2=\"%d\" y1=\"%d\" x1=\"%d\" stroke-linecap=\"null\" stroke-linejoin=\"null\" stroke-dasharray=\"null\" stroke-width=\"2\" stroke=\"#000000\" fill=\"none\"/>\n", i, etposy+svgyoff, etposx+svgxoff, efposy+svgyoff, efposx+svgxoff);
  2011. }
  2012. }
  2013. }
  2014. }
  2015. /* draw nodes */
  2016. i = 0;
  2017. spn = splay_tree_min (svg_callgraph_tree_nodes);
  2018. while (spn)
  2019. {
  2020. i++;
  2021. spnkey = spn->key;
  2022. spnvalue = spn->value;
  2023. nxpos = sfg_nodexpos ((int)spnkey);
  2024. nypos = sfg_nodeypos ((int)spnkey);
  2025. nxsize = sfg_nodexsize ((int)spnkey);
  2026. nysize = sfg_nodeysize ((int)spnkey);
  2027. fprintf(svg_callgraph_info_file, " <rect id=\"node_%d\" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" stroke-linecap=\"null\" stroke-linejoin=\"null\" stroke-dasharray=\"null\" stroke=\"#000000\" fill=\"#7fff00\"/>\n", i, nxpos+svgxoff, nypos+svgyoff, nxsize, nysize);
  2028. ntext = (char *) spn->value;
  2029. if (strlen (ntext) > 0) {
  2030. /* todo unesc special chars but can that happen with this data? */
  2031. fprintf(svg_callgraph_info_file, " <text x=\"%d\" y=\"%d\" class=\"small\">%s</text>\n", nxpos+1+svgxoff, nypos+nysize+svgyoff-1, ntext);
  2032. }
  2033. spn = splay_tree_successor (svg_callgraph_tree_nodes, (splay_tree_key)spnkey);
  2034. }
  2035. }
  2036. /* tail of svg */
  2037. fprintf(svg_callgraph_info_file, "%s\n", " </g>");
  2038. fprintf(svg_callgraph_info_file, "%s\n", "</svg>");
  2039. }
  2040. }
  2041. if (gv_callgraph_info_file) {
  2042. fprintf (gv_callgraph_info_file, "/* callgraph generated by GNU GCC Compiler -fcallgraph-info option version\n");
  2043. print_version (gv_callgraph_info_file, " *", true);
  2044. fprintf (gv_callgraph_info_file, "*/\n");
  2045. fprintf (gv_callgraph_info_file, "digraph \"option-fcallgraph-info\" {\n");
  2046. if (svg_callgraph_tree_nodes_count) {
  2047. i = 0;
  2048. spn = splay_tree_min (svg_callgraph_tree_nodes);
  2049. while (spn)
  2050. {
  2051. i++;
  2052. spnkey = spn->key;
  2053. spnvalue = spn->value;
  2054. fprintf (gv_callgraph_info_file, " \"%d\" [label=\"%s\"]; /* node %d */\n", (int)spnkey, (char *)spnvalue, i);
  2055. spn = splay_tree_successor (svg_callgraph_tree_nodes, (splay_tree_key)spnkey);
  2056. }
  2057. }
  2058. if (svg_callgraph_tree_edges_count) {
  2059. for (i = 0 ; i < (svg_callgraph_tree_edges_count + 1) ; i++)
  2060. {
  2061. spn = splay_tree_lookup (svg_callgraph_tree_edges, (splay_tree_key) i);
  2062. if (spn) {
  2063. callgraph_info_sce = (struct svg_callgraph_edge *) spn->value;
  2064. fprintf (gv_callgraph_info_file, " \"%d\" -> \"%d\"; /* edge %d */\n", callgraph_info_sce->fn, callgraph_info_sce->tn, i);
  2065. }
  2066. }
  2067. }
  2068. fprintf (gv_callgraph_info_file, "}\n");
  2069. }
  2070. if (gv_callgraph_info_file) {
  2071. fclose (gv_callgraph_info_file);
  2072. gv_callgraph_info_file = NULL;
  2073. }
  2074. if (svg_callgraph_info_file) {
  2075. fclose (svg_callgraph_info_file);
  2076. svg_callgraph_info_file = NULL;
  2077. }
  2078. if (svg_callgraph_tree_nodes) {
  2079. splay_tree_delete (svg_callgraph_tree_nodes);
  2080. svg_callgraph_tree_nodes = NULL;
  2081. svg_callgraph_tree_nodes_count = 0;
  2082. }
  2083. if (svg_callgraph_tree_edges) {
  2084. splay_tree_delete (svg_callgraph_tree_edges);
  2085. svg_callgraph_tree_edges = NULL;
  2086. svg_callgraph_tree_edges_count = 0;
  2087. }
  2088. /* ready with layouter */
  2089. status = sfg_deinit ();
  2090. if (status) { }
  2091. }
  2092. /*
  2093. * end added
  2094. */
  2095. }
  2096. if (seen_error ())
  2097. coverage_remove_note_file ();
  2098. if (!no_backend)
  2099. {
  2100. statistics_fini ();
  2101. debuginfo_fini ();
  2102. g->get_passes ()->finish_optimization_passes ();
  2103. lra_finish_once ();
  2104. }
  2105. if (mem_report)
  2106. dump_memory_report ("Final");
  2107. if (profile_report)
  2108. dump_profile_report ();
  2109. if (flag_dbg_cnt_list)
  2110. dbg_cnt_list_all_counters ();
  2111. /* Language-specific end of compilation actions. */
  2112. lang_hooks.finish ();
  2113. }
  2114. static bool
  2115. standard_type_bitsize (int bitsize)
  2116. {
  2117. /* As a special exception, we always want __int128 enabled if possible. */
  2118. if (bitsize == 128)
  2119. return false;
  2120. if (bitsize == CHAR_TYPE_SIZE
  2121. || bitsize == SHORT_TYPE_SIZE
  2122. || bitsize == INT_TYPE_SIZE
  2123. || bitsize == LONG_TYPE_SIZE
  2124. || bitsize == LONG_LONG_TYPE_SIZE)
  2125. return true;
  2126. return false;
  2127. }
  2128. /* Initialize the compiler, and compile the input file. */
  2129. static void
  2130. do_compile ()
  2131. {
  2132. process_options ();
  2133. /* Don't do any more if an error has already occurred. */
  2134. if (!seen_error ())
  2135. {
  2136. int i;
  2137. timevar_start (TV_PHASE_SETUP);
  2138. if (flag_save_optimization_record)
  2139. {
  2140. dump_context::get ().set_json_writer (new optrecord_json_writer ());
  2141. }
  2142. /* This must be run always, because it is needed to compute the FP
  2143. predefined macros, such as __LDBL_MAX__, for targets using non
  2144. default FP formats. */
  2145. init_adjust_machine_modes ();
  2146. init_derived_machine_modes ();
  2147. /* This must happen after the backend has a chance to process
  2148. command line options, but before the parsers are
  2149. initialized. */
  2150. for (i = 0; i < NUM_INT_N_ENTS; i ++)
  2151. if (targetm.scalar_mode_supported_p (int_n_data[i].m)
  2152. && ! standard_type_bitsize (int_n_data[i].bitsize))
  2153. int_n_enabled_p[i] = true;
  2154. else
  2155. int_n_enabled_p[i] = false;
  2156. /* Initialize mpfrs exponent range. This is important to get
  2157. underflow/overflow in a reasonable timeframe. */
  2158. machine_mode mode;
  2159. int min_exp = -1;
  2160. int max_exp = 1;
  2161. FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT)
  2162. if (SCALAR_FLOAT_MODE_P (mode))
  2163. {
  2164. const real_format *fmt = REAL_MODE_FORMAT (mode);
  2165. if (fmt)
  2166. {
  2167. /* fmt->emin - fmt->p + 1 should be enough but the
  2168. back-and-forth dance in real_to_decimal_for_mode we
  2169. do for checking fails due to rounding effects then. */
  2170. if ((fmt->emin - fmt->p) < min_exp)
  2171. min_exp = fmt->emin - fmt->p;
  2172. if (fmt->emax > max_exp)
  2173. max_exp = fmt->emax;
  2174. }
  2175. }
  2176. /* E.g. mpc_norm assumes it can square a number without bothering with
  2177. with range scaling, so until that is fixed, double the minimum
  2178. and maximum exponents, plus add some buffer for arithmetics
  2179. on the squared numbers. */
  2180. if (mpfr_set_emin (2 * (min_exp - 1))
  2181. || mpfr_set_emax (2 * (max_exp + 1)))
  2182. sorry ("mpfr not configured to handle all floating modes");
  2183. /* Set up the back-end if requested. */
  2184. if (!no_backend)
  2185. backend_init ();
  2186. /* Language-dependent initialization. Returns true on success. */
  2187. if (lang_dependent_init (main_input_filename))
  2188. {
  2189. /* Initialize yet another pass. */
  2190. ggc_protect_identifiers = true;
  2191. symtab->initialize ();
  2192. init_final (main_input_filename);
  2193. coverage_init (aux_base_name);
  2194. statistics_init ();
  2195. debuginfo_init ();
  2196. invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
  2197. timevar_stop (TV_PHASE_SETUP);
  2198. compile_file ();
  2199. }
  2200. else
  2201. {
  2202. timevar_stop (TV_PHASE_SETUP);
  2203. }
  2204. timevar_start (TV_PHASE_FINALIZE);
  2205. finalize (no_backend);
  2206. timevar_stop (TV_PHASE_FINALIZE);
  2207. }
  2208. }
  2209. toplev::toplev (timer *external_timer,
  2210. bool init_signals)
  2211. : m_use_TV_TOTAL (external_timer == NULL),
  2212. m_init_signals (init_signals)
  2213. {
  2214. if (external_timer)
  2215. g_timer = external_timer;
  2216. }
  2217. toplev::~toplev ()
  2218. {
  2219. if (g_timer && m_use_TV_TOTAL)
  2220. {
  2221. g_timer->stop (TV_TOTAL);
  2222. g_timer->print (stderr);
  2223. delete g_timer;
  2224. g_timer = NULL;
  2225. }
  2226. }
  2227. /* Potentially call timevar_init (which will create g_timevars if it
  2228. doesn't already exist). */
  2229. void
  2230. toplev::start_timevars ()
  2231. {
  2232. if (time_report || !quiet_flag || flag_detailed_statistics)
  2233. timevar_init ();
  2234. timevar_start (TV_TOTAL);
  2235. }
  2236. /* Handle -fself-test. */
  2237. void
  2238. toplev::run_self_tests ()
  2239. {
  2240. if (no_backend)
  2241. {
  2242. error_at (UNKNOWN_LOCATION, "self-tests incompatible with %<-E%>");
  2243. return;
  2244. }
  2245. #if CHECKING_P
  2246. /* Reset some state. */
  2247. input_location = UNKNOWN_LOCATION;
  2248. bitmap_obstack_initialize (NULL);
  2249. /* Run the tests; any failures will lead to an abort of the process.
  2250. Use "make selftests-gdb" to run under the debugger. */
  2251. ::selftest::run_tests ();
  2252. /* Cleanup. */
  2253. bitmap_obstack_release (NULL);
  2254. #else
  2255. inform (UNKNOWN_LOCATION, "self-tests are not enabled in this build");
  2256. #endif /* #if CHECKING_P */
  2257. }
  2258. /* Entry point of cc1, cc1plus, jc1, f771, etc.
  2259. Exit code is FATAL_EXIT_CODE if can't open files or if there were
  2260. any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
  2261. It is not safe to call this function more than once. */
  2262. int
  2263. toplev::main (int argc, char **argv)
  2264. {
  2265. /* Parsing and gimplification sometimes need quite large stack.
  2266. Increase stack size limits if possible. */
  2267. stack_limit_increase (64 * 1024 * 1024);
  2268. expandargv (&argc, &argv);
  2269. /* Initialization of GCC's environment, and diagnostics. */
  2270. general_init (argv[0], m_init_signals);
  2271. /* One-off initialization of options that does not need to be
  2272. repeated when options are added for particular functions. */
  2273. init_options_once ();
  2274. init_opts_obstack ();
  2275. /* Initialize global options structures; this must be repeated for
  2276. each structure used for parsing options. */
  2277. init_options_struct (&global_options, &global_options_set);
  2278. lang_hooks.init_options_struct (&global_options);
  2279. /* Init GGC heuristics must be caller after we initialize
  2280. options. */
  2281. init_ggc_heuristics ();
  2282. /* Convert the options to an array. */
  2283. decode_cmdline_options_to_array_default_mask (argc,
  2284. CONST_CAST2 (const char **,
  2285. char **, argv),
  2286. &save_decoded_options,
  2287. &save_decoded_options_count);
  2288. /* Perform language-specific options initialization. */
  2289. lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
  2290. /* Parse the options and do minimal processing; basically just
  2291. enough to default flags appropriately. */
  2292. decode_options (&global_options, &global_options_set,
  2293. save_decoded_options, save_decoded_options_count,
  2294. UNKNOWN_LOCATION, global_dc,
  2295. targetm.target_option.override);
  2296. handle_common_deferred_options ();
  2297. init_local_tick ();
  2298. initialize_plugins ();
  2299. if (version_flag)
  2300. print_version (stderr, "", true);
  2301. if (help_flag)
  2302. print_plugins_help (stderr, "");
  2303. /* Exit early if we can (e.g. -help). */
  2304. if (!exit_after_options)
  2305. {
  2306. if (m_use_TV_TOTAL)
  2307. start_timevars ();
  2308. do_compile ();
  2309. }
  2310. if (warningcount || errorcount || werrorcount)
  2311. print_ignored_options ();
  2312. if (flag_self_test)
  2313. run_self_tests ();
  2314. /* Invoke registered plugin callbacks if any. Some plugins could
  2315. emit some diagnostics here. */
  2316. invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
  2317. if (flag_diagnostics_generate_patch)
  2318. {
  2319. gcc_assert (global_dc->edit_context_ptr);
  2320. pretty_printer pp;
  2321. pp_show_color (&pp) = pp_show_color (global_dc->printer);
  2322. global_dc->edit_context_ptr->print_diff (&pp, true);
  2323. pp_flush (&pp);
  2324. }
  2325. diagnostic_finish (global_dc);
  2326. finalize_plugins ();
  2327. after_memory_report = true;
  2328. if (seen_error () || werrorcount)
  2329. return (FATAL_EXIT_CODE);
  2330. return (SUCCESS_EXIT_CODE);
  2331. }
  2332. /* For those that want to, this function aims to clean up enough state that
  2333. you can call toplev::main again. */
  2334. void
  2335. toplev::finalize (void)
  2336. {
  2337. rtl_initialized = false;
  2338. this_target_rtl->target_specific_initialized = false;
  2339. /* Needs to be called before cgraph_c_finalize since it uses symtab. */
  2340. ipa_reference_c_finalize ();
  2341. ipa_fnsummary_c_finalize ();
  2342. ipa_modref_c_finalize ();
  2343. cgraph_c_finalize ();
  2344. cgraphunit_c_finalize ();
  2345. symtab_thunks_cc_finalize ();
  2346. dwarf2out_c_finalize ();
  2347. gcse_c_finalize ();
  2348. ipa_cp_c_finalize ();
  2349. ira_costs_c_finalize ();
  2350. /* save_decoded_options uses opts_obstack, so these must
  2351. be cleaned up together. */
  2352. obstack_free (&opts_obstack, NULL);
  2353. XDELETEVEC (save_decoded_options);
  2354. save_decoded_options = NULL;
  2355. save_decoded_options_count = 0;
  2356. /* Clean up the context (and pass_manager etc). */
  2357. delete g;
  2358. g = NULL;
  2359. }