toplev.c.orig 68 KB

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