lto-lang.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /* Language-dependent hooks for LTO.
  2. Copyright (C) 2009-2015 Free Software Foundation, Inc.
  3. Contributed by CodeSourcery, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "flags.h"
  20. #include "tm.h"
  21. #include "hash-set.h"
  22. #include "machmode.h"
  23. #include "vec.h"
  24. #include "double-int.h"
  25. #include "input.h"
  26. #include "alias.h"
  27. #include "symtab.h"
  28. #include "wide-int.h"
  29. #include "inchash.h"
  30. #include "tree.h"
  31. #include "fold-const.h"
  32. #include "stringpool.h"
  33. #include "stor-layout.h"
  34. #include "target.h"
  35. #include "langhooks.h"
  36. #include "langhooks-def.h"
  37. #include "debug.h"
  38. #include "lto-tree.h"
  39. #include "lto.h"
  40. #include "tree-inline.h"
  41. #include "predict.h"
  42. #include "hard-reg-set.h"
  43. #include "input.h"
  44. #include "function.h"
  45. #include "basic-block.h"
  46. #include "tree-ssa-alias.h"
  47. #include "internal-fn.h"
  48. #include "gimple-expr.h"
  49. #include "is-a.h"
  50. #include "gimple.h"
  51. #include "diagnostic-core.h"
  52. #include "toplev.h"
  53. #include "hash-map.h"
  54. #include "plugin-api.h"
  55. #include "ipa-ref.h"
  56. #include "cgraph.h"
  57. #include "lto-streamer.h"
  58. #include "cilk.h"
  59. static tree lto_type_for_size (unsigned, int);
  60. static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
  61. static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
  62. static tree handle_const_attribute (tree *, tree, tree, int, bool *);
  63. static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
  64. static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
  65. static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
  66. static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
  67. static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
  68. static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
  69. static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
  70. static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *);
  71. static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
  72. static tree ignore_attribute (tree *, tree, tree, int, bool *);
  73. static tree handle_format_attribute (tree *, tree, tree, int, bool *);
  74. static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
  75. static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
  76. /* Table of machine-independent attributes supported in GIMPLE. */
  77. const struct attribute_spec lto_attribute_table[] =
  78. {
  79. /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
  80. do_diagnostic } */
  81. { "noreturn", 0, 0, true, false, false,
  82. handle_noreturn_attribute, false },
  83. { "leaf", 0, 0, true, false, false,
  84. handle_leaf_attribute, false },
  85. /* The same comments as for noreturn attributes apply to const ones. */
  86. { "const", 0, 0, true, false, false,
  87. handle_const_attribute, false },
  88. { "malloc", 0, 0, true, false, false,
  89. handle_malloc_attribute, false },
  90. { "pure", 0, 0, true, false, false,
  91. handle_pure_attribute, false },
  92. { "no vops", 0, 0, true, false, false,
  93. handle_novops_attribute, false },
  94. { "nonnull", 0, -1, false, true, true,
  95. handle_nonnull_attribute, false },
  96. { "nothrow", 0, 0, true, false, false,
  97. handle_nothrow_attribute, false },
  98. { "returns_twice", 0, 0, true, false, false,
  99. handle_returns_twice_attribute, false },
  100. { "sentinel", 0, 1, false, true, true,
  101. handle_sentinel_attribute, false },
  102. { "type generic", 0, 0, false, true, true,
  103. handle_type_generic_attribute, false },
  104. { "fn spec", 1, 1, false, true, true,
  105. handle_fnspec_attribute, false },
  106. { "transaction_pure", 0, 0, false, true, true,
  107. handle_transaction_pure_attribute, false },
  108. /* For internal use only. The leading '*' both prevents its usage in
  109. source code and signals that it may be overridden by machine tables. */
  110. { "*tm regparm", 0, 0, false, true, true,
  111. ignore_attribute, false },
  112. { NULL, 0, 0, false, false, false, NULL, false }
  113. };
  114. /* Give the specifications for the format attributes, used by C and all
  115. descendants. */
  116. const struct attribute_spec lto_format_attribute_table[] =
  117. {
  118. /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
  119. affects_type_identity } */
  120. { "format", 3, 3, false, true, true,
  121. handle_format_attribute, false },
  122. { "format_arg", 1, 1, false, true, true,
  123. handle_format_arg_attribute, false },
  124. { NULL, 0, 0, false, false, false, NULL, false }
  125. };
  126. enum built_in_attribute
  127. {
  128. #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
  129. #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
  130. #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
  131. #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
  132. #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
  133. #include "builtin-attrs.def"
  134. #undef DEF_ATTR_NULL_TREE
  135. #undef DEF_ATTR_INT
  136. #undef DEF_ATTR_STRING
  137. #undef DEF_ATTR_IDENT
  138. #undef DEF_ATTR_TREE_LIST
  139. ATTR_LAST
  140. };
  141. static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
  142. /* Builtin types. */
  143. enum lto_builtin_type
  144. {
  145. #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
  146. #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
  147. #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
  148. #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
  149. #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
  150. #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
  151. #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
  152. #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  153. ARG6) NAME,
  154. #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  155. ARG6, ARG7) NAME,
  156. #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  157. ARG6, ARG7, ARG8) NAME,
  158. #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
  159. #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
  160. #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
  161. #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
  162. #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
  163. #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
  164. NAME,
  165. #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  166. ARG6, ARG7) NAME,
  167. #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  168. ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
  169. #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
  170. #include "builtin-types.def"
  171. #undef DEF_PRIMITIVE_TYPE
  172. #undef DEF_FUNCTION_TYPE_0
  173. #undef DEF_FUNCTION_TYPE_1
  174. #undef DEF_FUNCTION_TYPE_2
  175. #undef DEF_FUNCTION_TYPE_3
  176. #undef DEF_FUNCTION_TYPE_4
  177. #undef DEF_FUNCTION_TYPE_5
  178. #undef DEF_FUNCTION_TYPE_6
  179. #undef DEF_FUNCTION_TYPE_7
  180. #undef DEF_FUNCTION_TYPE_8
  181. #undef DEF_FUNCTION_TYPE_VAR_0
  182. #undef DEF_FUNCTION_TYPE_VAR_1
  183. #undef DEF_FUNCTION_TYPE_VAR_2
  184. #undef DEF_FUNCTION_TYPE_VAR_3
  185. #undef DEF_FUNCTION_TYPE_VAR_4
  186. #undef DEF_FUNCTION_TYPE_VAR_5
  187. #undef DEF_FUNCTION_TYPE_VAR_7
  188. #undef DEF_FUNCTION_TYPE_VAR_11
  189. #undef DEF_POINTER_TYPE
  190. BT_LAST
  191. };
  192. typedef enum lto_builtin_type builtin_type;
  193. static GTY(()) tree builtin_types[(int) BT_LAST + 1];
  194. static GTY(()) tree string_type_node;
  195. static GTY(()) tree const_string_type_node;
  196. static GTY(()) tree wint_type_node;
  197. static GTY(()) tree intmax_type_node;
  198. static GTY(()) tree uintmax_type_node;
  199. static GTY(()) tree signed_size_type_node;
  200. /* Flags needed to process builtins.def. */
  201. int flag_isoc94;
  202. int flag_isoc99;
  203. int flag_isoc11;
  204. /* Attribute handlers. */
  205. /* Handle a "noreturn" attribute; arguments as in
  206. struct attribute_spec.handler. */
  207. static tree
  208. handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
  209. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  210. bool * ARG_UNUSED (no_add_attrs))
  211. {
  212. tree type = TREE_TYPE (*node);
  213. if (TREE_CODE (*node) == FUNCTION_DECL)
  214. TREE_THIS_VOLATILE (*node) = 1;
  215. else if (TREE_CODE (type) == POINTER_TYPE
  216. && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
  217. TREE_TYPE (*node)
  218. = build_pointer_type
  219. (build_type_variant (TREE_TYPE (type),
  220. TYPE_READONLY (TREE_TYPE (type)), 1));
  221. else
  222. gcc_unreachable ();
  223. return NULL_TREE;
  224. }
  225. /* Handle a "leaf" attribute; arguments as in
  226. struct attribute_spec.handler. */
  227. static tree
  228. handle_leaf_attribute (tree *node, tree name,
  229. tree ARG_UNUSED (args),
  230. int ARG_UNUSED (flags), bool *no_add_attrs)
  231. {
  232. if (TREE_CODE (*node) != FUNCTION_DECL)
  233. {
  234. warning (OPT_Wattributes, "%qE attribute ignored", name);
  235. *no_add_attrs = true;
  236. }
  237. if (!TREE_PUBLIC (*node))
  238. {
  239. warning (OPT_Wattributes, "%qE attribute has no effect on unit local functions", name);
  240. *no_add_attrs = true;
  241. }
  242. return NULL_TREE;
  243. }
  244. /* Handle a "const" attribute; arguments as in
  245. struct attribute_spec.handler. */
  246. static tree
  247. handle_const_attribute (tree *node, tree ARG_UNUSED (name),
  248. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  249. bool * ARG_UNUSED (no_add_attrs))
  250. {
  251. tree type = TREE_TYPE (*node);
  252. /* See FIXME comment on noreturn in c_common_attribute_table. */
  253. if (TREE_CODE (*node) == FUNCTION_DECL)
  254. TREE_READONLY (*node) = 1;
  255. else if (TREE_CODE (type) == POINTER_TYPE
  256. && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
  257. TREE_TYPE (*node)
  258. = build_pointer_type
  259. (build_type_variant (TREE_TYPE (type), 1,
  260. TREE_THIS_VOLATILE (TREE_TYPE (type))));
  261. else
  262. gcc_unreachable ();
  263. return NULL_TREE;
  264. }
  265. /* Handle a "malloc" attribute; arguments as in
  266. struct attribute_spec.handler. */
  267. static tree
  268. handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
  269. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  270. bool * ARG_UNUSED (no_add_attrs))
  271. {
  272. if (TREE_CODE (*node) == FUNCTION_DECL
  273. && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
  274. DECL_IS_MALLOC (*node) = 1;
  275. else
  276. gcc_unreachable ();
  277. return NULL_TREE;
  278. }
  279. /* Handle a "pure" attribute; arguments as in
  280. struct attribute_spec.handler. */
  281. static tree
  282. handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
  283. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  284. bool * ARG_UNUSED (no_add_attrs))
  285. {
  286. if (TREE_CODE (*node) == FUNCTION_DECL)
  287. DECL_PURE_P (*node) = 1;
  288. else
  289. gcc_unreachable ();
  290. return NULL_TREE;
  291. }
  292. /* Handle a "no vops" attribute; arguments as in
  293. struct attribute_spec.handler. */
  294. static tree
  295. handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
  296. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  297. bool *ARG_UNUSED (no_add_attrs))
  298. {
  299. gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
  300. DECL_IS_NOVOPS (*node) = 1;
  301. return NULL_TREE;
  302. }
  303. /* Helper for nonnull attribute handling; fetch the operand number
  304. from the attribute argument list. */
  305. static bool
  306. get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
  307. {
  308. /* Verify the arg number is a constant. */
  309. if (!tree_fits_uhwi_p (arg_num_expr))
  310. return false;
  311. *valp = TREE_INT_CST_LOW (arg_num_expr);
  312. return true;
  313. }
  314. /* Handle the "nonnull" attribute. */
  315. static tree
  316. handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
  317. tree args, int ARG_UNUSED (flags),
  318. bool * ARG_UNUSED (no_add_attrs))
  319. {
  320. tree type = *node;
  321. /* If no arguments are specified, all pointer arguments should be
  322. non-null. Verify a full prototype is given so that the arguments
  323. will have the correct types when we actually check them later. */
  324. if (!args)
  325. {
  326. gcc_assert (prototype_p (type));
  327. return NULL_TREE;
  328. }
  329. /* Argument list specified. Verify that each argument number references
  330. a pointer argument. */
  331. for (; args; args = TREE_CHAIN (args))
  332. {
  333. tree argument;
  334. unsigned HOST_WIDE_INT arg_num = 0, ck_num;
  335. if (!get_nonnull_operand (TREE_VALUE (args), &arg_num))
  336. gcc_unreachable ();
  337. argument = TYPE_ARG_TYPES (type);
  338. if (argument)
  339. {
  340. for (ck_num = 1; ; ck_num++)
  341. {
  342. if (!argument || ck_num == arg_num)
  343. break;
  344. argument = TREE_CHAIN (argument);
  345. }
  346. gcc_assert (argument
  347. && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE);
  348. }
  349. }
  350. return NULL_TREE;
  351. }
  352. /* Handle a "nothrow" attribute; arguments as in
  353. struct attribute_spec.handler. */
  354. static tree
  355. handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
  356. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  357. bool * ARG_UNUSED (no_add_attrs))
  358. {
  359. if (TREE_CODE (*node) == FUNCTION_DECL)
  360. TREE_NOTHROW (*node) = 1;
  361. else
  362. gcc_unreachable ();
  363. return NULL_TREE;
  364. }
  365. /* Handle a "sentinel" attribute. */
  366. static tree
  367. handle_sentinel_attribute (tree *node, tree ARG_UNUSED (name), tree args,
  368. int ARG_UNUSED (flags),
  369. bool * ARG_UNUSED (no_add_attrs))
  370. {
  371. gcc_assert (stdarg_p (*node));
  372. if (args)
  373. {
  374. tree position = TREE_VALUE (args);
  375. gcc_assert (TREE_CODE (position) == INTEGER_CST);
  376. if (tree_int_cst_lt (position, integer_zero_node))
  377. gcc_unreachable ();
  378. }
  379. return NULL_TREE;
  380. }
  381. /* Handle a "type_generic" attribute. */
  382. static tree
  383. handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
  384. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  385. bool * ARG_UNUSED (no_add_attrs))
  386. {
  387. /* Ensure we have a function type. */
  388. gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
  389. /* Ensure we have a variadic function. */
  390. gcc_assert (!prototype_p (*node) || stdarg_p (*node));
  391. return NULL_TREE;
  392. }
  393. /* Handle a "transaction_pure" attribute. */
  394. static tree
  395. handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
  396. tree ARG_UNUSED (args),
  397. int ARG_UNUSED (flags),
  398. bool * ARG_UNUSED (no_add_attrs))
  399. {
  400. /* Ensure we have a function type. */
  401. gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
  402. return NULL_TREE;
  403. }
  404. /* Handle a "returns_twice" attribute. */
  405. static tree
  406. handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
  407. tree ARG_UNUSED (args),
  408. int ARG_UNUSED (flags),
  409. bool * ARG_UNUSED (no_add_attrs))
  410. {
  411. gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
  412. DECL_IS_RETURNS_TWICE (*node) = 1;
  413. return NULL_TREE;
  414. }
  415. /* Ignore the given attribute. Used when this attribute may be usefully
  416. overridden by the target, but is not used generically. */
  417. static tree
  418. ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
  419. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  420. bool *no_add_attrs)
  421. {
  422. *no_add_attrs = true;
  423. return NULL_TREE;
  424. }
  425. /* Handle a "format" attribute; arguments as in
  426. struct attribute_spec.handler. */
  427. static tree
  428. handle_format_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
  429. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  430. bool *no_add_attrs)
  431. {
  432. *no_add_attrs = true;
  433. return NULL_TREE;
  434. }
  435. /* Handle a "format_arg" attribute; arguments as in
  436. struct attribute_spec.handler. */
  437. tree
  438. handle_format_arg_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
  439. tree ARG_UNUSED (args), int ARG_UNUSED (flags),
  440. bool *no_add_attrs)
  441. {
  442. *no_add_attrs = true;
  443. return NULL_TREE;
  444. }
  445. /* Handle a "fn spec" attribute; arguments as in
  446. struct attribute_spec.handler. */
  447. static tree
  448. handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
  449. tree args, int ARG_UNUSED (flags),
  450. bool *no_add_attrs ATTRIBUTE_UNUSED)
  451. {
  452. gcc_assert (args
  453. && TREE_CODE (TREE_VALUE (args)) == STRING_CST
  454. && !TREE_CHAIN (args));
  455. return NULL_TREE;
  456. }
  457. /* Cribbed from c-common.c. */
  458. static void
  459. def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
  460. {
  461. tree t;
  462. tree *args = XALLOCAVEC (tree, n);
  463. va_list list;
  464. int i;
  465. bool err = false;
  466. va_start (list, n);
  467. for (i = 0; i < n; ++i)
  468. {
  469. builtin_type a = (builtin_type) va_arg (list, int);
  470. t = builtin_types[a];
  471. if (t == error_mark_node)
  472. err = true;
  473. args[i] = t;
  474. }
  475. va_end (list);
  476. t = builtin_types[ret];
  477. if (err)
  478. t = error_mark_node;
  479. if (t == error_mark_node)
  480. ;
  481. else if (var)
  482. t = build_varargs_function_type_array (t, n, args);
  483. else
  484. t = build_function_type_array (t, n, args);
  485. builtin_types[def] = t;
  486. }
  487. /* Used to help initialize the builtin-types.def table. When a type of
  488. the correct size doesn't exist, use error_mark_node instead of NULL.
  489. The later results in segfaults even when a decl using the type doesn't
  490. get invoked. */
  491. static tree
  492. builtin_type_for_size (int size, bool unsignedp)
  493. {
  494. tree type = lto_type_for_size (size, unsignedp);
  495. return type ? type : error_mark_node;
  496. }
  497. /* Support for DEF_BUILTIN. */
  498. static void
  499. def_builtin_1 (enum built_in_function fncode, const char *name,
  500. enum built_in_class fnclass, tree fntype, tree libtype,
  501. bool both_p, bool fallback_p, bool nonansi_p,
  502. tree fnattrs, bool implicit_p)
  503. {
  504. tree decl;
  505. const char *libname;
  506. if (fntype == error_mark_node)
  507. return;
  508. libname = name + strlen ("__builtin_");
  509. decl = add_builtin_function (name, fntype, fncode, fnclass,
  510. (fallback_p ? libname : NULL),
  511. fnattrs);
  512. if (both_p
  513. && !flag_no_builtin
  514. && !(nonansi_p && flag_no_nonansi_builtin))
  515. add_builtin_function (libname, libtype, fncode, fnclass,
  516. NULL, fnattrs);
  517. set_builtin_decl (fncode, decl, implicit_p);
  518. }
  519. /* Initialize the attribute table for all the supported builtins. */
  520. static void
  521. lto_init_attributes (void)
  522. {
  523. /* Fill in the built_in_attributes array. */
  524. #define DEF_ATTR_NULL_TREE(ENUM) \
  525. built_in_attributes[(int) ENUM] = NULL_TREE;
  526. #define DEF_ATTR_INT(ENUM, VALUE) \
  527. built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
  528. #define DEF_ATTR_STRING(ENUM, VALUE) \
  529. built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
  530. #define DEF_ATTR_IDENT(ENUM, STRING) \
  531. built_in_attributes[(int) ENUM] = get_identifier (STRING);
  532. #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
  533. built_in_attributes[(int) ENUM] \
  534. = tree_cons (built_in_attributes[(int) PURPOSE], \
  535. built_in_attributes[(int) VALUE], \
  536. built_in_attributes[(int) CHAIN]);
  537. #include "builtin-attrs.def"
  538. #undef DEF_ATTR_NULL_TREE
  539. #undef DEF_ATTR_INT
  540. #undef DEF_ATTR_STRING
  541. #undef DEF_ATTR_IDENT
  542. #undef DEF_ATTR_TREE_LIST
  543. }
  544. /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
  545. VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
  546. static void
  547. lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
  548. tree va_list_arg_type_node ATTRIBUTE_UNUSED)
  549. {
  550. #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
  551. builtin_types[ENUM] = VALUE;
  552. #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
  553. def_fn_type (ENUM, RETURN, 0, 0);
  554. #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
  555. def_fn_type (ENUM, RETURN, 0, 1, ARG1);
  556. #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
  557. def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
  558. #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
  559. def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
  560. #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
  561. def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
  562. #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
  563. def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
  564. #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  565. ARG6) \
  566. def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
  567. #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  568. ARG6, ARG7) \
  569. def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
  570. #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  571. ARG6, ARG7, ARG8) \
  572. def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
  573. ARG7, ARG8);
  574. #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
  575. def_fn_type (ENUM, RETURN, 1, 0);
  576. #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
  577. def_fn_type (ENUM, RETURN, 1, 1, ARG1);
  578. #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
  579. def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
  580. #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
  581. def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
  582. #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
  583. def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
  584. #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
  585. def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
  586. #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  587. ARG6, ARG7) \
  588. def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
  589. #define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  590. ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
  591. def_fn_type (ENUM, RETURN, 1, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
  592. ARG7, ARG8, ARG9, ARG10, ARG11);
  593. #define DEF_POINTER_TYPE(ENUM, TYPE) \
  594. builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
  595. #include "builtin-types.def"
  596. #undef DEF_PRIMITIVE_TYPE
  597. #undef DEF_FUNCTION_TYPE_0
  598. #undef DEF_FUNCTION_TYPE_1
  599. #undef DEF_FUNCTION_TYPE_2
  600. #undef DEF_FUNCTION_TYPE_3
  601. #undef DEF_FUNCTION_TYPE_4
  602. #undef DEF_FUNCTION_TYPE_5
  603. #undef DEF_FUNCTION_TYPE_6
  604. #undef DEF_FUNCTION_TYPE_7
  605. #undef DEF_FUNCTION_TYPE_8
  606. #undef DEF_FUNCTION_TYPE_VAR_0
  607. #undef DEF_FUNCTION_TYPE_VAR_1
  608. #undef DEF_FUNCTION_TYPE_VAR_2
  609. #undef DEF_FUNCTION_TYPE_VAR_3
  610. #undef DEF_FUNCTION_TYPE_VAR_4
  611. #undef DEF_FUNCTION_TYPE_VAR_5
  612. #undef DEF_FUNCTION_TYPE_VAR_7
  613. #undef DEF_FUNCTION_TYPE_VAR_11
  614. #undef DEF_POINTER_TYPE
  615. builtin_types[(int) BT_LAST] = NULL_TREE;
  616. lto_init_attributes ();
  617. #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
  618. NONANSI_P, ATTRS, IMPLICIT, COND) \
  619. if (NAME && COND) \
  620. def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
  621. builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
  622. NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
  623. #include "builtins.def"
  624. #undef DEF_BUILTIN
  625. }
  626. static GTY(()) tree registered_builtin_types;
  627. /* Language hooks. */
  628. static unsigned int
  629. lto_option_lang_mask (void)
  630. {
  631. return CL_LTO;
  632. }
  633. static bool
  634. lto_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
  635. {
  636. /* The LTO front end inherits all the options from the first front
  637. end that was used. However, not all the original front end
  638. options make sense in LTO.
  639. A real solution would be to filter this in collect2, but collect2
  640. does not have access to all the option attributes to know what to
  641. filter. So, in lto1 we silently accept inherited flags and do
  642. nothing about it. */
  643. return false;
  644. }
  645. static void
  646. lto_init_options_struct (struct gcc_options *opts)
  647. {
  648. /* By default, C99-like requirements for complex multiply and divide.
  649. ??? Until the complex method is encoded in the IL this is the only
  650. safe choice. This will pessimize Fortran code with LTO unless
  651. people specify a complex method manually or use -ffast-math. */
  652. opts->x_flag_complex_method = 2;
  653. }
  654. /* Handle command-line option SCODE. If the option takes an argument, it is
  655. stored in ARG, which is otherwise NULL. VALUE holds either a numerical
  656. argument or a binary value indicating whether the positive or negative form
  657. of the option was supplied. */
  658. const char *resolution_file_name;
  659. static bool
  660. lto_handle_option (size_t scode, const char *arg,
  661. int value ATTRIBUTE_UNUSED, int kind ATTRIBUTE_UNUSED,
  662. location_t loc ATTRIBUTE_UNUSED,
  663. const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
  664. {
  665. enum opt_code code = (enum opt_code) scode;
  666. bool result = true;
  667. switch (code)
  668. {
  669. case OPT_fresolution_:
  670. resolution_file_name = arg;
  671. break;
  672. case OPT_Wabi:
  673. warn_psabi = value;
  674. break;
  675. case OPT_fwpa:
  676. flag_wpa = value ? "" : NULL;
  677. break;
  678. default:
  679. break;
  680. }
  681. return result;
  682. }
  683. /* Perform post-option processing. Does additional initialization based on
  684. command-line options. PFILENAME is the main input filename. Returns false
  685. to enable subsequent back-end initialization. */
  686. static bool
  687. lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
  688. {
  689. /* -fltrans and -fwpa are mutually exclusive. Check for that here. */
  690. if (flag_wpa && flag_ltrans)
  691. error ("-fwpa and -fltrans are mutually exclusive");
  692. if (flag_ltrans)
  693. {
  694. flag_generate_lto = 0;
  695. /* During LTRANS, we are not looking at the whole program, only
  696. a subset of the whole callgraph. */
  697. flag_whole_program = 0;
  698. }
  699. if (flag_wpa)
  700. flag_generate_lto = 1;
  701. /* Excess precision other than "fast" requires front-end
  702. support. */
  703. flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
  704. /* Initialize the compiler back end. */
  705. return false;
  706. }
  707. /* Return an integer type with PRECISION bits of precision,
  708. that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
  709. static tree
  710. lto_type_for_size (unsigned precision, int unsignedp)
  711. {
  712. if (precision == TYPE_PRECISION (integer_type_node))
  713. return unsignedp ? unsigned_type_node : integer_type_node;
  714. if (precision == TYPE_PRECISION (signed_char_type_node))
  715. return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  716. if (precision == TYPE_PRECISION (short_integer_type_node))
  717. return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  718. if (precision == TYPE_PRECISION (long_integer_type_node))
  719. return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  720. if (precision == TYPE_PRECISION (long_long_integer_type_node))
  721. return unsignedp
  722. ? long_long_unsigned_type_node
  723. : long_long_integer_type_node;
  724. if (precision <= TYPE_PRECISION (intQI_type_node))
  725. return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
  726. if (precision <= TYPE_PRECISION (intHI_type_node))
  727. return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
  728. if (precision <= TYPE_PRECISION (intSI_type_node))
  729. return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
  730. if (precision <= TYPE_PRECISION (intDI_type_node))
  731. return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
  732. if (precision <= TYPE_PRECISION (intTI_type_node))
  733. return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
  734. return NULL_TREE;
  735. }
  736. /* Return a data type that has machine mode MODE.
  737. If the mode is an integer,
  738. then UNSIGNEDP selects between signed and unsigned types.
  739. If the mode is a fixed-point mode,
  740. then UNSIGNEDP selects between saturating and nonsaturating types. */
  741. static tree
  742. lto_type_for_mode (machine_mode mode, int unsigned_p)
  743. {
  744. tree t;
  745. if (mode == TYPE_MODE (integer_type_node))
  746. return unsigned_p ? unsigned_type_node : integer_type_node;
  747. if (mode == TYPE_MODE (signed_char_type_node))
  748. return unsigned_p ? unsigned_char_type_node : signed_char_type_node;
  749. if (mode == TYPE_MODE (short_integer_type_node))
  750. return unsigned_p ? short_unsigned_type_node : short_integer_type_node;
  751. if (mode == TYPE_MODE (long_integer_type_node))
  752. return unsigned_p ? long_unsigned_type_node : long_integer_type_node;
  753. if (mode == TYPE_MODE (long_long_integer_type_node))
  754. return unsigned_p ? long_long_unsigned_type_node : long_long_integer_type_node;
  755. if (mode == QImode)
  756. return unsigned_p ? unsigned_intQI_type_node : intQI_type_node;
  757. if (mode == HImode)
  758. return unsigned_p ? unsigned_intHI_type_node : intHI_type_node;
  759. if (mode == SImode)
  760. return unsigned_p ? unsigned_intSI_type_node : intSI_type_node;
  761. if (mode == DImode)
  762. return unsigned_p ? unsigned_intDI_type_node : intDI_type_node;
  763. #if HOST_BITS_PER_WIDE_INT >= 64
  764. if (mode == TYPE_MODE (intTI_type_node))
  765. return unsigned_p ? unsigned_intTI_type_node : intTI_type_node;
  766. #endif
  767. if (mode == TYPE_MODE (float_type_node))
  768. return float_type_node;
  769. if (mode == TYPE_MODE (double_type_node))
  770. return double_type_node;
  771. if (mode == TYPE_MODE (long_double_type_node))
  772. return long_double_type_node;
  773. if (mode == TYPE_MODE (void_type_node))
  774. return void_type_node;
  775. if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
  776. return (unsigned_p
  777. ? make_unsigned_type (GET_MODE_PRECISION (mode))
  778. : make_signed_type (GET_MODE_PRECISION (mode)));
  779. if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
  780. return (unsigned_p
  781. ? make_unsigned_type (GET_MODE_PRECISION (mode))
  782. : make_signed_type (GET_MODE_PRECISION (mode)));
  783. if (COMPLEX_MODE_P (mode))
  784. {
  785. machine_mode inner_mode;
  786. tree inner_type;
  787. if (mode == TYPE_MODE (complex_float_type_node))
  788. return complex_float_type_node;
  789. if (mode == TYPE_MODE (complex_double_type_node))
  790. return complex_double_type_node;
  791. if (mode == TYPE_MODE (complex_long_double_type_node))
  792. return complex_long_double_type_node;
  793. if (mode == TYPE_MODE (complex_integer_type_node) && !unsigned_p)
  794. return complex_integer_type_node;
  795. inner_mode = GET_MODE_INNER (mode);
  796. inner_type = lto_type_for_mode (inner_mode, unsigned_p);
  797. if (inner_type != NULL_TREE)
  798. return build_complex_type (inner_type);
  799. }
  800. else if (VECTOR_MODE_P (mode))
  801. {
  802. machine_mode inner_mode = GET_MODE_INNER (mode);
  803. tree inner_type = lto_type_for_mode (inner_mode, unsigned_p);
  804. if (inner_type != NULL_TREE)
  805. return build_vector_type_for_mode (inner_type, mode);
  806. }
  807. if (mode == TYPE_MODE (dfloat32_type_node))
  808. return dfloat32_type_node;
  809. if (mode == TYPE_MODE (dfloat64_type_node))
  810. return dfloat64_type_node;
  811. if (mode == TYPE_MODE (dfloat128_type_node))
  812. return dfloat128_type_node;
  813. if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
  814. {
  815. if (mode == TYPE_MODE (short_fract_type_node))
  816. return unsigned_p ? sat_short_fract_type_node : short_fract_type_node;
  817. if (mode == TYPE_MODE (fract_type_node))
  818. return unsigned_p ? sat_fract_type_node : fract_type_node;
  819. if (mode == TYPE_MODE (long_fract_type_node))
  820. return unsigned_p ? sat_long_fract_type_node : long_fract_type_node;
  821. if (mode == TYPE_MODE (long_long_fract_type_node))
  822. return unsigned_p ? sat_long_long_fract_type_node
  823. : long_long_fract_type_node;
  824. if (mode == TYPE_MODE (unsigned_short_fract_type_node))
  825. return unsigned_p ? sat_unsigned_short_fract_type_node
  826. : unsigned_short_fract_type_node;
  827. if (mode == TYPE_MODE (unsigned_fract_type_node))
  828. return unsigned_p ? sat_unsigned_fract_type_node
  829. : unsigned_fract_type_node;
  830. if (mode == TYPE_MODE (unsigned_long_fract_type_node))
  831. return unsigned_p ? sat_unsigned_long_fract_type_node
  832. : unsigned_long_fract_type_node;
  833. if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
  834. return unsigned_p ? sat_unsigned_long_long_fract_type_node
  835. : unsigned_long_long_fract_type_node;
  836. if (mode == TYPE_MODE (short_accum_type_node))
  837. return unsigned_p ? sat_short_accum_type_node : short_accum_type_node;
  838. if (mode == TYPE_MODE (accum_type_node))
  839. return unsigned_p ? sat_accum_type_node : accum_type_node;
  840. if (mode == TYPE_MODE (long_accum_type_node))
  841. return unsigned_p ? sat_long_accum_type_node : long_accum_type_node;
  842. if (mode == TYPE_MODE (long_long_accum_type_node))
  843. return unsigned_p ? sat_long_long_accum_type_node
  844. : long_long_accum_type_node;
  845. if (mode == TYPE_MODE (unsigned_short_accum_type_node))
  846. return unsigned_p ? sat_unsigned_short_accum_type_node
  847. : unsigned_short_accum_type_node;
  848. if (mode == TYPE_MODE (unsigned_accum_type_node))
  849. return unsigned_p ? sat_unsigned_accum_type_node
  850. : unsigned_accum_type_node;
  851. if (mode == TYPE_MODE (unsigned_long_accum_type_node))
  852. return unsigned_p ? sat_unsigned_long_accum_type_node
  853. : unsigned_long_accum_type_node;
  854. if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
  855. return unsigned_p ? sat_unsigned_long_long_accum_type_node
  856. : unsigned_long_long_accum_type_node;
  857. if (mode == QQmode)
  858. return unsigned_p ? sat_qq_type_node : qq_type_node;
  859. if (mode == HQmode)
  860. return unsigned_p ? sat_hq_type_node : hq_type_node;
  861. if (mode == SQmode)
  862. return unsigned_p ? sat_sq_type_node : sq_type_node;
  863. if (mode == DQmode)
  864. return unsigned_p ? sat_dq_type_node : dq_type_node;
  865. if (mode == TQmode)
  866. return unsigned_p ? sat_tq_type_node : tq_type_node;
  867. if (mode == UQQmode)
  868. return unsigned_p ? sat_uqq_type_node : uqq_type_node;
  869. if (mode == UHQmode)
  870. return unsigned_p ? sat_uhq_type_node : uhq_type_node;
  871. if (mode == USQmode)
  872. return unsigned_p ? sat_usq_type_node : usq_type_node;
  873. if (mode == UDQmode)
  874. return unsigned_p ? sat_udq_type_node : udq_type_node;
  875. if (mode == UTQmode)
  876. return unsigned_p ? sat_utq_type_node : utq_type_node;
  877. if (mode == HAmode)
  878. return unsigned_p ? sat_ha_type_node : ha_type_node;
  879. if (mode == SAmode)
  880. return unsigned_p ? sat_sa_type_node : sa_type_node;
  881. if (mode == DAmode)
  882. return unsigned_p ? sat_da_type_node : da_type_node;
  883. if (mode == TAmode)
  884. return unsigned_p ? sat_ta_type_node : ta_type_node;
  885. if (mode == UHAmode)
  886. return unsigned_p ? sat_uha_type_node : uha_type_node;
  887. if (mode == USAmode)
  888. return unsigned_p ? sat_usa_type_node : usa_type_node;
  889. if (mode == UDAmode)
  890. return unsigned_p ? sat_uda_type_node : uda_type_node;
  891. if (mode == UTAmode)
  892. return unsigned_p ? sat_uta_type_node : uta_type_node;
  893. }
  894. for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
  895. if (TYPE_MODE (TREE_VALUE (t)) == mode)
  896. return TREE_VALUE (t);
  897. return NULL_TREE;
  898. }
  899. /* Return true if we are in the global binding level. */
  900. static bool
  901. lto_global_bindings_p (void)
  902. {
  903. return cfun == NULL;
  904. }
  905. static void
  906. lto_set_decl_assembler_name (tree decl)
  907. {
  908. /* This is almost the same as lhd_set_decl_assembler_name, except that
  909. we need to uniquify file-scope names, even if they are not
  910. TREE_PUBLIC, to avoid conflicts between individual files. */
  911. tree id;
  912. if (TREE_PUBLIC (decl))
  913. id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
  914. else
  915. {
  916. const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
  917. char *label;
  918. ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
  919. id = get_identifier (label);
  920. }
  921. SET_DECL_ASSEMBLER_NAME (decl, id);
  922. }
  923. static tree
  924. lto_pushdecl (tree t ATTRIBUTE_UNUSED)
  925. {
  926. /* Do nothing, since we get all information from DWARF and LTO
  927. sections. */
  928. return NULL_TREE;
  929. }
  930. static tree
  931. lto_getdecls (void)
  932. {
  933. /* We have our own write_globals langhook, hence the getdecls
  934. langhook shouldn't be used, except by dbxout.c, so we can't
  935. just abort here. */
  936. return NULL_TREE;
  937. }
  938. static void
  939. lto_write_globals (void)
  940. {
  941. if (flag_wpa)
  942. return;
  943. /* Output debug info for global variables. */
  944. varpool_node *vnode;
  945. FOR_EACH_DEFINED_VARIABLE (vnode)
  946. if (!decl_function_context (vnode->decl))
  947. debug_hooks->global_decl (vnode->decl);
  948. }
  949. static tree
  950. lto_builtin_function (tree decl)
  951. {
  952. return decl;
  953. }
  954. static void
  955. lto_register_builtin_type (tree type, const char *name)
  956. {
  957. tree decl;
  958. if (!TYPE_NAME (type))
  959. {
  960. decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
  961. get_identifier (name), type);
  962. DECL_ARTIFICIAL (decl) = 1;
  963. TYPE_NAME (type) = decl;
  964. }
  965. registered_builtin_types = tree_cons (0, type, registered_builtin_types);
  966. }
  967. /* Build nodes that would have be created by the C front-end; necessary
  968. for including builtin-types.def and ultimately builtins.def. */
  969. static void
  970. lto_build_c_type_nodes (void)
  971. {
  972. gcc_assert (void_type_node);
  973. void_list_node = build_tree_list (NULL_TREE, void_type_node);
  974. string_type_node = build_pointer_type (char_type_node);
  975. const_string_type_node
  976. = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
  977. if (strcmp (SIZE_TYPE, "unsigned int") == 0)
  978. {
  979. intmax_type_node = integer_type_node;
  980. uintmax_type_node = unsigned_type_node;
  981. signed_size_type_node = integer_type_node;
  982. }
  983. else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
  984. {
  985. intmax_type_node = long_integer_type_node;
  986. uintmax_type_node = long_unsigned_type_node;
  987. signed_size_type_node = long_integer_type_node;
  988. }
  989. else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
  990. {
  991. intmax_type_node = long_long_integer_type_node;
  992. uintmax_type_node = long_long_unsigned_type_node;
  993. signed_size_type_node = long_long_integer_type_node;
  994. }
  995. else
  996. {
  997. int i;
  998. signed_size_type_node = NULL_TREE;
  999. for (i = 0; i < NUM_INT_N_ENTS; i++)
  1000. if (int_n_enabled_p[i])
  1001. {
  1002. char name[50];
  1003. sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
  1004. if (strcmp (name, SIZE_TYPE) == 0)
  1005. {
  1006. intmax_type_node = int_n_trees[i].signed_type;
  1007. uintmax_type_node = int_n_trees[i].unsigned_type;
  1008. signed_size_type_node = int_n_trees[i].signed_type;
  1009. }
  1010. }
  1011. if (signed_size_type_node == NULL_TREE)
  1012. gcc_unreachable ();
  1013. }
  1014. wint_type_node = unsigned_type_node;
  1015. pid_type_node = integer_type_node;
  1016. }
  1017. /* Perform LTO-specific initialization. */
  1018. static bool
  1019. lto_init (void)
  1020. {
  1021. int i;
  1022. /* We need to generate LTO if running in WPA mode. */
  1023. flag_generate_lto = (flag_wpa != NULL);
  1024. /* Create the basic integer types. */
  1025. build_common_tree_nodes (flag_signed_char, flag_short_double);
  1026. /* The global tree for the main identifier is filled in by
  1027. language-specific front-end initialization that is not run in the
  1028. LTO back-end. It appears that all languages that perform such
  1029. initialization currently do so in the same way, so we do it here. */
  1030. if (main_identifier_node == NULL_TREE)
  1031. main_identifier_node = get_identifier ("main");
  1032. /* In the C++ front-end, fileptr_type_node is defined as a variant
  1033. copy of of ptr_type_node, rather than ptr_node itself. The
  1034. distinction should only be relevant to the front-end, so we
  1035. always use the C definition here in lto1. */
  1036. gcc_assert (fileptr_type_node == ptr_type_node);
  1037. gcc_assert (TYPE_MAIN_VARIANT (fileptr_type_node) == ptr_type_node);
  1038. ptrdiff_type_node = integer_type_node;
  1039. lto_build_c_type_nodes ();
  1040. gcc_assert (va_list_type_node);
  1041. if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
  1042. {
  1043. tree x = build_pointer_type (TREE_TYPE (va_list_type_node));
  1044. lto_define_builtins (x, x);
  1045. }
  1046. else
  1047. {
  1048. lto_define_builtins (build_reference_type (va_list_type_node),
  1049. va_list_type_node);
  1050. }
  1051. if (flag_cilkplus)
  1052. cilk_init_builtins ();
  1053. targetm.init_builtins ();
  1054. build_common_builtin_nodes ();
  1055. /* Assign names to the builtin types, otherwise they'll end up
  1056. as __unknown__ in debug info.
  1057. ??? We simply need to stop pre-seeding the streamer cache.
  1058. Below is modeled after from c-common.c:c_common_nodes_and_builtins */
  1059. #define NAME_TYPE(t,n) \
  1060. if (t) \
  1061. TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \
  1062. get_identifier (n), t)
  1063. NAME_TYPE (integer_type_node, "int");
  1064. NAME_TYPE (char_type_node, "char");
  1065. NAME_TYPE (long_integer_type_node, "long int");
  1066. NAME_TYPE (unsigned_type_node, "unsigned int");
  1067. NAME_TYPE (long_unsigned_type_node, "long unsigned int");
  1068. NAME_TYPE (long_long_integer_type_node, "long long int");
  1069. NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int");
  1070. NAME_TYPE (short_integer_type_node, "short int");
  1071. NAME_TYPE (short_unsigned_type_node, "short unsigned int");
  1072. if (signed_char_type_node != char_type_node)
  1073. NAME_TYPE (signed_char_type_node, "signed char");
  1074. if (unsigned_char_type_node != char_type_node)
  1075. NAME_TYPE (unsigned_char_type_node, "unsigned char");
  1076. NAME_TYPE (float_type_node, "float");
  1077. NAME_TYPE (double_type_node, "double");
  1078. NAME_TYPE (long_double_type_node, "long double");
  1079. NAME_TYPE (void_type_node, "void");
  1080. NAME_TYPE (boolean_type_node, "bool");
  1081. NAME_TYPE (complex_float_type_node, "complex float");
  1082. NAME_TYPE (complex_double_type_node, "complex double");
  1083. NAME_TYPE (complex_long_double_type_node, "complex long double");
  1084. for (i = 0; i < NUM_INT_N_ENTS; i++)
  1085. if (int_n_enabled_p[i])
  1086. {
  1087. char name[50];
  1088. sprintf (name, "__int%d", int_n_data[i].bitsize);
  1089. NAME_TYPE (int_n_trees[i].signed_type, name);
  1090. }
  1091. #undef NAME_TYPE
  1092. /* Initialize LTO-specific data structures. */
  1093. in_lto_p = true;
  1094. return true;
  1095. }
  1096. /* Initialize tree structures required by the LTO front end. */
  1097. static void lto_init_ts (void)
  1098. {
  1099. tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
  1100. }
  1101. #undef LANG_HOOKS_NAME
  1102. #define LANG_HOOKS_NAME "GNU GIMPLE"
  1103. #undef LANG_HOOKS_OPTION_LANG_MASK
  1104. #define LANG_HOOKS_OPTION_LANG_MASK lto_option_lang_mask
  1105. #undef LANG_HOOKS_COMPLAIN_WRONG_LANG_P
  1106. #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lto_complain_wrong_lang_p
  1107. #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
  1108. #define LANG_HOOKS_INIT_OPTIONS_STRUCT lto_init_options_struct
  1109. #undef LANG_HOOKS_HANDLE_OPTION
  1110. #define LANG_HOOKS_HANDLE_OPTION lto_handle_option
  1111. #undef LANG_HOOKS_POST_OPTIONS
  1112. #define LANG_HOOKS_POST_OPTIONS lto_post_options
  1113. #undef LANG_HOOKS_GET_ALIAS_SET
  1114. #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
  1115. #undef LANG_HOOKS_TYPE_FOR_MODE
  1116. #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
  1117. #undef LANG_HOOKS_TYPE_FOR_SIZE
  1118. #define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
  1119. #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
  1120. #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
  1121. #undef LANG_HOOKS_GLOBAL_BINDINGS_P
  1122. #define LANG_HOOKS_GLOBAL_BINDINGS_P lto_global_bindings_p
  1123. #undef LANG_HOOKS_PUSHDECL
  1124. #define LANG_HOOKS_PUSHDECL lto_pushdecl
  1125. #undef LANG_HOOKS_GETDECLS
  1126. #define LANG_HOOKS_GETDECLS lto_getdecls
  1127. #undef LANG_HOOKS_WRITE_GLOBALS
  1128. #define LANG_HOOKS_WRITE_GLOBALS lto_write_globals
  1129. #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
  1130. #define LANG_HOOKS_REGISTER_BUILTIN_TYPE lto_register_builtin_type
  1131. #undef LANG_HOOKS_BUILTIN_FUNCTION
  1132. #define LANG_HOOKS_BUILTIN_FUNCTION lto_builtin_function
  1133. #undef LANG_HOOKS_INIT
  1134. #define LANG_HOOKS_INIT lto_init
  1135. #undef LANG_HOOKS_PARSE_FILE
  1136. #define LANG_HOOKS_PARSE_FILE lto_main
  1137. #undef LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS
  1138. #define LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS true
  1139. #undef LANG_HOOKS_TYPES_COMPATIBLE_P
  1140. #define LANG_HOOKS_TYPES_COMPATIBLE_P NULL
  1141. #undef LANG_HOOKS_EH_PERSONALITY
  1142. #define LANG_HOOKS_EH_PERSONALITY lto_eh_personality
  1143. /* Attribute hooks. */
  1144. #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
  1145. #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lto_attribute_table
  1146. #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
  1147. #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE lto_format_attribute_table
  1148. #undef LANG_HOOKS_BEGIN_SECTION
  1149. #define LANG_HOOKS_BEGIN_SECTION lto_obj_begin_section
  1150. #undef LANG_HOOKS_APPEND_DATA
  1151. #define LANG_HOOKS_APPEND_DATA lto_obj_append_data
  1152. #undef LANG_HOOKS_END_SECTION
  1153. #define LANG_HOOKS_END_SECTION lto_obj_end_section
  1154. #undef LANG_HOOKS_INIT_TS
  1155. #define LANG_HOOKS_INIT_TS lto_init_ts
  1156. struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
  1157. /* Language hooks that are not part of lang_hooks. */
  1158. tree
  1159. convert (tree type ATTRIBUTE_UNUSED, tree expr ATTRIBUTE_UNUSED)
  1160. {
  1161. gcc_unreachable ();
  1162. }
  1163. /* Tree walking support. */
  1164. static enum lto_tree_node_structure_enum
  1165. lto_tree_node_structure (union lang_tree_node *t ATTRIBUTE_UNUSED)
  1166. {
  1167. return TS_LTO_GENERIC;
  1168. }
  1169. #include "gtype-lto.h"
  1170. #include "gt-lto-lto-lang.h"