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"
31 #include "basic-block.h"
36 #if BUILDING_GCC_VERSION < 10000
42 #if BUILDING_GCC_VERSION >= 7000
48 #include "langhooks.h"
52 #include "tree-pretty-print.h"
53 #include "gimple-pretty-print.h"
54 #include "c-family/c-common.h"
55 #include "tree-cfgcleanup.h"
56 #include "tree-ssa-operands.h"
57 #include "tree-into-ssa.h"
59 #include "diagnostic.h"
60 #include "tree-dump.h"
61 #include "tree-pass.h"
62 #include "pass_manager.h"
64 #include "ipa-utils.h"
65 #include "stringpool.h"
68 #include "stor-layout.h"
69 #include "internal-fn.h"
71 #include "gimple-expr.h"
72 #include "gimple-iterator.h"
73 #include "gimple-fold.h"
75 #include "tree-ssa-alias.h"
77 #if BUILDING_GCC_VERSION >= 7000
80 #include "tree-ssanames.h"
81 #include "print-tree.h"
85 #include "tree-phinodes.h"
87 #include "gimple-ssa.h"
88 #include "ssa-iterators.h"
92 /* missing from basic_block.h... */
93 void debug_dominance_info(enum cdi_direction dir);
94 void debug_dominance_tree(enum cdi_direction dir, basic_block root);
97 #define __unused __attribute__((__unused__))
100 #define __visible __attribute__((visibility("default")))
103 #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
104 #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
105 #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
106 #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
108 /* should come from c-tree.h if only it were installed for gcc 4.5... */
109 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111 static inline tree build_const_char_string(int len, const char *str)
113 tree cstr, elem, index, type;
115 cstr = build_string(len, str);
116 elem = build_type_variant(char_type_node, 1, 0);
117 index = build_index_type(size_int(len - 1));
118 type = build_array_type(elem, index);
119 TREE_TYPE(cstr) = type;
120 TREE_CONSTANT(cstr) = 1;
121 TREE_READONLY(cstr) = 1;
122 TREE_STATIC(cstr) = 1;
126 #define PASS_INFO(NAME, REF, ID, POS) \
127 struct register_pass_info NAME##_pass_info = { \
128 .pass = make_##NAME##_pass(), \
129 .reference_pass_name = REF, \
130 .ref_pass_instance_number = ID, \
134 #define add_referenced_var(var)
135 #define mark_sym_for_renaming(var)
136 #define varpool_mark_needed_node(node)
137 #define create_var_ann(var)
138 #define TODO_dump_func 0
139 #define TODO_dump_cgraph 0
141 #define TODO_ggc_collect 0
142 #define NODE_SYMBOL(node) (node)
143 #define NODE_DECL(node) (node)->decl
144 #define cgraph_node_name(node) (node)->name()
145 #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
147 static inline opt_pass *get_pass_for_id(int id)
149 return g->get_passes()->get_pass_for_id(id);
152 #if BUILDING_GCC_VERSION < 6000
156 inline bool is_a_helper<const gassign *>::test(const_gimple gs)
158 return gs->code == GIMPLE_ASSIGN;
162 #define TODO_verify_ssa TODO_verify_il
163 #define TODO_verify_flow TODO_verify_il
164 #define TODO_verify_stmts TODO_verify_il
165 #define TODO_verify_rtl_sharing TODO_verify_il
167 #define INSN_DELETED_P(insn) (insn)->deleted()
169 static inline const char *get_decl_section_name(const_tree decl)
171 return DECL_SECTION_NAME(decl);
174 /* symtab/cgraph related */
175 #define debug_cgraph_node(node) (node)->debug()
176 #define cgraph_get_node(decl) cgraph_node::get(decl)
177 #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
178 #define cgraph_create_node(decl) cgraph_node::create(decl)
179 #define cgraph_n_nodes symtab->cgraph_count
180 #define cgraph_max_uid symtab->cgraph_max_uid
181 #define varpool_get_node(decl) varpool_node::get(decl)
182 #define dump_varpool_node(file, node) (node)->dump(file)
184 #if BUILDING_GCC_VERSION >= 8000
185 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
186 (caller)->create_edge((callee), (call_stmt), (count))
188 #define cgraph_create_edge_including_clones(caller, callee, \
189 old_call_stmt, call_stmt, count, freq, reason) \
190 (caller)->create_edge_including_clones((callee), \
191 (old_call_stmt), (call_stmt), (count), (reason))
193 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
194 (caller)->create_edge((callee), (call_stmt), (count), (freq))
196 #define cgraph_create_edge_including_clones(caller, callee, \
197 old_call_stmt, call_stmt, count, freq, reason) \
198 (caller)->create_edge_including_clones((callee), \
199 (old_call_stmt), (call_stmt), (count), (freq), (reason))
202 typedef struct cgraph_node *cgraph_node_ptr;
203 typedef struct cgraph_edge *cgraph_edge_p;
204 typedef struct varpool_node *varpool_node_ptr;
206 static inline void change_decl_assembler_name(tree decl, tree name)
208 symtab->change_decl_assembler_name(decl, name);
211 static inline void varpool_finalize_decl(tree decl)
213 varpool_node::finalize_decl(decl);
216 static inline void varpool_add_new_variable(tree decl)
218 varpool_node::add(decl);
221 static inline unsigned int rebuild_cgraph_edges(void)
223 return cgraph_edge::rebuild_edges();
226 static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
228 return node->function_symbol(availability);
231 static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
233 return node->ultimate_alias_target(availability);
236 static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
238 return node->only_called_directly_p();
241 static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
243 return node->get_availability();
246 static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
248 return node->get_alias_target();
251 static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
253 return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
256 static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
258 return symtab->add_cgraph_insertion_hook(hook, data);
261 static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
263 symtab->remove_cgraph_insertion_hook(entry);
266 static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
268 return symtab->add_cgraph_removal_hook(hook, data);
271 static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
273 symtab->remove_cgraph_removal_hook(entry);
276 static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
278 return symtab->add_cgraph_duplication_hook(hook, data);
281 static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
283 symtab->remove_cgraph_duplication_hook(entry);
286 static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
288 symtab->call_cgraph_duplication_hooks(node, node2);
291 static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
293 symtab->call_edge_duplication_hooks(cs1, cs2);
296 #if BUILDING_GCC_VERSION >= 6000
297 typedef gimple *gimple_ptr;
298 typedef const gimple *const_gimple_ptr;
299 #define gimple gimple_ptr
300 #define const_gimple const_gimple_ptr
301 #undef CONST_CAST_GIMPLE
302 #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
306 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
308 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
311 #if BUILDING_GCC_VERSION < 10000
314 inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
316 return gs->code == GIMPLE_GOTO;
321 inline bool is_a_helper<const greturn *>::test(const_gimple gs)
323 return gs->code == GIMPLE_RETURN;
327 static inline gasm *as_a_gasm(gimple stmt)
329 return as_a<gasm *>(stmt);
332 static inline const gasm *as_a_const_gasm(const_gimple stmt)
334 return as_a<const gasm *>(stmt);
337 static inline gassign *as_a_gassign(gimple stmt)
339 return as_a<gassign *>(stmt);
342 static inline const gassign *as_a_const_gassign(const_gimple stmt)
344 return as_a<const gassign *>(stmt);
347 static inline gcall *as_a_gcall(gimple stmt)
349 return as_a<gcall *>(stmt);
352 static inline const gcall *as_a_const_gcall(const_gimple stmt)
354 return as_a<const gcall *>(stmt);
357 static inline ggoto *as_a_ggoto(gimple stmt)
359 return as_a<ggoto *>(stmt);
362 static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
364 return as_a<const ggoto *>(stmt);
367 static inline gphi *as_a_gphi(gimple stmt)
369 return as_a<gphi *>(stmt);
372 static inline const gphi *as_a_const_gphi(const_gimple stmt)
374 return as_a<const gphi *>(stmt);
377 static inline greturn *as_a_greturn(gimple stmt)
379 return as_a<greturn *>(stmt);
382 static inline const greturn *as_a_const_greturn(const_gimple stmt)
384 return as_a<const greturn *>(stmt);
387 /* IPA/LTO related */
388 #define ipa_ref_list_referring_iterate(L, I, P) \
389 (L)->referring.iterate((I), &(P))
390 #define ipa_ref_list_reference_iterate(L, I, P) \
391 (L)->reference.iterate((I), &(P))
393 static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
395 return dyn_cast<cgraph_node_ptr>(ref->referring);
398 static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
400 referring_node->remove_stmt_references(stmt);
403 #if BUILDING_GCC_VERSION < 6000
404 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
405 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
406 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
409 #if BUILDING_GCC_VERSION >= 6000
410 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
414 static inline void debug_tree(const_tree t)
416 debug_tree(CONST_CAST_TREE(t));
419 static inline void debug_gimple_stmt(const_gimple s)
421 debug_gimple_stmt(CONST_CAST_GIMPLE(s));
424 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
425 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
428 #if BUILDING_GCC_VERSION >= 7000
429 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
430 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
433 #if BUILDING_GCC_VERSION < 7000
434 #define SET_DECL_ALIGN(decl, align) DECL_ALIGN(decl) = (align)
435 #define SET_DECL_MODE(decl, mode) DECL_MODE(decl) = (mode)
438 #if BUILDING_GCC_VERSION >= 14000
439 #define last_stmt(x) last_nondebug_stmt(x)