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