gcc-common.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef GCC_COMMON_H_INCLUDED
  3. #define GCC_COMMON_H_INCLUDED
  4. #include "bversion.h"
  5. #if BUILDING_GCC_VERSION >= 6000
  6. #include "gcc-plugin.h"
  7. #else
  8. #include "plugin.h"
  9. #endif
  10. #include "plugin-version.h"
  11. #include "config.h"
  12. #include "system.h"
  13. #include "coretypes.h"
  14. #include "tm.h"
  15. #include "line-map.h"
  16. #include "input.h"
  17. #include "tree.h"
  18. #include "tree-inline.h"
  19. #include "version.h"
  20. #include "rtl.h"
  21. #include "tm_p.h"
  22. #include "flags.h"
  23. #include "hard-reg-set.h"
  24. #include "output.h"
  25. #include "except.h"
  26. #include "function.h"
  27. #include "toplev.h"
  28. #include "expr.h"
  29. #include "basic-block.h"
  30. #include "intl.h"
  31. #include "ggc.h"
  32. #include "timevar.h"
  33. #if BUILDING_GCC_VERSION < 10000
  34. #include "params.h"
  35. #endif
  36. #include "hash-map.h"
  37. #if BUILDING_GCC_VERSION >= 7000
  38. #include "memmodel.h"
  39. #endif
  40. #include "emit-rtl.h"
  41. #include "debug.h"
  42. #include "target.h"
  43. #include "langhooks.h"
  44. #include "cfgloop.h"
  45. #include "cgraph.h"
  46. #include "opts.h"
  47. #include "tree-pretty-print.h"
  48. #include "gimple-pretty-print.h"
  49. #include "c-family/c-common.h"
  50. #include "tree-cfgcleanup.h"
  51. #include "tree-ssa-operands.h"
  52. #include "tree-into-ssa.h"
  53. #include "is-a.h"
  54. #include "diagnostic.h"
  55. #include "tree-dump.h"
  56. #include "tree-pass.h"
  57. #include "pass_manager.h"
  58. #include "predict.h"
  59. #include "ipa-utils.h"
  60. #include "stringpool.h"
  61. #include "attribs.h"
  62. #include "varasm.h"
  63. #include "stor-layout.h"
  64. #include "internal-fn.h"
  65. #include "gimple.h"
  66. #include "gimple-expr.h"
  67. #include "gimple-iterator.h"
  68. #include "gimple-fold.h"
  69. #include "context.h"
  70. #include "tree-ssa-alias.h"
  71. #include "tree-ssa.h"
  72. #if BUILDING_GCC_VERSION >= 7000
  73. #include "tree-vrp.h"
  74. #endif
  75. #include "tree-ssanames.h"
  76. #include "print-tree.h"
  77. #include "tree-eh.h"
  78. #include "stmt.h"
  79. #include "gimplify.h"
  80. #include "tree-phinodes.h"
  81. #include "tree-cfg.h"
  82. #include "gimple-ssa.h"
  83. #include "ssa-iterators.h"
  84. #include "builtins.h"
  85. /* missing from basic_block.h... */
  86. void debug_dominance_info(enum cdi_direction dir);
  87. void debug_dominance_tree(enum cdi_direction dir, basic_block root);
  88. #ifndef __unused
  89. #define __unused __attribute__((__unused__))
  90. #endif
  91. #ifndef __visible
  92. #define __visible __attribute__((visibility("default")))
  93. #endif
  94. #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
  95. #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
  96. #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
  97. #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
  98. /* should come from c-tree.h if only it were installed for gcc 4.5... */
  99. #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
  100. static inline tree build_const_char_string(int len, const char *str)
  101. {
  102. tree cstr, elem, index, type;
  103. cstr = build_string(len, str);
  104. elem = build_type_variant(char_type_node, 1, 0);
  105. index = build_index_type(size_int(len - 1));
  106. type = build_array_type(elem, index);
  107. TREE_TYPE(cstr) = type;
  108. TREE_CONSTANT(cstr) = 1;
  109. TREE_READONLY(cstr) = 1;
  110. TREE_STATIC(cstr) = 1;
  111. return cstr;
  112. }
  113. static inline void __add_type_attr(tree type, const char *attr, tree args)
  114. {
  115. tree oldattr;
  116. if (type == NULL_TREE)
  117. return;
  118. oldattr = lookup_attribute(attr, TYPE_ATTRIBUTES(type));
  119. if (oldattr != NULL_TREE) {
  120. gcc_assert(TREE_VALUE(oldattr) == args || TREE_VALUE(TREE_VALUE(oldattr)) == TREE_VALUE(args));
  121. return;
  122. }
  123. TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
  124. TYPE_ATTRIBUTES(type) = tree_cons(get_identifier(attr), args, TYPE_ATTRIBUTES(type));
  125. }
  126. static inline void add_type_attr(tree type, const char *attr, tree args)
  127. {
  128. tree main_variant = TYPE_MAIN_VARIANT(type);
  129. __add_type_attr(TYPE_CANONICAL(type), attr, args);
  130. __add_type_attr(TYPE_CANONICAL(main_variant), attr, args);
  131. __add_type_attr(main_variant, attr, args);
  132. for (type = TYPE_NEXT_VARIANT(main_variant); type; type = TYPE_NEXT_VARIANT(type)) {
  133. if (!lookup_attribute(attr, TYPE_ATTRIBUTES(type)))
  134. TYPE_ATTRIBUTES(type) = TYPE_ATTRIBUTES(main_variant);
  135. __add_type_attr(TYPE_CANONICAL(type), attr, args);
  136. }
  137. }
  138. #define PASS_INFO(NAME, REF, ID, POS) \
  139. struct register_pass_info NAME##_pass_info = { \
  140. .pass = make_##NAME##_pass(), \
  141. .reference_pass_name = REF, \
  142. .ref_pass_instance_number = ID, \
  143. .pos_op = POS, \
  144. }
  145. #define add_referenced_var(var)
  146. #define mark_sym_for_renaming(var)
  147. #define varpool_mark_needed_node(node)
  148. #define create_var_ann(var)
  149. #define TODO_dump_func 0
  150. #define TODO_dump_cgraph 0
  151. #define TODO_ggc_collect 0
  152. #define NODE_SYMBOL(node) (node)
  153. #define NODE_DECL(node) (node)->decl
  154. #define cgraph_node_name(node) (node)->name()
  155. #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
  156. static inline opt_pass *get_pass_for_id(int id)
  157. {
  158. return g->get_passes()->get_pass_for_id(id);
  159. }
  160. #if BUILDING_GCC_VERSION < 6000
  161. /* gimple related */
  162. template <>
  163. template <>
  164. inline bool is_a_helper<const gassign *>::test(const_gimple gs)
  165. {
  166. return gs->code == GIMPLE_ASSIGN;
  167. }
  168. #endif
  169. #if BUILDING_GCC_VERSION < 16000
  170. #define TODO_verify_ssa TODO_verify_il
  171. #define TODO_verify_flow TODO_verify_il
  172. #define TODO_verify_stmts TODO_verify_il
  173. #define TODO_verify_rtl_sharing TODO_verify_il
  174. #else
  175. #define TODO_verify_ssa 0
  176. #define TODO_verify_flow 0
  177. #define TODO_verify_stmts 0
  178. #define TODO_verify_rtl_sharing 0
  179. #endif
  180. #define INSN_DELETED_P(insn) (insn)->deleted()
  181. static inline const char *get_decl_section_name(const_tree decl)
  182. {
  183. return DECL_SECTION_NAME(decl);
  184. }
  185. /* symtab/cgraph related */
  186. #define debug_cgraph_node(node) (node)->debug()
  187. #define cgraph_get_node(decl) cgraph_node::get(decl)
  188. #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
  189. #define cgraph_create_node(decl) cgraph_node::create(decl)
  190. #define cgraph_n_nodes symtab->cgraph_count
  191. #define cgraph_max_uid symtab->cgraph_max_uid
  192. #define varpool_get_node(decl) varpool_node::get(decl)
  193. #define dump_varpool_node(file, node) (node)->dump(file)
  194. #if BUILDING_GCC_VERSION >= 8000
  195. #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
  196. (caller)->create_edge((callee), (call_stmt), (count))
  197. #define cgraph_create_edge_including_clones(caller, callee, \
  198. old_call_stmt, call_stmt, count, freq, reason) \
  199. (caller)->create_edge_including_clones((callee), \
  200. (old_call_stmt), (call_stmt), (count), (reason))
  201. #else
  202. #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
  203. (caller)->create_edge((callee), (call_stmt), (count), (freq))
  204. #define cgraph_create_edge_including_clones(caller, callee, \
  205. old_call_stmt, call_stmt, count, freq, reason) \
  206. (caller)->create_edge_including_clones((callee), \
  207. (old_call_stmt), (call_stmt), (count), (freq), (reason))
  208. #endif
  209. typedef struct cgraph_node *cgraph_node_ptr;
  210. typedef struct cgraph_edge *cgraph_edge_p;
  211. typedef struct varpool_node *varpool_node_ptr;
  212. static inline void change_decl_assembler_name(tree decl, tree name)
  213. {
  214. symtab->change_decl_assembler_name(decl, name);
  215. }
  216. static inline void varpool_finalize_decl(tree decl)
  217. {
  218. varpool_node::finalize_decl(decl);
  219. }
  220. static inline void varpool_add_new_variable(tree decl)
  221. {
  222. varpool_node::add(decl);
  223. }
  224. static inline unsigned int rebuild_cgraph_edges(void)
  225. {
  226. return cgraph_edge::rebuild_edges();
  227. }
  228. static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
  229. {
  230. return node->function_symbol(availability);
  231. }
  232. static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
  233. {
  234. return node->ultimate_alias_target(availability);
  235. }
  236. static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
  237. {
  238. return node->only_called_directly_p();
  239. }
  240. static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
  241. {
  242. return node->get_availability();
  243. }
  244. static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
  245. {
  246. return node->get_alias_target();
  247. }
  248. static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
  249. {
  250. return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
  251. }
  252. static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
  253. {
  254. return symtab->add_cgraph_insertion_hook(hook, data);
  255. }
  256. static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
  257. {
  258. symtab->remove_cgraph_insertion_hook(entry);
  259. }
  260. static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
  261. {
  262. return symtab->add_cgraph_removal_hook(hook, data);
  263. }
  264. static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
  265. {
  266. symtab->remove_cgraph_removal_hook(entry);
  267. }
  268. static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
  269. {
  270. return symtab->add_cgraph_duplication_hook(hook, data);
  271. }
  272. static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
  273. {
  274. symtab->remove_cgraph_duplication_hook(entry);
  275. }
  276. static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
  277. {
  278. symtab->call_cgraph_duplication_hooks(node, node2);
  279. }
  280. static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
  281. {
  282. symtab->call_edge_duplication_hooks(cs1, cs2);
  283. }
  284. #if BUILDING_GCC_VERSION >= 6000
  285. typedef gimple *gimple_ptr;
  286. typedef const gimple *const_gimple_ptr;
  287. #define gimple gimple_ptr
  288. #define const_gimple const_gimple_ptr
  289. #undef CONST_CAST_GIMPLE
  290. #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
  291. #endif
  292. /* gimple related */
  293. static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
  294. {
  295. return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
  296. }
  297. #if BUILDING_GCC_VERSION < 10000
  298. template <>
  299. template <>
  300. inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
  301. {
  302. return gs->code == GIMPLE_GOTO;
  303. }
  304. template <>
  305. template <>
  306. inline bool is_a_helper<const greturn *>::test(const_gimple gs)
  307. {
  308. return gs->code == GIMPLE_RETURN;
  309. }
  310. #endif
  311. static inline gasm *as_a_gasm(gimple stmt)
  312. {
  313. return as_a<gasm *>(stmt);
  314. }
  315. static inline const gasm *as_a_const_gasm(const_gimple stmt)
  316. {
  317. return as_a<const gasm *>(stmt);
  318. }
  319. static inline gassign *as_a_gassign(gimple stmt)
  320. {
  321. return as_a<gassign *>(stmt);
  322. }
  323. static inline const gassign *as_a_const_gassign(const_gimple stmt)
  324. {
  325. return as_a<const gassign *>(stmt);
  326. }
  327. static inline gcall *as_a_gcall(gimple stmt)
  328. {
  329. return as_a<gcall *>(stmt);
  330. }
  331. static inline const gcall *as_a_const_gcall(const_gimple stmt)
  332. {
  333. return as_a<const gcall *>(stmt);
  334. }
  335. static inline ggoto *as_a_ggoto(gimple stmt)
  336. {
  337. return as_a<ggoto *>(stmt);
  338. }
  339. static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
  340. {
  341. return as_a<const ggoto *>(stmt);
  342. }
  343. static inline gphi *as_a_gphi(gimple stmt)
  344. {
  345. return as_a<gphi *>(stmt);
  346. }
  347. static inline const gphi *as_a_const_gphi(const_gimple stmt)
  348. {
  349. return as_a<const gphi *>(stmt);
  350. }
  351. static inline greturn *as_a_greturn(gimple stmt)
  352. {
  353. return as_a<greturn *>(stmt);
  354. }
  355. static inline const greturn *as_a_const_greturn(const_gimple stmt)
  356. {
  357. return as_a<const greturn *>(stmt);
  358. }
  359. /* IPA/LTO related */
  360. #define ipa_ref_list_referring_iterate(L, I, P) \
  361. (L)->referring.iterate((I), &(P))
  362. #define ipa_ref_list_reference_iterate(L, I, P) \
  363. (L)->reference.iterate((I), &(P))
  364. static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
  365. {
  366. return dyn_cast<cgraph_node_ptr>(ref->referring);
  367. }
  368. static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
  369. {
  370. referring_node->remove_stmt_references(stmt);
  371. }
  372. #if BUILDING_GCC_VERSION < 6000
  373. #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
  374. get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
  375. #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
  376. #endif
  377. #if BUILDING_GCC_VERSION >= 6000
  378. #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
  379. #endif
  380. #ifdef __cplusplus
  381. static inline void debug_tree(const_tree t)
  382. {
  383. debug_tree(CONST_CAST_TREE(t));
  384. }
  385. static inline void debug_gimple_stmt(const_gimple s)
  386. {
  387. debug_gimple_stmt(CONST_CAST_GIMPLE(s));
  388. }
  389. #else
  390. #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
  391. #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
  392. #endif
  393. #if BUILDING_GCC_VERSION >= 7000
  394. #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
  395. get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
  396. #endif
  397. #if BUILDING_GCC_VERSION < 7000
  398. #define SET_DECL_ALIGN(decl, align) DECL_ALIGN(decl) = (align)
  399. #define SET_DECL_MODE(decl, mode) DECL_MODE(decl) = (mode)
  400. #endif
  401. #if BUILDING_GCC_VERSION >= 14000
  402. #define last_stmt(x) last_nondebug_stmt(x)
  403. #endif
  404. #endif