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