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