1 #ifndef GCC_COMMON_H_INCLUDED
2 #define GCC_COMMON_H_INCLUDED
5 #if BUILDING_GCC_VERSION >= 6000
6 #include "gcc-plugin.h"
10 #include "plugin-version.h"
13 #include "coretypes.h"
19 #include "tree-inline.h"
24 #include "hard-reg-set.h"
29 #include "basic-block.h"
36 #if BUILDING_GCC_VERSION <= 4009
37 #include "pointer-set.h"
45 #include "langhooks.h"
50 #if BUILDING_GCC_VERSION == 4005
54 #if BUILDING_GCC_VERSION >= 4007
55 #include "tree-pretty-print.h"
56 #include "gimple-pretty-print.h"
59 #if BUILDING_GCC_VERSION >= 4006
60 #include "c-family/c-common.h"
65 #if BUILDING_GCC_VERSION <= 4008
66 #include "tree-flow.h"
68 #include "tree-cfgcleanup.h"
69 #include "tree-ssa-operands.h"
70 #include "tree-into-ssa.h"
73 #if BUILDING_GCC_VERSION >= 4008
77 #include "diagnostic.h"
78 #include "tree-dump.h"
79 #include "tree-pass.h"
81 #include "ipa-utils.h"
83 #if BUILDING_GCC_VERSION >= 4009
86 #include "stor-layout.h"
87 #include "internal-fn.h"
88 #include "gimple-expr.h"
89 #include "gimple-fold.h"
91 #include "tree-ssa-alias.h"
93 #include "stringpool.h"
94 #include "tree-ssanames.h"
95 #include "print-tree.h"
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"
112 #if BUILDING_GCC_VERSION >= 5000
113 #include "builtins.h"
116 /* #include "expr.h" where are you... */
117 extern rtx emit_move_insn(rtx x, rtx y);
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);
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);
132 #define __unused __attribute__((__unused__))
133 #define __visible __attribute__((visibility("default")))
135 #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
136 #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
137 #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
138 #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
140 /* should come from c-tree.h if only it were installed for gcc 4.5... */
141 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
143 #if BUILDING_GCC_VERSION == 4005
144 #define FOR_EACH_LOCAL_DECL(FUN, I, D) \
145 for (tree vars = (FUN)->local_decls, (I) = 0; \
146 vars && ((D) = TREE_VALUE(vars)); \
147 vars = TREE_CHAIN(vars), (I)++)
148 #define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
149 #define FOR_EACH_VEC_ELT(T, V, I, P) \
150 for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
151 #define TODO_rebuild_cgraph_edges 0
152 #define SCOPE_FILE_SCOPE_P(EXP) (!(EXP))
158 typedef struct varpool_node *varpool_node_ptr;
160 static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
164 if (!is_gimple_call(stmt))
166 fndecl = gimple_call_fndecl(stmt);
167 if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
169 return DECL_FUNCTION_CODE(fndecl) == code;
172 static inline bool is_simple_builtin(tree decl)
174 if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
177 switch (DECL_FUNCTION_CODE(decl)) {
178 /* Builtins that expand to constants. */
179 case BUILT_IN_CONSTANT_P:
180 case BUILT_IN_EXPECT:
181 case BUILT_IN_OBJECT_SIZE:
182 case BUILT_IN_UNREACHABLE:
183 /* Simple register moves or loads from stack. */
184 case BUILT_IN_RETURN_ADDRESS:
185 case BUILT_IN_EXTRACT_RETURN_ADDR:
186 case BUILT_IN_FROB_RETURN_ADDR:
187 case BUILT_IN_RETURN:
188 case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
189 case BUILT_IN_FRAME_ADDRESS:
190 case BUILT_IN_VA_END:
191 case BUILT_IN_STACK_SAVE:
192 case BUILT_IN_STACK_RESTORE:
193 /* Exception state returns or moves registers around. */
194 case BUILT_IN_EH_FILTER:
195 case BUILT_IN_EH_POINTER:
196 case BUILT_IN_EH_COPY_VALUES:
204 static inline void add_local_decl(struct function *fun, tree d)
206 gcc_assert(TREE_CODE(d) == VAR_DECL);
207 fun->local_decls = tree_cons(NULL_TREE, d, fun->local_decls);
211 #if BUILDING_GCC_VERSION <= 4006
212 #define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
213 #define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
214 #define EDGE_PRESERVE 0ULL
215 #define HOST_WIDE_INT_PRINT_HEX_PURE "%" HOST_WIDE_INT_PRINT "x"
216 #define flag_fat_lto_objects true
218 #define get_random_seed(noinit) ({ \
219 unsigned HOST_WIDE_INT seed; \
220 sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
223 #define int_const_binop(code, arg1, arg2) \
224 int_const_binop((code), (arg1), (arg2), 0)
226 static inline bool gimple_clobber_p(gimple s __unused)
231 static inline bool gimple_asm_clobbers_memory_p(const_gimple stmt)
235 for (i = 0; i < gimple_asm_nclobbers(stmt); i++) {
236 tree op = gimple_asm_clobber_op(stmt, i);
238 if (!strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "memory"))
245 static inline tree builtin_decl_implicit(enum built_in_function fncode)
247 return implicit_built_in_decls[fncode];
250 static inline int ipa_reverse_postorder(struct cgraph_node **order)
252 return cgraph_postorder(order);
255 static inline struct cgraph_node *cgraph_create_node(tree decl)
257 return cgraph_node(decl);
260 static inline struct cgraph_node *cgraph_get_create_node(tree decl)
262 struct cgraph_node *node = cgraph_get_node(decl);
264 return node ? node : cgraph_node(decl);
267 static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
269 return node->analyzed && !node->thunk.thunk_p && !node->alias;
272 static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
274 struct cgraph_node *node;
276 for (node = cgraph_nodes; node; node = node->next)
277 if (cgraph_function_with_gimple_body_p(node))
282 static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
284 for (node = node->next; node; node = node->next)
285 if (cgraph_function_with_gimple_body_p(node))
290 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
291 for ((node) = cgraph_first_function_with_gimple_body(); (node); \
292 (node) = cgraph_next_function_with_gimple_body(node))
294 static inline void varpool_add_new_variable(tree decl)
296 varpool_finalize_decl(decl);
300 #if BUILDING_GCC_VERSION <= 4007
301 #define FOR_EACH_FUNCTION(node) \
302 for (node = cgraph_nodes; node; node = node->next)
303 #define FOR_EACH_VARIABLE(node) \
304 for (node = varpool_nodes; node; node = node->next)
306 #define NODE_SYMBOL(node) (node)
307 #define NODE_DECL(node) (node)->decl
308 #define INSN_LOCATION(INSN) RTL_LOCATION(INSN)
311 static inline int bb_loop_depth(const_basic_block bb)
313 return bb->loop_father ? loop_depth(bb->loop_father) : 0;
316 static inline bool gimple_store_p(gimple gs)
318 tree lhs = gimple_get_lhs(gs);
320 return lhs && !is_gimple_reg(lhs);
323 static inline void gimple_init_singleton(gimple g __unused)
328 #if BUILDING_GCC_VERSION == 4007 || BUILDING_GCC_VERSION == 4008
329 static inline struct cgraph_node *cgraph_alias_target(struct cgraph_node *n)
331 return cgraph_alias_aliased_node(n);
335 #if BUILDING_GCC_VERSION >= 4007 && BUILDING_GCC_VERSION <= 4009
336 #define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
337 cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
338 #define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
339 cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
342 #if BUILDING_GCC_VERSION <= 4008
343 #define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
344 #define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
345 #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
346 #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
347 #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
348 #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
349 #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
350 #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
351 #define BASIC_BLOCK_FOR_FN(FN, N) BASIC_BLOCK_FOR_FUNCTION((FN), (N))
352 #define NODE_IMPLICIT_ALIAS(node) (node)->same_body_alias
353 #define VAR_P(NODE) (TREE_CODE(NODE) == VAR_DECL)
355 static inline bool tree_fits_shwi_p(const_tree t)
357 if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
360 if (TREE_INT_CST_HIGH(t) == 0 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) >= 0)
363 if (TREE_INT_CST_HIGH(t) == -1 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) < 0 && !TYPE_UNSIGNED(TREE_TYPE(t)))
369 static inline bool tree_fits_uhwi_p(const_tree t)
371 if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST)
374 return TREE_INT_CST_HIGH(t) == 0;
377 static inline HOST_WIDE_INT tree_to_shwi(const_tree t)
379 gcc_assert(tree_fits_shwi_p(t));
380 return TREE_INT_CST_LOW(t);
383 static inline unsigned HOST_WIDE_INT tree_to_uhwi(const_tree t)
385 gcc_assert(tree_fits_uhwi_p(t));
386 return TREE_INT_CST_LOW(t);
389 static inline const char *get_tree_code_name(enum tree_code code)
391 gcc_assert(code < MAX_TREE_CODES);
392 return tree_code_name[code];
395 #define ipa_remove_stmt_references(cnode, stmt)
397 typedef union gimple_statement_d gasm;
398 typedef union gimple_statement_d gassign;
399 typedef union gimple_statement_d gcall;
400 typedef union gimple_statement_d gcond;
401 typedef union gimple_statement_d gdebug;
402 typedef union gimple_statement_d gphi;
403 typedef union gimple_statement_d greturn;
405 static inline gasm *as_a_gasm(gimple stmt)
410 static inline const gasm *as_a_const_gasm(const_gimple stmt)
415 static inline gassign *as_a_gassign(gimple stmt)
420 static inline const gassign *as_a_const_gassign(const_gimple stmt)
425 static inline gcall *as_a_gcall(gimple stmt)
430 static inline const gcall *as_a_const_gcall(const_gimple stmt)
435 static inline gcond *as_a_gcond(gimple stmt)
440 static inline const gcond *as_a_const_gcond(const_gimple stmt)
445 static inline gdebug *as_a_gdebug(gimple stmt)
450 static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
455 static inline gphi *as_a_gphi(gimple stmt)
460 static inline const gphi *as_a_const_gphi(const_gimple stmt)
465 static inline greturn *as_a_greturn(gimple stmt)
470 static inline const greturn *as_a_const_greturn(const_gimple stmt)
476 #if BUILDING_GCC_VERSION == 4008
477 #define NODE_SYMBOL(node) (&(node)->symbol)
478 #define NODE_DECL(node) (node)->symbol.decl
481 #if BUILDING_GCC_VERSION >= 4008
482 #define add_referenced_var(var)
483 #define mark_sym_for_renaming(var)
484 #define varpool_mark_needed_node(node)
485 #define create_var_ann(var)
486 #define TODO_dump_func 0
487 #define TODO_dump_cgraph 0
490 #if BUILDING_GCC_VERSION <= 4009
491 #define TODO_verify_il 0
492 #define AVAIL_INTERPOSABLE AVAIL_OVERWRITABLE
494 #define section_name_prefix LTO_SECTION_NAME_PREFIX
495 #define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)
497 typedef struct rtx_def rtx_insn;
499 static inline void set_decl_section_name(tree node, const char *value)
502 DECL_SECTION_NAME(node) = build_string(strlen(value) + 1, value);
504 DECL_SECTION_NAME(node) = NULL;
508 #if BUILDING_GCC_VERSION == 4009
509 typedef struct gimple_statement_asm gasm;
510 typedef struct gimple_statement_base gassign;
511 typedef struct gimple_statement_call gcall;
512 typedef struct gimple_statement_base gcond;
513 typedef struct gimple_statement_base gdebug;
514 typedef struct gimple_statement_phi gphi;
515 typedef struct gimple_statement_base greturn;
517 static inline gasm *as_a_gasm(gimple stmt)
519 return as_a<gasm>(stmt);
522 static inline const gasm *as_a_const_gasm(const_gimple stmt)
524 return as_a<const gasm>(stmt);
527 static inline gassign *as_a_gassign(gimple stmt)
532 static inline const gassign *as_a_const_gassign(const_gimple stmt)
537 static inline gcall *as_a_gcall(gimple stmt)
539 return as_a<gcall>(stmt);
542 static inline const gcall *as_a_const_gcall(const_gimple stmt)
544 return as_a<const gcall>(stmt);
547 static inline gcond *as_a_gcond(gimple stmt)
552 static inline const gcond *as_a_const_gcond(const_gimple stmt)
557 static inline gdebug *as_a_gdebug(gimple stmt)
562 static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
567 static inline gphi *as_a_gphi(gimple stmt)
569 return as_a<gphi>(stmt);
572 static inline const gphi *as_a_const_gphi(const_gimple stmt)
574 return as_a<const gphi>(stmt);
577 static inline greturn *as_a_greturn(gimple stmt)
582 static inline const greturn *as_a_const_greturn(const_gimple stmt)
588 #if BUILDING_GCC_VERSION >= 4009
589 #define TODO_ggc_collect 0
590 #define NODE_SYMBOL(node) (node)
591 #define NODE_DECL(node) (node)->decl
592 #define cgraph_node_name(node) (node)->name()
593 #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
596 #if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000
600 inline bool is_a_helper<const gassign *>::test(const_gimple gs)
602 return gs->code == GIMPLE_ASSIGN;
606 #if BUILDING_GCC_VERSION >= 5000
607 #define TODO_verify_ssa TODO_verify_il
608 #define TODO_verify_flow TODO_verify_il
609 #define TODO_verify_stmts TODO_verify_il
610 #define TODO_verify_rtl_sharing TODO_verify_il
612 #define INSN_DELETED_P(insn) (insn)->deleted()
614 /* symtab/cgraph related */
615 #define debug_cgraph_node(node) (node)->debug()
616 #define cgraph_get_node(decl) cgraph_node::get(decl)
617 #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
618 #define cgraph_create_node(decl) cgraph_node::create(decl)
619 #define cgraph_n_nodes symtab->cgraph_count
620 #define cgraph_max_uid symtab->cgraph_max_uid
621 #define varpool_get_node(decl) varpool_node::get(decl)
623 #define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
624 (caller)->create_edge((callee), (call_stmt), (count), (freq))
625 #define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
626 (caller)->create_edge_including_clones((callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
628 typedef struct cgraph_node *cgraph_node_ptr;
629 typedef struct cgraph_edge *cgraph_edge_p;
630 typedef struct varpool_node *varpool_node_ptr;
632 static inline void change_decl_assembler_name(tree decl, tree name)
634 symtab->change_decl_assembler_name(decl, name);
637 static inline void varpool_finalize_decl(tree decl)
639 varpool_node::finalize_decl(decl);
642 static inline void varpool_add_new_variable(tree decl)
644 varpool_node::add(decl);
647 static inline unsigned int rebuild_cgraph_edges(void)
649 return cgraph_edge::rebuild_edges();
652 static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
654 return node->function_symbol(availability);
657 static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
659 return node->ultimate_alias_target(availability);
662 static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
664 return node->only_called_directly_p();
667 static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
669 return node->get_availability();
672 static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
674 return node->get_alias_target();
677 static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
679 return symtab->add_cgraph_insertion_hook(hook, data);
682 static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
684 symtab->remove_cgraph_insertion_hook(entry);
687 static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
689 return symtab->add_cgraph_removal_hook(hook, data);
692 static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
694 symtab->remove_cgraph_removal_hook(entry);
697 static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
699 return symtab->add_cgraph_duplication_hook(hook, data);
702 static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
704 symtab->remove_cgraph_duplication_hook(entry);
707 static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
709 symtab->call_cgraph_duplication_hooks(node, node2);
712 static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
714 symtab->call_edge_duplication_hooks(cs1, cs2);
717 #if BUILDING_GCC_VERSION >= 6000
718 typedef gimple *gimple_ptr;
719 typedef const gimple *const_gimple_ptr;
720 #define gimple gimple_ptr
721 #define const_gimple const_gimple_ptr
722 #undef CONST_CAST_GIMPLE
723 #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
727 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
729 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
734 inline bool is_a_helper<const greturn *>::test(const_gimple gs)
736 return gs->code == GIMPLE_RETURN;
739 static inline gasm *as_a_gasm(gimple stmt)
741 return as_a<gasm *>(stmt);
744 static inline const gasm *as_a_const_gasm(const_gimple stmt)
746 return as_a<const gasm *>(stmt);
749 static inline gassign *as_a_gassign(gimple stmt)
751 return as_a<gassign *>(stmt);
754 static inline const gassign *as_a_const_gassign(const_gimple stmt)
756 return as_a<const gassign *>(stmt);
759 static inline gcall *as_a_gcall(gimple stmt)
761 return as_a<gcall *>(stmt);
764 static inline const gcall *as_a_const_gcall(const_gimple stmt)
766 return as_a<const gcall *>(stmt);
769 static inline gphi *as_a_gphi(gimple stmt)
771 return as_a<gphi *>(stmt);
774 static inline const gphi *as_a_const_gphi(const_gimple stmt)
776 return as_a<const gphi *>(stmt);
779 static inline greturn *as_a_greturn(gimple stmt)
781 return as_a<greturn *>(stmt);
784 static inline const greturn *as_a_const_greturn(const_gimple stmt)
786 return as_a<const greturn *>(stmt);
789 /* IPA/LTO related */
790 #define ipa_ref_list_referring_iterate(L, I, P) \
791 (L)->referring.iterate((I), &(P))
792 #define ipa_ref_list_reference_iterate(L, I, P) \
793 (L)->reference.iterate((I), &(P))
795 static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
797 return dyn_cast<cgraph_node_ptr>(ref->referring);
800 static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
802 referring_node->remove_stmt_references(stmt);
806 #if BUILDING_GCC_VERSION < 6000
807 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
808 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
809 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
812 #if BUILDING_GCC_VERSION >= 6000
813 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
817 static inline void debug_tree(const_tree t)
819 debug_tree(CONST_CAST_TREE(t));
822 static inline void debug_gimple_stmt(const_gimple s)
824 debug_gimple_stmt(CONST_CAST_GIMPLE(s));
827 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
828 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))