1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef GCC_COMMON_H_INCLUDED
3 #define GCC_COMMON_H_INCLUDED
6 #if BUILDING_GCC_VERSION >= 6000
7 #include "gcc-plugin.h"
11 #include "plugin-version.h"
14 #include "coretypes.h"
20 #include "tree-inline.h"
25 #include "hard-reg-set.h"
30 #if BUILDING_GCC_VERSION >= 5000
33 #include "basic-block.h"
38 #if BUILDING_GCC_VERSION < 10000
42 #if BUILDING_GCC_VERSION <= 4009
43 #include "pointer-set.h"
48 #if BUILDING_GCC_VERSION >= 7000
54 #include "langhooks.h"
58 #include "tree-pretty-print.h"
59 #include "gimple-pretty-print.h"
60 #include "c-family/c-common.h"
61 #include "tree-cfgcleanup.h"
62 #include "tree-ssa-operands.h"
63 #include "tree-into-ssa.h"
65 #include "diagnostic.h"
66 #include "tree-dump.h"
67 #include "tree-pass.h"
68 #include "pass_manager.h"
70 #include "ipa-utils.h"
72 #if BUILDING_GCC_VERSION >= 8000
73 #include "stringpool.h"
78 #include "stor-layout.h"
79 #include "internal-fn.h"
80 #include "gimple-expr.h"
81 #include "gimple-fold.h"
83 #include "tree-ssa-alias.h"
85 #include "stringpool.h"
86 #if BUILDING_GCC_VERSION >= 7000
89 #include "tree-ssanames.h"
90 #include "print-tree.h"
95 #include "tree-ssa-operands.h"
96 #include "tree-phinodes.h"
98 #include "gimple-iterator.h"
99 #include "gimple-ssa.h"
100 #include "ssa-iterators.h"
102 #if BUILDING_GCC_VERSION >= 5000
103 #include "builtins.h"
106 /* missing from basic_block.h... */
107 void debug_dominance_info(enum cdi_direction dir
);
108 void debug_dominance_tree(enum cdi_direction dir
, basic_block root
);
111 #define __unused __attribute__((__unused__))
114 #define __visible __attribute__((visibility("default")))
117 #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
118 #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
119 #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
120 #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
122 /* should come from c-tree.h if only it were installed for gcc 4.5... */
123 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
125 static inline tree
build_const_char_string(int len
, const char *str
)
127 tree cstr
, elem
, index
, type
;
129 cstr
= build_string(len
, str
);
130 elem
= build_type_variant(char_type_node
, 1, 0);
131 index
= build_index_type(size_int(len
- 1));
132 type
= build_array_type(elem
, index
);
133 TREE_TYPE(cstr
) = type
;
134 TREE_CONSTANT(cstr
) = 1;
135 TREE_READONLY(cstr
) = 1;
136 TREE_STATIC(cstr
) = 1;
140 #define PASS_INFO(NAME, REF, ID, POS) \
141 struct register_pass_info NAME##_pass_info = { \
142 .pass = make_##NAME##_pass(), \
143 .reference_pass_name = REF, \
144 .ref_pass_instance_number = ID, \
148 #define add_referenced_var(var)
149 #define mark_sym_for_renaming(var)
150 #define varpool_mark_needed_node(node)
151 #define create_var_ann(var)
152 #define TODO_dump_func 0
153 #define TODO_dump_cgraph 0
155 #if BUILDING_GCC_VERSION <= 4009
156 #define TODO_verify_il 0
157 #define AVAIL_INTERPOSABLE AVAIL_OVERWRITABLE
159 #define section_name_prefix LTO_SECTION_NAME_PREFIX
160 #define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)
162 rtx
emit_move_insn(rtx x
, rtx y
);
164 typedef struct rtx_def rtx_insn
;
166 static inline const char *get_decl_section_name(const_tree decl
)
168 if (DECL_SECTION_NAME(decl
) == NULL_TREE
)
171 return TREE_STRING_POINTER(DECL_SECTION_NAME(decl
));
174 static inline void set_decl_section_name(tree node
, const char *value
)
177 DECL_SECTION_NAME(node
) = build_string(strlen(value
) + 1, value
);
179 DECL_SECTION_NAME(node
) = NULL
;
183 #if BUILDING_GCC_VERSION == 4009
184 typedef struct gimple_statement_asm gasm
;
185 typedef struct gimple_statement_base gassign
;
186 typedef struct gimple_statement_call gcall
;
187 typedef struct gimple_statement_base gcond
;
188 typedef struct gimple_statement_base gdebug
;
189 typedef struct gimple_statement_base ggoto
;
190 typedef struct gimple_statement_phi gphi
;
191 typedef struct gimple_statement_base greturn
;
193 static inline gasm
*as_a_gasm(gimple stmt
)
195 return as_a
<gasm
>(stmt
);
198 static inline const gasm
*as_a_const_gasm(const_gimple stmt
)
200 return as_a
<const gasm
>(stmt
);
203 static inline gassign
*as_a_gassign(gimple stmt
)
208 static inline const gassign
*as_a_const_gassign(const_gimple stmt
)
213 static inline gcall
*as_a_gcall(gimple stmt
)
215 return as_a
<gcall
>(stmt
);
218 static inline const gcall
*as_a_const_gcall(const_gimple stmt
)
220 return as_a
<const gcall
>(stmt
);
223 static inline gcond
*as_a_gcond(gimple stmt
)
228 static inline const gcond
*as_a_const_gcond(const_gimple stmt
)
233 static inline gdebug
*as_a_gdebug(gimple stmt
)
238 static inline const gdebug
*as_a_const_gdebug(const_gimple stmt
)
243 static inline ggoto
*as_a_ggoto(gimple stmt
)
248 static inline const ggoto
*as_a_const_ggoto(const_gimple stmt
)
253 static inline gphi
*as_a_gphi(gimple stmt
)
255 return as_a
<gphi
>(stmt
);
258 static inline const gphi
*as_a_const_gphi(const_gimple stmt
)
260 return as_a
<const gphi
>(stmt
);
263 static inline greturn
*as_a_greturn(gimple stmt
)
268 static inline const greturn
*as_a_const_greturn(const_gimple stmt
)
274 #define TODO_ggc_collect 0
275 #define NODE_SYMBOL(node) (node)
276 #define NODE_DECL(node) (node)->decl
277 #define cgraph_node_name(node) (node)->name()
278 #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
280 static inline opt_pass
*get_pass_for_id(int id
)
282 return g
->get_passes()->get_pass_for_id(id
);
285 #if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000
289 inline bool is_a_helper
<const gassign
*>::test(const_gimple gs
)
291 return gs
->code
== GIMPLE_ASSIGN
;
295 #if BUILDING_GCC_VERSION >= 5000
296 #define TODO_verify_ssa TODO_verify_il
297 #define TODO_verify_flow TODO_verify_il
298 #define TODO_verify_stmts TODO_verify_il
299 #define TODO_verify_rtl_sharing TODO_verify_il
301 #define INSN_DELETED_P(insn) (insn)->deleted()
303 static inline const char *get_decl_section_name(const_tree decl
)
305 return DECL_SECTION_NAME(decl
);
308 /* symtab/cgraph related */
309 #define debug_cgraph_node(node) (node)->debug()
310 #define cgraph_get_node(decl) cgraph_node::get(decl)
311 #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
312 #define cgraph_create_node(decl) cgraph_node::create(decl)
313 #define cgraph_n_nodes symtab->cgraph_count
314 #define cgraph_max_uid symtab->cgraph_max_uid
315 #define varpool_get_node(decl) varpool_node::get(decl)
316 #define dump_varpool_node(file, node) (node)->dump(file)
318 #if BUILDING_GCC_VERSION >= 8000
319 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
320 (caller)->create_edge((callee), (call_stmt), (count))
322 #define cgraph_create_edge_including_clones(caller, callee, \
323 old_call_stmt, call_stmt, count, freq, reason) \
324 (caller)->create_edge_including_clones((callee), \
325 (old_call_stmt), (call_stmt), (count), (reason))
327 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
328 (caller)->create_edge((callee), (call_stmt), (count), (freq))
330 #define cgraph_create_edge_including_clones(caller, callee, \
331 old_call_stmt, call_stmt, count, freq, reason) \
332 (caller)->create_edge_including_clones((callee), \
333 (old_call_stmt), (call_stmt), (count), (freq), (reason))
336 typedef struct cgraph_node
*cgraph_node_ptr
;
337 typedef struct cgraph_edge
*cgraph_edge_p
;
338 typedef struct varpool_node
*varpool_node_ptr
;
340 static inline void change_decl_assembler_name(tree decl
, tree name
)
342 symtab
->change_decl_assembler_name(decl
, name
);
345 static inline void varpool_finalize_decl(tree decl
)
347 varpool_node::finalize_decl(decl
);
350 static inline void varpool_add_new_variable(tree decl
)
352 varpool_node::add(decl
);
355 static inline unsigned int rebuild_cgraph_edges(void)
357 return cgraph_edge::rebuild_edges();
360 static inline cgraph_node_ptr
cgraph_function_node(cgraph_node_ptr node
, enum availability
*availability
)
362 return node
->function_symbol(availability
);
365 static inline cgraph_node_ptr
cgraph_function_or_thunk_node(cgraph_node_ptr node
, enum availability
*availability
= NULL
)
367 return node
->ultimate_alias_target(availability
);
370 static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node
)
372 return node
->only_called_directly_p();
375 static inline enum availability
cgraph_function_body_availability(cgraph_node_ptr node
)
377 return node
->get_availability();
380 static inline cgraph_node_ptr
cgraph_alias_target(cgraph_node_ptr node
)
382 return node
->get_alias_target();
385 static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node
, bool (*callback
)(cgraph_node_ptr
, void *), void *data
, bool include_overwritable
)
387 return node
->call_for_symbol_thunks_and_aliases(callback
, data
, include_overwritable
);
390 static inline struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook(cgraph_node_hook hook
, void *data
)
392 return symtab
->add_cgraph_insertion_hook(hook
, data
);
395 static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list
*entry
)
397 symtab
->remove_cgraph_insertion_hook(entry
);
400 static inline struct cgraph_node_hook_list
*cgraph_add_node_removal_hook(cgraph_node_hook hook
, void *data
)
402 return symtab
->add_cgraph_removal_hook(hook
, data
);
405 static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list
*entry
)
407 symtab
->remove_cgraph_removal_hook(entry
);
410 static inline struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook(cgraph_2node_hook hook
, void *data
)
412 return symtab
->add_cgraph_duplication_hook(hook
, data
);
415 static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list
*entry
)
417 symtab
->remove_cgraph_duplication_hook(entry
);
420 static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node
, cgraph_node_ptr node2
)
422 symtab
->call_cgraph_duplication_hooks(node
, node2
);
425 static inline void cgraph_call_edge_duplication_hooks(cgraph_edge
*cs1
, cgraph_edge
*cs2
)
427 symtab
->call_edge_duplication_hooks(cs1
, cs2
);
430 #if BUILDING_GCC_VERSION >= 6000
431 typedef gimple
*gimple_ptr
;
432 typedef const gimple
*const_gimple_ptr
;
433 #define gimple gimple_ptr
434 #define const_gimple const_gimple_ptr
435 #undef CONST_CAST_GIMPLE
436 #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
440 static inline gimple
gimple_build_assign_with_ops(enum tree_code subcode
, tree lhs
, tree op1
, tree op2 MEM_STAT_DECL
)
442 return gimple_build_assign(lhs
, subcode
, op1
, op2 PASS_MEM_STAT
);
445 #if BUILDING_GCC_VERSION < 10000
448 inline bool is_a_helper
<const ggoto
*>::test(const_gimple gs
)
450 return gs
->code
== GIMPLE_GOTO
;
455 inline bool is_a_helper
<const greturn
*>::test(const_gimple gs
)
457 return gs
->code
== GIMPLE_RETURN
;
461 static inline gasm
*as_a_gasm(gimple stmt
)
463 return as_a
<gasm
*>(stmt
);
466 static inline const gasm
*as_a_const_gasm(const_gimple stmt
)
468 return as_a
<const gasm
*>(stmt
);
471 static inline gassign
*as_a_gassign(gimple stmt
)
473 return as_a
<gassign
*>(stmt
);
476 static inline const gassign
*as_a_const_gassign(const_gimple stmt
)
478 return as_a
<const gassign
*>(stmt
);
481 static inline gcall
*as_a_gcall(gimple stmt
)
483 return as_a
<gcall
*>(stmt
);
486 static inline const gcall
*as_a_const_gcall(const_gimple stmt
)
488 return as_a
<const gcall
*>(stmt
);
491 static inline ggoto
*as_a_ggoto(gimple stmt
)
493 return as_a
<ggoto
*>(stmt
);
496 static inline const ggoto
*as_a_const_ggoto(const_gimple stmt
)
498 return as_a
<const ggoto
*>(stmt
);
501 static inline gphi
*as_a_gphi(gimple stmt
)
503 return as_a
<gphi
*>(stmt
);
506 static inline const gphi
*as_a_const_gphi(const_gimple stmt
)
508 return as_a
<const gphi
*>(stmt
);
511 static inline greturn
*as_a_greturn(gimple stmt
)
513 return as_a
<greturn
*>(stmt
);
516 static inline const greturn
*as_a_const_greturn(const_gimple stmt
)
518 return as_a
<const greturn
*>(stmt
);
521 /* IPA/LTO related */
522 #define ipa_ref_list_referring_iterate(L, I, P) \
523 (L)->referring.iterate((I), &(P))
524 #define ipa_ref_list_reference_iterate(L, I, P) \
525 (L)->reference.iterate((I), &(P))
527 static inline cgraph_node_ptr
ipa_ref_referring_node(struct ipa_ref
*ref
)
529 return dyn_cast
<cgraph_node_ptr
>(ref
->referring
);
532 static inline void ipa_remove_stmt_references(symtab_node
*referring_node
, gimple stmt
)
534 referring_node
->remove_stmt_references(stmt
);
538 #if BUILDING_GCC_VERSION < 6000
539 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
540 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
541 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
544 #if BUILDING_GCC_VERSION >= 6000
545 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
549 static inline void debug_tree(const_tree t
)
551 debug_tree(CONST_CAST_TREE(t
));
554 static inline void debug_gimple_stmt(const_gimple s
)
556 debug_gimple_stmt(CONST_CAST_GIMPLE(s
));
559 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
560 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
563 #if BUILDING_GCC_VERSION >= 7000
564 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
565 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
568 #if BUILDING_GCC_VERSION < 7000
569 #define SET_DECL_ALIGN(decl, align) DECL_ALIGN(decl) = (align)
570 #define SET_DECL_MODE(decl, mode) DECL_MODE(decl) = (mode)