gcc-common.h 11 KB

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