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... */ 85 void debug_dominance_info(enum cdi_direction dir); 86 void 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 103 static 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 118 #define PASS_INFO(NAME, REF, ID, POS) \ 119 struct register_pass_info NAME##_pass_info = { \ 120 .pass = make_##NAME##_pass(), \ 121 .reference_pass_name = REF, \ 122 .ref_pass_instance_number = ID, \ 123 .pos_op = POS, \ 124 } 125 126 #define add_referenced_var(var) 127 #define mark_sym_for_renaming(var) 128 #define varpool_mark_needed_node(node) 129 #define create_var_ann(var) 130 #define TODO_dump_func 0 131 #define TODO_dump_cgraph 0 132 133 #define TODO_ggc_collect 0 134 #define NODE_SYMBOL(node) (node) 135 #define NODE_DECL(node) (node)->decl 136 #define cgraph_node_name(node) (node)->name() 137 #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias 138 139 static inline opt_pass *get_pass_for_id(int id) 140 { 141 return g->get_passes()->get_pass_for_id(id); 142 } 143 144 #define TODO_verify_ssa TODO_verify_il 145 #define TODO_verify_flow TODO_verify_il 146 #define TODO_verify_stmts TODO_verify_il 147 #define TODO_verify_rtl_sharing TODO_verify_il 148 149 #define INSN_DELETED_P(insn) (insn)->deleted() 150 151 static inline const char *get_decl_section_name(const_tree decl) 152 { 153 return DECL_SECTION_NAME(decl); 154 } 155 156 /* symtab/cgraph related */ 157 #define debug_cgraph_node(node) (node)->debug() 158 #define cgraph_get_node(decl) cgraph_node::get(decl) 159 #define cgraph_get_create_node(decl) cgraph_node::get_create(decl) 160 #define cgraph_create_node(decl) cgraph_node::create(decl) 161 #define cgraph_n_nodes symtab->cgraph_count 162 #define cgraph_max_uid symtab->cgraph_max_uid 163 #define varpool_get_node(decl) varpool_node::get(decl) 164 #define dump_varpool_node(file, node) (node)->dump(file) 165 166 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \ 167 (caller)->create_edge((callee), (call_stmt), (count)) 168 169 #define cgraph_create_edge_including_clones(caller, callee, \ 170 old_call_stmt, call_stmt, count, freq, reason) \ 171 (caller)->create_edge_including_clones((callee), \ 172 (old_call_stmt), (call_stmt), (count), (reason)) 173 174 typedef struct cgraph_node *cgraph_node_ptr; 175 typedef struct cgraph_edge *cgraph_edge_p; 176 typedef struct varpool_node *varpool_node_ptr; 177 178 static inline void change_decl_assembler_name(tree decl, tree name) 179 { 180 symtab->change_decl_assembler_name(decl, name); 181 } 182 183 static inline void varpool_finalize_decl(tree decl) 184 { 185 varpool_node::finalize_decl(decl); 186 } 187 188 static inline void varpool_add_new_variable(tree decl) 189 { 190 varpool_node::add(decl); 191 } 192 193 static inline unsigned int rebuild_cgraph_edges(void) 194 { 195 return cgraph_edge::rebuild_edges(); 196 } 197 198 static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability) 199 { 200 return node->function_symbol(availability); 201 } 202 203 static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL) 204 { 205 return node->ultimate_alias_target(availability); 206 } 207 208 static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node) 209 { 210 return node->only_called_directly_p(); 211 } 212 213 static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node) 214 { 215 return node->get_availability(); 216 } 217 218 static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node) 219 { 220 return node->get_alias_target(); 221 } 222 223 static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable) 224 { 225 return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable); 226 } 227 228 static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data) 229 { 230 return symtab->add_cgraph_insertion_hook(hook, data); 231 } 232 233 static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry) 234 { 235 symtab->remove_cgraph_insertion_hook(entry); 236 } 237 238 static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data) 239 { 240 return symtab->add_cgraph_removal_hook(hook, data); 241 } 242 243 static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry) 244 { 245 symtab->remove_cgraph_removal_hook(entry); 246 } 247 248 static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data) 249 { 250 return symtab->add_cgraph_duplication_hook(hook, data); 251 } 252 253 static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry) 254 { 255 symtab->remove_cgraph_duplication_hook(entry); 256 } 257 258 static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2) 259 { 260 symtab->call_cgraph_duplication_hooks(node, node2); 261 } 262 263 static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2) 264 { 265 symtab->call_edge_duplication_hooks(cs1, cs2); 266 } 267 268 typedef gimple *gimple_ptr; 269 typedef const gimple *const_gimple_ptr; 270 #define gimple gimple_ptr 271 #define const_gimple const_gimple_ptr 272 #undef CONST_CAST_GIMPLE 273 #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X)) 274 275 /* gimple related */ 276 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL) 277 { 278 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT); 279 } 280 281 #if BUILDING_GCC_VERSION < 10000 282 template <> 283 template <> 284 inline bool is_a_helper<const ggoto *>::test(const_gimple gs) 285 { 286 return gs->code == GIMPLE_GOTO; 287 } 288 289 template <> 290 template <> 291 inline bool is_a_helper<const greturn *>::test(const_gimple gs) 292 { 293 return gs->code == GIMPLE_RETURN; 294 } 295 #endif 296 297 static inline gasm *as_a_gasm(gimple stmt) 298 { 299 return as_a<gasm *>(stmt); 300 } 301 302 static inline const gasm *as_a_const_gasm(const_gimple stmt) 303 { 304 return as_a<const gasm *>(stmt); 305 } 306 307 static inline gassign *as_a_gassign(gimple stmt) 308 { 309 return as_a<gassign *>(stmt); 310 } 311 312 static inline const gassign *as_a_const_gassign(const_gimple stmt) 313 { 314 return as_a<const gassign *>(stmt); 315 } 316 317 static inline gcall *as_a_gcall(gimple stmt) 318 { 319 return as_a<gcall *>(stmt); 320 } 321 322 static inline const gcall *as_a_const_gcall(const_gimple stmt) 323 { 324 return as_a<const gcall *>(stmt); 325 } 326 327 static inline ggoto *as_a_ggoto(gimple stmt) 328 { 329 return as_a<ggoto *>(stmt); 330 } 331 332 static inline const ggoto *as_a_const_ggoto(const_gimple stmt) 333 { 334 return as_a<const ggoto *>(stmt); 335 } 336 337 static inline gphi *as_a_gphi(gimple stmt) 338 { 339 return as_a<gphi *>(stmt); 340 } 341 342 static inline const gphi *as_a_const_gphi(const_gimple stmt) 343 { 344 return as_a<const gphi *>(stmt); 345 } 346 347 static inline greturn *as_a_greturn(gimple stmt) 348 { 349 return as_a<greturn *>(stmt); 350 } 351 352 static inline const greturn *as_a_const_greturn(const_gimple stmt) 353 { 354 return as_a<const greturn *>(stmt); 355 } 356 357 /* IPA/LTO related */ 358 #define ipa_ref_list_referring_iterate(L, I, P) \ 359 (L)->referring.iterate((I), &(P)) 360 #define ipa_ref_list_reference_iterate(L, I, P) \ 361 (L)->reference.iterate((I), &(P)) 362 363 static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref) 364 { 365 return dyn_cast<cgraph_node_ptr>(ref->referring); 366 } 367 368 static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt) 369 { 370 referring_node->remove_stmt_references(stmt); 371 } 372 373 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1)) 374 375 #ifdef __cplusplus 376 static inline void debug_tree(const_tree t) 377 { 378 debug_tree(CONST_CAST_TREE(t)); 379 } 380 381 static inline void debug_gimple_stmt(const_gimple s) 382 { 383 debug_gimple_stmt(CONST_CAST_GIMPLE(s)); 384 } 385 #else 386 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t)) 387 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s)) 388 #endif 389 390 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \ 391 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep) 392 393 #if BUILDING_GCC_VERSION >= 14000 394 #define last_stmt(x) last_nondebug_stmt(x) 395 #endif 396 397 #endif 398