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