gcc-common.h 11 KB

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