Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / scripts / gcc-plugins / gcc-common.h
blob0c087614fc3e412f9f868d7d7386743210320b23
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef GCC_COMMON_H_INCLUDED
3 #define GCC_COMMON_H_INCLUDED
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"
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 #if BUILDING_GCC_VERSION >= 5000
31 #include "expr.h"
32 #endif
33 #include "basic-block.h"
34 #include "intl.h"
35 #include "ggc.h"
36 #include "timevar.h"
38 #if BUILDING_GCC_VERSION < 10000
39 #include "params.h"
40 #endif
42 #if BUILDING_GCC_VERSION <= 4009
43 #include "pointer-set.h"
44 #else
45 #include "hash-map.h"
46 #endif
48 #if BUILDING_GCC_VERSION >= 7000
49 #include "memmodel.h"
50 #endif
51 #include "emit-rtl.h"
52 #include "debug.h"
53 #include "target.h"
54 #include "langhooks.h"
55 #include "cfgloop.h"
56 #include "cgraph.h"
57 #include "opts.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"
64 #include "is-a.h"
65 #include "diagnostic.h"
66 #include "tree-dump.h"
67 #include "tree-pass.h"
68 #include "pass_manager.h"
69 #include "predict.h"
70 #include "ipa-utils.h"
72 #if BUILDING_GCC_VERSION >= 8000
73 #include "stringpool.h"
74 #endif
76 #include "attribs.h"
77 #include "varasm.h"
78 #include "stor-layout.h"
79 #include "internal-fn.h"
80 #include "gimple-expr.h"
81 #include "gimple-fold.h"
82 #include "context.h"
83 #include "tree-ssa-alias.h"
84 #include "tree-ssa.h"
85 #include "stringpool.h"
86 #if BUILDING_GCC_VERSION >= 7000
87 #include "tree-vrp.h"
88 #endif
89 #include "tree-ssanames.h"
90 #include "print-tree.h"
91 #include "tree-eh.h"
92 #include "stmt.h"
93 #include "gimplify.h"
94 #include "gimple.h"
95 #include "tree-ssa-operands.h"
96 #include "tree-phinodes.h"
97 #include "tree-cfg.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"
104 #endif
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);
110 #ifndef __unused
111 #define __unused __attribute__((__unused__))
112 #endif
113 #ifndef __visible
114 #define __visible __attribute__((visibility("default")))
115 #endif
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;
137 return cstr;
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, \
145 .pos_op = POS, \
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)
169 return NULL;
171 return TREE_STRING_POINTER(DECL_SECTION_NAME(decl));
174 static inline void set_decl_section_name(tree node, const char *value)
176 if (value)
177 DECL_SECTION_NAME(node) = build_string(strlen(value) + 1, value);
178 else
179 DECL_SECTION_NAME(node) = NULL;
181 #endif
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)
205 return stmt;
208 static inline const gassign *as_a_const_gassign(const_gimple stmt)
210 return 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)
225 return stmt;
228 static inline const gcond *as_a_const_gcond(const_gimple stmt)
230 return stmt;
233 static inline gdebug *as_a_gdebug(gimple stmt)
235 return stmt;
238 static inline const gdebug *as_a_const_gdebug(const_gimple stmt)
240 return stmt;
243 static inline ggoto *as_a_ggoto(gimple stmt)
245 return stmt;
248 static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
250 return 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)
265 return stmt;
268 static inline const greturn *as_a_const_greturn(const_gimple stmt)
270 return stmt;
272 #endif
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
286 /* gimple related */
287 template <>
288 template <>
289 inline bool is_a_helper<const gassign *>::test(const_gimple gs)
291 return gs->code == GIMPLE_ASSIGN;
293 #endif
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))
326 #else
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))
334 #endif
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))
437 #endif
439 /* gimple related */
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
446 template <>
447 template <>
448 inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
450 return gs->code == GIMPLE_GOTO;
453 template <>
454 template <>
455 inline bool is_a_helper<const greturn *>::test(const_gimple gs)
457 return gs->code == GIMPLE_RETURN;
459 #endif
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);
536 #endif
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))
542 #endif
544 #if BUILDING_GCC_VERSION >= 6000
545 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
546 #endif
548 #ifdef __cplusplus
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));
558 #else
559 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
560 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
561 #endif
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)
566 #endif
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)
571 #endif
573 #endif