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#define TODO_verify_ssa TODO_verify_il
177#define TODO_verify_flow TODO_verify_il
178#define TODO_verify_stmts TODO_verify_il
179#define TODO_verify_rtl_sharing TODO_verify_il
180
181#define INSN_DELETED_P(insn) (insn)->deleted()
182
183static inline const char *get_decl_section_name(const_tree decl)
184{
185 return DECL_SECTION_NAME(decl);
186}
187
188/* symtab/cgraph related */
189#define debug_cgraph_node(node) (node)->debug()
190#define cgraph_get_node(decl) cgraph_node::get(decl)
191#define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
192#define cgraph_create_node(decl) cgraph_node::create(decl)
193#define cgraph_n_nodes symtab->cgraph_count
194#define cgraph_max_uid symtab->cgraph_max_uid
195#define varpool_get_node(decl) varpool_node::get(decl)
196#define dump_varpool_node(file, node) (node)->dump(file)
197
198#define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
199 (caller)->create_edge((callee), (call_stmt), (count))
200
201#define cgraph_create_edge_including_clones(caller, callee, \
202 old_call_stmt, call_stmt, count, freq, reason) \
203 (caller)->create_edge_including_clones((callee), \
204 (old_call_stmt), (call_stmt), (count), (reason))
205
206typedef struct cgraph_node *cgraph_node_ptr;
207typedef struct cgraph_edge *cgraph_edge_p;
208typedef struct varpool_node *varpool_node_ptr;
209
210static inline void change_decl_assembler_name(tree decl, tree name)
211{
212 symtab->change_decl_assembler_name(decl, name);
213}
214
215static inline void varpool_finalize_decl(tree decl)
216{
217 varpool_node::finalize_decl(decl);
218}
219
220static inline void varpool_add_new_variable(tree decl)
221{
222 varpool_node::add(decl);
223}
224
225static inline unsigned int rebuild_cgraph_edges(void)
226{
227 return cgraph_edge::rebuild_edges();
228}
229
230static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
231{
232 return node->function_symbol(availability);
233}
234
235static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
236{
237 return node->ultimate_alias_target(availability);
238}
239
240static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
241{
242 return node->only_called_directly_p();
243}
244
245static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
246{
247 return node->get_availability();
248}
249
250static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
251{
252 return node->get_alias_target();
253}
254
255static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
256{
257 return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
258}
259
260static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
261{
262 return symtab->add_cgraph_insertion_hook(hook, data);
263}
264
265static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
266{
267 symtab->remove_cgraph_insertion_hook(entry);
268}
269
270static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
271{
272 return symtab->add_cgraph_removal_hook(hook, data);
273}
274
275static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
276{
277 symtab->remove_cgraph_removal_hook(entry);
278}
279
280static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
281{
282 return symtab->add_cgraph_duplication_hook(hook, data);
283}
284
285static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
286{
287 symtab->remove_cgraph_duplication_hook(entry);
288}
289
290static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
291{
292 symtab->call_cgraph_duplication_hooks(node, node2);
293}
294
295static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
296{
297 symtab->call_edge_duplication_hooks(cs1, cs2);
298}
299
300typedef gimple *gimple_ptr;
301typedef const gimple *const_gimple_ptr;
302#define gimple gimple_ptr
303#define const_gimple const_gimple_ptr
304#undef CONST_CAST_GIMPLE
305#define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
306
307/* gimple related */
308static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
309{
310 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
311}
312
313#if BUILDING_GCC_VERSION < 10000
314template <>
315template <>
316inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
317{
318 return gs->code == GIMPLE_GOTO;
319}
320
321template <>
322template <>
323inline bool is_a_helper<const greturn *>::test(const_gimple gs)
324{
325 return gs->code == GIMPLE_RETURN;
326}
327#endif
328
329static inline gasm *as_a_gasm(gimple stmt)
330{
331 return as_a<gasm *>(stmt);
332}
333
334static inline const gasm *as_a_const_gasm(const_gimple stmt)
335{
336 return as_a<const gasm *>(stmt);
337}
338
339static inline gassign *as_a_gassign(gimple stmt)
340{
341 return as_a<gassign *>(stmt);
342}
343
344static inline const gassign *as_a_const_gassign(const_gimple stmt)
345{
346 return as_a<const gassign *>(stmt);
347}
348
349static inline gcall *as_a_gcall(gimple stmt)
350{
351 return as_a<gcall *>(stmt);
352}
353
354static inline const gcall *as_a_const_gcall(const_gimple stmt)
355{
356 return as_a<const gcall *>(stmt);
357}
358
359static inline ggoto *as_a_ggoto(gimple stmt)
360{
361 return as_a<ggoto *>(stmt);
362}
363
364static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
365{
366 return as_a<const ggoto *>(stmt);
367}
368
369static inline gphi *as_a_gphi(gimple stmt)
370{
371 return as_a<gphi *>(stmt);
372}
373
374static inline const gphi *as_a_const_gphi(const_gimple stmt)
375{
376 return as_a<const gphi *>(stmt);
377}
378
379static inline greturn *as_a_greturn(gimple stmt)
380{
381 return as_a<greturn *>(stmt);
382}
383
384static inline const greturn *as_a_const_greturn(const_gimple stmt)
385{
386 return as_a<const greturn *>(stmt);
387}
388
389/* IPA/LTO related */
390#define ipa_ref_list_referring_iterate(L, I, P) \
391 (L)->referring.iterate((I), &(P))
392#define ipa_ref_list_reference_iterate(L, I, P) \
393 (L)->reference.iterate((I), &(P))
394
395static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
396{
397 return dyn_cast<cgraph_node_ptr>(ref->referring);
398}
399
400static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
401{
402 referring_node->remove_stmt_references(stmt);
403}
404
405#define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
406
407#ifdef __cplusplus
408static inline void debug_tree(const_tree t)
409{
410 debug_tree(CONST_CAST_TREE(t));
411}
412
413static inline void debug_gimple_stmt(const_gimple s)
414{
415 debug_gimple_stmt(CONST_CAST_GIMPLE(s));
416}
417#else
418#define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
419#define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
420#endif
421
422#define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \
423 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
424
425#if BUILDING_GCC_VERSION >= 14000
426#define last_stmt(x) last_nondebug_stmt(x)
427#endif
428
429#endif