gcc-common.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  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. #if BUILDING_GCC_VERSION >= 5000
  29. #include "expr.h"
  30. #endif
  31. #include "basic-block.h"
  32. #include "intl.h"
  33. #include "ggc.h"
  34. #include "timevar.h"
  35. #include "params.h"
  36. #if BUILDING_GCC_VERSION <= 4009
  37. #include "pointer-set.h"
  38. #else
  39. #include "hash-map.h"
  40. #endif
  41. #if BUILDING_GCC_VERSION >= 7000
  42. #include "memmodel.h"
  43. #endif
  44. #include "emit-rtl.h"
  45. #include "debug.h"
  46. #include "target.h"
  47. #include "langhooks.h"
  48. #include "cfgloop.h"
  49. #include "cgraph.h"
  50. #include "opts.h"
  51. #if BUILDING_GCC_VERSION == 4005
  52. #include <sys/mman.h>
  53. #endif
  54. #if BUILDING_GCC_VERSION >= 4007
  55. #include "tree-pretty-print.h"
  56. #include "gimple-pretty-print.h"
  57. #endif
  58. #if BUILDING_GCC_VERSION >= 4006
  59. /*
  60. * The c-family headers were moved into a subdirectory in GCC version
  61. * 4.7, but most plugin-building users of GCC 4.6 are using the Debian
  62. * or Ubuntu package, which has an out-of-tree patch to move this to the
  63. * same location as found in 4.7 and later:
  64. * https://sources.debian.net/src/gcc-4.6/4.6.3-14/debian/patches/pr45078.diff/
  65. */
  66. #include "c-family/c-common.h"
  67. #else
  68. #include "c-common.h"
  69. #endif
  70. #if BUILDING_GCC_VERSION <= 4008
  71. #include "tree-flow.h"
  72. #else
  73. #include "tree-cfgcleanup.h"
  74. #include "tree-ssa-operands.h"
  75. #include "tree-into-ssa.h"
  76. #endif
  77. #if BUILDING_GCC_VERSION >= 4008
  78. #include "is-a.h"
  79. #endif
  80. #include "diagnostic.h"
  81. #include "tree-dump.h"
  82. #include "tree-pass.h"
  83. #if BUILDING_GCC_VERSION >= 4009
  84. #include "pass_manager.h"
  85. #endif
  86. #include "predict.h"
  87. #include "ipa-utils.h"
  88. #if BUILDING_GCC_VERSION >= 8000
  89. #include "stringpool.h"
  90. #endif
  91. #if BUILDING_GCC_VERSION >= 4009
  92. #include "attribs.h"
  93. #include "varasm.h"
  94. #include "stor-layout.h"
  95. #include "internal-fn.h"
  96. #include "gimple-expr.h"
  97. #include "gimple-fold.h"
  98. #include "context.h"
  99. #include "tree-ssa-alias.h"
  100. #include "tree-ssa.h"
  101. #include "stringpool.h"
  102. #if BUILDING_GCC_VERSION >= 7000
  103. #include "tree-vrp.h"
  104. #endif
  105. #include "tree-ssanames.h"
  106. #include "print-tree.h"
  107. #include "tree-eh.h"
  108. #include "stmt.h"
  109. #include "gimplify.h"
  110. #endif
  111. #include "gimple.h"
  112. #if BUILDING_GCC_VERSION >= 4009
  113. #include "tree-ssa-operands.h"
  114. #include "tree-phinodes.h"
  115. #include "tree-cfg.h"
  116. #include "gimple-iterator.h"
  117. #include "gimple-ssa.h"
  118. #include "ssa-iterators.h"
  119. #endif
  120. #if BUILDING_GCC_VERSION >= 5000
  121. #include "builtins.h"
  122. #endif
  123. /* missing from basic_block.h... */
  124. void debug_dominance_info(enum cdi_direction dir);
  125. void debug_dominance_tree(enum cdi_direction dir, basic_block root);
  126. #if BUILDING_GCC_VERSION == 4006
  127. void debug_gimple_stmt(gimple);
  128. void debug_gimple_seq(gimple_seq);
  129. void print_gimple_seq(FILE *, gimple_seq, int, int);
  130. void print_gimple_stmt(FILE *, gimple, int, int);
  131. void print_gimple_expr(FILE *, gimple, int, int);
  132. void dump_gimple_stmt(pretty_printer *, gimple, int, int);
  133. #endif
  134. #define __unused __attribute__((__unused__))
  135. #define __visible __attribute__((visibility("default")))
  136. #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
  137. #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
  138. #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
  139. #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
  140. /* should come from c-tree.h if only it were installed for gcc 4.5... */
  141. #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
  142. static inline tree build_const_char_string(int len, const char *str)
  143. {
  144. tree cstr, elem, index, type;
  145. cstr = build_string(len, str);
  146. elem = build_type_variant(char_type_node, 1, 0);
  147. index = build_index_type(size_int(len - 1));
  148. type = build_array_type(elem, index);
  149. TREE_TYPE(cstr) = type;
  150. TREE_CONSTANT(cstr) = 1;
  151. TREE_READONLY(cstr) = 1;
  152. TREE_STATIC(cstr) = 1;
  153. return cstr;
  154. }
  155. #define PASS_INFO(NAME, REF, ID, POS) \
  156. struct register_pass_info NAME##_pass_info = { \
  157. .pass = make_##NAME##_pass(), \
  158. .reference_pass_name = REF, \
  159. .ref_pass_instance_number = ID, \
  160. .pos_op = POS, \
  161. }
  162. #if BUILDING_GCC_VERSION == 4005
  163. #define FOR_EACH_LOCAL_DECL(FUN, I, D) \
  164. for (tree vars = (FUN)->local_decls, (I) = 0; \
  165. vars && ((D) = TREE_VALUE(vars)); \
  166. vars = TREE_CHAIN(vars), (I)++)
  167. #define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
  168. #define FOR_EACH_VEC_ELT(T, V, I, P) \
  169. for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
  170. #define TODO_rebuild_cgraph_edges 0
  171. #define SCOPE_FILE_SCOPE_P(EXP) (!(EXP))
  172. #ifndef O_BINARY
  173. #define O_BINARY 0
  174. #endif
  175. typedef struct varpool_node *varpool_node_ptr;
  176. static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
  177. {
  178. tree fndecl;
  179. if (!is_gimple_call(stmt))
  180. return false;
  181. fndecl = gimple_call_fndecl(stmt);
  182. if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
  183. return false;
  184. return DECL_FUNCTION_CODE(fndecl) == code;
  185. }
  186. static inline bool is_simple_builtin(tree decl)
  187. {
  188. if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
  189. return false;
  190. switch (DECL_FUNCTION_CODE(decl)) {
  191. /* Builtins that expand to constants. */
  192. case BUILT_IN_CONSTANT_P:
  193. case BUILT_IN_EXPECT:
  194. case BUILT_IN_OBJECT_SIZE:
  195. case BUILT_IN_UNREACHABLE:
  196. /* Simple register moves or loads from stack. */
  197. case BUILT_IN_RETURN_ADDRESS:
  198. case BUILT_IN_EXTRACT_RETURN_ADDR:
  199. case BUILT_IN_FROB_RETURN_ADDR:
  200. case BUILT_IN_RETURN:
  201. case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
  202. case BUILT_IN_FRAME_ADDRESS:
  203. case BUILT_IN_VA_END:
  204. case BUILT_IN_STACK_SAVE:
  205. case BUILT_IN_STACK_RESTORE:
  206. /* Exception state returns or moves registers around. */
  207. case BUILT_IN_EH_FILTER:
  208. case BUILT_IN_EH_POINTER:
  209. case BUILT_IN_EH_COPY_VALUES:
  210. return true;
  211. default:
  212. return false;
  213. }
  214. }
  215. static inline void add_local_decl(struct function *fun, tree d)
  216. {
  217. gcc_assert(TREE_CODE(d) == VAR_DECL);
  218. fun->local_decls = tree_cons(NULL_TREE, d, fun->local_decls);
  219. }
  220. #endif
  221. #if BUILDING_GCC_VERSION <= 4006
  222. #define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
  223. #define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
  224. #define EDGE_PRESERVE 0ULL
  225. #define HOST_WIDE_INT_PRINT_HEX_PURE "%" HOST_WIDE_INT_PRINT "x"
  226. #define flag_fat_lto_objects true
  227. #define get_random_seed(noinit) ({ \
  228. unsigned HOST_WIDE_INT seed; \
  229. sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
  230. seed * seed; })
  231. #define int_const_binop(code, arg1, arg2) \
  232. int_const_binop((code), (arg1), (arg2), 0)
  233. static inline bool gimple_clobber_p(gimple s __unused)
  234. {
  235. return false;
  236. }
  237. static inline bool gimple_asm_clobbers_memory_p(const_gimple stmt)
  238. {
  239. unsigned i;
  240. for (i = 0; i < gimple_asm_nclobbers(stmt); i++) {
  241. tree op = gimple_asm_clobber_op(stmt, i);
  242. if (!strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "memory"))
  243. return true;
  244. }
  245. return false;
  246. }
  247. static inline tree builtin_decl_implicit(enum built_in_function fncode)
  248. {
  249. return implicit_built_in_decls[fncode];
  250. }
  251. static inline int ipa_reverse_postorder(struct cgraph_node **order)
  252. {
  253. return cgraph_postorder(order);
  254. }
  255. static inline struct cgraph_node *cgraph_create_node(tree decl)
  256. {
  257. return cgraph_node(decl);
  258. }
  259. static inline struct cgraph_node *cgraph_get_create_node(tree decl)
  260. {
  261. struct cgraph_node *node = cgraph_get_node(decl);
  262. return node ? node : cgraph_node(decl);
  263. }
  264. static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
  265. {
  266. return node->analyzed && !node->thunk.thunk_p && !node->alias;
  267. }
  268. static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
  269. {
  270. struct cgraph_node *node;
  271. for (node = cgraph_nodes; node; node = node->next)
  272. if (cgraph_function_with_gimple_body_p(node))
  273. return node;
  274. return NULL;
  275. }
  276. static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
  277. {
  278. for (node = node->next; node; node = node->next)
  279. if (cgraph_function_with_gimple_body_p(node))
  280. return node;
  281. return NULL;
  282. }
  283. static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
  284. {
  285. cgraph_node_ptr alias;
  286. if (callback(node, data))
  287. return true;
  288. for (alias = node->same_body; alias; alias = alias->next) {
  289. if (include_overwritable || cgraph_function_body_availability(alias) > AVAIL_OVERWRITABLE)
  290. if (cgraph_for_node_and_aliases(alias, callback, data, include_overwritable))
  291. return true;
  292. }
  293. return false;
  294. }
  295. #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
  296. for ((node) = cgraph_first_function_with_gimple_body(); (node); \
  297. (node) = cgraph_next_function_with_gimple_body(node))
  298. static inline void varpool_add_new_variable(tree decl)
  299. {
  300. varpool_finalize_decl(decl);
  301. }
  302. #endif
  303. #if BUILDING_GCC_VERSION <= 4007
  304. #define FOR_EACH_FUNCTION(node) \
  305. for (node = cgraph_nodes; node; node = node->next)
  306. #define FOR_EACH_VARIABLE(node) \
  307. for (node = varpool_nodes; node; node = node->next)
  308. #define PROP_loops 0
  309. #define NODE_SYMBOL(node) (node)
  310. #define NODE_DECL(node) (node)->decl
  311. #define INSN_LOCATION(INSN) RTL_LOCATION(INSN)
  312. #define vNULL NULL
  313. static inline int bb_loop_depth(const_basic_block bb)
  314. {
  315. return bb->loop_father ? loop_depth(bb->loop_father) : 0;
  316. }
  317. static inline bool gimple_store_p(gimple gs)
  318. {
  319. tree lhs = gimple_get_lhs(gs);
  320. return lhs && !is_gimple_reg(lhs);
  321. }
  322. static inline void gimple_init_singleton(gimple g __unused)
  323. {
  324. }
  325. #endif
  326. #if BUILDING_GCC_VERSION == 4007 || BUILDING_GCC_VERSION == 4008
  327. static inline struct cgraph_node *cgraph_alias_target(struct cgraph_node *n)
  328. {
  329. return cgraph_alias_aliased_node(n);
  330. }
  331. #endif
  332. #if BUILDING_GCC_VERSION >= 4007 && BUILDING_GCC_VERSION <= 4009
  333. #define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
  334. cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
  335. #define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
  336. cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
  337. #endif
  338. #if BUILDING_GCC_VERSION <= 4008
  339. #define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
  340. #define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
  341. #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
  342. #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
  343. #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
  344. #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
  345. #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
  346. #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
  347. #define BASIC_BLOCK_FOR_FN(FN, N) BASIC_BLOCK_FOR_FUNCTION((FN), (N))
  348. #define NODE_IMPLICIT_ALIAS(node) (node)->same_body_alias
  349. #define VAR_P(NODE) (TREE_CODE(NODE) == VAR_DECL)
  350. static inline bool tree_fits_shwi_p(const_tree t)
  351. {
  352. if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
  353. return false;
  354. if (TREE_INT_CST_HIGH(t) == 0 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) >= 0)
  355. return true;
  356. if (TREE_INT_CST_HIGH(t) == -1 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) < 0 && !TYPE_UNSIGNED(TREE_TYPE(t)))
  357. return true;
  358. return false;
  359. }
  360. static inline bool tree_fits_uhwi_p(const_tree t)
  361. {
  362. if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
  363. return false;
  364. return TREE_INT_CST_HIGH(t) == 0;
  365. }
  366. static inline HOST_WIDE_INT tree_to_shwi(const_tree t)
  367. {
  368. gcc_assert(tree_fits_shwi_p(t));
  369. return TREE_INT_CST_LOW(t);
  370. }
  371. static inline unsigned HOST_WIDE_INT tree_to_uhwi(const_tree t)
  372. {
  373. gcc_assert(tree_fits_uhwi_p(t));
  374. return TREE_INT_CST_LOW(t);
  375. }
  376. static inline const char *get_tree_code_name(enum tree_code code)
  377. {
  378. gcc_assert(code < MAX_TREE_CODES);
  379. return tree_code_name[code];
  380. }
  381. #define ipa_remove_stmt_references(cnode, stmt)
  382. typedef union gimple_statement_d gasm;
  383. typedef union gimple_statement_d gassign;
  384. typedef union gimple_statement_d gcall;
  385. typedef union gimple_statement_d gcond;
  386. typedef union gimple_statement_d gdebug;
  387. typedef union gimple_statement_d ggoto;
  388. typedef union gimple_statement_d gphi;
  389. typedef union gimple_statement_d greturn;
  390. static inline gasm *as_a_gasm(gimple stmt)
  391. {
  392. return stmt;
  393. }
  394. static inline const gasm *as_a_const_gasm(const_gimple stmt)
  395. {
  396. return stmt;
  397. }
  398. static inline gassign *as_a_gassign(gimple stmt)
  399. {
  400. return stmt;
  401. }
  402. static inline const gassign *as_a_const_gassign(const_gimple stmt)
  403. {
  404. return stmt;
  405. }
  406. static inline gcall *as_a_gcall(gimple stmt)
  407. {
  408. return stmt;
  409. }
  410. static inline const gcall *as_a_const_gcall(const_gimple stmt)
  411. {
  412. return stmt;
  413. }
  414. static inline gcond *as_a_gcond(gimple stmt)
  415. {
  416. return stmt;
  417. }
  418. static inline const gcond *as_a_const_gcond(const_gimple stmt)
  419. {
  420. return stmt;
  421. }
  422. static inline gdebug *as_a_gdebug(gimple stmt)
  423. {
  424. return stmt;
  425. }
  426. static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
  427. {
  428. return stmt;
  429. }
  430. static inline ggoto *as_a_ggoto(gimple stmt)
  431. {
  432. return stmt;
  433. }
  434. static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
  435. {
  436. return stmt;
  437. }
  438. static inline gphi *as_a_gphi(gimple stmt)
  439. {
  440. return stmt;
  441. }
  442. static inline const gphi *as_a_const_gphi(const_gimple stmt)
  443. {
  444. return stmt;
  445. }
  446. static inline greturn *as_a_greturn(gimple stmt)
  447. {
  448. return stmt;
  449. }
  450. static inline const greturn *as_a_const_greturn(const_gimple stmt)
  451. {
  452. return stmt;
  453. }
  454. #endif
  455. #if BUILDING_GCC_VERSION == 4008
  456. #define NODE_SYMBOL(node) (&(node)->symbol)
  457. #define NODE_DECL(node) (node)->symbol.decl
  458. #endif
  459. #if BUILDING_GCC_VERSION >= 4008
  460. #define add_referenced_var(var)
  461. #define mark_sym_for_renaming(var)
  462. #define varpool_mark_needed_node(node)
  463. #define create_var_ann(var)
  464. #define TODO_dump_func 0
  465. #define TODO_dump_cgraph 0
  466. #endif
  467. #if BUILDING_GCC_VERSION <= 4009
  468. #define TODO_verify_il 0
  469. #define AVAIL_INTERPOSABLE AVAIL_OVERWRITABLE
  470. #define section_name_prefix LTO_SECTION_NAME_PREFIX
  471. #define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)
  472. rtx emit_move_insn(rtx x, rtx y);
  473. typedef struct rtx_def rtx_insn;
  474. static inline const char *get_decl_section_name(const_tree decl)
  475. {
  476. if (DECL_SECTION_NAME(decl) == NULL_TREE)
  477. return NULL;
  478. return TREE_STRING_POINTER(DECL_SECTION_NAME(decl));
  479. }
  480. static inline void set_decl_section_name(tree node, const char *value)
  481. {
  482. if (value)
  483. DECL_SECTION_NAME(node) = build_string(strlen(value) + 1, value);
  484. else
  485. DECL_SECTION_NAME(node) = NULL;
  486. }
  487. #endif
  488. #if BUILDING_GCC_VERSION == 4009
  489. typedef struct gimple_statement_asm gasm;
  490. typedef struct gimple_statement_base gassign;
  491. typedef struct gimple_statement_call gcall;
  492. typedef struct gimple_statement_base gcond;
  493. typedef struct gimple_statement_base gdebug;
  494. typedef struct gimple_statement_base ggoto;
  495. typedef struct gimple_statement_phi gphi;
  496. typedef struct gimple_statement_base greturn;
  497. static inline gasm *as_a_gasm(gimple stmt)
  498. {
  499. return as_a<gasm>(stmt);
  500. }
  501. static inline const gasm *as_a_const_gasm(const_gimple stmt)
  502. {
  503. return as_a<const gasm>(stmt);
  504. }
  505. static inline gassign *as_a_gassign(gimple stmt)
  506. {
  507. return stmt;
  508. }
  509. static inline const gassign *as_a_const_gassign(const_gimple stmt)
  510. {
  511. return stmt;
  512. }
  513. static inline gcall *as_a_gcall(gimple stmt)
  514. {
  515. return as_a<gcall>(stmt);
  516. }
  517. static inline const gcall *as_a_const_gcall(const_gimple stmt)
  518. {
  519. return as_a<const gcall>(stmt);
  520. }
  521. static inline gcond *as_a_gcond(gimple stmt)
  522. {
  523. return stmt;
  524. }
  525. static inline const gcond *as_a_const_gcond(const_gimple stmt)
  526. {
  527. return stmt;
  528. }
  529. static inline gdebug *as_a_gdebug(gimple stmt)
  530. {
  531. return stmt;
  532. }
  533. static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
  534. {
  535. return stmt;
  536. }
  537. static inline ggoto *as_a_ggoto(gimple stmt)
  538. {
  539. return stmt;
  540. }
  541. static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
  542. {
  543. return stmt;
  544. }
  545. static inline gphi *as_a_gphi(gimple stmt)
  546. {
  547. return as_a<gphi>(stmt);
  548. }
  549. static inline const gphi *as_a_const_gphi(const_gimple stmt)
  550. {
  551. return as_a<const gphi>(stmt);
  552. }
  553. static inline greturn *as_a_greturn(gimple stmt)
  554. {
  555. return stmt;
  556. }
  557. static inline const greturn *as_a_const_greturn(const_gimple stmt)
  558. {
  559. return stmt;
  560. }
  561. #endif
  562. #if BUILDING_GCC_VERSION >= 4009
  563. #define TODO_ggc_collect 0
  564. #define NODE_SYMBOL(node) (node)
  565. #define NODE_DECL(node) (node)->decl
  566. #define cgraph_node_name(node) (node)->name()
  567. #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
  568. static inline opt_pass *get_pass_for_id(int id)
  569. {
  570. return g->get_passes()->get_pass_for_id(id);
  571. }
  572. #endif
  573. #if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000
  574. /* gimple related */
  575. template <>
  576. template <>
  577. inline bool is_a_helper<const gassign *>::test(const_gimple gs)
  578. {
  579. return gs->code == GIMPLE_ASSIGN;
  580. }
  581. #endif
  582. #if BUILDING_GCC_VERSION >= 5000
  583. #define TODO_verify_ssa TODO_verify_il
  584. #define TODO_verify_flow TODO_verify_il
  585. #define TODO_verify_stmts TODO_verify_il
  586. #define TODO_verify_rtl_sharing TODO_verify_il
  587. #define INSN_DELETED_P(insn) (insn)->deleted()
  588. static inline const char *get_decl_section_name(const_tree decl)
  589. {
  590. return DECL_SECTION_NAME(decl);
  591. }
  592. /* symtab/cgraph related */
  593. #define debug_cgraph_node(node) (node)->debug()
  594. #define cgraph_get_node(decl) cgraph_node::get(decl)
  595. #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
  596. #define cgraph_create_node(decl) cgraph_node::create(decl)
  597. #define cgraph_n_nodes symtab->cgraph_count
  598. #define cgraph_max_uid symtab->cgraph_max_uid
  599. #define varpool_get_node(decl) varpool_node::get(decl)
  600. #define dump_varpool_node(file, node) (node)->dump(file)
  601. #define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
  602. (caller)->create_edge((callee), (call_stmt), (count), (freq))
  603. #define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
  604. (caller)->create_edge_including_clones((callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
  605. typedef struct cgraph_node *cgraph_node_ptr;
  606. typedef struct cgraph_edge *cgraph_edge_p;
  607. typedef struct varpool_node *varpool_node_ptr;
  608. static inline void change_decl_assembler_name(tree decl, tree name)
  609. {
  610. symtab->change_decl_assembler_name(decl, name);
  611. }
  612. static inline void varpool_finalize_decl(tree decl)
  613. {
  614. varpool_node::finalize_decl(decl);
  615. }
  616. static inline void varpool_add_new_variable(tree decl)
  617. {
  618. varpool_node::add(decl);
  619. }
  620. static inline unsigned int rebuild_cgraph_edges(void)
  621. {
  622. return cgraph_edge::rebuild_edges();
  623. }
  624. static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
  625. {
  626. return node->function_symbol(availability);
  627. }
  628. static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
  629. {
  630. return node->ultimate_alias_target(availability);
  631. }
  632. static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
  633. {
  634. return node->only_called_directly_p();
  635. }
  636. static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
  637. {
  638. return node->get_availability();
  639. }
  640. static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
  641. {
  642. return node->get_alias_target();
  643. }
  644. static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
  645. {
  646. return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
  647. }
  648. static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
  649. {
  650. return symtab->add_cgraph_insertion_hook(hook, data);
  651. }
  652. static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
  653. {
  654. symtab->remove_cgraph_insertion_hook(entry);
  655. }
  656. static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
  657. {
  658. return symtab->add_cgraph_removal_hook(hook, data);
  659. }
  660. static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
  661. {
  662. symtab->remove_cgraph_removal_hook(entry);
  663. }
  664. static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
  665. {
  666. return symtab->add_cgraph_duplication_hook(hook, data);
  667. }
  668. static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
  669. {
  670. symtab->remove_cgraph_duplication_hook(entry);
  671. }
  672. static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
  673. {
  674. symtab->call_cgraph_duplication_hooks(node, node2);
  675. }
  676. static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
  677. {
  678. symtab->call_edge_duplication_hooks(cs1, cs2);
  679. }
  680. #if BUILDING_GCC_VERSION >= 6000
  681. typedef gimple *gimple_ptr;
  682. typedef const gimple *const_gimple_ptr;
  683. #define gimple gimple_ptr
  684. #define const_gimple const_gimple_ptr
  685. #undef CONST_CAST_GIMPLE
  686. #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
  687. #endif
  688. /* gimple related */
  689. static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
  690. {
  691. return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
  692. }
  693. template <>
  694. template <>
  695. inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
  696. {
  697. return gs->code == GIMPLE_GOTO;
  698. }
  699. template <>
  700. template <>
  701. inline bool is_a_helper<const greturn *>::test(const_gimple gs)
  702. {
  703. return gs->code == GIMPLE_RETURN;
  704. }
  705. static inline gasm *as_a_gasm(gimple stmt)
  706. {
  707. return as_a<gasm *>(stmt);
  708. }
  709. static inline const gasm *as_a_const_gasm(const_gimple stmt)
  710. {
  711. return as_a<const gasm *>(stmt);
  712. }
  713. static inline gassign *as_a_gassign(gimple stmt)
  714. {
  715. return as_a<gassign *>(stmt);
  716. }
  717. static inline const gassign *as_a_const_gassign(const_gimple stmt)
  718. {
  719. return as_a<const gassign *>(stmt);
  720. }
  721. static inline gcall *as_a_gcall(gimple stmt)
  722. {
  723. return as_a<gcall *>(stmt);
  724. }
  725. static inline const gcall *as_a_const_gcall(const_gimple stmt)
  726. {
  727. return as_a<const gcall *>(stmt);
  728. }
  729. static inline ggoto *as_a_ggoto(gimple stmt)
  730. {
  731. return as_a<ggoto *>(stmt);
  732. }
  733. static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
  734. {
  735. return as_a<const ggoto *>(stmt);
  736. }
  737. static inline gphi *as_a_gphi(gimple stmt)
  738. {
  739. return as_a<gphi *>(stmt);
  740. }
  741. static inline const gphi *as_a_const_gphi(const_gimple stmt)
  742. {
  743. return as_a<const gphi *>(stmt);
  744. }
  745. static inline greturn *as_a_greturn(gimple stmt)
  746. {
  747. return as_a<greturn *>(stmt);
  748. }
  749. static inline const greturn *as_a_const_greturn(const_gimple stmt)
  750. {
  751. return as_a<const greturn *>(stmt);
  752. }
  753. /* IPA/LTO related */
  754. #define ipa_ref_list_referring_iterate(L, I, P) \
  755. (L)->referring.iterate((I), &(P))
  756. #define ipa_ref_list_reference_iterate(L, I, P) \
  757. (L)->reference.iterate((I), &(P))
  758. static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
  759. {
  760. return dyn_cast<cgraph_node_ptr>(ref->referring);
  761. }
  762. static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
  763. {
  764. referring_node->remove_stmt_references(stmt);
  765. }
  766. #endif
  767. #if BUILDING_GCC_VERSION < 6000
  768. #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
  769. get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
  770. #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
  771. #endif
  772. #if BUILDING_GCC_VERSION >= 6000
  773. #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
  774. #endif
  775. #ifdef __cplusplus
  776. static inline void debug_tree(const_tree t)
  777. {
  778. debug_tree(CONST_CAST_TREE(t));
  779. }
  780. static inline void debug_gimple_stmt(const_gimple s)
  781. {
  782. debug_gimple_stmt(CONST_CAST_GIMPLE(s));
  783. }
  784. #else
  785. #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
  786. #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
  787. #endif
  788. #if BUILDING_GCC_VERSION >= 7000
  789. #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
  790. get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
  791. #endif
  792. #if BUILDING_GCC_VERSION < 7000
  793. #define SET_DECL_ALIGN(decl, align) DECL_ALIGN(decl) = (align)
  794. #define SET_DECL_MODE(decl, mode) DECL_MODE(decl) = (mode)
  795. #endif
  796. #endif