toplev.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. /* Top level of GCC compilers (cc1, cc1plus, etc.)
  2. Copyright (C) 1987-2015 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 "tm.h"
  23. #include "line-map.h"
  24. #include "input.h"
  25. #include "hash-set.h"
  26. #include "machmode.h"
  27. #include "vec.h"
  28. #include "double-int.h"
  29. #include "alias.h"
  30. #include "symtab.h"
  31. #include "wide-int.h"
  32. #include "inchash.h"
  33. #include "tree.h"
  34. #include "fold-const.h"
  35. #include "varasm.h"
  36. #include "tree-inline.h"
  37. #include "realmpfr.h" /* For GMP/MPFR/MPC versions, in print_version. */
  38. #include "version.h"
  39. #include "rtl.h"
  40. #include "tm_p.h"
  41. #include "flags.h"
  42. #include "insn-attr.h"
  43. #include "insn-config.h"
  44. #include "insn-flags.h"
  45. #include "hard-reg-set.h"
  46. #include "recog.h"
  47. #include "output.h"
  48. #include "except.h"
  49. #include "function.h"
  50. #include "toplev.h"
  51. #include "hashtab.h"
  52. #include "statistics.h"
  53. #include "real.h"
  54. #include "fixed-value.h"
  55. #include "expmed.h"
  56. #include "dojump.h"
  57. #include "explow.h"
  58. #include "calls.h"
  59. #include "emit-rtl.h"
  60. #include "stmt.h"
  61. #include "expr.h"
  62. #include "intl.h"
  63. #include "regs.h"
  64. #include "timevar.h"
  65. #include "diagnostic.h"
  66. #include "tree-diagnostic.h"
  67. #include "tree-pretty-print.h"
  68. #include "params.h"
  69. #include "reload.h"
  70. #include "ira.h"
  71. #include "lra.h"
  72. #include "dwarf2asm.h"
  73. #include "debug.h"
  74. #include "target.h"
  75. #include "common/common-target.h"
  76. #include "langhooks.h"
  77. #include "cfgloop.h" /* for init_set_costs */
  78. #include "hosthooks.h"
  79. #include "predict.h"
  80. #include "basic-block.h"
  81. #include "hash-map.h"
  82. #include "is-a.h"
  83. #include "plugin-api.h"
  84. #include "ipa-ref.h"
  85. #include "cgraph.h"
  86. #include "opts.h"
  87. #include "opts-diagnostic.h"
  88. #include "coverage.h"
  89. #include "value-prof.h"
  90. #include "alloc-pool.h"
  91. #include "asan.h"
  92. #include "tsan.h"
  93. #include "tree-ssa-alias.h"
  94. #include "internal-fn.h"
  95. #include "gimple-expr.h"
  96. #include "gimple.h"
  97. #include "plugin.h"
  98. #include "context.h"
  99. #include "pass_manager.h"
  100. #include "auto-profile.h"
  101. #include "dwarf2out.h"
  102. #include "bitmap.h"
  103. #include "ipa-reference.h"
  104. #include "symbol-summary.h"
  105. #include "ipa-prop.h"
  106. #include "gcse.h"
  107. #include "insn-codes.h"
  108. #include "optabs.h"
  109. #include "tree-chkp.h"
  110. #include "omp-low.h"
  111. #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
  112. #include "dbxout.h"
  113. #endif
  114. #ifdef SDB_DEBUGGING_INFO
  115. #include "sdbout.h"
  116. #endif
  117. #ifdef XCOFF_DEBUGGING_INFO
  118. #include "xcoffout.h" /* Needed for external data
  119. declarations for e.g. AIX 4.x. */
  120. #endif
  121. #ifndef HAVE_epilogue
  122. #define HAVE_epilogue 0
  123. #endif
  124. #ifndef HAVE_prologue
  125. #define HAVE_prologue 0
  126. #endif
  127. #include <new>
  128. static void general_init (const char *, bool);
  129. static void do_compile ();
  130. static void process_options (void);
  131. static void backend_init (void);
  132. static int lang_dependent_init (const char *);
  133. static void init_asm_output (const char *);
  134. static void finalize (bool);
  135. static void crash_signal (int) ATTRIBUTE_NORETURN;
  136. static void compile_file (void);
  137. /* True if we don't need a backend (e.g. preprocessing only). */
  138. static bool no_backend;
  139. /* Length of line when printing switch values. */
  140. #define MAX_LINE 75
  141. /* Decoded options, and number of such options. */
  142. struct cl_decoded_option *save_decoded_options;
  143. unsigned int save_decoded_options_count;
  144. /* Used to enable -fvar-tracking, -fweb and -frename-registers according
  145. to optimize in process_options (). */
  146. #define AUTODETECT_VALUE 2
  147. /* Debug hooks - dependent upon command line options. */
  148. const struct gcc_debug_hooks *debug_hooks;
  149. /* The FUNCTION_DECL for the function currently being compiled,
  150. or 0 if between functions. */
  151. tree current_function_decl;
  152. /* Set to the FUNC_BEGIN label of the current function, or NULL
  153. if none. */
  154. const char * current_function_func_begin_label;
  155. /* A random sequence of characters, unless overridden by user. */
  156. static const char *flag_random_seed;
  157. /* A local time stamp derived from the time of compilation. It will be
  158. zero if the system cannot provide a time. It will be -1u, if the
  159. user has specified a particular random seed. */
  160. unsigned local_tick;
  161. /* Random number for this compilation */
  162. HOST_WIDE_INT random_seed;
  163. /* -f flags. */
  164. /* When non-NULL, indicates that whenever space is allocated on the
  165. stack, the resulting stack pointer must not pass this
  166. address---that is, for stacks that grow downward, the stack pointer
  167. must always be greater than or equal to this address; for stacks
  168. that grow upward, the stack pointer must be less than this address.
  169. At present, the rtx may be either a REG or a SYMBOL_REF, although
  170. the support provided depends on the backend. */
  171. rtx stack_limit_rtx;
  172. /* True if the user has tagged the function with the 'section'
  173. attribute. */
  174. bool user_defined_section_attribute = false;
  175. struct target_flag_state default_target_flag_state;
  176. #if SWITCHABLE_TARGET
  177. struct target_flag_state *this_target_flag_state = &default_target_flag_state;
  178. #else
  179. #define this_target_flag_state (&default_target_flag_state)
  180. #endif
  181. /* The user symbol prefix after having resolved same. */
  182. const char *user_label_prefix;
  183. /* Output files for assembler code (real compiler output)
  184. and debugging dumps. */
  185. FILE *asm_out_file;
  186. FILE *aux_info_file;
  187. FILE *stack_usage_file = NULL;
  188. /* The current working directory of a translation. It's generally the
  189. directory from which compilation was initiated, but a preprocessed
  190. file may specify the original directory in which it was
  191. created. */
  192. static const char *src_pwd;
  193. /* Initialize src_pwd with the given string, and return true. If it
  194. was already initialized, return false. As a special case, it may
  195. be called with a NULL argument to test whether src_pwd has NOT been
  196. initialized yet. */
  197. bool
  198. set_src_pwd (const char *pwd)
  199. {
  200. if (src_pwd)
  201. {
  202. if (strcmp (src_pwd, pwd) == 0)
  203. return true;
  204. else
  205. return false;
  206. }
  207. src_pwd = xstrdup (pwd);
  208. return true;
  209. }
  210. /* Return the directory from which the translation unit was initiated,
  211. in case set_src_pwd() was not called before to assign it a
  212. different value. */
  213. const char *
  214. get_src_pwd (void)
  215. {
  216. if (! src_pwd)
  217. {
  218. src_pwd = getpwd ();
  219. if (!src_pwd)
  220. src_pwd = ".";
  221. }
  222. return src_pwd;
  223. }
  224. /* Called when the start of a function definition is parsed,
  225. this function prints on stderr the name of the function. */
  226. void
  227. announce_function (tree decl)
  228. {
  229. if (!quiet_flag)
  230. {
  231. if (rtl_dump_and_exit)
  232. fprintf (stderr, "%s ",
  233. identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
  234. else
  235. fprintf (stderr, " %s",
  236. identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
  237. fflush (stderr);
  238. pp_needs_newline (global_dc->printer) = true;
  239. diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
  240. }
  241. }
  242. /* Initialize local_tick with a random number or -1 if
  243. flag_random_seed is set. */
  244. static void
  245. init_local_tick (void)
  246. {
  247. if (!flag_random_seed)
  248. {
  249. /* Try urandom first. Time of day is too likely to collide.
  250. In case of any error we just use the local tick. */
  251. int fd = open ("/dev/urandom", O_RDONLY);
  252. if (fd >= 0)
  253. {
  254. if (read (fd, &random_seed, sizeof (random_seed))
  255. != sizeof (random_seed))
  256. random_seed = 0;
  257. close (fd);
  258. }
  259. /* Now get the tick anyways */
  260. #ifdef HAVE_GETTIMEOFDAY
  261. {
  262. struct timeval tv;
  263. gettimeofday (&tv, NULL);
  264. local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;
  265. }
  266. #else
  267. {
  268. time_t now = time (NULL);
  269. if (now != (time_t)-1)
  270. local_tick = (unsigned) now;
  271. }
  272. #endif
  273. }
  274. else
  275. local_tick = -1;
  276. }
  277. /* Set up a default flag_random_seed and local_tick, unless the user
  278. already specified one. Must be called after init_local_tick. */
  279. static void
  280. init_random_seed (void)
  281. {
  282. if (!random_seed)
  283. random_seed = local_tick ^ getpid (); /* Old racey fallback method */
  284. }
  285. /* Obtain the random_seed. Unless NOINIT, initialize it if
  286. it's not provided in the command line. */
  287. HOST_WIDE_INT
  288. get_random_seed (bool noinit)
  289. {
  290. if (!flag_random_seed && !noinit)
  291. init_random_seed ();
  292. return random_seed;
  293. }
  294. /* Modify the random_seed string to VAL. Return its previous
  295. value. */
  296. const char *
  297. set_random_seed (const char *val)
  298. {
  299. const char *old = flag_random_seed;
  300. flag_random_seed = val;
  301. if (flag_random_seed)
  302. {
  303. char *endp;
  304. /* When the driver passed in a hex number don't crc it again */
  305. random_seed = strtoul (flag_random_seed, &endp, 0);
  306. if (!(endp > flag_random_seed && *endp == 0))
  307. random_seed = crc32_string (0, flag_random_seed);
  308. }
  309. return old;
  310. }
  311. /* Handler for fatal signals, such as SIGSEGV. These are transformed
  312. into ICE messages, which is much more user friendly. In case the
  313. error printer crashes, reset the signal to prevent infinite recursion. */
  314. static void
  315. crash_signal (int signo)
  316. {
  317. signal (signo, SIG_DFL);
  318. /* If we crashed while processing an ASM statement, then be a little more
  319. graceful. It's most likely the user's fault. */
  320. if (this_is_asm_operands)
  321. {
  322. output_operand_lossage ("unrecoverable error");
  323. exit (FATAL_EXIT_CODE);
  324. }
  325. internal_error ("%s", strsignal (signo));
  326. }
  327. /* A subroutine of wrapup_global_declarations. We've come to the end of
  328. the compilation unit. All deferred variables should be undeferred,
  329. and all incomplete decls should be finalized. */
  330. void
  331. wrapup_global_declaration_1 (tree decl)
  332. {
  333. /* We're not deferring this any longer. Assignment is conditional to
  334. avoid needlessly dirtying PCH pages. */
  335. if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
  336. && DECL_DEFER_OUTPUT (decl) != 0)
  337. DECL_DEFER_OUTPUT (decl) = 0;
  338. if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
  339. lang_hooks.finish_incomplete_decl (decl);
  340. }
  341. /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
  342. needs to be output. Return true if it is output. */
  343. bool
  344. wrapup_global_declaration_2 (tree decl)
  345. {
  346. if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)
  347. || (TREE_CODE (decl) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (decl)))
  348. return false;
  349. /* Don't write out static consts, unless we still need them.
  350. We also keep static consts if not optimizing (for debugging),
  351. unless the user specified -fno-keep-static-consts.
  352. ??? They might be better written into the debug information.
  353. This is possible when using DWARF.
  354. A language processor that wants static constants to be always
  355. written out (even if it is not used) is responsible for
  356. calling rest_of_decl_compilation itself. E.g. the C front-end
  357. calls rest_of_decl_compilation from finish_decl.
  358. One motivation for this is that is conventional in some
  359. environments to write things like:
  360. static const char rcsid[] = "... version string ...";
  361. intending to force the string to be in the executable.
  362. A language processor that would prefer to have unneeded
  363. static constants "optimized away" would just defer writing
  364. them out until here. E.g. C++ does this, because static
  365. constants are often defined in header files.
  366. ??? A tempting alternative (for both C and C++) would be
  367. to force a constant to be written if and only if it is
  368. defined in a main file, as opposed to an include file. */
  369. if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
  370. {
  371. varpool_node *node;
  372. bool needed = true;
  373. node = varpool_node::get (decl);
  374. if (!node && flag_ltrans)
  375. needed = false;
  376. else if (node && node->definition)
  377. needed = false;
  378. else if (node && node->alias)
  379. needed = false;
  380. else if (!symtab->global_info_ready
  381. && (TREE_USED (decl)
  382. || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
  383. /* needed */;
  384. else if (node && node->analyzed)
  385. /* needed */;
  386. else if (DECL_COMDAT (decl))
  387. needed = false;
  388. else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
  389. && (optimize || !flag_keep_static_consts
  390. || DECL_ARTIFICIAL (decl)))
  391. needed = false;
  392. if (needed)
  393. {
  394. rest_of_decl_compilation (decl, 1, 1);
  395. return true;
  396. }
  397. }
  398. return false;
  399. }
  400. /* Do any final processing required for the declarations in VEC, of
  401. which there are LEN. We write out inline functions and variables
  402. that have been deferred until this point, but which are required.
  403. Returns nonzero if anything was put out. */
  404. bool
  405. wrapup_global_declarations (tree *vec, int len)
  406. {
  407. bool reconsider, output_something = false;
  408. int i;
  409. for (i = 0; i < len; i++)
  410. wrapup_global_declaration_1 (vec[i]);
  411. /* Now emit any global variables or functions that we have been
  412. putting off. We need to loop in case one of the things emitted
  413. here references another one which comes earlier in the list. */
  414. do
  415. {
  416. reconsider = false;
  417. for (i = 0; i < len; i++)
  418. reconsider |= wrapup_global_declaration_2 (vec[i]);
  419. if (reconsider)
  420. output_something = true;
  421. }
  422. while (reconsider);
  423. return output_something;
  424. }
  425. /* A subroutine of check_global_declarations. Issue appropriate warnings
  426. for the global declaration DECL. */
  427. void
  428. check_global_declaration_1 (tree decl)
  429. {
  430. /* Warn about any function declared static but not defined. We don't
  431. warn about variables, because many programs have static variables
  432. that exist only to get some text into the object file. */
  433. if (TREE_CODE (decl) == FUNCTION_DECL
  434. && DECL_INITIAL (decl) == 0
  435. && DECL_EXTERNAL (decl)
  436. && ! DECL_ARTIFICIAL (decl)
  437. && ! TREE_NO_WARNING (decl)
  438. && ! TREE_PUBLIC (decl)
  439. && (warn_unused_function
  440. || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
  441. {
  442. if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
  443. pedwarn (input_location, 0, "%q+F used but never defined", decl);
  444. else
  445. warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
  446. /* This symbol is effectively an "extern" declaration now. */
  447. TREE_PUBLIC (decl) = 1;
  448. }
  449. /* Warn about static fns or vars defined but not used. */
  450. if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
  451. /* We don't warn about "static const" variables because the
  452. "rcs_id" idiom uses that construction. */
  453. || (warn_unused_variable
  454. && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
  455. && ! DECL_IN_SYSTEM_HEADER (decl)
  456. && ! TREE_USED (decl)
  457. /* The TREE_USED bit for file-scope decls is kept in the identifier,
  458. to handle multiple external decls in different scopes. */
  459. && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
  460. && ! DECL_EXTERNAL (decl)
  461. && ! TREE_PUBLIC (decl)
  462. /* A volatile variable might be used in some non-obvious way. */
  463. && ! TREE_THIS_VOLATILE (decl)
  464. /* Global register variables must be declared to reserve them. */
  465. && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
  466. /* Otherwise, ask the language. */
  467. && lang_hooks.decls.warn_unused_global (decl))
  468. warning ((TREE_CODE (decl) == FUNCTION_DECL)
  469. ? OPT_Wunused_function
  470. : OPT_Wunused_variable,
  471. "%q+D defined but not used", decl);
  472. }
  473. /* Issue appropriate warnings for the global declarations in V (of
  474. which there are LEN). */
  475. void
  476. check_global_declarations (tree *v, int len)
  477. {
  478. int i;
  479. for (i = 0; i < len; i++)
  480. check_global_declaration_1 (v[i]);
  481. }
  482. /* Emit debugging information for all global declarations in VEC. */
  483. void
  484. emit_debug_global_declarations (tree *vec, int len)
  485. {
  486. int i;
  487. /* Avoid confusing the debug information machinery when there are errors. */
  488. if (seen_error ())
  489. return;
  490. timevar_push (TV_SYMOUT);
  491. for (i = 0; i < len; i++)
  492. debug_hooks->global_decl (vec[i]);
  493. timevar_pop (TV_SYMOUT);
  494. }
  495. /* Compile an entire translation unit. Write a file of assembly
  496. output and various debugging dumps. */
  497. static void
  498. compile_file (void)
  499. {
  500. timevar_start (TV_PHASE_PARSING);
  501. timevar_push (TV_PARSE_GLOBAL);
  502. /* Call the parser, which parses the entire file (calling
  503. rest_of_compilation for each function). */
  504. lang_hooks.parse_file ();
  505. timevar_pop (TV_PARSE_GLOBAL);
  506. timevar_stop (TV_PHASE_PARSING);
  507. /* Compilation is now finished except for writing
  508. what's left of the symbol table output. */
  509. if (flag_syntax_only || flag_wpa)
  510. return;
  511. /* Reset maximum_field_alignment, it can be adjusted by #pragma pack
  512. and this shouldn't influence any types built by the middle-end
  513. from now on (like gcov_info_type). */
  514. maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
  515. ggc_protect_identifiers = false;
  516. /* This must also call finalize_compilation_unit. */
  517. lang_hooks.decls.final_write_globals ();
  518. if (seen_error ())
  519. return;
  520. timevar_start (TV_PHASE_LATE_ASM);
  521. /* Compilation unit is finalized. When producing non-fat LTO object, we are
  522. basically finished. */
  523. if (in_lto_p || !flag_lto || flag_fat_lto_objects)
  524. {
  525. /* File-scope initialization for AddressSanitizer. */
  526. if (flag_sanitize & SANITIZE_ADDRESS)
  527. asan_finish_file ();
  528. if (flag_sanitize & SANITIZE_THREAD)
  529. tsan_finish_file ();
  530. if (flag_check_pointer_bounds)
  531. chkp_finish_file ();
  532. omp_finish_file ();
  533. output_shared_constant_pool ();
  534. output_object_blocks ();
  535. finish_tm_clone_pairs ();
  536. /* Write out any pending weak symbol declarations. */
  537. weak_finish ();
  538. /* This must be at the end before unwind and debug info.
  539. Some target ports emit PIC setup thunks here. */
  540. targetm.asm_out.code_end ();
  541. /* Do dbx symbols. */
  542. timevar_push (TV_SYMOUT);
  543. #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
  544. if (dwarf2out_do_frame ())
  545. dwarf2out_frame_finish ();
  546. #endif
  547. (*debug_hooks->finish) (main_input_filename);
  548. timevar_pop (TV_SYMOUT);
  549. /* Output some stuff at end of file if nec. */
  550. dw2_output_indirect_constants ();
  551. /* Flush any pending external directives. */
  552. process_pending_assemble_externals ();
  553. }
  554. /* Emit LTO marker if LTO info has been previously emitted. This is
  555. used by collect2 to determine whether an object file contains IL.
  556. We used to emit an undefined reference here, but this produces
  557. link errors if an object file with IL is stored into a shared
  558. library without invoking lto1. */
  559. if (flag_generate_lto || flag_generate_offload)
  560. {
  561. #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
  562. ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
  563. "__gnu_lto_v1",
  564. (unsigned HOST_WIDE_INT) 1, 8);
  565. #elif defined ASM_OUTPUT_ALIGNED_COMMON
  566. ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
  567. (unsigned HOST_WIDE_INT) 1, 8);
  568. #else
  569. ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
  570. (unsigned HOST_WIDE_INT) 1,
  571. (unsigned HOST_WIDE_INT) 1);
  572. #endif
  573. }
  574. /* Let linker plugin know that this is a slim object and must be LTOed
  575. even when user did not ask for it. */
  576. if (flag_generate_lto && !flag_fat_lto_objects)
  577. {
  578. #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
  579. ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE, "__gnu_lto_slim",
  580. (unsigned HOST_WIDE_INT) 1, 8);
  581. #elif defined ASM_OUTPUT_ALIGNED_COMMON
  582. ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_slim",
  583. (unsigned HOST_WIDE_INT) 1, 8);
  584. #else
  585. ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_slim",
  586. (unsigned HOST_WIDE_INT) 1,
  587. (unsigned HOST_WIDE_INT) 1);
  588. #endif
  589. }
  590. /* Attach a special .ident directive to the end of the file to identify
  591. the version of GCC which compiled this code. The format of the .ident
  592. string is patterned after the ones produced by native SVR4 compilers. */
  593. if (!flag_no_ident)
  594. {
  595. const char *pkg_version = "(GNU) ";
  596. char *ident_str;
  597. if (strcmp ("(GCC) ", pkgversion_string))
  598. pkg_version = pkgversion_string;
  599. ident_str = ACONCAT (("GCC: ", pkg_version, version_string, NULL));
  600. targetm.asm_out.output_ident (ident_str);
  601. }
  602. /* Auto profile finalization. */
  603. if (flag_auto_profile)
  604. end_auto_profile ();
  605. /* Invoke registered plugin callbacks. */
  606. invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
  607. /* This must be at the end. Some target ports emit end of file directives
  608. into the assembly file here, and hence we can not output anything to the
  609. assembly file after this point. */
  610. targetm.asm_out.file_end ();
  611. timevar_stop (TV_PHASE_LATE_ASM);
  612. }
  613. /* Print version information to FILE.
  614. Each line begins with INDENT (for the case where FILE is the
  615. assembler output file).
  616. If SHOW_GLOBAL_STATE is true (for cc1 etc), we are within the compiler
  617. proper and can print pertinent state (e.g. params and plugins).
  618. If SHOW_GLOBAL_STATE is false (for use by libgccjit), we are outside the
  619. compiler, and we don't hold the mutex on the compiler's global state:
  620. we can't print params and plugins, since they might not be initialized,
  621. or might be being manipulated by a compile running in another
  622. thread. */
  623. void
  624. print_version (FILE *file, const char *indent, bool show_global_state)
  625. {
  626. static const char fmt1[] =
  627. #ifdef __GNUC__
  628. N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
  629. #else
  630. N_("%s%s%s %sversion %s (%s) compiled by CC, ")
  631. #endif
  632. ;
  633. static const char fmt2[] =
  634. N_("GMP version %s, MPFR version %s, MPC version %s\n");
  635. static const char fmt3[] =
  636. N_("%s%swarning: %s header version %s differs from library version %s.\n");
  637. static const char fmt4[] =
  638. N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
  639. #ifndef __VERSION__
  640. #define __VERSION__ "[?]"
  641. #endif
  642. fprintf (file,
  643. file == stderr ? _(fmt1) : fmt1,
  644. indent, *indent != 0 ? " " : "",
  645. lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
  646. indent, __VERSION__);
  647. /* We need to stringify the GMP macro values. Ugh, gmp_version has
  648. two string formats, "i.j.k" and "i.j" when k is zero. As of
  649. gmp-4.3.0, GMP always uses the 3 number format. */
  650. #define GCC_GMP_STRINGIFY_VERSION3(X) #X
  651. #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3 (X)
  652. #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
  653. #define GCC_GMP_VERSION \
  654. GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
  655. #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
  656. #define GCC_GMP_STRINGIFY_VERSION \
  657. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
  658. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR)
  659. #else
  660. #define GCC_GMP_STRINGIFY_VERSION \
  661. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION) "." \
  662. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_MINOR) "." \
  663. GCC_GMP_STRINGIFY_VERSION2 (__GNU_MP_VERSION_PATCHLEVEL)
  664. #endif
  665. fprintf (file,
  666. file == stderr ? _(fmt2) : fmt2,
  667. GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
  668. if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
  669. fprintf (file,
  670. file == stderr ? _(fmt3) : fmt3,
  671. indent, *indent != 0 ? " " : "",
  672. "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
  673. if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
  674. fprintf (file,
  675. file == stderr ? _(fmt3) : fmt3,
  676. indent, *indent != 0 ? " " : "",
  677. "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
  678. if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
  679. fprintf (file,
  680. file == stderr ? _(fmt3) : fmt3,
  681. indent, *indent != 0 ? " " : "",
  682. "MPC", MPC_VERSION_STRING, mpc_get_version ());
  683. if (show_global_state)
  684. {
  685. fprintf (file,
  686. file == stderr ? _(fmt4) : fmt4,
  687. indent, *indent != 0 ? " " : "",
  688. PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
  689. print_plugins_versions (file, indent);
  690. }
  691. }
  692. static int
  693. print_to_asm_out_file (print_switch_type type, const char * text)
  694. {
  695. bool prepend_sep = true;
  696. switch (type)
  697. {
  698. case SWITCH_TYPE_LINE_END:
  699. putc ('\n', asm_out_file);
  700. return 1;
  701. case SWITCH_TYPE_LINE_START:
  702. fputs (ASM_COMMENT_START, asm_out_file);
  703. return strlen (ASM_COMMENT_START);
  704. case SWITCH_TYPE_DESCRIPTIVE:
  705. if (ASM_COMMENT_START[0] == 0)
  706. prepend_sep = false;
  707. /* Drop through. */
  708. case SWITCH_TYPE_PASSED:
  709. case SWITCH_TYPE_ENABLED:
  710. if (prepend_sep)
  711. fputc (' ', asm_out_file);
  712. fputs (text, asm_out_file);
  713. /* No need to return the length here as
  714. print_single_switch has already done it. */
  715. return 0;
  716. default:
  717. return -1;
  718. }
  719. }
  720. static int
  721. print_to_stderr (print_switch_type type, const char * text)
  722. {
  723. switch (type)
  724. {
  725. case SWITCH_TYPE_LINE_END:
  726. putc ('\n', stderr);
  727. return 1;
  728. case SWITCH_TYPE_LINE_START:
  729. return 0;
  730. case SWITCH_TYPE_PASSED:
  731. case SWITCH_TYPE_ENABLED:
  732. fputc (' ', stderr);
  733. /* Drop through. */
  734. case SWITCH_TYPE_DESCRIPTIVE:
  735. fputs (text, stderr);
  736. /* No need to return the length here as
  737. print_single_switch has already done it. */
  738. return 0;
  739. default:
  740. return -1;
  741. }
  742. }
  743. /* Print an option value and return the adjusted position in the line.
  744. ??? print_fn doesn't handle errors, eg disk full; presumably other
  745. code will catch a disk full though. */
  746. static int
  747. print_single_switch (print_switch_fn_type print_fn,
  748. int pos,
  749. print_switch_type type,
  750. const char * text)
  751. {
  752. /* The ultrix fprintf returns 0 on success, so compute the result
  753. we want here since we need it for the following test. The +1
  754. is for the separator character that will probably be emitted. */
  755. int len = strlen (text) + 1;
  756. if (pos != 0
  757. && pos + len > MAX_LINE)
  758. {
  759. print_fn (SWITCH_TYPE_LINE_END, NULL);
  760. pos = 0;
  761. }
  762. if (pos == 0)
  763. pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
  764. print_fn (type, text);
  765. return pos + len;
  766. }
  767. /* Print active target switches using PRINT_FN.
  768. POS is the current cursor position and MAX is the size of a "line".
  769. Each line begins with INDENT and ends with TERM.
  770. Each switch is separated from the next by SEP. */
  771. static void
  772. print_switch_values (print_switch_fn_type print_fn)
  773. {
  774. int pos = 0;
  775. size_t j;
  776. /* Fill in the -frandom-seed option, if the user didn't pass it, so
  777. that it can be printed below. This helps reproducibility. */
  778. if (!flag_random_seed)
  779. init_random_seed ();
  780. /* Print the options as passed. */
  781. pos = print_single_switch (print_fn, pos,
  782. SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
  783. for (j = 1; j < save_decoded_options_count; j++)
  784. {
  785. switch (save_decoded_options[j].opt_index)
  786. {
  787. case OPT_o:
  788. case OPT_d:
  789. case OPT_dumpbase:
  790. case OPT_dumpdir:
  791. case OPT_auxbase:
  792. case OPT_quiet:
  793. case OPT_version:
  794. /* Ignore these. */
  795. continue;
  796. }
  797. pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED,
  798. save_decoded_options[j].orig_option_with_args_text);
  799. }
  800. if (pos > 0)
  801. print_fn (SWITCH_TYPE_LINE_END, NULL);
  802. /* Print the -f and -m options that have been enabled.
  803. We don't handle language specific options but printing argv
  804. should suffice. */
  805. pos = print_single_switch (print_fn, 0,
  806. SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
  807. for (j = 0; j < cl_options_count; j++)
  808. if (cl_options[j].cl_report
  809. && option_enabled (j, &global_options) > 0)
  810. pos = print_single_switch (print_fn, pos,
  811. SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
  812. print_fn (SWITCH_TYPE_LINE_END, NULL);
  813. }
  814. /* Open assembly code output file. Do this even if -fsyntax-only is
  815. on, because then the driver will have provided the name of a
  816. temporary file or bit bucket for us. NAME is the file specified on
  817. the command line, possibly NULL. */
  818. static void
  819. init_asm_output (const char *name)
  820. {
  821. if (name == NULL && asm_file_name == 0)
  822. asm_out_file = stdout;
  823. else
  824. {
  825. if (asm_file_name == 0)
  826. {
  827. int len = strlen (dump_base_name);
  828. char *dumpname = XNEWVEC (char, len + 6);
  829. memcpy (dumpname, dump_base_name, len + 1);
  830. strip_off_ending (dumpname, len);
  831. strcat (dumpname, ".s");
  832. asm_file_name = dumpname;
  833. }
  834. if (!strcmp (asm_file_name, "-"))
  835. asm_out_file = stdout;
  836. else if (!canonical_filename_eq (asm_file_name, name)
  837. || !strcmp (asm_file_name, HOST_BIT_BUCKET))
  838. asm_out_file = fopen (asm_file_name, "w");
  839. else
  840. /* Use UNKOWN_LOCATION to prevent gcc from printing the first
  841. line in the current file. */
  842. fatal_error (UNKNOWN_LOCATION,
  843. "input file %qs is the same as output file",
  844. asm_file_name);
  845. if (asm_out_file == 0)
  846. fatal_error (UNKNOWN_LOCATION,
  847. "can%'t open %qs for writing: %m", asm_file_name);
  848. }
  849. if (!flag_syntax_only)
  850. {
  851. targetm.asm_out.file_start ();
  852. if (flag_record_gcc_switches)
  853. {
  854. if (targetm.asm_out.record_gcc_switches)
  855. {
  856. /* Let the target know that we are about to start recording. */
  857. targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
  858. NULL);
  859. /* Now record the switches. */
  860. print_switch_values (targetm.asm_out.record_gcc_switches);
  861. /* Let the target know that the recording is over. */
  862. targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
  863. NULL);
  864. }
  865. else
  866. inform (input_location, "-frecord-gcc-switches is not supported by the current target");
  867. }
  868. if (flag_verbose_asm)
  869. {
  870. /* Print the list of switches in effect
  871. into the assembler file as comments. */
  872. print_version (asm_out_file, ASM_COMMENT_START, true);
  873. print_switch_values (print_to_asm_out_file);
  874. putc ('\n', asm_out_file);
  875. }
  876. }
  877. }
  878. /* A helper function; used as the reallocator function for cpp's line
  879. table. */
  880. static void *
  881. realloc_for_line_map (void *ptr, size_t len)
  882. {
  883. return ggc_realloc (ptr, len);
  884. }
  885. /* A helper function: used as the allocator function for
  886. identifier_to_locale. */
  887. static void *
  888. alloc_for_identifier_to_locale (size_t len)
  889. {
  890. return ggc_alloc_atomic (len);
  891. }
  892. /* Output stack usage information. */
  893. void
  894. output_stack_usage (void)
  895. {
  896. static bool warning_issued = false;
  897. enum stack_usage_kind_type { STATIC = 0, DYNAMIC, DYNAMIC_BOUNDED };
  898. const char *stack_usage_kind_str[] = {
  899. "static",
  900. "dynamic",
  901. "dynamic,bounded"
  902. };
  903. HOST_WIDE_INT stack_usage = current_function_static_stack_size;
  904. enum stack_usage_kind_type stack_usage_kind;
  905. if (stack_usage < 0)
  906. {
  907. if (!warning_issued)
  908. {
  909. warning (0, "stack usage computation not supported for this target");
  910. warning_issued = true;
  911. }
  912. return;
  913. }
  914. stack_usage_kind = STATIC;
  915. /* Add the maximum amount of space pushed onto the stack. */
  916. if (current_function_pushed_stack_size > 0)
  917. {
  918. stack_usage += current_function_pushed_stack_size;
  919. stack_usage_kind = DYNAMIC_BOUNDED;
  920. }
  921. /* Now on to the tricky part: dynamic stack allocation. */
  922. if (current_function_allocates_dynamic_stack_space)
  923. {
  924. if (current_function_has_unbounded_dynamic_stack_size)
  925. stack_usage_kind = DYNAMIC;
  926. else
  927. stack_usage_kind = DYNAMIC_BOUNDED;
  928. /* Add the size even in the unbounded case, this can't hurt. */
  929. stack_usage += current_function_dynamic_stack_size;
  930. }
  931. if (flag_stack_usage)
  932. {
  933. expanded_location loc
  934. = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
  935. /* We don't want to print the full qualified name because it can be long,
  936. so we strip the scope prefix, but we may need to deal with the suffix
  937. created by the compiler. */
  938. const char *suffix
  939. = strchr (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), '.');
  940. const char *name
  941. = lang_hooks.decl_printable_name (current_function_decl, 2);
  942. if (suffix)
  943. {
  944. const char *dot = strchr (name, '.');
  945. while (dot && strcasecmp (dot, suffix) != 0)
  946. {
  947. name = dot + 1;
  948. dot = strchr (name, '.');
  949. }
  950. }
  951. else
  952. {
  953. const char *dot = strrchr (name, '.');
  954. if (dot)
  955. name = dot + 1;
  956. }
  957. fprintf (stack_usage_file,
  958. "%s:%d:%d:%s\t"HOST_WIDE_INT_PRINT_DEC"\t%s\n",
  959. lbasename (loc.file),
  960. loc.line,
  961. loc.column,
  962. name,
  963. stack_usage,
  964. stack_usage_kind_str[stack_usage_kind]);
  965. }
  966. if (warn_stack_usage >= 0)
  967. {
  968. const location_t loc = DECL_SOURCE_LOCATION (current_function_decl);
  969. if (stack_usage_kind == DYNAMIC)
  970. warning_at (loc, OPT_Wstack_usage_, "stack usage might be unbounded");
  971. else if (stack_usage > warn_stack_usage)
  972. {
  973. if (stack_usage_kind == DYNAMIC_BOUNDED)
  974. warning_at (loc,
  975. OPT_Wstack_usage_, "stack usage might be %wd bytes",
  976. stack_usage);
  977. else
  978. warning_at (loc, OPT_Wstack_usage_, "stack usage is %wd bytes",
  979. stack_usage);
  980. }
  981. }
  982. }
  983. /* Open an auxiliary output file. */
  984. static FILE *
  985. open_auxiliary_file (const char *ext)
  986. {
  987. char *filename;
  988. FILE *file;
  989. filename = concat (aux_base_name, ".", ext, NULL);
  990. file = fopen (filename, "w");
  991. if (!file)
  992. fatal_error (input_location, "can%'t open %s for writing: %m", filename);
  993. free (filename);
  994. return file;
  995. }
  996. /* Initialization of the front end environment, before command line
  997. options are parsed. Signal handlers, internationalization etc.
  998. ARGV0 is main's argv[0]. */
  999. static void
  1000. general_init (const char *argv0, bool init_signals)
  1001. {
  1002. const char *p;
  1003. p = argv0 + strlen (argv0);
  1004. while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
  1005. --p;
  1006. progname = p;
  1007. xmalloc_set_program_name (progname);
  1008. hex_init ();
  1009. /* Unlock the stdio streams. */
  1010. unlock_std_streams ();
  1011. gcc_init_libintl ();
  1012. identifier_to_locale_alloc = alloc_for_identifier_to_locale;
  1013. identifier_to_locale_free = ggc_free;
  1014. /* Initialize the diagnostics reporting machinery, so option parsing
  1015. can give warnings and errors. */
  1016. diagnostic_initialize (global_dc, N_OPTS);
  1017. /* Set a default printer. Language specific initializations will
  1018. override it later. */
  1019. tree_diagnostics_defaults (global_dc);
  1020. global_dc->show_caret
  1021. = global_options_init.x_flag_diagnostics_show_caret;
  1022. global_dc->show_option_requested
  1023. = global_options_init.x_flag_diagnostics_show_option;
  1024. global_dc->show_column
  1025. = global_options_init.x_flag_show_column;
  1026. global_dc->internal_error = plugins_internal_error_function;
  1027. global_dc->option_enabled = option_enabled;
  1028. global_dc->option_state = &global_options;
  1029. global_dc->option_name = option_name;
  1030. if (init_signals)
  1031. {
  1032. /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
  1033. #ifdef SIGSEGV
  1034. signal (SIGSEGV, crash_signal);
  1035. #endif
  1036. #ifdef SIGILL
  1037. signal (SIGILL, crash_signal);
  1038. #endif
  1039. #ifdef SIGBUS
  1040. signal (SIGBUS, crash_signal);
  1041. #endif
  1042. #ifdef SIGABRT
  1043. signal (SIGABRT, crash_signal);
  1044. #endif
  1045. #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
  1046. signal (SIGIOT, crash_signal);
  1047. #endif
  1048. #ifdef SIGFPE
  1049. signal (SIGFPE, crash_signal);
  1050. #endif
  1051. /* Other host-specific signal setup. */
  1052. (*host_hooks.extra_signals)();
  1053. }
  1054. /* Initialize the garbage-collector, string pools and tree type hash
  1055. table. */
  1056. init_ggc ();
  1057. init_stringpool ();
  1058. input_location = UNKNOWN_LOCATION;
  1059. line_table = ggc_alloc<line_maps> ();
  1060. linemap_init (line_table, BUILTINS_LOCATION);
  1061. line_table->reallocator = realloc_for_line_map;
  1062. line_table->round_alloc_size = ggc_round_alloc_size;
  1063. init_ttree ();
  1064. /* Initialize register usage now so switches may override. */
  1065. init_reg_sets ();
  1066. /* Register the language-independent parameters. */
  1067. global_init_params ();
  1068. /* This must be done after global_init_params but before argument
  1069. processing. */
  1070. init_ggc_heuristics ();
  1071. /* Create the singleton holder for global state.
  1072. Doing so also creates the pass manager and with it the passes. */
  1073. g = new gcc::context ();
  1074. symtab = new (ggc_cleared_alloc <symbol_table> ()) symbol_table ();
  1075. statistics_early_init ();
  1076. finish_params ();
  1077. }
  1078. /* Return true if the current target supports -fsection-anchors. */
  1079. static bool
  1080. target_supports_section_anchors_p (void)
  1081. {
  1082. if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
  1083. return false;
  1084. if (targetm.asm_out.output_anchor == NULL)
  1085. return false;
  1086. return true;
  1087. }
  1088. /* Default the align_* variables to 1 if they're still unset, and
  1089. set up the align_*_log variables. */
  1090. static void
  1091. init_alignments (void)
  1092. {
  1093. if (align_loops <= 0)
  1094. align_loops = 1;
  1095. if (align_loops_max_skip > align_loops)
  1096. align_loops_max_skip = align_loops - 1;
  1097. align_loops_log = floor_log2 (align_loops * 2 - 1);
  1098. if (align_jumps <= 0)
  1099. align_jumps = 1;
  1100. if (align_jumps_max_skip > align_jumps)
  1101. align_jumps_max_skip = align_jumps - 1;
  1102. align_jumps_log = floor_log2 (align_jumps * 2 - 1);
  1103. if (align_labels <= 0)
  1104. align_labels = 1;
  1105. align_labels_log = floor_log2 (align_labels * 2 - 1);
  1106. if (align_labels_max_skip > align_labels)
  1107. align_labels_max_skip = align_labels - 1;
  1108. if (align_functions <= 0)
  1109. align_functions = 1;
  1110. align_functions_log = floor_log2 (align_functions * 2 - 1);
  1111. }
  1112. /* Process the options that have been parsed. */
  1113. static void
  1114. process_options (void)
  1115. {
  1116. /* Just in case lang_hooks.post_options ends up calling a debug_hook.
  1117. This can happen with incorrect pre-processed input. */
  1118. debug_hooks = &do_nothing_debug_hooks;
  1119. maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
  1120. /* Allow the front end to perform consistency checks and do further
  1121. initialization based on the command line options. This hook also
  1122. sets the original filename if appropriate (e.g. foo.i -> foo.c)
  1123. so we can correctly initialize debug output. */
  1124. no_backend = lang_hooks.post_options (&main_input_filename);
  1125. /* Some machines may reject certain combinations of options. */
  1126. targetm.target_option.override ();
  1127. /* Avoid any informative notes in the second run of -fcompare-debug. */
  1128. if (flag_compare_debug)
  1129. diagnostic_inhibit_notes (global_dc);
  1130. if (flag_section_anchors && !target_supports_section_anchors_p ())
  1131. {
  1132. warning (OPT_fsection_anchors,
  1133. "this target does not support %qs", "-fsection-anchors");
  1134. flag_section_anchors = 0;
  1135. }
  1136. if (flag_short_enums == 2)
  1137. flag_short_enums = targetm.default_short_enums ();
  1138. /* Set aux_base_name if not already set. */
  1139. if (aux_base_name)
  1140. ;
  1141. else if (main_input_filename)
  1142. {
  1143. char *name = xstrdup (lbasename (main_input_filename));
  1144. strip_off_ending (name, strlen (name));
  1145. aux_base_name = name;
  1146. }
  1147. else
  1148. aux_base_name = "gccaux";
  1149. #ifndef HAVE_isl
  1150. if (flag_graphite
  1151. || flag_graphite_identity
  1152. || flag_loop_block
  1153. || flag_loop_interchange
  1154. || flag_loop_strip_mine
  1155. || flag_loop_parallelize_all
  1156. || flag_loop_unroll_jam)
  1157. sorry ("Graphite loop optimizations cannot be used (ISL is not available)"
  1158. "(-fgraphite, -fgraphite-identity, -floop-block, "
  1159. "-floop-interchange, -floop-strip-mine, -floop-parallelize-all, "
  1160. "-floop-unroll-and-jam, and -ftree-loop-linear)");
  1161. #endif
  1162. if (flag_check_pointer_bounds)
  1163. {
  1164. if (targetm.chkp_bound_mode () == VOIDmode)
  1165. {
  1166. error ("-fcheck-pointer-bounds is not supported for this target");
  1167. flag_check_pointer_bounds = 0;
  1168. }
  1169. if (flag_sanitize & SANITIZE_ADDRESS)
  1170. {
  1171. error ("-fcheck-pointer-bounds is not supported with "
  1172. "Address Sanitizer");
  1173. flag_check_pointer_bounds = 0;
  1174. }
  1175. }
  1176. /* One region RA really helps to decrease the code size. */
  1177. if (flag_ira_region == IRA_REGION_AUTODETECT)
  1178. flag_ira_region
  1179. = optimize_size || !optimize ? IRA_REGION_ONE : IRA_REGION_MIXED;
  1180. if (!abi_version_at_least (2))
  1181. {
  1182. /* -fabi-version=1 support was removed after GCC 4.9. */
  1183. error ("%<-fabi-version=1%> is no longer supported");
  1184. flag_abi_version = 2;
  1185. }
  1186. /* Unrolling all loops implies that standard loop unrolling must also
  1187. be done. */
  1188. if (flag_unroll_all_loops)
  1189. flag_unroll_loops = 1;
  1190. /* web and rename-registers help when run after loop unrolling. */
  1191. if (flag_web == AUTODETECT_VALUE)
  1192. flag_web = flag_unroll_loops || flag_peel_loops;
  1193. if (flag_rename_registers == AUTODETECT_VALUE)
  1194. flag_rename_registers = flag_unroll_loops || flag_peel_loops;
  1195. if (flag_non_call_exceptions)
  1196. flag_asynchronous_unwind_tables = 1;
  1197. if (flag_asynchronous_unwind_tables)
  1198. flag_unwind_tables = 1;
  1199. if (flag_value_profile_transformations)
  1200. flag_profile_values = 1;
  1201. /* Warn about options that are not supported on this machine. */
  1202. #ifndef INSN_SCHEDULING
  1203. if (flag_schedule_insns || flag_schedule_insns_after_reload)
  1204. warning (0, "instruction scheduling not supported on this target machine");
  1205. #endif
  1206. #ifndef DELAY_SLOTS
  1207. if (flag_delayed_branch)
  1208. warning (0, "this target machine does not have delayed branches");
  1209. #endif
  1210. user_label_prefix = USER_LABEL_PREFIX;
  1211. if (flag_leading_underscore != -1)
  1212. {
  1213. /* If the default prefix is more complicated than "" or "_",
  1214. issue a warning and ignore this option. */
  1215. if (user_label_prefix[0] == 0 ||
  1216. (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
  1217. {
  1218. user_label_prefix = flag_leading_underscore ? "_" : "";
  1219. }
  1220. else
  1221. warning (0, "-f%sleading-underscore not supported on this target machine",
  1222. flag_leading_underscore ? "" : "no-");
  1223. }
  1224. /* If we are in verbose mode, write out the version and maybe all the
  1225. option flags in use. */
  1226. if (version_flag)
  1227. {
  1228. print_version (stderr, "", true);
  1229. if (! quiet_flag)
  1230. print_switch_values (print_to_stderr);
  1231. }
  1232. if (flag_syntax_only)
  1233. {
  1234. write_symbols = NO_DEBUG;
  1235. profile_flag = 0;
  1236. }
  1237. if (flag_gtoggle)
  1238. {
  1239. if (debug_info_level == DINFO_LEVEL_NONE)
  1240. {
  1241. debug_info_level = DINFO_LEVEL_NORMAL;
  1242. if (write_symbols == NO_DEBUG)
  1243. write_symbols = PREFERRED_DEBUGGING_TYPE;
  1244. }
  1245. else
  1246. debug_info_level = DINFO_LEVEL_NONE;
  1247. }
  1248. if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
  1249. {
  1250. FILE *final_output = fopen (flag_dump_final_insns, "w");
  1251. if (!final_output)
  1252. {
  1253. error ("could not open final insn dump file %qs: %m",
  1254. flag_dump_final_insns);
  1255. flag_dump_final_insns = NULL;
  1256. }
  1257. else if (fclose (final_output))
  1258. {
  1259. error ("could not close zeroed insn dump file %qs: %m",
  1260. flag_dump_final_insns);
  1261. flag_dump_final_insns = NULL;
  1262. }
  1263. }
  1264. /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
  1265. level is 0. */
  1266. if (debug_info_level == DINFO_LEVEL_NONE)
  1267. write_symbols = NO_DEBUG;
  1268. if (write_symbols == NO_DEBUG)
  1269. ;
  1270. #if defined(DBX_DEBUGGING_INFO)
  1271. else if (write_symbols == DBX_DEBUG)
  1272. debug_hooks = &dbx_debug_hooks;
  1273. #endif
  1274. #if defined(XCOFF_DEBUGGING_INFO)
  1275. else if (write_symbols == XCOFF_DEBUG)
  1276. debug_hooks = &xcoff_debug_hooks;
  1277. #endif
  1278. #ifdef SDB_DEBUGGING_INFO
  1279. else if (write_symbols == SDB_DEBUG)
  1280. debug_hooks = &sdb_debug_hooks;
  1281. #endif
  1282. #ifdef DWARF2_DEBUGGING_INFO
  1283. else if (write_symbols == DWARF2_DEBUG)
  1284. debug_hooks = &dwarf2_debug_hooks;
  1285. #endif
  1286. #ifdef VMS_DEBUGGING_INFO
  1287. else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
  1288. debug_hooks = &vmsdbg_debug_hooks;
  1289. #endif
  1290. else
  1291. error ("target system does not support the %qs debug format",
  1292. debug_type_names[write_symbols]);
  1293. /* We know which debug output will be used so we can set flag_var_tracking
  1294. and flag_var_tracking_uninit if the user has not specified them. */
  1295. if (debug_info_level < DINFO_LEVEL_NORMAL
  1296. || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
  1297. {
  1298. if (flag_var_tracking == 1
  1299. || flag_var_tracking_uninit == 1)
  1300. {
  1301. if (debug_info_level < DINFO_LEVEL_NORMAL)
  1302. warning (0, "variable tracking requested, but useless unless "
  1303. "producing debug info");
  1304. else
  1305. warning (0, "variable tracking requested, but not supported "
  1306. "by this debug format");
  1307. }
  1308. flag_var_tracking = 0;
  1309. flag_var_tracking_uninit = 0;
  1310. }
  1311. /* The debug hooks are used to implement -fdump-go-spec because it
  1312. gives a simple and stable API for all the information we need to
  1313. dump. */
  1314. if (flag_dump_go_spec != NULL)
  1315. debug_hooks = dump_go_spec_init (flag_dump_go_spec, debug_hooks);
  1316. /* If the user specifically requested variable tracking with tagging
  1317. uninitialized variables, we need to turn on variable tracking.
  1318. (We already determined above that variable tracking is feasible.) */
  1319. if (flag_var_tracking_uninit == 1)
  1320. flag_var_tracking = 1;
  1321. if (flag_var_tracking == AUTODETECT_VALUE)
  1322. flag_var_tracking = optimize >= 1;
  1323. if (flag_var_tracking_uninit == AUTODETECT_VALUE)
  1324. flag_var_tracking_uninit = flag_var_tracking;
  1325. if (flag_var_tracking_assignments == AUTODETECT_VALUE)
  1326. flag_var_tracking_assignments = flag_var_tracking
  1327. && !(flag_selective_scheduling || flag_selective_scheduling2);
  1328. if (flag_var_tracking_assignments_toggle)
  1329. flag_var_tracking_assignments = !flag_var_tracking_assignments;
  1330. if (flag_var_tracking_assignments && !flag_var_tracking)
  1331. flag_var_tracking = flag_var_tracking_assignments = -1;
  1332. if (flag_var_tracking_assignments
  1333. && (flag_selective_scheduling || flag_selective_scheduling2))
  1334. warning (0, "var-tracking-assignments changes selective scheduling");
  1335. if (flag_tree_cselim == AUTODETECT_VALUE)
  1336. #ifdef HAVE_conditional_move
  1337. flag_tree_cselim = 1;
  1338. #else
  1339. flag_tree_cselim = 0;
  1340. #endif
  1341. /* If auxiliary info generation is desired, open the output file.
  1342. This goes in the same directory as the source file--unlike
  1343. all the other output files. */
  1344. if (flag_gen_aux_info)
  1345. {
  1346. aux_info_file = fopen (aux_info_file_name, "w");
  1347. if (aux_info_file == 0)
  1348. fatal_error (input_location, "can%'t open %s: %m", aux_info_file_name);
  1349. }
  1350. if (!targetm_common.have_named_sections)
  1351. {
  1352. if (flag_function_sections)
  1353. {
  1354. warning (0, "-ffunction-sections not supported for this target");
  1355. flag_function_sections = 0;
  1356. }
  1357. if (flag_data_sections)
  1358. {
  1359. warning (0, "-fdata-sections not supported for this target");
  1360. flag_data_sections = 0;
  1361. }
  1362. }
  1363. #ifndef HAVE_prefetch
  1364. if (flag_prefetch_loop_arrays > 0)
  1365. {
  1366. warning (0, "-fprefetch-loop-arrays not supported for this target");
  1367. flag_prefetch_loop_arrays = 0;
  1368. }
  1369. #else
  1370. if (flag_prefetch_loop_arrays > 0 && !HAVE_prefetch)
  1371. {
  1372. warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
  1373. flag_prefetch_loop_arrays = 0;
  1374. }
  1375. #endif
  1376. /* This combination of options isn't handled for i386 targets and doesn't
  1377. make much sense anyway, so don't allow it. */
  1378. if (flag_prefetch_loop_arrays > 0 && optimize_size)
  1379. {
  1380. warning (0, "-fprefetch-loop-arrays is not supported with -Os");
  1381. flag_prefetch_loop_arrays = 0;
  1382. }
  1383. /* The presence of IEEE signaling NaNs, implies all math can trap. */
  1384. if (flag_signaling_nans)
  1385. flag_trapping_math = 1;
  1386. /* We cannot reassociate if we want traps or signed zeros. */
  1387. if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
  1388. {
  1389. warning (0, "-fassociative-math disabled; other options take precedence");
  1390. flag_associative_math = 0;
  1391. }
  1392. /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
  1393. if (flag_cx_limited_range)
  1394. flag_complex_method = 0;
  1395. /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
  1396. if (flag_cx_fortran_rules)
  1397. flag_complex_method = 1;
  1398. /* Targets must be able to place spill slots at lower addresses. If the
  1399. target already uses a soft frame pointer, the transition is trivial. */
  1400. if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
  1401. {
  1402. warning (0, "-fstack-protector not supported for this target");
  1403. flag_stack_protect = 0;
  1404. }
  1405. if (!flag_stack_protect)
  1406. warn_stack_protect = 0;
  1407. /* Address Sanitizer needs porting to each target architecture. */
  1408. if ((flag_sanitize & SANITIZE_ADDRESS)
  1409. && !FRAME_GROWS_DOWNWARD)
  1410. {
  1411. warning (0,
  1412. "-fsanitize=address and -fsanitize=kernel-address "
  1413. "are not supported for this target");
  1414. flag_sanitize &= ~SANITIZE_ADDRESS;
  1415. }
  1416. if ((flag_sanitize & SANITIZE_USER_ADDRESS)
  1417. && targetm.asan_shadow_offset == NULL)
  1418. {
  1419. warning (0, "-fsanitize=address not supported for this target");
  1420. flag_sanitize &= ~SANITIZE_ADDRESS;
  1421. }
  1422. /* Do not use IPA optimizations for register allocation if profiler is active
  1423. or port does not emit prologue and epilogue as RTL. */
  1424. if (profile_flag || !HAVE_prologue || !HAVE_epilogue)
  1425. flag_ipa_ra = 0;
  1426. /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
  1427. have not been set. */
  1428. if (!global_options_set.x_warnings_are_errors
  1429. && warn_coverage_mismatch
  1430. && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
  1431. DK_UNSPECIFIED))
  1432. diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
  1433. DK_ERROR, UNKNOWN_LOCATION);
  1434. /* Save the current optimization options. */
  1435. optimization_default_node = build_optimization_node (&global_options);
  1436. optimization_current_node = optimization_default_node;
  1437. /* Please don't change global_options after this point, those changes won't
  1438. be reflected in optimization_{default,current}_node. */
  1439. }
  1440. /* This function can be called multiple times to reinitialize the compiler
  1441. back end when register classes or instruction sets have changed,
  1442. before each function. */
  1443. static void
  1444. backend_init_target (void)
  1445. {
  1446. /* Initialize alignment variables. */
  1447. init_alignments ();
  1448. /* This depends on stack_pointer_rtx. */
  1449. init_fake_stack_mems ();
  1450. /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
  1451. mode-dependent. */
  1452. init_alias_target ();
  1453. /* Depends on HARD_FRAME_POINTER_REGNUM. */
  1454. init_reload ();
  1455. /* Depends on the enabled attribute. */
  1456. recog_init ();
  1457. /* The following initialization functions need to generate rtl, so
  1458. provide a dummy function context for them. */
  1459. init_dummy_function_start ();
  1460. /* rtx_cost is mode-dependent, so cached values need to be recomputed
  1461. on a mode change. */
  1462. init_expmed ();
  1463. init_lower_subreg ();
  1464. init_set_costs ();
  1465. init_expr_target ();
  1466. ira_init ();
  1467. /* We may need to recompute regno_save_code[] and regno_restore_code[]
  1468. after a mode change as well. */
  1469. caller_save_initialized_p = false;
  1470. expand_dummy_function_end ();
  1471. }
  1472. /* Initialize the compiler back end. This function is called only once,
  1473. when starting the compiler. */
  1474. static void
  1475. backend_init (void)
  1476. {
  1477. init_emit_once ();
  1478. init_rtlanal ();
  1479. init_inline_once ();
  1480. init_varasm_once ();
  1481. save_register_info ();
  1482. /* Middle end needs this initialization for default mem attributes
  1483. used by early calls to make_decl_rtl. */
  1484. init_emit_regs ();
  1485. /* Middle end needs this initialization for mode tables used to assign
  1486. modes to vector variables. */
  1487. init_regs ();
  1488. }
  1489. /* Initialize excess precision settings. */
  1490. static void
  1491. init_excess_precision (void)
  1492. {
  1493. /* Adjust excess precision handling based on the target options. If
  1494. the front end cannot handle it, flag_excess_precision_cmdline
  1495. will already have been set accordingly in the post_options
  1496. hook. */
  1497. gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
  1498. flag_excess_precision = flag_excess_precision_cmdline;
  1499. if (flag_unsafe_math_optimizations)
  1500. flag_excess_precision = EXCESS_PRECISION_FAST;
  1501. if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
  1502. {
  1503. int flt_eval_method = TARGET_FLT_EVAL_METHOD;
  1504. switch (flt_eval_method)
  1505. {
  1506. case -1:
  1507. case 0:
  1508. /* Either the target acts unpredictably (-1) or has all the
  1509. operations required not to have excess precision (0). */
  1510. flag_excess_precision = EXCESS_PRECISION_FAST;
  1511. break;
  1512. case 1:
  1513. case 2:
  1514. /* In these cases, predictable excess precision makes
  1515. sense. */
  1516. break;
  1517. default:
  1518. /* Any other implementation-defined FLT_EVAL_METHOD values
  1519. require the compiler to handle the associated excess
  1520. precision rules in excess_precision_type. */
  1521. gcc_unreachable ();
  1522. }
  1523. }
  1524. }
  1525. /* Initialize things that are both lang-dependent and target-dependent.
  1526. This function can be called more than once if target parameters change. */
  1527. static void
  1528. lang_dependent_init_target (void)
  1529. {
  1530. /* This determines excess precision settings. */
  1531. init_excess_precision ();
  1532. /* This creates various _DECL nodes, so needs to be called after the
  1533. front end is initialized. It also depends on the HAVE_xxx macros
  1534. generated from the target machine description. */
  1535. init_optabs ();
  1536. gcc_assert (!this_target_rtl->target_specific_initialized);
  1537. }
  1538. /* Perform initializations that are lang-dependent or target-dependent.
  1539. but matters only for late optimizations and RTL generation. */
  1540. static int rtl_initialized;
  1541. void
  1542. initialize_rtl (void)
  1543. {
  1544. /* Initialization done just once per compilation, but delayed
  1545. till code generation. */
  1546. if (!rtl_initialized)
  1547. ira_init_once ();
  1548. rtl_initialized = true;
  1549. /* Target specific RTL backend initialization. */
  1550. if (!this_target_rtl->target_specific_initialized)
  1551. {
  1552. backend_init_target ();
  1553. this_target_rtl->target_specific_initialized = true;
  1554. }
  1555. }
  1556. /* Language-dependent initialization. Returns nonzero on success. */
  1557. static int
  1558. lang_dependent_init (const char *name)
  1559. {
  1560. location_t save_loc = input_location;
  1561. if (dump_base_name == 0)
  1562. dump_base_name = name && name[0] ? name : "gccdump";
  1563. /* Other front-end initialization. */
  1564. input_location = BUILTINS_LOCATION;
  1565. if (lang_hooks.init () == 0)
  1566. return 0;
  1567. input_location = save_loc;
  1568. if (!flag_wpa)
  1569. {
  1570. init_asm_output (name);
  1571. /* If stack usage information is desired, open the output file. */
  1572. if (flag_stack_usage)
  1573. stack_usage_file = open_auxiliary_file ("su");
  1574. }
  1575. /* This creates various _DECL nodes, so needs to be called after the
  1576. front end is initialized. */
  1577. init_eh ();
  1578. /* Do the target-specific parts of the initialization. */
  1579. lang_dependent_init_target ();
  1580. if (!flag_wpa)
  1581. {
  1582. /* If dbx symbol table desired, initialize writing it and output the
  1583. predefined types. */
  1584. timevar_push (TV_SYMOUT);
  1585. /* Now we have the correct original filename, we can initialize
  1586. debug output. */
  1587. (*debug_hooks->init) (name);
  1588. timevar_pop (TV_SYMOUT);
  1589. }
  1590. return 1;
  1591. }
  1592. /* Reinitialize everything when target parameters, such as register usage,
  1593. have changed. */
  1594. void
  1595. target_reinit (void)
  1596. {
  1597. struct rtl_data saved_x_rtl;
  1598. rtx *saved_regno_reg_rtx;
  1599. tree saved_optimization_current_node;
  1600. struct target_optabs *saved_this_fn_optabs;
  1601. /* Temporarily switch to the default optimization node, so that
  1602. *this_target_optabs is set to the default, not reflecting
  1603. whatever a previous function used for the optimize
  1604. attribute. */
  1605. saved_optimization_current_node = optimization_current_node;
  1606. saved_this_fn_optabs = this_fn_optabs;
  1607. if (saved_optimization_current_node != optimization_default_node)
  1608. {
  1609. optimization_current_node = optimization_default_node;
  1610. cl_optimization_restore
  1611. (&global_options,
  1612. TREE_OPTIMIZATION (optimization_default_node));
  1613. }
  1614. this_fn_optabs = this_target_optabs;
  1615. /* Save *crtl and regno_reg_rtx around the reinitialization
  1616. to allow target_reinit being called even after prepare_function_start. */
  1617. saved_regno_reg_rtx = regno_reg_rtx;
  1618. if (saved_regno_reg_rtx)
  1619. {
  1620. saved_x_rtl = *crtl;
  1621. memset (crtl, '\0', sizeof (*crtl));
  1622. regno_reg_rtx = NULL;
  1623. }
  1624. this_target_rtl->target_specific_initialized = false;
  1625. /* This initializes hard_frame_pointer, and calls init_reg_modes_target()
  1626. to initialize reg_raw_mode[]. */
  1627. init_emit_regs ();
  1628. /* This invokes target hooks to set fixed_reg[] etc, which is
  1629. mode-dependent. */
  1630. init_regs ();
  1631. /* Reinitialize lang-dependent parts. */
  1632. lang_dependent_init_target ();
  1633. /* Restore the original optimization node. */
  1634. if (saved_optimization_current_node != optimization_default_node)
  1635. {
  1636. optimization_current_node = saved_optimization_current_node;
  1637. cl_optimization_restore (&global_options,
  1638. TREE_OPTIMIZATION (optimization_current_node));
  1639. }
  1640. this_fn_optabs = saved_this_fn_optabs;
  1641. /* Restore regno_reg_rtx at the end, as free_after_compilation from
  1642. expand_dummy_function_end clears it. */
  1643. if (saved_regno_reg_rtx)
  1644. {
  1645. *crtl = saved_x_rtl;
  1646. regno_reg_rtx = saved_regno_reg_rtx;
  1647. saved_regno_reg_rtx = NULL;
  1648. }
  1649. }
  1650. void
  1651. dump_memory_report (bool final)
  1652. {
  1653. dump_line_table_statistics ();
  1654. ggc_print_statistics ();
  1655. stringpool_statistics ();
  1656. dump_tree_statistics ();
  1657. dump_gimple_statistics ();
  1658. dump_rtx_statistics ();
  1659. dump_alloc_pool_statistics ();
  1660. dump_bitmap_statistics ();
  1661. dump_vec_loc_statistics ();
  1662. dump_ggc_loc_statistics (final);
  1663. dump_alias_stats (stderr);
  1664. dump_pta_stats (stderr);
  1665. }
  1666. /* Clean up: close opened files, etc. */
  1667. static void
  1668. finalize (bool no_backend)
  1669. {
  1670. /* Close the dump files. */
  1671. if (flag_gen_aux_info)
  1672. {
  1673. fclose (aux_info_file);
  1674. if (seen_error ())
  1675. unlink (aux_info_file_name);
  1676. }
  1677. /* Close non-debugging input and output files. Take special care to note
  1678. whether fclose returns an error, since the pages might still be on the
  1679. buffer chain while the file is open. */
  1680. if (asm_out_file)
  1681. {
  1682. if (ferror (asm_out_file) != 0)
  1683. fatal_error (input_location, "error writing to %s: %m", asm_file_name);
  1684. if (fclose (asm_out_file) != 0)
  1685. fatal_error (input_location, "error closing %s: %m", asm_file_name);
  1686. }
  1687. if (stack_usage_file)
  1688. fclose (stack_usage_file);
  1689. if (!no_backend)
  1690. {
  1691. statistics_fini ();
  1692. g->get_passes ()->finish_optimization_passes ();
  1693. lra_finish_once ();
  1694. }
  1695. if (mem_report)
  1696. dump_memory_report (true);
  1697. if (profile_report)
  1698. dump_profile_report ();
  1699. /* Language-specific end of compilation actions. */
  1700. lang_hooks.finish ();
  1701. }
  1702. static bool
  1703. standard_type_bitsize (int bitsize)
  1704. {
  1705. /* As a special exception, we always want __int128 enabled if possible. */
  1706. if (bitsize == 128)
  1707. return false;
  1708. if (bitsize == CHAR_TYPE_SIZE
  1709. || bitsize == SHORT_TYPE_SIZE
  1710. || bitsize == INT_TYPE_SIZE
  1711. || bitsize == LONG_TYPE_SIZE
  1712. || bitsize == LONG_LONG_TYPE_SIZE)
  1713. return true;
  1714. return false;
  1715. }
  1716. /* Initialize the compiler, and compile the input file. */
  1717. static void
  1718. do_compile ()
  1719. {
  1720. process_options ();
  1721. /* Don't do any more if an error has already occurred. */
  1722. if (!seen_error ())
  1723. {
  1724. int i;
  1725. timevar_start (TV_PHASE_SETUP);
  1726. /* This must be run always, because it is needed to compute the FP
  1727. predefined macros, such as __LDBL_MAX__, for targets using non
  1728. default FP formats. */
  1729. init_adjust_machine_modes ();
  1730. init_derived_machine_modes ();
  1731. /* This must happen after the backend has a chance to process
  1732. command line options, but before the parsers are
  1733. initialized. */
  1734. for (i = 0; i < NUM_INT_N_ENTS; i ++)
  1735. if (targetm.scalar_mode_supported_p (int_n_data[i].m)
  1736. && ! standard_type_bitsize (int_n_data[i].bitsize))
  1737. int_n_enabled_p[i] = true;
  1738. else
  1739. int_n_enabled_p[i] = false;
  1740. /* Set up the back-end if requested. */
  1741. if (!no_backend)
  1742. backend_init ();
  1743. /* Language-dependent initialization. Returns true on success. */
  1744. if (lang_dependent_init (main_input_filename))
  1745. {
  1746. /* Initialize yet another pass. */
  1747. ggc_protect_identifiers = true;
  1748. symtab->initialize ();
  1749. init_final (main_input_filename);
  1750. coverage_init (aux_base_name);
  1751. statistics_init ();
  1752. invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
  1753. timevar_stop (TV_PHASE_SETUP);
  1754. compile_file ();
  1755. }
  1756. else
  1757. {
  1758. timevar_stop (TV_PHASE_SETUP);
  1759. }
  1760. timevar_start (TV_PHASE_FINALIZE);
  1761. finalize (no_backend);
  1762. timevar_stop (TV_PHASE_FINALIZE);
  1763. }
  1764. }
  1765. toplev::toplev (bool use_TV_TOTAL, bool init_signals)
  1766. : m_use_TV_TOTAL (use_TV_TOTAL),
  1767. m_init_signals (init_signals)
  1768. {
  1769. if (!m_use_TV_TOTAL)
  1770. start_timevars ();
  1771. }
  1772. toplev::~toplev ()
  1773. {
  1774. timevar_stop (TV_TOTAL);
  1775. timevar_print (stderr);
  1776. }
  1777. void
  1778. toplev::start_timevars ()
  1779. {
  1780. if (time_report || !quiet_flag || flag_detailed_statistics)
  1781. timevar_init ();
  1782. timevar_start (TV_TOTAL);
  1783. }
  1784. /* Entry point of cc1, cc1plus, jc1, f771, etc.
  1785. Exit code is FATAL_EXIT_CODE if can't open files or if there were
  1786. any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
  1787. It is not safe to call this function more than once. */
  1788. int
  1789. toplev::main (int argc, char **argv)
  1790. {
  1791. /* Parsing and gimplification sometimes need quite large stack.
  1792. Increase stack size limits if possible. */
  1793. stack_limit_increase (64 * 1024 * 1024);
  1794. expandargv (&argc, &argv);
  1795. /* Initialization of GCC's environment, and diagnostics. */
  1796. general_init (argv[0], m_init_signals);
  1797. /* One-off initialization of options that does not need to be
  1798. repeated when options are added for particular functions. */
  1799. init_options_once ();
  1800. /* Initialize global options structures; this must be repeated for
  1801. each structure used for parsing options. */
  1802. init_options_struct (&global_options, &global_options_set);
  1803. lang_hooks.init_options_struct (&global_options);
  1804. /* Convert the options to an array. */
  1805. decode_cmdline_options_to_array_default_mask (argc,
  1806. CONST_CAST2 (const char **,
  1807. char **, argv),
  1808. &save_decoded_options,
  1809. &save_decoded_options_count);
  1810. /* Perform language-specific options initialization. */
  1811. lang_hooks.init_options (save_decoded_options_count, save_decoded_options);
  1812. /* Parse the options and do minimal processing; basically just
  1813. enough to default flags appropriately. */
  1814. decode_options (&global_options, &global_options_set,
  1815. save_decoded_options, save_decoded_options_count,
  1816. UNKNOWN_LOCATION, global_dc);
  1817. handle_common_deferred_options ();
  1818. init_local_tick ();
  1819. initialize_plugins ();
  1820. if (version_flag)
  1821. print_version (stderr, "", true);
  1822. if (help_flag)
  1823. print_plugins_help (stderr, "");
  1824. /* Exit early if we can (e.g. -help). */
  1825. if (!exit_after_options)
  1826. {
  1827. if (m_use_TV_TOTAL)
  1828. start_timevars ();
  1829. do_compile ();
  1830. }
  1831. if (warningcount || errorcount || werrorcount)
  1832. print_ignored_options ();
  1833. /* Invoke registered plugin callbacks if any. Some plugins could
  1834. emit some diagnostics here. */
  1835. invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
  1836. diagnostic_finish (global_dc);
  1837. finalize_plugins ();
  1838. location_adhoc_data_fini (line_table);
  1839. if (seen_error () || werrorcount)
  1840. return (FATAL_EXIT_CODE);
  1841. return (SUCCESS_EXIT_CODE);
  1842. }
  1843. /* For those that want to, this function aims to clean up enough state that
  1844. you can call toplev::main again. */
  1845. void
  1846. toplev::finalize (void)
  1847. {
  1848. rtl_initialized = false;
  1849. this_target_rtl->target_specific_initialized = false;
  1850. /* Needs to be called before cgraph_c_finalize since it uses symtab. */
  1851. ipa_reference_c_finalize ();
  1852. cgraph_c_finalize ();
  1853. cgraphunit_c_finalize ();
  1854. dwarf2out_c_finalize ();
  1855. gcse_c_finalize ();
  1856. ipa_cp_c_finalize ();
  1857. ira_costs_c_finalize ();
  1858. params_c_finalize ();
  1859. finalize_options_struct (&global_options);
  1860. finalize_options_struct (&global_options_set);
  1861. XDELETEVEC (save_decoded_options);
  1862. /* Clean up the context (and pass_manager etc). */
  1863. delete g;
  1864. g = NULL;
  1865. obstack_free (&opts_obstack, NULL);
  1866. }