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

source code of linux/scripts/gcc-plugins/gcc-common.h