Linux Audio

Check our new training course

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