gcc-common.h 22 KB

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