mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-25 23:36:24 +08:00
gcc/ada: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * gcc-interface/utils.c (init_gnat_to_gnu): Use typed GC allocation. (init_dummy_type): Likewise. (gnat_pushlevel): Likewise. * gcc-interface/trans.c (Attribute_to_gnu): Likewise. (Subprogram_Body_to_gnu): Likewise. (Compilation_Unit_to_gnu): Likewise. (start_stmt_group): Likewise. (extract_encoding): Likewise. (decode_name): Likewise. * gcc-interface/misc.c (gnat_printable_name): Likewise. * gcc-interface/decl.c (annotate_value): Likewise. * gcc-interface/ada-tree.h (struct lang_type): Add variable_size GTY option. (struct lang_decl): Likewise. (SET_TYPE_LANG_SPECIFIC): Use typed GC allocation. (SET_DECL_LANG_SPECIFIC): Likewise. gcc/c-family: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * c-pragma.c (push_alignment): Use typed GC allocation. (handle_pragma_push_options): Likewise. * c-common.c (parse_optimize_options): Likewise. * c-common.h (struct sorted_fields_type): Add variable_size GTY option. gcc/cp: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * typeck2.c (abstract_virtuals_error): Likewise. * pt.c (maybe_process_partial_specialization): Likewise. (register_specialization): Likewise. (add_pending_template): Likewise. (lookup_template_class): Likewise. (push_tinst_level): Likewise. * parser.c (cp_lexer_new_main): Likewise. (cp_lexer_new_from_tokens): Likewise. (cp_token_cache_new): Likewise. (cp_parser_context_new): Likewise. (cp_parser_new): Likewise. (cp_parser_nested_name_specifier_opt): Likewise. (cp_parser_template_id): Likewise. * name-lookup.c (binding_entry_make): Likewise. (binding_table_construct): Likewise. (binding_table_new): Likewise. (cxx_binding_make): Likewise. (pushdecl_maybe_friend): Likewise. (begin_scope): Likewise. (push_to_top_level): Likewise. * lex.c (init_reswords): Likewise. (retrofit_lang_decl): Likewise. (cxx_dup_lang_specific_decl): Likewise. (copy_lang_type): Likewise. (cxx_make_type): Likewise. * decl.c (make_label_decl): Likewise. (check_goto): Likewise. (start_preparsed_function): Likewise. (save_function_data): Likewise. * cp-tree.h (TYPE_SET_PTRMEMFUNC_TYPE): Likewise. * cp-objcp-common.c (decl_shadowed_for_var_insert): Likewise. * class.c (finish_struct_1): Likewise. * cp-tree.h (struct lang_type): Add variable_size GTY option. (struct lang_decl): Likewise. * parser.c (cp_parser_new): Update comment to not reference ggc_alloc. gcc/fortran: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * trans-types.c (gfc_get_nodesc_array_type): Use typed GC allocation. (gfc_get_array_type_bounds): Likewise. * trans-decl.c (gfc_allocate_lang_decl): Likewise. (gfc_find_module): Likewise. * f95-lang.c (pushlevel): Likewise. * trans.h (struct lang_type): Add variable_size GTY option. (struct lang_decl): Likewise. gcc/java: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * jcf-reader.c (jcf_parse_constant_pool): Use typed GC allocation. * jcf-parse.c (java_parse_file): Likewise. (process_zip_dir): Likewise. * java-tree.h (MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC): Likewise. (MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC): Likewise. * expr.c (add_type_assertion): Likewise. * decl.c (make_binding_level): Likewise. (java_dup_lang_specific_decl): Likewise. * constants.c (set_constant_entry): Likewise. (cpool_for_class): Likewise. * class.c (add_method_1): Likewise. (java_treetreehash_new): Likewise. * java-tree.h (struct lang_type): Add variable_size GTY option. (struct lang_decl): Likewise. * jch.h (struct cpool_entry): Likewise. * java-tree.h (java_treetreehash_create): Remove parameter ggc. * except.c (prepare_eh_table_type): Update java_treetreehash_create call. * class.c (add_method_1): Update java_treetreehash_create call. (java_treetreehash_create): Remove parameter gc. Use htab_create_ggc. gcc/lto: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * lto.c (lto_read_in_decl_state): Use typed GC allocation. (lto_file_read): Likewise. (new_partition): Likewise. (read_cgraph_and_symbols): Likewise. gcc/objc: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * objc-act.h (ALLOC_OBJC_TYPE_LANG_SPECIFIC): Use typed GC allocation. * objc-act.c (objc_volatilize_decl): Likewise. (objc_build_string_object): Likewise. (hash_init): Likewise. (hash_enter): Likewise. (hash_add_attr): Likewise. (add_class): Likewise. (start_class): Likewise. gcc/objcp: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * objcp-decl.h (ALLOC_OBJC_TYPE_LANG_SPECIFIC): Use typed GC allocation. gcc: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * doc/tm.texi (Per-Function Data): Do not reference ggc_alloc. * doc/gty.texi (GTY Options): Document typed GC allocation and variable_size GTY option. * ggc-internal.h: New. * ggc.h: Update copyright year. (digit_string): Move to stringpool.c. (ggc_mark_stringpool, ggc_purge_stringpool, ggc_mark_roots) (gt_pch_save_stringpool, gt_pch_fixup_stringpool) (gt_pach_restore_stringpool, gt_pch_p_S, gt_pch_note_object) (init_ggc_pch, ggc_pch_count_object, ggc_pch_total_size) (ggc_pch_this_base, ggc_pch_alloc_object, ggc_pch_prepare_write) (ggc_pch_write_object, ggc_pch_finish, ggc_pch_read) (ggc_force_collect, ggc_get_size, ggc_statistics) (ggc_print_common_statistics): Move to ggc-internal.h. (digit_vector, new_ggc_zone, destroy_ggc_zone, ggc_alloc_stat) (ggc_alloc, ggc_alloc_cleared, ggc_realloc, ggc_calloc, GGC_NEW) (GGC_CNEW, GGC_NEWVEC, GGC_CNEWVEC, GGC_NEWVAR, ggc_alloc_rtvec) (ggc_alloc_tree, gt_pch_save, ggc_min_expand_heuristic) (ggc_min_heapsize_heuristic, ggc_alloc_zone) (ggc_alloc_zone_pass_stat): Remove. (ggc_internal_alloc_stat, ggc_internal_alloc) (ggc_internal_cleared_alloc_stat): New. (GGC_RESIZEVEC, GGC_RESIZEVAR): Redefine. (ggc_internal_vec_alloc_stat) (ggc_internal_cleared_vec_alloc_stat) (ggc_internal_vec_alloc_stat, ggc_internal_cleared_vec_alloc) (ggc_alloc_atomic_stat, ggc_alloc_atomic) (ggc_alloc_cleared_atomic, ggc_cleared_alloc_htab_ignore_args) (ggc_cleared_alloc_ptr_array_two_args): New. (htab_create_ggc, splay_tree_new_ggc): Redefine. (ggc_splay_alloc): Change the type of the first argument to enum gt_types_enum. (ggc_alloc_string): Make macro. (ggc_alloc_string_stat): New. (ggc_strdup): Redefine. (rtl_zone, tree_zone, tree_id_zone): Declare unconditionally. (ggc_alloc_rtvec_sized): New. (ggc_alloc_zone_stat): Rename to ggc_internal_alloc_zone_stat. (ggc_internal_alloc_zone_pass_stat, ggc_internal_alloc_zone_stat) (ggc_internal_cleared_alloc_zone_stat) (ggc_internal_zone_alloc_stat) (ggc_internal_zone_cleared_alloc_stat) (ggc_internal_zone_vec_alloc_stat) (ggc_alloc_zone_rtx_def_stat) (ggc_alloc_zone_tree_node_stat) (ggc_alloc_zone_cleared_tree_node_stat) (ggc_alloc_cleared_gimple_statement_d_stat): New. * ggc-common.c: Include ggc-internal.h. (ggc_internal_cleared_alloc_stat): Rename from ggc_alloc_cleared_stat. (ggc_realloc_stat): Use ggc_internal_alloc_stat. (ggc_calloc): Remove. (ggc_cleared_alloc_htab_ignore_args): New. (ggc_cleared_alloc_ptr_array_two_args): New. (ggc_splay_alloc): Add obj_type parameter. (init_ggc_heuristics): Formatting fixes. * ggc-none.c: Update copyright year. (ggc_alloc_stat): Rename to ggc_alloc_stat. (ggc_alloc_cleared_stat): Rename to ggc_internal_cleared_alloc_stat. (struct alloc_zone, rtl_zone, tree_zone, tree_id_zone): New. * ggc-page.c: Update copyright year. Include ggc-internal.h. Remove references to ggc_alloc in comments. (ggc_alloc_typed_stat): Call ggc_internal_alloc_stat. (ggc_alloc_stat): Rename to ggc_internal_alloc_stat. (new_ggc_zone, destroy_ggc_zone): Remove. (struct alloc_zone, rtl_zone, tree_zone, tree_id_zone): New. * ggc-zone.c: Include ggc-internal.h. Remove references to ggc_alloc in comments. (ggc_alloc_zone_stat): ggc_internal_alloc_zone_stat. (ggc_internal_alloc_zone_pass_stat): New. (ggc_internal_cleared_alloc_zone_stat): New. (ggc_alloc_typed_stat): Use ggc_internal_alloc_zone_pass_stat. (ggc_alloc_stat): Rename ggc_internal_alloc_stat. (new_ggc_zone, destroy_ggc_zone): Remove. * stringpool.c: Update copyright year. Include ggc-internal.h (digit_vector): Make static. (digit_string): Moved from ggc.h. (stringpool_ggc_alloc): Use ggc_alloc_atomic. (ggc_alloc_string): Rename to ggc_alloc_string_stat. * Makefile.in (GGC_INTERNAL_H): New. (ggc_common.o, ggc-page.o, ggc-zone.o, stringpool.o): Add $(GGC_INTERNAL_H) to dependencies. * gentype.c: Update copyright year. (walk_type): Accept variable_size GTY option. (USED_BY_TYPED_GC_P): New macro. (write_enum_defn): Use USED_BY_TYPED_GC_P. Do not output whitespace at the end of strings. (get_type_specifier, variable_size_p): New functions. (alloc_quantity, alloc_zone): New enums. (write_typed_alloc_def): New function. (write_typed_struct_alloc_def): Likewise. (write_typed_typed_typedef_alloc_def): Likewise. (write_typed_alloc_defns): Likewise. (output_typename, write_splay_tree_allocator_def): Likewise. (write_splay_tree_allocators): Likewise. (main): Call write_typed_alloc_defns and write_splay_tree_allocators. * lto-streamer.h (lto_file_decl_data_ptr): New. * passes.c (order): Define using cgraph_node_ptr. * strinpool.c (struct string_pool_data): Declare nested_ptr using ht_identifier_ptr. * gimple.h (union gimple_statement_d): Likewise. * rtl.h (struct rtx_def): Likewise. (struct rtvec_def): Likewise. * tree.h (union tree_node): Likewise. * tree-ssa-operands.h (struct ssa_operand_memory_d): Likewise. * cfgloop.c (record_loop_exits): Use htab_create_ggc. * tree-scalar-evolution.c (scev_initialize): Likewise. * alias.c (record_alias_subset): Update splay_tree_new_ggc call. * dwarf2asm.c (dw2_force_const_mem): Likewise. * omp-low.c (lower_omp_critical): Likewise. * bitmap.h (struct bitmap_head_def): Update comment to not reference ggc_alloc. * config/pa/pa.c (get_deferred_label): Use GGC_RESIZEVEC. * ira.c (fix_reg_equiv_init): Use GGC_RESIZEVEC. * ipa-prop.c (duplicate_ggc_array): Rename to duplicate_ipa_jump_func_array. Use typed GC allocation. (ipa_edge_duplication_hook): Call duplicate_ipa_jump_func_array. * gimple.c (gimple_alloc_stat): Use ggc_alloc_cleared_gimple_statement_d_stat. * varasm.c (create_block_symbol): Use ggc_alloc_zone_rtx_def. * tree.c (make_node_stat): Use ggc_alloc_zone_cleared_tree_node_stat. (make_tree_vec_stat): Likewise. (build_vl_exp_stat): Likewise. (copy_node_stat): Use ggc_alloc_zone_tree_node_stat. (make_tree_binfo_stat): Likewise. (tree_cons_stat): Likewise. * rtl.c (rtx_alloc_stat): Use ggc_alloc_zone_rtx_def_stat. (shallow_copy_rtx_stat): Likewise. (make_node_stat): Likewise. * lto-symtab.c: Fix comment. * tree-cfg.c (create_bb): Update comment to not reference ggc_alloc_cleared. * tree-ssa-structalias.c (struct heapvar_for_stmt): Fix param_is value. * varpool.c (varpool_node): Use typed GC allocation. (varpool_extra_name_alias): Likewise. * varasm.c (emutls_decl): Likewise. (get_unnamed_section): Likewise. (get_noswitch_section): Likewise. (get_section): Likewise. (get_block_for_section): Likewise. (build_constant_desc): Likewise. (create_constant_pool): Likewise. (force_const_mem): Likewise. * tree.c (build_vl_exp_stat): Likewise. (build_real): Likewise. (build_string): Likewise. (decl_debug_expr_insert): Likewise. (decl_value_expr_insert): Likewise. (type_hash_add): Likewise. (build_omp_clause): Likewise. * tree-ssanames.c (duplicate_ssa_name_ptr_info): Likewise. * tree-ssa.c (init_tree_ssa): Likewise. * tree-ssa-structalias.c (heapvar_insert): Likewise. * tree-ssa-operands.c (ssa_operand_alloc): Likewise. * tree-ssa-loop-niter.c (record_estimate): Likewise. * tree-ssa-alias.c (get_ptr_info): Likewise. * tree-scalar-evolution.c (new_scev_info_str): Likewise. * tree-phinodes.c (allocate_phi_node): Likewise. * tree-iterator.c (tsi_link_before): Likewise. (tsi_link_after): Likewise. * tree-eh.c (add_stmt_to_eh_lp_fn): Likewise. * tree-dfa.c (create_var_ann): Likewise. * tree-cfg.c (create_bb): Likewise. * toplev.c (alloc_for_identifier_to_locale): Likewise. (general_init): Likewise. * stringpool.c (stringpool_ggc_alloc): Likewise. (gt_pch_save_stringpool): Likewise. * sese.c (if_region_set_false_region): Likewise. * passes.c (do_per_function_toporder): Likewise. * optabs.c (set_optab_libfunc): Likewise. (set_conv_libfunc): Likewise. * lto-symtab.c (lto_symtab_register_decl): Likewise. * lto-streamer-in.c (lto_input_eh_catch_list): Likewise. (input_eh_region): Likewise. (input_eh_lp): Likewise. (make_new_block): Likewise. (unpack_ts_real_cst_value_fields): Likewise. * lto-section-in.c (lto_new_in_decl_state): Likewise. * lto-cgraph.c (input_node_opt_summary): Likewise. * loop-init.c (loop_optimizer_init): Likewise. * lambda.h (lambda_vector_new): Likewise. * lambda-code.c (replace_uses_equiv_to_x_with_y): Likewise. * ira.c (update_equiv_regs): Likewise. * ipa.c (cgraph_node_set_new): Likewise. (cgraph_node_set_add): Likewise. (varpool_node_set_new): Likewise. (varpool_node_set_add): Likewise. * ipa-prop.c (ipa_compute_jump_functions_for_edge): Likewise. (duplicate_ipa_jump_func_array): Likewise. (ipa_read_node_info): Likewise. * ipa-cp.c (ipcp_create_replace_map): Likewise. * integrate.c (get_hard_reg_initial_val): Likewise. * gimple.c (gimple_alloc_stat): Likewise. (gimple_build_omp_for): Likewise. (gimple_seq_alloc): Likewise. (gimple_copy): Likewise. * gimple-iterator.c (gsi_insert_before_without_update): Likewise. (gsi_insert_after_without_update): Likewise. * function.c (add_frame_space): Likewise. (insert_temp_slot_address): Likewise. (assign_stack_temp_for_type): Likewise. (allocate_struct_function): Likewise. (types_used_by_var_decl_insert): Likewise. * except.c (init_eh_for_function): Likewise. (gen_eh_region): Likewise. (gen_eh_region_catch): Likewise. (gen_eh_landing_pad): Likewise. (add_call_site): Likewise. * emit-rtl.c (get_mem_attrs): Likewise. (get_reg_attrs): Likewise. (start_sequence): Likewise. (init_emit): Likewise. * dwarf2out.c (new_cfi): Likewise. (queue_reg_save): Likewise. (dwarf2out_frame_init): Likewise. (new_loc_descr): Likewise. (find_AT_string): Likewise. (new_die): Likewise. (add_var_loc_to_decl): Likewise. (clone_die): Likewise. (clone_as_declaration): Likewise. (break_out_comdat_types): Likewise. (new_loc_list): Likewise. (loc_descriptor): Likewise. (add_loc_descr_to_each): Likewise. (add_const_value_attribute): Likewise. (tree_add_const_value_attribute): Likewise. (add_comp_dir_attribute): Likewise. (add_name_and_src_coords_attributes): Likewise. (lookup_filename): Likewise. (store_vcall_insn): Likewise. (dwarf2out_init): Likewise. * dbxout.c (dbxout_init): Likewise. * config/xtensa/xtensa.c (xtensa_init_machine_status): Likewise. * config/sparc/sparc.c (sparc_init_machine_status): Likewise. * config/score/score7.c (score7_output_external): Likewise. * config/score/score3.c (score3_output_external): Likewise. * config/s390/s390.c (s390_init_machine_status): Likewise. * config/rs6000/rs6000.c (builtin_function_type): Likewise. (rs6000_init_machine_status): Likewise. (output_toc): Likewise. * config/pa/pa.c (pa_init_machine_status): Likewise. (get_deferred_plabel): Likewise. * config/moxie/moxie.c (moxie_init_machine_status): Likewise. * config/mmix/mmix.c (mmix_init_machine_status): Likewise. * config/mips/mips.c (mflip_mips16_use_mips16_p): Likewise. * config/mep/mep.c (mep_init_machine_status): Likewise. (mep_note_pragma_flag): Likewise. * config/m32c/m32c.c (m32c_init_machine_status): Likewise. * config/iq2000/iq2000.c (iq2000_init_machine_status): Likewise. * config/ia64/ia64.c (ia64_init_machine_status): Likewise. * config/i386/winnt.c (i386_pe_record_external_function): Likewise. (i386_pe_maybe_record_exported_symbol): Likewise. * config/i386/i386.c (get_dllimport_decl): Likewise. (ix86_init_machine_status): Likewise. (assign_386_stack_local): Likewise. * config/frv/frv.c (frv_init_machine_status): Likewise. * config/darwin.c (machopic_indirection_name): Likewise. * config/cris/cris.c (cris_init_machine_status): Likewise. * config/bfin/bfin.c (bfin_init_machine_status): Likewise. * config/avr/avr.c (avr_init_machine_status): Likewise. * config/arm/arm.c (arm_init_machine_status): Likewise. * config/alpha/alpha.c (alpha_init_machine_status): Likewise. (alpha_need_linkage): Likewise. (alpha_use_linkage): Likewise. * cgraph.c (cgraph_allocate_node): Likewise. (cgraph_create_edge_1): Likewise. (cgraph_create_indirect_edge): Likewise. (cgraph_add_asm_node): Likewise. * cfgrtl.c (init_rtl_bb_info): Likewise. * cfgloop.c (alloc_loop): Likewise. (rescan_loop_exit): Likewise. * cfg.c (init_flow): Likewise. (alloc_block): Likewise. (unchecked_make_edge): Likewise. * c-parser.c (c_parse_init): Likewise. (c_parse_file): Likewise. * c-decl.c (bind): Likewise. (record_inline_static): Likewise. (push_scope): Likewise. (make_label): Likewise. (lookup_label_for_goto): Likewise. (finish_struct): Likewise. (finish_enum): Likewise. (c_push_function_context): Likewise. * bitmap.c (bitmap_element_allocate): Likewise. (bitmap_gc_alloc_stat): Likewise. * alias.c (record_alias_subset): Likewise. (init_alias_analysis): Likewise. include: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * splay-tree.h: Update copyright years. (splay_tree_s): Document fields. (splay_tree_new_typed_alloc): New. * hashtab.h: Update copyright years. (htab_create_typed_alloc): New. libcpp: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * include/symtab.h (ht_identifier_ptr): New. libiberty: 2010-06-08 Laurynas Biveinis <laurynas.biveinis@gmail.com> * splay-tree.c: Update copyright years. (splay_tree_new_typed_alloc): New. (splay_tree_new_with_allocator): Use it. * hashtab.c: Update copyright years. (htab_create_typed_alloc): New. (htab_create_alloc): Use it. * functions.texi: Regenerate. From-SVN: r160425
502 lines
15 KiB
C
502 lines
15 KiB
C
/* Generic routines for manipulating PHIs
|
|
Copyright (C) 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
GCC is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tm.h"
|
|
#include "tree.h"
|
|
#include "rtl.h" /* FIXME: Only for ceil_log2, of all things... */
|
|
#include "ggc.h"
|
|
#include "basic-block.h"
|
|
#include "tree-flow.h"
|
|
#include "toplev.h"
|
|
#include "gimple.h"
|
|
|
|
/* Rewriting a function into SSA form can create a huge number of PHIs
|
|
many of which may be thrown away shortly after their creation if jumps
|
|
were threaded through PHI nodes.
|
|
|
|
While our garbage collection mechanisms will handle this situation, it
|
|
is extremely wasteful to create nodes and throw them away, especially
|
|
when the nodes can be reused.
|
|
|
|
For PR 8361, we can significantly reduce the number of nodes allocated
|
|
and thus the total amount of memory allocated by managing PHIs a
|
|
little. This additionally helps reduce the amount of work done by the
|
|
garbage collector. Similar results have been seen on a wider variety
|
|
of tests (such as the compiler itself).
|
|
|
|
Right now we maintain our free list on a per-function basis. It may
|
|
or may not make sense to maintain the free list for the duration of
|
|
a compilation unit.
|
|
|
|
We could also use a zone allocator for these objects since they have
|
|
a very well defined lifetime. If someone wants to experiment with that
|
|
this is the place to try it.
|
|
|
|
PHI nodes have different sizes, so we can't have a single list of all
|
|
the PHI nodes as it would be too expensive to walk down that list to
|
|
find a PHI of a suitable size.
|
|
|
|
Instead we have an array of lists of free PHI nodes. The array is
|
|
indexed by the number of PHI alternatives that PHI node can hold.
|
|
Except for the last array member, which holds all remaining PHI
|
|
nodes.
|
|
|
|
So to find a free PHI node, we compute its index into the free PHI
|
|
node array and see if there are any elements with an exact match.
|
|
If so, then we are done. Otherwise, we test the next larger size
|
|
up and continue until we are in the last array element.
|
|
|
|
We do not actually walk members of the last array element. While it
|
|
might allow us to pick up a few reusable PHI nodes, it could potentially
|
|
be very expensive if the program has released a bunch of large PHI nodes,
|
|
but keeps asking for even larger PHI nodes. Experiments have shown that
|
|
walking the elements of the last array entry would result in finding less
|
|
than .1% additional reusable PHI nodes.
|
|
|
|
Note that we can never have less than two PHI argument slots. Thus,
|
|
the -2 on all the calculations below. */
|
|
|
|
#define NUM_BUCKETS 10
|
|
static GTY ((deletable (""))) VEC(gimple,gc) *free_phinodes[NUM_BUCKETS - 2];
|
|
static unsigned long free_phinode_count;
|
|
|
|
static int ideal_phi_node_len (int);
|
|
|
|
#ifdef GATHER_STATISTICS
|
|
unsigned int phi_nodes_reused;
|
|
unsigned int phi_nodes_created;
|
|
#endif
|
|
|
|
/* Initialize management of PHIs. */
|
|
|
|
void
|
|
init_phinodes (void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < NUM_BUCKETS - 2; i++)
|
|
free_phinodes[i] = NULL;
|
|
free_phinode_count = 0;
|
|
}
|
|
|
|
/* Finalize management of PHIs. */
|
|
|
|
void
|
|
fini_phinodes (void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < NUM_BUCKETS - 2; i++)
|
|
free_phinodes[i] = NULL;
|
|
free_phinode_count = 0;
|
|
}
|
|
|
|
/* Dump some simple statistics regarding the re-use of PHI nodes. */
|
|
|
|
#ifdef GATHER_STATISTICS
|
|
void
|
|
phinodes_print_statistics (void)
|
|
{
|
|
fprintf (stderr, "PHI nodes allocated: %u\n", phi_nodes_created);
|
|
fprintf (stderr, "PHI nodes reused: %u\n", phi_nodes_reused);
|
|
}
|
|
#endif
|
|
|
|
/* Allocate a PHI node with at least LEN arguments. If the free list
|
|
happens to contain a PHI node with LEN arguments or more, return
|
|
that one. */
|
|
|
|
static inline gimple
|
|
allocate_phi_node (size_t len)
|
|
{
|
|
gimple phi;
|
|
size_t bucket = NUM_BUCKETS - 2;
|
|
size_t size = sizeof (struct gimple_statement_phi)
|
|
+ (len - 1) * sizeof (struct phi_arg_d);
|
|
|
|
if (free_phinode_count)
|
|
for (bucket = len - 2; bucket < NUM_BUCKETS - 2; bucket++)
|
|
if (free_phinodes[bucket])
|
|
break;
|
|
|
|
/* If our free list has an element, then use it. */
|
|
if (bucket < NUM_BUCKETS - 2
|
|
&& gimple_phi_capacity (VEC_index (gimple, free_phinodes[bucket], 0))
|
|
>= len)
|
|
{
|
|
free_phinode_count--;
|
|
phi = VEC_pop (gimple, free_phinodes[bucket]);
|
|
if (VEC_empty (gimple, free_phinodes[bucket]))
|
|
VEC_free (gimple, gc, free_phinodes[bucket]);
|
|
#ifdef GATHER_STATISTICS
|
|
phi_nodes_reused++;
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
phi = ggc_alloc_gimple_statement_d (size);
|
|
#ifdef GATHER_STATISTICS
|
|
phi_nodes_created++;
|
|
{
|
|
enum gimple_alloc_kind kind = gimple_alloc_kind (GIMPLE_PHI);
|
|
gimple_alloc_counts[(int) kind]++;
|
|
gimple_alloc_sizes[(int) kind] += size;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
return phi;
|
|
}
|
|
|
|
/* Given LEN, the original number of requested PHI arguments, return
|
|
a new, "ideal" length for the PHI node. The "ideal" length rounds
|
|
the total size of the PHI node up to the next power of two bytes.
|
|
|
|
Rounding up will not result in wasting any memory since the size request
|
|
will be rounded up by the GC system anyway. [ Note this is not entirely
|
|
true since the original length might have fit on one of the special
|
|
GC pages. ] By rounding up, we may avoid the need to reallocate the
|
|
PHI node later if we increase the number of arguments for the PHI. */
|
|
|
|
static int
|
|
ideal_phi_node_len (int len)
|
|
{
|
|
size_t size, new_size;
|
|
int log2, new_len;
|
|
|
|
/* We do not support allocations of less than two PHI argument slots. */
|
|
if (len < 2)
|
|
len = 2;
|
|
|
|
/* Compute the number of bytes of the original request. */
|
|
size = sizeof (struct gimple_statement_phi)
|
|
+ (len - 1) * sizeof (struct phi_arg_d);
|
|
|
|
/* Round it up to the next power of two. */
|
|
log2 = ceil_log2 (size);
|
|
new_size = 1 << log2;
|
|
|
|
/* Now compute and return the number of PHI argument slots given an
|
|
ideal size allocation. */
|
|
new_len = len + (new_size - size) / sizeof (struct phi_arg_d);
|
|
return new_len;
|
|
}
|
|
|
|
/* Return a PHI node with LEN argument slots for variable VAR. */
|
|
|
|
gimple
|
|
make_phi_node (tree var, int len)
|
|
{
|
|
gimple phi;
|
|
int capacity, i;
|
|
|
|
capacity = ideal_phi_node_len (len);
|
|
|
|
phi = allocate_phi_node (capacity);
|
|
|
|
/* We need to clear the entire PHI node, including the argument
|
|
portion, because we represent a "missing PHI argument" by placing
|
|
NULL_TREE in PHI_ARG_DEF. */
|
|
memset (phi, 0, (sizeof (struct gimple_statement_phi)
|
|
- sizeof (struct phi_arg_d)
|
|
+ sizeof (struct phi_arg_d) * len));
|
|
phi->gsbase.code = GIMPLE_PHI;
|
|
phi->gimple_phi.nargs = len;
|
|
phi->gimple_phi.capacity = capacity;
|
|
if (TREE_CODE (var) == SSA_NAME)
|
|
gimple_phi_set_result (phi, var);
|
|
else
|
|
gimple_phi_set_result (phi, make_ssa_name (var, phi));
|
|
|
|
for (i = 0; i < capacity; i++)
|
|
{
|
|
use_operand_p imm;
|
|
|
|
gimple_phi_arg_set_location (phi, i, UNKNOWN_LOCATION);
|
|
imm = gimple_phi_arg_imm_use_ptr (phi, i);
|
|
imm->use = gimple_phi_arg_def_ptr (phi, i);
|
|
imm->prev = NULL;
|
|
imm->next = NULL;
|
|
imm->loc.stmt = phi;
|
|
}
|
|
|
|
return phi;
|
|
}
|
|
|
|
/* We no longer need PHI, release it so that it may be reused. */
|
|
|
|
void
|
|
release_phi_node (gimple phi)
|
|
{
|
|
size_t bucket;
|
|
size_t len = gimple_phi_capacity (phi);
|
|
size_t x;
|
|
|
|
for (x = 0; x < gimple_phi_num_args (phi); x++)
|
|
{
|
|
use_operand_p imm;
|
|
imm = gimple_phi_arg_imm_use_ptr (phi, x);
|
|
delink_imm_use (imm);
|
|
}
|
|
|
|
bucket = len > NUM_BUCKETS - 1 ? NUM_BUCKETS - 1 : len;
|
|
bucket -= 2;
|
|
VEC_safe_push (gimple, gc, free_phinodes[bucket], phi);
|
|
free_phinode_count++;
|
|
}
|
|
|
|
|
|
/* Resize an existing PHI node. The only way is up. Return the
|
|
possibly relocated phi. */
|
|
|
|
static void
|
|
resize_phi_node (gimple *phi, size_t len)
|
|
{
|
|
size_t old_size, i;
|
|
gimple new_phi;
|
|
|
|
gcc_assert (len > gimple_phi_capacity (*phi));
|
|
|
|
/* The garbage collector will not look at the PHI node beyond the
|
|
first PHI_NUM_ARGS elements. Therefore, all we have to copy is a
|
|
portion of the PHI node currently in use. */
|
|
old_size = sizeof (struct gimple_statement_phi)
|
|
+ (gimple_phi_num_args (*phi) - 1) * sizeof (struct phi_arg_d);
|
|
|
|
new_phi = allocate_phi_node (len);
|
|
|
|
memcpy (new_phi, *phi, old_size);
|
|
|
|
for (i = 0; i < gimple_phi_num_args (new_phi); i++)
|
|
{
|
|
use_operand_p imm, old_imm;
|
|
imm = gimple_phi_arg_imm_use_ptr (new_phi, i);
|
|
old_imm = gimple_phi_arg_imm_use_ptr (*phi, i);
|
|
imm->use = gimple_phi_arg_def_ptr (new_phi, i);
|
|
relink_imm_use_stmt (imm, old_imm, new_phi);
|
|
}
|
|
|
|
new_phi->gimple_phi.capacity = len;
|
|
|
|
for (i = gimple_phi_num_args (new_phi); i < len; i++)
|
|
{
|
|
use_operand_p imm;
|
|
|
|
gimple_phi_arg_set_location (new_phi, i, UNKNOWN_LOCATION);
|
|
imm = gimple_phi_arg_imm_use_ptr (new_phi, i);
|
|
imm->use = gimple_phi_arg_def_ptr (new_phi, i);
|
|
imm->prev = NULL;
|
|
imm->next = NULL;
|
|
imm->loc.stmt = new_phi;
|
|
}
|
|
|
|
*phi = new_phi;
|
|
}
|
|
|
|
/* Reserve PHI arguments for a new edge to basic block BB. */
|
|
|
|
void
|
|
reserve_phi_args_for_new_edge (basic_block bb)
|
|
{
|
|
size_t len = EDGE_COUNT (bb->preds);
|
|
size_t cap = ideal_phi_node_len (len + 4);
|
|
gimple_stmt_iterator gsi;
|
|
|
|
for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
|
|
{
|
|
gimple *loc = gsi_stmt_ptr (&gsi);
|
|
|
|
if (len > gimple_phi_capacity (*loc))
|
|
{
|
|
gimple old_phi = *loc;
|
|
|
|
resize_phi_node (loc, cap);
|
|
|
|
/* The result of the PHI is defined by this PHI node. */
|
|
SSA_NAME_DEF_STMT (gimple_phi_result (*loc)) = *loc;
|
|
|
|
release_phi_node (old_phi);
|
|
}
|
|
|
|
/* We represent a "missing PHI argument" by placing NULL_TREE in
|
|
the corresponding slot. If PHI arguments were added
|
|
immediately after an edge is created, this zeroing would not
|
|
be necessary, but unfortunately this is not the case. For
|
|
example, the loop optimizer duplicates several basic blocks,
|
|
redirects edges, and then fixes up PHI arguments later in
|
|
batch. */
|
|
SET_PHI_ARG_DEF (*loc, len - 1, NULL_TREE);
|
|
|
|
(*loc)->gimple_phi.nargs++;
|
|
}
|
|
}
|
|
|
|
/* Adds PHI to BB. */
|
|
|
|
void
|
|
add_phi_node_to_bb (gimple phi, basic_block bb)
|
|
{
|
|
gimple_stmt_iterator gsi;
|
|
/* Add the new PHI node to the list of PHI nodes for block BB. */
|
|
if (phi_nodes (bb) == NULL)
|
|
set_phi_nodes (bb, gimple_seq_alloc ());
|
|
|
|
gsi = gsi_last (phi_nodes (bb));
|
|
gsi_insert_after (&gsi, phi, GSI_NEW_STMT);
|
|
|
|
/* Associate BB to the PHI node. */
|
|
gimple_set_bb (phi, bb);
|
|
|
|
}
|
|
|
|
/* Create a new PHI node for variable VAR at basic block BB. */
|
|
|
|
gimple
|
|
create_phi_node (tree var, basic_block bb)
|
|
{
|
|
gimple phi = make_phi_node (var, EDGE_COUNT (bb->preds));
|
|
|
|
add_phi_node_to_bb (phi, bb);
|
|
return phi;
|
|
}
|
|
|
|
|
|
/* Add a new argument to PHI node PHI. DEF is the incoming reaching
|
|
definition and E is the edge through which DEF reaches PHI. The new
|
|
argument is added at the end of the argument list.
|
|
If PHI has reached its maximum capacity, add a few slots. In this case,
|
|
PHI points to the reallocated phi node when we return. */
|
|
|
|
void
|
|
add_phi_arg (gimple phi, tree def, edge e, source_location locus)
|
|
{
|
|
basic_block bb = e->dest;
|
|
|
|
gcc_assert (bb == gimple_bb (phi));
|
|
|
|
/* We resize PHI nodes upon edge creation. We should always have
|
|
enough room at this point. */
|
|
gcc_assert (gimple_phi_num_args (phi) <= gimple_phi_capacity (phi));
|
|
|
|
/* We resize PHI nodes upon edge creation. We should always have
|
|
enough room at this point. */
|
|
gcc_assert (e->dest_idx < gimple_phi_num_args (phi));
|
|
|
|
/* Copy propagation needs to know what object occur in abnormal
|
|
PHI nodes. This is a convenient place to record such information. */
|
|
if (e->flags & EDGE_ABNORMAL)
|
|
{
|
|
SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def) = 1;
|
|
SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)) = 1;
|
|
}
|
|
|
|
SET_PHI_ARG_DEF (phi, e->dest_idx, def);
|
|
gimple_phi_arg_set_location (phi, e->dest_idx, locus);
|
|
}
|
|
|
|
|
|
/* Remove the Ith argument from PHI's argument list. This routine
|
|
implements removal by swapping the last alternative with the
|
|
alternative we want to delete and then shrinking the vector, which
|
|
is consistent with how we remove an edge from the edge vector. */
|
|
|
|
static void
|
|
remove_phi_arg_num (gimple phi, int i)
|
|
{
|
|
int num_elem = gimple_phi_num_args (phi);
|
|
|
|
gcc_assert (i < num_elem);
|
|
|
|
/* Delink the item which is being removed. */
|
|
delink_imm_use (gimple_phi_arg_imm_use_ptr (phi, i));
|
|
|
|
/* If it is not the last element, move the last element
|
|
to the element we want to delete, resetting all the links. */
|
|
if (i != num_elem - 1)
|
|
{
|
|
use_operand_p old_p, new_p;
|
|
old_p = gimple_phi_arg_imm_use_ptr (phi, num_elem - 1);
|
|
new_p = gimple_phi_arg_imm_use_ptr (phi, i);
|
|
/* Set use on new node, and link into last element's place. */
|
|
*(new_p->use) = *(old_p->use);
|
|
relink_imm_use (new_p, old_p);
|
|
/* Move the location as well. */
|
|
gimple_phi_arg_set_location (phi, i,
|
|
gimple_phi_arg_location (phi, num_elem - 1));
|
|
}
|
|
|
|
/* Shrink the vector and return. Note that we do not have to clear
|
|
PHI_ARG_DEF because the garbage collector will not look at those
|
|
elements beyond the first PHI_NUM_ARGS elements of the array. */
|
|
phi->gimple_phi.nargs--;
|
|
}
|
|
|
|
|
|
/* Remove all PHI arguments associated with edge E. */
|
|
|
|
void
|
|
remove_phi_args (edge e)
|
|
{
|
|
gimple_stmt_iterator gsi;
|
|
|
|
for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
|
|
remove_phi_arg_num (gsi_stmt (gsi), e->dest_idx);
|
|
}
|
|
|
|
|
|
/* Remove the PHI node pointed-to by iterator GSI from basic block BB. After
|
|
removal, iterator GSI is updated to point to the next PHI node in the
|
|
sequence. If RELEASE_LHS_P is true, the LHS of this PHI node is released
|
|
into the free pool of SSA names. */
|
|
|
|
void
|
|
remove_phi_node (gimple_stmt_iterator *gsi, bool release_lhs_p)
|
|
{
|
|
gimple phi = gsi_stmt (*gsi);
|
|
|
|
if (release_lhs_p)
|
|
insert_debug_temps_for_defs (gsi);
|
|
|
|
gsi_remove (gsi, false);
|
|
|
|
/* If we are deleting the PHI node, then we should release the
|
|
SSA_NAME node so that it can be reused. */
|
|
release_phi_node (phi);
|
|
if (release_lhs_p)
|
|
release_ssa_name (gimple_phi_result (phi));
|
|
}
|
|
|
|
/* Remove all the phi nodes from BB. */
|
|
|
|
void
|
|
remove_phi_nodes (basic_block bb)
|
|
{
|
|
gimple_stmt_iterator gsi;
|
|
|
|
for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); )
|
|
remove_phi_node (&gsi, true);
|
|
|
|
set_phi_nodes (bb, NULL);
|
|
}
|
|
|
|
#include "gt-tree-phinodes.h"
|