1 #ifndef GCC_COMMON_H_INCLUDED 2 #define GCC_COMMON_H_INCLUDED 3 4 #include "bversion.h" 5 #if BUILDING_GCC_VERSION >= 6000 6 #include "gcc-plugin.h" 7 #else 8 #include "plugin.h" 9 #endif 10 #include "plugin-version.h" 11 #include "config.h" 12 #include "system.h" 13 #include "coretypes.h" 14 #include "tm.h" 15 #include "line-map.h" 16 #include "input.h" 17 #include "tree.h" 18 19 #include "tree-inline.h" 20 #include "version.h" 21 #include "rtl.h" 22 #include "tm_p.h" 23 #include "flags.h" 24 #include "hard-reg-set.h" 25 #include "output.h" 26 #include "except.h" 27 #include "function.h" 28 #include "toplev.h" 29 #if BUILDING_GCC_VERSION >= 5000 30 #include "expr.h" 31 #endif 32 #include "basic-block.h" 33 #include "intl.h" 34 #include "ggc.h" 35 #include "timevar.h" 36 37 #include "params.h" 38 39 #if BUILDING_GCC_VERSION <= 4009 40 #include "pointer-set.h" 41 #else 42 #include "hash-map.h" 43 #endif 44 45 #if BUILDING_GCC_VERSION >= 7000 46 #include "memmodel.h" 47 #endif 48 #include "emit-rtl.h" 49 #include "debug.h" 50 #include "target.h" 51 #include "langhooks.h" 52 #include "cfgloop.h" 53 #include "cgraph.h" 54 #include "opts.h" 55 56 #if BUILDING_GCC_VERSION == 4005 57 #include <sys/mman.h> 58 #endif 59 60 #if BUILDING_GCC_VERSION >= 4007 61 #include "tree-pretty-print.h" 62 #include "gimple-pretty-print.h" 63 #endif 64 65 #if BUILDING_GCC_VERSION >= 4006 66 #include "c-family/c-common.h" 67 #else 68 #include "c-common.h" 69 #endif 70 71 #if BUILDING_GCC_VERSION <= 4008 72 #include "tree-flow.h" 73 #else 74 #include "tree-cfgcleanup.h" 75 #include "tree-ssa-operands.h" 76 #include "tree-into-ssa.h" 77 #endif 78 79 #if BUILDING_GCC_VERSION >= 4008 80 #include "is-a.h" 81 #endif 82 83 #include "diagnostic.h" 84 #include "tree-dump.h" 85 #include "tree-pass.h" 86 #if BUILDING_GCC_VERSION >= 4009 87 #include "pass_manager.h" 88 #endif 89 #include "predict.h" 90 #include "ipa-utils.h" 91 92 #if BUILDING_GCC_VERSION >= 4009 93 #include "attribs.h" 94 #include "varasm.h" 95 #include "stor-layout.h" 96 #include "internal-fn.h" 97 #include "gimple-expr.h" 98 #include "gimple-fold.h" 99 #include "context.h" 100 #include "tree-ssa-alias.h" 101 #include "tree-ssa.h" 102 #include "stringpool.h" 103 #if BUILDING_GCC_VERSION >= 7000 104 #include "tree-vrp.h" 105 #endif 106 #include "tree-ssanames.h" 107 #include "print-tree.h" 108 #include "tree-eh.h" 109 #include "stmt.h" 110 #include "gimplify.h" 111 #endif 112 113 #include "gimple.h" 114 115 #if BUILDING_GCC_VERSION >= 4009 116 #include "tree-ssa-operands.h" 117 #include "tree-phinodes.h" 118 #include "tree-cfg.h" 119 #include "gimple-iterator.h" 120 #include "gimple-ssa.h" 121 #include "ssa-iterators.h" 122 #endif 123 124 #if BUILDING_GCC_VERSION >= 5000 125 #include "builtins.h" 126 #endif 127 128 /* missing from basic_block.h... */ 129 void debug_dominance_info(enum cdi_direction dir); 130 void debug_dominance_tree(enum cdi_direction dir, basic_block root); 131 132 #if BUILDING_GCC_VERSION == 4006 133 void debug_gimple_stmt(gimple); 134 void debug_gimple_seq(gimple_seq); 135 void print_gimple_seq(FILE *, gimple_seq, int, int); 136 void print_gimple_stmt(FILE *, gimple, int, int); 137 void print_gimple_expr(FILE *, gimple, int, int); 138 void dump_gimple_stmt(pretty_printer *, gimple, int, int); 139 #endif 140 141 #define __unused __attribute__((__unused__)) 142 #define __visible __attribute__((visibility("default"))) 143 144 #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node)) 145 #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node)) 146 #define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node)) 147 #define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node)) 148 149 /* should come from c-tree.h if only it were installed for gcc 4.5... */ 150 #define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE) 151 152 static inline tree build_const_char_string(int len, const char *str) 153 { 154 tree cstr, elem, index, type; 155 156 cstr = build_string(len, str); 157 elem = build_type_variant(char_type_node, 1, 0); 158 index = build_index_type(size_int(len - 1)); 159 type = build_array_type(elem, index); 160 TREE_TYPE(cstr) = type; 161 TREE_CONSTANT(cstr) = 1; 162 TREE_READONLY(cstr) = 1; 163 TREE_STATIC(cstr) = 1; 164 return cstr; 165 } 166 167 #define PASS_INFO(NAME, REF, ID, POS) \ 168 struct register_pass_info NAME##_pass_info = { \ 169 .pass = make_##NAME##_pass(), \ 170 .reference_pass_name = REF, \ 171 .ref_pass_instance_number = ID, \ 172 .pos_op = POS, \ 173 } 174 175 #if BUILDING_GCC_VERSION == 4005 176 #define FOR_EACH_LOCAL_DECL(FUN, I, D) \ 177 for (tree vars = (FUN)->local_decls, (I) = 0; \ 178 vars && ((D) = TREE_VALUE(vars)); \ 179 vars = TREE_CHAIN(vars), (I)++) 180 #define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE))) 181 #define FOR_EACH_VEC_ELT(T, V, I, P) \ 182 for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I)) 183 #define TODO_rebuild_cgraph_edges 0 184 #define SCOPE_FILE_SCOPE_P(EXP) (!(EXP)) 185 186 #ifndef O_BINARY 187 #define O_BINARY 0 188 #endif 189 190 typedef struct varpool_node *varpool_node_ptr; 191 192 static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code) 193 { 194 tree fndecl; 195 196 if (!is_gimple_call(stmt)) 197 return false; 198 fndecl = gimple_call_fndecl(stmt); 199 if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL) 200 return false; 201 return DECL_FUNCTION_CODE(fndecl) == code; 202 } 203 204 static inline bool is_simple_builtin(tree decl) 205 { 206 if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL) 207 return false; 208 209 switch (DECL_FUNCTION_CODE(decl)) { 210 /* Builtins that expand to constants. */ 211 case BUILT_IN_CONSTANT_P: 212 case BUILT_IN_EXPECT: 213 case BUILT_IN_OBJECT_SIZE: 214 case BUILT_IN_UNREACHABLE: 215 /* Simple register moves or loads from stack. */ 216 case BUILT_IN_RETURN_ADDRESS: 217 case BUILT_IN_EXTRACT_RETURN_ADDR: 218 case BUILT_IN_FROB_RETURN_ADDR: 219 case BUILT_IN_RETURN: 220 case BUILT_IN_AGGREGATE_INCOMING_ADDRESS: 221 case BUILT_IN_FRAME_ADDRESS: 222 case BUILT_IN_VA_END: 223 case BUILT_IN_STACK_SAVE: 224 case BUILT_IN_STACK_RESTORE: 225 /* Exception state returns or moves registers around. */ 226 case BUILT_IN_EH_FILTER: 227 case BUILT_IN_EH_POINTER: 228 case BUILT_IN_EH_COPY_VALUES: 229 return true; 230 231 default: 232 return false; 233 } 234 } 235 236 static inline void add_local_decl(struct function *fun, tree d) 237 { 238 gcc_assert(TREE_CODE(d) == VAR_DECL); 239 fun->local_decls = tree_cons(NULL_TREE, d, fun->local_decls); 240 } 241 #endif 242 243 #if BUILDING_GCC_VERSION <= 4006 244 #define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN) 245 #define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP) 246 #define EDGE_PRESERVE 0ULL 247 #define HOST_WIDE_INT_PRINT_HEX_PURE "%" HOST_WIDE_INT_PRINT "x" 248 #define flag_fat_lto_objects true 249 250 #define get_random_seed(noinit) ({ \ 251 unsigned HOST_WIDE_INT seed; \ 252 sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \ 253 seed * seed; }) 254 255 #define int_const_binop(code, arg1, arg2) \ 256 int_const_binop((code), (arg1), (arg2), 0) 257 258 static inline bool gimple_clobber_p(gimple s __unused) 259 { 260 return false; 261 } 262 263 static inline bool gimple_asm_clobbers_memory_p(const_gimple stmt) 264 { 265 unsigned i; 266 267 for (i = 0; i < gimple_asm_nclobbers(stmt); i++) { 268 tree op = gimple_asm_clobber_op(stmt, i); 269 270 if (!strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "memory")) 271 return true; 272 } 273 274 return false; 275 } 276 277 static inline tree builtin_decl_implicit(enum built_in_function fncode) 278 { 279 return implicit_built_in_decls[fncode]; 280 } 281 282 static inline int ipa_reverse_postorder(struct cgraph_node **order) 283 { 284 return cgraph_postorder(order); 285 } 286 287 static inline struct cgraph_node *cgraph_create_node(tree decl) 288 { 289 return cgraph_node(decl); 290 } 291 292 static inline struct cgraph_node *cgraph_get_create_node(tree decl) 293 { 294 struct cgraph_node *node = cgraph_get_node(decl); 295 296 return node ? node : cgraph_node(decl); 297 } 298 299 static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node) 300 { 301 return node->analyzed && !node->thunk.thunk_p && !node->alias; 302 } 303 304 static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void) 305 { 306 struct cgraph_node *node; 307 308 for (node = cgraph_nodes; node; node = node->next) 309 if (cgraph_function_with_gimple_body_p(node)) 310 return node; 311 return NULL; 312 } 313 314 static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node) 315 { 316 for (node = node->next; node; node = node->next) 317 if (cgraph_function_with_gimple_body_p(node)) 318 return node; 319 return NULL; 320 } 321 322 static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable) 323 { 324 cgraph_node_ptr alias; 325 326 if (callback(node, data)) 327 return true; 328 329 for (alias = node->same_body; alias; alias = alias->next) { 330 if (include_overwritable || cgraph_function_body_availability(alias) > AVAIL_OVERWRITABLE) 331 if (cgraph_for_node_and_aliases(alias, callback, data, include_overwritable)) 332 return true; 333 } 334 335 return false; 336 } 337 338 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ 339 for ((node) = cgraph_first_function_with_gimple_body(); (node); \ 340 (node) = cgraph_next_function_with_gimple_body(node)) 341 342 static inline void varpool_add_new_variable(tree decl) 343 { 344 varpool_finalize_decl(decl); 345 } 346 #endif 347 348 #if BUILDING_GCC_VERSION <= 4007 349 #define FOR_EACH_FUNCTION(node) \ 350 for (node = cgraph_nodes; node; node = node->next) 351 #define FOR_EACH_VARIABLE(node) \ 352 for (node = varpool_nodes; node; node = node->next) 353 #define PROP_loops 0 354 #define NODE_SYMBOL(node) (node) 355 #define NODE_DECL(node) (node)->decl 356 #define INSN_LOCATION(INSN) RTL_LOCATION(INSN) 357 #define vNULL NULL 358 359 static inline int bb_loop_depth(const_basic_block bb) 360 { 361 return bb->loop_father ? loop_depth(bb->loop_father) : 0; 362 } 363 364 static inline bool gimple_store_p(gimple gs) 365 { 366 tree lhs = gimple_get_lhs(gs); 367 368 return lhs && !is_gimple_reg(lhs); 369 } 370 371 static inline void gimple_init_singleton(gimple g __unused) 372 { 373 } 374 #endif 375 376 #if BUILDING_GCC_VERSION == 4007 || BUILDING_GCC_VERSION == 4008 377 static inline struct cgraph_node *cgraph_alias_target(struct cgraph_node *n) 378 { 379 return cgraph_alias_aliased_node(n); 380 } 381 #endif 382 383 #if BUILDING_GCC_VERSION >= 4007 && BUILDING_GCC_VERSION <= 4009 384 #define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \ 385 cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq)) 386 #define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \ 387 cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason)) 388 #endif 389 390 #if BUILDING_GCC_VERSION <= 4008 391 #define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN) 392 #define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN) 393 #define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info) 394 #define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks) 395 #define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges) 396 #define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block) 397 #define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map) 398 #define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status) 399 #define BASIC_BLOCK_FOR_FN(FN, N) BASIC_BLOCK_FOR_FUNCTION((FN), (N)) 400 #define NODE_IMPLICIT_ALIAS(node) (node)->same_body_alias 401 #define VAR_P(NODE) (TREE_CODE(NODE) == VAR_DECL) 402 403 static inline bool tree_fits_shwi_p(const_tree t) 404 { 405 if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST) 406 return false; 407 408 if (TREE_INT_CST_HIGH(t) == 0 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) >= 0) 409 return true; 410 411 if (TREE_INT_CST_HIGH(t) == -1 && (HOST_WIDE_INT)TREE_INT_CST_LOW(t) < 0 && !TYPE_UNSIGNED(TREE_TYPE(t))) 412 return true; 413 414 return false; 415 } 416 417 static inline bool tree_fits_uhwi_p(const_tree t) 418 { 419 if (t == NULL_TREE || TREE_CODE(t) != INTEGER_CST) 420 return false; 421 422 return TREE_INT_CST_HIGH(t) == 0; 423 } 424 425 static inline HOST_WIDE_INT tree_to_shwi(const_tree t) 426 { 427 gcc_assert(tree_fits_shwi_p(t)); 428 return TREE_INT_CST_LOW(t); 429 } 430 431 static inline unsigned HOST_WIDE_INT tree_to_uhwi(const_tree t) 432 { 433 gcc_assert(tree_fits_uhwi_p(t)); 434 return TREE_INT_CST_LOW(t); 435 } 436 437 static inline const char *get_tree_code_name(enum tree_code code) 438 { 439 gcc_assert(code < MAX_TREE_CODES); 440 return tree_code_name[code]; 441 } 442 443 #define ipa_remove_stmt_references(cnode, stmt) 444 445 typedef union gimple_statement_d gasm; 446 typedef union gimple_statement_d gassign; 447 typedef union gimple_statement_d gcall; 448 typedef union gimple_statement_d gcond; 449 typedef union gimple_statement_d gdebug; 450 typedef union gimple_statement_d ggoto; 451 typedef union gimple_statement_d gphi; 452 typedef union gimple_statement_d greturn; 453 454 static inline gasm *as_a_gasm(gimple stmt) 455 { 456 return stmt; 457 } 458 459 static inline const gasm *as_a_const_gasm(const_gimple stmt) 460 { 461 return stmt; 462 } 463 464 static inline gassign *as_a_gassign(gimple stmt) 465 { 466 return stmt; 467 } 468 469 static inline const gassign *as_a_const_gassign(const_gimple stmt) 470 { 471 return stmt; 472 } 473 474 static inline gcall *as_a_gcall(gimple stmt) 475 { 476 return stmt; 477 } 478 479 static inline const gcall *as_a_const_gcall(const_gimple stmt) 480 { 481 return stmt; 482 } 483 484 static inline gcond *as_a_gcond(gimple stmt) 485 { 486 return stmt; 487 } 488 489 static inline const gcond *as_a_const_gcond(const_gimple stmt) 490 { 491 return stmt; 492 } 493 494 static inline gdebug *as_a_gdebug(gimple stmt) 495 { 496 return stmt; 497 } 498 499 static inline const gdebug *as_a_const_gdebug(const_gimple stmt) 500 { 501 return stmt; 502 } 503 504 static inline ggoto *as_a_ggoto(gimple stmt) 505 { 506 return stmt; 507 } 508 509 static inline const ggoto *as_a_const_ggoto(const_gimple stmt) 510 { 511 return stmt; 512 } 513 514 static inline gphi *as_a_gphi(gimple stmt) 515 { 516 return stmt; 517 } 518 519 static inline const gphi *as_a_const_gphi(const_gimple stmt) 520 { 521 return stmt; 522 } 523 524 static inline greturn *as_a_greturn(gimple stmt) 525 { 526 return stmt; 527 } 528 529 static inline const greturn *as_a_const_greturn(const_gimple stmt) 530 { 531 return stmt; 532 } 533 #endif 534 535 #if BUILDING_GCC_VERSION == 4008 536 #define NODE_SYMBOL(node) (&(node)->symbol) 537 #define NODE_DECL(node) (node)->symbol.decl 538 #endif 539 540 #if BUILDING_GCC_VERSION >= 4008 541 #define add_referenced_var(var) 542 #define mark_sym_for_renaming(var) 543 #define varpool_mark_needed_node(node) 544 #define create_var_ann(var) 545 #define TODO_dump_func 0 546 #define TODO_dump_cgraph 0 547 #endif 548 549 #if BUILDING_GCC_VERSION <= 4009 550 #define TODO_verify_il 0 551 #define AVAIL_INTERPOSABLE AVAIL_OVERWRITABLE 552 553 #define section_name_prefix LTO_SECTION_NAME_PREFIX 554 #define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__) 555 556 rtx emit_move_insn(rtx x, rtx y); 557 558 typedef struct rtx_def rtx_insn; 559 560 static inline const char *get_decl_section_name(const_tree decl) 561 { 562 if (DECL_SECTION_NAME(decl) == NULL_TREE) 563 return NULL; 564 565 return TREE_STRING_POINTER(DECL_SECTION_NAME(decl)); 566 } 567 568 static inline void set_decl_section_name(tree node, const char *value) 569 { 570 if (value) 571 DECL_SECTION_NAME(node) = build_string(strlen(value) + 1, value); 572 else 573 DECL_SECTION_NAME(node) = NULL; 574 } 575 #endif 576 577 #if BUILDING_GCC_VERSION == 4009 578 typedef struct gimple_statement_asm gasm; 579 typedef struct gimple_statement_base gassign; 580 typedef struct gimple_statement_call gcall; 581 typedef struct gimple_statement_base gcond; 582 typedef struct gimple_statement_base gdebug; 583 typedef struct gimple_statement_base ggoto; 584 typedef struct gimple_statement_phi gphi; 585 typedef struct gimple_statement_base greturn; 586 587 static inline gasm *as_a_gasm(gimple stmt) 588 { 589 return as_a<gasm>(stmt); 590 } 591 592 static inline const gasm *as_a_const_gasm(const_gimple stmt) 593 { 594 return as_a<const gasm>(stmt); 595 } 596 597 static inline gassign *as_a_gassign(gimple stmt) 598 { 599 return stmt; 600 } 601 602 static inline const gassign *as_a_const_gassign(const_gimple stmt) 603 { 604 return stmt; 605 } 606 607 static inline gcall *as_a_gcall(gimple stmt) 608 { 609 return as_a<gcall>(stmt); 610 } 611 612 static inline const gcall *as_a_const_gcall(const_gimple stmt) 613 { 614 return as_a<const gcall>(stmt); 615 } 616 617 static inline gcond *as_a_gcond(gimple stmt) 618 { 619 return stmt; 620 } 621 622 static inline const gcond *as_a_const_gcond(const_gimple stmt) 623 { 624 return stmt; 625 } 626 627 static inline gdebug *as_a_gdebug(gimple stmt) 628 { 629 return stmt; 630 } 631 632 static inline const gdebug *as_a_const_gdebug(const_gimple stmt) 633 { 634 return stmt; 635 } 636 637 static inline ggoto *as_a_ggoto(gimple stmt) 638 { 639 return stmt; 640 } 641 642 static inline const ggoto *as_a_const_ggoto(const_gimple stmt) 643 { 644 return stmt; 645 } 646 647 static inline gphi *as_a_gphi(gimple stmt) 648 { 649 return as_a<gphi>(stmt); 650 } 651 652 static inline const gphi *as_a_const_gphi(const_gimple stmt) 653 { 654 return as_a<const gphi>(stmt); 655 } 656 657 static inline greturn *as_a_greturn(gimple stmt) 658 { 659 return stmt; 660 } 661 662 static inline const greturn *as_a_const_greturn(const_gimple stmt) 663 { 664 return stmt; 665 } 666 #endif 667 668 #if BUILDING_GCC_VERSION >= 4009 669 #define TODO_ggc_collect 0 670 #define NODE_SYMBOL(node) (node) 671 #define NODE_DECL(node) (node)->decl 672 #define cgraph_node_name(node) (node)->name() 673 #define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias 674 675 static inline opt_pass *get_pass_for_id(int id) 676 { 677 return g->get_passes()->get_pass_for_id(id); 678 } 679 #endif 680 681 #if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000 682 /* gimple related */ 683 template <> 684 template <> 685 inline bool is_a_helper<const gassign *>::test(const_gimple gs) 686 { 687 return gs->code == GIMPLE_ASSIGN; 688 } 689 #endif 690 691 #if BUILDING_GCC_VERSION >= 5000 692 #define TODO_verify_ssa TODO_verify_il 693 #define TODO_verify_flow TODO_verify_il 694 #define TODO_verify_stmts TODO_verify_il 695 #define TODO_verify_rtl_sharing TODO_verify_il 696 697 #define INSN_DELETED_P(insn) (insn)->deleted() 698 699 static inline const char *get_decl_section_name(const_tree decl) 700 { 701 return DECL_SECTION_NAME(decl); 702 } 703 704 /* symtab/cgraph related */ 705 #define debug_cgraph_node(node) (node)->debug() 706 #define cgraph_get_node(decl) cgraph_node::get(decl) 707 #define cgraph_get_create_node(decl) cgraph_node::get_create(decl) 708 #define cgraph_create_node(decl) cgraph_node::create(decl) 709 #define cgraph_n_nodes symtab->cgraph_count 710 #define cgraph_max_uid symtab->cgraph_max_uid 711 #define varpool_get_node(decl) varpool_node::get(decl) 712 #define dump_varpool_node(file, node) (node)->dump(file) 713 714 #define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \ 715 (caller)->create_edge((callee), (call_stmt), (count), (freq)) 716 #define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \ 717 (caller)->create_edge_including_clones((callee), (old_call_stmt), (call_stmt), (count), (freq), (reason)) 718 719 typedef struct cgraph_node *cgraph_node_ptr; 720 typedef struct cgraph_edge *cgraph_edge_p; 721 typedef struct varpool_node *varpool_node_ptr; 722 723 static inline void change_decl_assembler_name(tree decl, tree name) 724 { 725 symtab->change_decl_assembler_name(decl, name); 726 } 727 728 static inline void varpool_finalize_decl(tree decl) 729 { 730 varpool_node::finalize_decl(decl); 731 } 732 733 static inline void varpool_add_new_variable(tree decl) 734 { 735 varpool_node::add(decl); 736 } 737 738 static inline unsigned int rebuild_cgraph_edges(void) 739 { 740 return cgraph_edge::rebuild_edges(); 741 } 742 743 static inline cgraph_node_ptr cgraph_function_node(cgraph_node_ptr node, enum availability *availability) 744 { 745 return node->function_symbol(availability); 746 } 747 748 static inline cgraph_node_ptr cgraph_function_or_thunk_node(cgraph_node_ptr node, enum availability *availability = NULL) 749 { 750 return node->ultimate_alias_target(availability); 751 } 752 753 static inline bool cgraph_only_called_directly_p(cgraph_node_ptr node) 754 { 755 return node->only_called_directly_p(); 756 } 757 758 static inline enum availability cgraph_function_body_availability(cgraph_node_ptr node) 759 { 760 return node->get_availability(); 761 } 762 763 static inline cgraph_node_ptr cgraph_alias_target(cgraph_node_ptr node) 764 { 765 return node->get_alias_target(); 766 } 767 768 static inline bool cgraph_for_node_and_aliases(cgraph_node_ptr node, bool (*callback)(cgraph_node_ptr, void *), void *data, bool include_overwritable) 769 { 770 return node->call_for_symbol_thunks_and_aliases(callback, data, include_overwritable); 771 } 772 773 static inline struct cgraph_node_hook_list *cgraph_add_function_insertion_hook(cgraph_node_hook hook, void *data) 774 { 775 return symtab->add_cgraph_insertion_hook(hook, data); 776 } 777 778 static inline void cgraph_remove_function_insertion_hook(struct cgraph_node_hook_list *entry) 779 { 780 symtab->remove_cgraph_insertion_hook(entry); 781 } 782 783 static inline struct cgraph_node_hook_list *cgraph_add_node_removal_hook(cgraph_node_hook hook, void *data) 784 { 785 return symtab->add_cgraph_removal_hook(hook, data); 786 } 787 788 static inline void cgraph_remove_node_removal_hook(struct cgraph_node_hook_list *entry) 789 { 790 symtab->remove_cgraph_removal_hook(entry); 791 } 792 793 static inline struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook(cgraph_2node_hook hook, void *data) 794 { 795 return symtab->add_cgraph_duplication_hook(hook, data); 796 } 797 798 static inline void cgraph_remove_node_duplication_hook(struct cgraph_2node_hook_list *entry) 799 { 800 symtab->remove_cgraph_duplication_hook(entry); 801 } 802 803 static inline void cgraph_call_node_duplication_hooks(cgraph_node_ptr node, cgraph_node_ptr node2) 804 { 805 symtab->call_cgraph_duplication_hooks(node, node2); 806 } 807 808 static inline void cgraph_call_edge_duplication_hooks(cgraph_edge *cs1, cgraph_edge *cs2) 809 { 810 symtab->call_edge_duplication_hooks(cs1, cs2); 811 } 812 813 #if BUILDING_GCC_VERSION >= 6000 814 typedef gimple *gimple_ptr; 815 typedef const gimple *const_gimple_ptr; 816 #define gimple gimple_ptr 817 #define const_gimple const_gimple_ptr 818 #undef CONST_CAST_GIMPLE 819 #define CONST_CAST_GIMPLE(X) CONST_CAST(gimple, (X)) 820 #endif 821 822 /* gimple related */ 823 static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree lhs, tree op1, tree op2 MEM_STAT_DECL) 824 { 825 return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT); 826 } 827 828 template <> 829 template <> 830 inline bool is_a_helper<const ggoto *>::test(const_gimple gs) 831 { 832 return gs->code == GIMPLE_GOTO; 833 } 834 835 template <> 836 template <> 837 inline bool is_a_helper<const greturn *>::test(const_gimple gs) 838 { 839 return gs->code == GIMPLE_RETURN; 840 } 841 842 static inline gasm *as_a_gasm(gimple stmt) 843 { 844 return as_a<gasm *>(stmt); 845 } 846 847 static inline const gasm *as_a_const_gasm(const_gimple stmt) 848 { 849 return as_a<const gasm *>(stmt); 850 } 851 852 static inline gassign *as_a_gassign(gimple stmt) 853 { 854 return as_a<gassign *>(stmt); 855 } 856 857 static inline const gassign *as_a_const_gassign(const_gimple stmt) 858 { 859 return as_a<const gassign *>(stmt); 860 } 861 862 static inline gcall *as_a_gcall(gimple stmt) 863 { 864 return as_a<gcall *>(stmt); 865 } 866 867 static inline const gcall *as_a_const_gcall(const_gimple stmt) 868 { 869 return as_a<const gcall *>(stmt); 870 } 871 872 static inline ggoto *as_a_ggoto(gimple stmt) 873 { 874 return as_a<ggoto *>(stmt); 875 } 876 877 static inline const ggoto *as_a_const_ggoto(const_gimple stmt) 878 { 879 return as_a<const ggoto *>(stmt); 880 } 881 882 static inline gphi *as_a_gphi(gimple stmt) 883 { 884 return as_a<gphi *>(stmt); 885 } 886 887 static inline const gphi *as_a_const_gphi(const_gimple stmt) 888 { 889 return as_a<const gphi *>(stmt); 890 } 891 892 static inline greturn *as_a_greturn(gimple stmt) 893 { 894 return as_a<greturn *>(stmt); 895 } 896 897 static inline const greturn *as_a_const_greturn(const_gimple stmt) 898 { 899 return as_a<const greturn *>(stmt); 900 } 901 902 /* IPA/LTO related */ 903 #define ipa_ref_list_referring_iterate(L, I, P) \ 904 (L)->referring.iterate((I), &(P)) 905 #define ipa_ref_list_reference_iterate(L, I, P) \ 906 (L)->reference.iterate((I), &(P)) 907 908 static inline cgraph_node_ptr ipa_ref_referring_node(struct ipa_ref *ref) 909 { 910 return dyn_cast<cgraph_node_ptr>(ref->referring); 911 } 912 913 static inline void ipa_remove_stmt_references(symtab_node *referring_node, gimple stmt) 914 { 915 referring_node->remove_stmt_references(stmt); 916 } 917 #endif 918 919 #if BUILDING_GCC_VERSION < 6000 920 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \ 921 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, pvolatilep, keep_aligning) 922 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET(VOIDmode, (ARG0), (ARG1)) 923 #endif 924 925 #if BUILDING_GCC_VERSION >= 6000 926 #define gen_rtx_set(ARG0, ARG1) gen_rtx_SET((ARG0), (ARG1)) 927 #endif 928 929 #ifdef __cplusplus 930 static inline void debug_tree(const_tree t) 931 { 932 debug_tree(CONST_CAST_TREE(t)); 933 } 934 935 static inline void debug_gimple_stmt(const_gimple s) 936 { 937 debug_gimple_stmt(CONST_CAST_GIMPLE(s)); 938 } 939 #else 940 #define debug_tree(t) debug_tree(CONST_CAST_TREE(t)) 941 #define debug_gimple_stmt(s) debug_gimple_stmt(CONST_CAST_GIMPLE(s)) 942 #endif 943 944 #if BUILDING_GCC_VERSION >= 7000 945 #define get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep, keep_aligning) \ 946 get_inner_reference(exp, pbitsize, pbitpos, poffset, pmode, punsignedp, preversep, pvolatilep) 947 #endif 948 949 #endif 950