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