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