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