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