Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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#include "gcc-plugin.h"
7#include "plugin-version.h"
8#include "config.h"
9#include "system.h"
10#include "coretypes.h"
11#include "tm.h"
12#include "line-map.h"
13#include "input.h"
14#include "tree.h"
15
16#include "tree-inline.h"
17#include "version.h"
18#include "rtl.h"
19#include "tm_p.h"
20#include "flags.h"
21#include "hard-reg-set.h"
22#include "output.h"
23#include "except.h"
24#include "function.h"
25#include "toplev.h"
26#include "expr.h"
27#include "basic-block.h"
28#include "intl.h"
29#include "ggc.h"
30#include "timevar.h"
31
32#if BUILDING_GCC_VERSION < 10000
33#include "params.h"
34#endif
35
36#include "hash-map.h"
37
38#include "memmodel.h"
39#include "emit-rtl.h"
40#include "debug.h"
41#include "target.h"
42#include "langhooks.h"
43#include "cfgloop.h"
44#include "cgraph.h"
45#include "opts.h"
46#include "tree-pretty-print.h"
47#include "gimple-pretty-print.h"
48#include "c-family/c-common.h"
49#include "tree-cfgcleanup.h"
50#include "tree-ssa-operands.h"
51#include "tree-into-ssa.h"
52#include "is-a.h"
53#include "diagnostic.h"
54#include "tree-dump.h"
55#include "tree-pass.h"
56#include "pass_manager.h"
57#include "predict.h"
58#include "ipa-utils.h"
59#include "stringpool.h"
60#include "attribs.h"
61#include "varasm.h"
62#include "stor-layout.h"
63#include "internal-fn.h"
64#include "gimple.h"
65#include "gimple-expr.h"
66#include "gimple-iterator.h"
67#include "gimple-fold.h"
68#include "context.h"
69#include "tree-ssa-alias.h"
70#include "tree-ssa.h"
71#include "tree-vrp.h"
72#include "tree-ssanames.h"
73#include "print-tree.h"
74#include "tree-eh.h"
75#include "stmt.h"
76#include "gimplify.h"
77#include "tree-phinodes.h"
78#include "tree-cfg.h"
79#include "gimple-ssa.h"
80#include "ssa-iterators.h"
81
82#include "builtins.h"
83
84/* missing from basic_block.h... */
85void debug_dominance_info(enum cdi_direction dir);
86void debug_dominance_tree(enum cdi_direction dir, basic_block root);
87
88#ifndef __unused
89#define __unused __attribute__((__unused__))
90#endif
91#ifndef __visible
92#define __visible __attribute__((visibility("default")))
93#endif
94
95#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
96#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
97#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
98#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
99
100/* should come from c-tree.h if only it were installed for gcc 4.5... */
101#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
102
103static inline tree build_const_char_string(int len, const char *str)
104{
105 tree cstr, elem, index, type;
106
107 cstr = build_string(len, str);
108 elem = build_type_variant(char_type_node, 1, 0);
109 index = build_index_type(size_int(len - 1));
110 type = build_array_type(elem, index);
111 TREE_TYPE(cstr) = type;
112 TREE_CONSTANT(cstr) = 1;
113 TREE_READONLY(cstr) = 1;
114 TREE_STATIC(cstr) = 1;
115 return cstr;
116}
117
118static inline void __add_type_attr(tree type, const char *attr, tree args)
119{
120 tree oldattr;
121
122 if (type == NULL_TREE)
123 return;
124 oldattr = lookup_attribute(attr, TYPE_ATTRIBUTES(type));
125 if (oldattr != NULL_TREE) {
126 gcc_assert(TREE_VALUE(oldattr) == args || TREE_VALUE(TREE_VALUE(oldattr)) == TREE_VALUE(args));
127 return;
128 }
129
130 TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
131 TYPE_ATTRIBUTES(type) = tree_cons(get_identifier(attr), args, TYPE_ATTRIBUTES(type));
132}
133
134static inline void add_type_attr(tree type, const char *attr, tree args)
135{
136 tree main_variant = TYPE_MAIN_VARIANT(type);
137
138 __add_type_attr(TYPE_CANONICAL(type), attr, args);
139 __add_type_attr(TYPE_CANONICAL(main_variant), attr, args);
140 __add_type_attr(main_variant, attr, args);
141
142 for (type = TYPE_NEXT_VARIANT(main_variant); type; type = TYPE_NEXT_VARIANT(type)) {
143 if (!lookup_attribute(attr, TYPE_ATTRIBUTES(type)))
144 TYPE_ATTRIBUTES(type) = TYPE_ATTRIBUTES(main_variant);
145
146 __add_type_attr(TYPE_CANONICAL(type), attr, args);
147 }
148}
149
150#define PASS_INFO(NAME, REF, ID, POS) \
151struct register_pass_info NAME##_pass_info = { \
152 .pass = make_##NAME##_pass(), \
153 .reference_pass_name = REF, \
154 .ref_pass_instance_number = ID, \
155 .pos_op = POS, \
156}
157
158#define add_referenced_var(var)
159#define mark_sym_for_renaming(var)
160#define varpool_mark_needed_node(node)
161#define create_var_ann(var)
162#define TODO_dump_func 0
163#define TODO_dump_cgraph 0
164
165#define TODO_ggc_collect 0
166#define NODE_SYMBOL(node) (node)
167#define NODE_DECL(node) (node)->decl
168#define cgraph_node_name(node) (node)->name()
169#define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
170
171static inline opt_pass *get_pass_for_id(int id)
172{
173 return g->get_passes()->get_pass_for_id(id);
174}
175
176#if BUILDING_GCC_VERSION < 16000
177#define TODO_verify_ssa TODO_verify_il
178#define TODO_verify_flow TODO_verify_il
179#define TODO_verify_stmts TODO_verify_il
180#define TODO_verify_rtl_sharing TODO_verify_il
181#else
182#define TODO_verify_ssa 0
183#define TODO_verify_flow 0
184#define TODO_verify_stmts 0
185#define TODO_verify_rtl_sharing 0
186#endif
187
188#define INSN_DELETED_P(insn) (insn)->deleted()
189
190static inline const char *get_decl_section_name(const_tree decl)
191{
192 return DECL_SECTION_NAME(decl);
193}
194
195/* symtab/cgraph related */
196#define debug_cgraph_node(node) (node)->debug()
197#define cgraph_get_node(decl) cgraph_node::get(decl)
198#define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
199#define cgraph_create_node(decl) cgraph_node::create(decl)
200#define cgraph_n_nodes symtab->cgraph_count
201#define cgraph_max_uid symtab->cgraph_max_uid
202#define varpool_get_node(decl) varpool_node::get(decl)
203#define dump_varpool_node(file, node) (node)->dump(file)
204
205#define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
206 (caller)->create_edge((callee), (call_stmt), (count))
207
208#define cgraph_create_edge_including_clones(caller, callee, \
209 old_call_stmt, call_stmt, count, freq, reason) \
210 (caller)->create_edge_including_clones((callee), \
211 (old_call_stmt), (call_stmt), (count), (reason))
212
213typedef struct cgraph_node *cgraph_node_ptr;
214typedef struct cgraph_edge *cgraph_edge_p;
215typedef struct varpool_node *varpool_node_ptr;
216
217static inline void change_decl_assembler_name(tree decl, tree name)
218{
219 symtab->change_decl_assembler_name(decl, name);
220}
221
222static inline void varpool_finalize_decl(tree decl)
223{
224 varpool_node::finalize_decl(decl);
225}
226
227static inline void varpool_add_new_variable(tree decl)
228{
229 varpool_node::add(decl);
230}
231
232static inline unsigned int rebuild_cgraph_edges(void)
233{
234 return cgraph_edge::rebuild_edges();
235}
236
237static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
238{
239 return node->function_symbol(availability);
240}
241
242static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
243{
244 return node->ultimate_alias_target(availability);
245}
246
247static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
248{
249 return node->only_called_directly_p();
250}
251
252static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
253{
254 return node->get_availability();
255}
256
257static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
258{
259 return node->get_alias_target();
260}
261
262static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
263{
264 return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
265}
266
267static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
268{
269 return symtab->add_cgraph_insertion_hook(hook, data);
270}
271
272static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
273{
274 symtab->remove_cgraph_insertion_hook(entry);
275}
276
277static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
278{
279 return symtab->add_cgraph_removal_hook(hook, data);
280}
281
282static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
283{
284 symtab->remove_cgraph_removal_hook(entry);
285}
286
287static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
288{
289 return symtab->add_cgraph_duplication_hook(hook, data);
290}
291
292static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
293{
294 symtab->remove_cgraph_duplication_hook(entry);
295}
296
297static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
298{
299 symtab->call_cgraph_duplication_hooks(node, node2);
300}
301
302static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
303{
304 symtab->call_edge_duplication_hooks(cs1, cs2);
305}
306
307typedef gimple *gimple_ptr;
308typedef const gimple *const_gimple_ptr;
309#define gimple gimple_ptr
310#define const_gimple const_gimple_ptr
311#undef CONST_CAST_GIMPLE
312#define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
313
314/* gimple related */
315static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
316{
317 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
318}
319
320#if BUILDING_GCC_VERSION < 10000
321template <>
322template <>
323inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
324{
325 return gs->code == GIMPLE_GOTO;
326}
327
328template <>
329template <>
330inline bool is_a_helper<const greturn *>::test(const_gimple gs)
331{
332 return gs->code == GIMPLE_RETURN;
333}
334#endif
335
336static inline gasm *as_a_gasm(gimple stmt)
337{
338 return as_a<gasm *>(stmt);
339}
340
341static inline const gasm *as_a_const_gasm(const_gimple stmt)
342{
343 return as_a<const gasm *>(stmt);
344}
345
346static inline gassign *as_a_gassign(gimple stmt)
347{
348 return as_a<gassign *>(stmt);
349}
350
351static inline const gassign *as_a_const_gassign(const_gimple stmt)
352{
353 return as_a<const gassign *>(stmt);
354}
355
356static inline gcall *as_a_gcall(gimple stmt)
357{
358 return as_a<gcall *>(stmt);
359}
360
361static inline const gcall *as_a_const_gcall(const_gimple stmt)
362{
363 return as_a<const gcall *>(stmt);
364}
365
366static inline ggoto *as_a_ggoto(gimple stmt)
367{
368 return as_a<ggoto *>(stmt);
369}
370
371static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
372{
373 return as_a<const ggoto *>(stmt);
374}
375
376static inline gphi *as_a_gphi(gimple stmt)
377{
378 return as_a<gphi *>(stmt);
379}
380
381static inline const gphi *as_a_const_gphi(const_gimple stmt)
382{
383 return as_a<const gphi *>(stmt);
384}
385
386static inline greturn *as_a_greturn(gimple stmt)
387{
388 return as_a<greturn *>(stmt);
389}
390
391static inline const greturn *as_a_const_greturn(const_gimple stmt)
392{
393 return as_a<const greturn *>(stmt);
394}
395
396/* IPA/LTO related */
397#define ipa_ref_list_referring_iterate(L, I, P) \
398 (L)->referring.iterate((I), &(P))
399#define ipa_ref_list_reference_iterate(L, I, P) \
400 (L)->reference.iterate((I), &(P))
401
402static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
403{
404 return dyn_cast<cgraph_node_ptr>(ref->referring);
405}
406
407static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
408{
409 referring_node->remove_stmt_references(stmt);
410}
411
412#define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
413
414#ifdef __cplusplus
415static inline void debug_tree(const_tree t)
416{
417 debug_tree(CONST_CAST_TREE(t));
418}
419
420static inline void debug_gimple_stmt(const_gimple s)
421{
422 debug_gimple_stmt(CONST_CAST_GIMPLE(s));
423}
424#else
425#define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
426#define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
427#endif
428
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)
431
432#if BUILDING_GCC_VERSION >= 14000
433#define last_stmt(x) last_nondebug_stmt(x)
434#endif
435
436#endif