Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef GCC_COMMON_H_INCLUDED
0003 #define GCC_COMMON_H_INCLUDED
0004 
0005 #include "bversion.h"
0006 #if BUILDING_GCC_VERSION >= 6000
0007 #include "gcc-plugin.h"
0008 #else
0009 #include "plugin.h"
0010 #endif
0011 #include "plugin-version.h"
0012 #include "config.h"
0013 #include "system.h"
0014 #include "coretypes.h"
0015 #include "tm.h"
0016 #include "line-map.h"
0017 #include "input.h"
0018 #include "tree.h"
0019 
0020 #include "tree-inline.h"
0021 #include "version.h"
0022 #include "rtl.h"
0023 #include "tm_p.h"
0024 #include "flags.h"
0025 #include "hard-reg-set.h"
0026 #include "output.h"
0027 #include "except.h"
0028 #include "function.h"
0029 #include "toplev.h"
0030 #include "expr.h"
0031 #include "basic-block.h"
0032 #include "intl.h"
0033 #include "ggc.h"
0034 #include "timevar.h"
0035 
0036 #if BUILDING_GCC_VERSION < 10000
0037 #include "params.h"
0038 #endif
0039 
0040 #include "hash-map.h"
0041 
0042 #if BUILDING_GCC_VERSION >= 7000
0043 #include "memmodel.h"
0044 #endif
0045 #include "emit-rtl.h"
0046 #include "debug.h"
0047 #include "target.h"
0048 #include "langhooks.h"
0049 #include "cfgloop.h"
0050 #include "cgraph.h"
0051 #include "opts.h"
0052 #include "tree-pretty-print.h"
0053 #include "gimple-pretty-print.h"
0054 #include "c-family/c-common.h"
0055 #include "tree-cfgcleanup.h"
0056 #include "tree-ssa-operands.h"
0057 #include "tree-into-ssa.h"
0058 #include "is-a.h"
0059 #include "diagnostic.h"
0060 #include "tree-dump.h"
0061 #include "tree-pass.h"
0062 #include "pass_manager.h"
0063 #include "predict.h"
0064 #include "ipa-utils.h"
0065 
0066 #if BUILDING_GCC_VERSION >= 8000
0067 #include "stringpool.h"
0068 #endif
0069 
0070 #include "attribs.h"
0071 #include "varasm.h"
0072 #include "stor-layout.h"
0073 #include "internal-fn.h"
0074 #include "gimple-expr.h"
0075 #include "gimple-fold.h"
0076 #include "context.h"
0077 #include "tree-ssa-alias.h"
0078 #include "tree-ssa.h"
0079 #include "stringpool.h"
0080 #if BUILDING_GCC_VERSION >= 7000
0081 #include "tree-vrp.h"
0082 #endif
0083 #include "tree-ssanames.h"
0084 #include "print-tree.h"
0085 #include "tree-eh.h"
0086 #include "stmt.h"
0087 #include "gimplify.h"
0088 #include "gimple.h"
0089 #include "tree-phinodes.h"
0090 #include "tree-cfg.h"
0091 #include "gimple-iterator.h"
0092 #include "gimple-ssa.h"
0093 #include "ssa-iterators.h"
0094 
0095 #include "builtins.h"
0096 
0097 /* missing from basic_block.h... */
0098 void debug_dominance_info(enum cdi_direction dir);
0099 void debug_dominance_tree(enum cdi_direction dir, basic_block root);
0100 
0101 #ifndef __unused
0102 #define __unused __attribute__((__unused__))
0103 #endif
0104 #ifndef __visible
0105 #define __visible __attribute__((visibility("default")))
0106 #endif
0107 
0108 #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
0109 #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
0110 #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
0111 #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
0112 
0113 /* should come from c-tree.h if only it were installed for gcc 4.5... */
0114 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
0115 
0116 static inline tree build_const_char_string(int len, const char *str)
0117 {
0118     tree cstr, elem, index, type;
0119 
0120     cstr = build_string(len, str);
0121     elem = build_type_variant(char_type_node, 1, 0);
0122     index = build_index_type(size_int(len - 1));
0123     type = build_array_type(elem, index);
0124     TREE_TYPE(cstr) = type;
0125     TREE_CONSTANT(cstr) = 1;
0126     TREE_READONLY(cstr) = 1;
0127     TREE_STATIC(cstr) = 1;
0128     return cstr;
0129 }
0130 
0131 #define PASS_INFO(NAME, REF, ID, POS)       \
0132 struct register_pass_info NAME##_pass_info = {  \
0133     .pass = make_##NAME##_pass(),       \
0134     .reference_pass_name = REF,     \
0135     .ref_pass_instance_number = ID,     \
0136     .pos_op = POS,              \
0137 }
0138 
0139 #define add_referenced_var(var)
0140 #define mark_sym_for_renaming(var)
0141 #define varpool_mark_needed_node(node)
0142 #define create_var_ann(var)
0143 #define TODO_dump_func 0
0144 #define TODO_dump_cgraph 0
0145 
0146 #define TODO_ggc_collect 0
0147 #define NODE_SYMBOL(node) (node)
0148 #define NODE_DECL(node) (node)->decl
0149 #define cgraph_node_name(node) (node)->name()
0150 #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias
0151 
0152 static inline opt_pass *get_pass_for_id(int id)
0153 {
0154     return g->get_passes()->get_pass_for_id(id);
0155 }
0156 
0157 #if BUILDING_GCC_VERSION < 6000
0158 /* gimple related */
0159 template <>
0160 template <>
0161 inline bool is_a_helper<const gassign *>::test(const_gimple gs)
0162 {
0163     return gs->code == GIMPLE_ASSIGN;
0164 }
0165 #endif
0166 
0167 #define TODO_verify_ssa TODO_verify_il
0168 #define TODO_verify_flow TODO_verify_il
0169 #define TODO_verify_stmts TODO_verify_il
0170 #define TODO_verify_rtl_sharing TODO_verify_il
0171 
0172 #define INSN_DELETED_P(insn) (insn)->deleted()
0173 
0174 static inline const char *get_decl_section_name(const_tree decl)
0175 {
0176     return DECL_SECTION_NAME(decl);
0177 }
0178 
0179 /* symtab/cgraph related */
0180 #define debug_cgraph_node(node) (node)->debug()
0181 #define cgraph_get_node(decl) cgraph_node::get(decl)
0182 #define cgraph_get_create_node(decl) cgraph_node::get_create(decl)
0183 #define cgraph_create_node(decl) cgraph_node::create(decl)
0184 #define cgraph_n_nodes symtab->cgraph_count
0185 #define cgraph_max_uid symtab->cgraph_max_uid
0186 #define varpool_get_node(decl) varpool_node::get(decl)
0187 #define dump_varpool_node(file, node) (node)->dump(file)
0188 
0189 #if BUILDING_GCC_VERSION >= 8000
0190 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
0191     (caller)->create_edge((callee), (call_stmt), (count))
0192 
0193 #define cgraph_create_edge_including_clones(caller, callee, \
0194         old_call_stmt, call_stmt, count, freq, reason)  \
0195     (caller)->create_edge_including_clones((callee),    \
0196         (old_call_stmt), (call_stmt), (count), (reason))
0197 #else
0198 #define cgraph_create_edge(caller, callee, call_stmt, count, freq) \
0199     (caller)->create_edge((callee), (call_stmt), (count), (freq))
0200 
0201 #define cgraph_create_edge_including_clones(caller, callee, \
0202         old_call_stmt, call_stmt, count, freq, reason)  \
0203     (caller)->create_edge_including_clones((callee),    \
0204         (old_call_stmt), (call_stmt), (count), (freq), (reason))
0205 #endif
0206 
0207 typedef struct cgraph_node *cgraph_node_ptr;
0208 typedef struct cgraph_edge *cgraph_edge_p;
0209 typedef struct varpool_node *varpool_node_ptr;
0210 
0211 static inline void change_decl_assembler_name(tree decl, tree name)
0212 {
0213     symtab->change_decl_assembler_name(decl, name);
0214 }
0215 
0216 static inline void varpool_finalize_decl(tree decl)
0217 {
0218     varpool_node::finalize_decl(decl);
0219 }
0220 
0221 static inline void varpool_add_new_variable(tree decl)
0222 {
0223     varpool_node::add(decl);
0224 }
0225 
0226 static inline unsigned int rebuild_cgraph_edges(void)
0227 {
0228     return cgraph_edge::rebuild_edges();
0229 }
0230 
0231 static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability)
0232 {
0233     return node->function_symbol(availability);
0234 }
0235 
0236 static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL)
0237 {
0238     return node->ultimate_alias_target(availability);
0239 }
0240 
0241 static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node)
0242 {
0243     return node->only_called_directly_p();
0244 }
0245 
0246 static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node)
0247 {
0248     return node->get_availability();
0249 }
0250 
0251 static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node)
0252 {
0253     return node->get_alias_target();
0254 }
0255 
0256 static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable)
0257 {
0258     return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable);
0259 }
0260 
0261 static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data)
0262 {
0263     return symtab->add_cgraph_insertion_hook(hook, data);
0264 }
0265 
0266 static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry)
0267 {
0268     symtab->remove_cgraph_insertion_hook(entry);
0269 }
0270 
0271 static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data)
0272 {
0273     return symtab->add_cgraph_removal_hook(hook, data);
0274 }
0275 
0276 static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry)
0277 {
0278     symtab->remove_cgraph_removal_hook(entry);
0279 }
0280 
0281 static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data)
0282 {
0283     return symtab->add_cgraph_duplication_hook(hook, data);
0284 }
0285 
0286 static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry)
0287 {
0288     symtab->remove_cgraph_duplication_hook(entry);
0289 }
0290 
0291 static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2)
0292 {
0293     symtab->call_cgraph_duplication_hooks(node, node2);
0294 }
0295 
0296 static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2)
0297 {
0298     symtab->call_edge_duplication_hooks(cs1, cs2);
0299 }
0300 
0301 #if BUILDING_GCC_VERSION >= 6000
0302 typedef gimple *gimple_ptr;
0303 typedef const gimple *const_gimple_ptr;
0304 #define gimple gimple_ptr
0305 #define const_gimple const_gimple_ptr
0306 #undef CONST_CAST_GIMPLE
0307 #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X))
0308 #endif
0309 
0310 /* gimple related */
0311 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL)
0312 {
0313     return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
0314 }
0315 
0316 #if BUILDING_GCC_VERSION < 10000
0317 template <>
0318 template <>
0319 inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
0320 {
0321     return gs->code == GIMPLE_GOTO;
0322 }
0323 
0324 template <>
0325 template <>
0326 inline bool is_a_helper<const greturn *>::test(const_gimple gs)
0327 {
0328     return gs->code == GIMPLE_RETURN;
0329 }
0330 #endif
0331 
0332 static inline gasm *as_a_gasm(gimple stmt)
0333 {
0334     return as_a<gasm *>(stmt);
0335 }
0336 
0337 static inline const gasm *as_a_const_gasm(const_gimple stmt)
0338 {
0339     return as_a<const gasm *>(stmt);
0340 }
0341 
0342 static inline gassign *as_a_gassign(gimple stmt)
0343 {
0344     return as_a<gassign *>(stmt);
0345 }
0346 
0347 static inline const gassign *as_a_const_gassign(const_gimple stmt)
0348 {
0349     return as_a<const gassign *>(stmt);
0350 }
0351 
0352 static inline gcall *as_a_gcall(gimple stmt)
0353 {
0354     return as_a<gcall *>(stmt);
0355 }
0356 
0357 static inline const gcall *as_a_const_gcall(const_gimple stmt)
0358 {
0359     return as_a<const gcall *>(stmt);
0360 }
0361 
0362 static inline ggoto *as_a_ggoto(gimple stmt)
0363 {
0364     return as_a<ggoto *>(stmt);
0365 }
0366 
0367 static inline const ggoto *as_a_const_ggoto(const_gimple stmt)
0368 {
0369     return as_a<const ggoto *>(stmt);
0370 }
0371 
0372 static inline gphi *as_a_gphi(gimple stmt)
0373 {
0374     return as_a<gphi *>(stmt);
0375 }
0376 
0377 static inline const gphi *as_a_const_gphi(const_gimple stmt)
0378 {
0379     return as_a<const gphi *>(stmt);
0380 }
0381 
0382 static inline greturn *as_a_greturn(gimple stmt)
0383 {
0384     return as_a<greturn *>(stmt);
0385 }
0386 
0387 static inline const greturn *as_a_const_greturn(const_gimple stmt)
0388 {
0389     return as_a<const greturn *>(stmt);
0390 }
0391 
0392 /* IPA/LTO related */
0393 #define ipa_ref_list_referring_iterate(L, I, P) \
0394     (L)->referring.iterate((I), &(P))
0395 #define ipa_ref_list_reference_iterate(L, I, P) \
0396     (L)->reference.iterate((I), &(P))
0397 
0398 static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref)
0399 {
0400     return dyn_cast<cgraph_node_ptr>(ref->referring);
0401 }
0402 
0403 static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt)
0404 {
0405     referring_node->remove_stmt_references(stmt);
0406 }
0407 
0408 #if BUILDING_GCC_VERSION < 6000
0409 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning)   \
0410     get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning)
0411 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1))
0412 #endif
0413 
0414 #if BUILDING_GCC_VERSION >= 6000
0415 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1))
0416 #endif
0417 
0418 #ifdef __cplusplus
0419 static inline void debug_tree(const_tree t)
0420 {
0421     debug_tree(CONST_CAST_TREE(t));
0422 }
0423 
0424 static inline void debug_gimple_stmt(const_gimple s)
0425 {
0426     debug_gimple_stmt(CONST_CAST_GIMPLE(s));
0427 }
0428 #else
0429 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t))
0430 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s))
0431 #endif
0432 
0433 #if BUILDING_GCC_VERSION >= 7000
0434 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning)   \
0435     get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep)
0436 #endif
0437 
0438 #if BUILDING_GCC_VERSION < 7000
0439 #define SET_DECL_ALIGN(decl, align) DECL_ALIGN(decl) = (align)
0440 #define SET_DECL_MODE(decl, mode)   DECL_MODE(decl) = (mode)
0441 #endif
0442 
0443 #endif