gcc-common.h 23 KB

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