gcc/gcc/gimple-fold.c

5383 lines
163 KiB
C
Raw Normal View History

/* Statement simplification on GIMPLE.
Copyright (C) 2010-2014 Free Software Foundation, Inc.
Split out from tree-ssa-ccp.c.
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"
Factor unrelated declarations out of tree.h. This patch applies the rule that functions defined in FOO.c must be declared in FOO.h. One of the worst offenders in the code base is tree.h, unsurprisingly. The patch creates several new headers: attribs.h calls.h fold-const.h gcc-symtab.h print-rtl.h print-tree.h stmt.h stor-layout.h stringpool.h tree-nested.h tree-object-size.h varasm.h. Functions in each corresponding .c file got moved to those headers and others that already existed. I wanted to make this patch as mechanical as possible, so I made no attempt to fix problems like having build_addr defined in tree-inline.c. I left that for later. There were some declarations that I could not move out of tree.h because of header poisoning or the use of target macros. We forbid the inclusion of things like expr.h from FE files. While that's a reasonable idea, the FE file *still* manage to at expr.c functionality because the declarations they want to use were defined in tree.h. The affected files are builtins.h, emit-rtl.h and expr.h. If that functionality is allowed to be accessed from the FEs, then I will later move those functions out of expr.c into tree.c. I have moved these declarations to the bottom of tree.h so they are easy to identify later. There is a namespace collision with libcpp. The file gcc/symtab.c cannot use gcc/symtab.h because the #include command picks up libcpp/include/symtab.h first. So I named this file gcc-symtab.h for now. Finally, I added a new header to PLUGIN_HEADERS to account for the tree.h refactoring. I did not add all headers factored out of tree.h because it is unclear (and impossible to tell) what plugins need. This adds the one header used by the plugins in the testsuite. This will be changing quite dramatically as we progress with the header refactoring. This patch should offer some minimal incremental build advantages by reducing the size of tree.h. Changes that would otherwise affected tree.h, will now go to other headers which are less frequently included. * tree.h: Include fold-const.h. (aggregate_value_p): Moved to function.h. (alloca_call_p): Moved to calls.h. (allocate_struct_function): Moved to function.h. (apply_tm_attr): Moved to attribs.h. (array_at_struct_end_p): Moved to expr.h. (array_ref_element_size): Moved to tree-dfa.h. (array_ref_low_bound): Moved to tree-dfa.h. (array_ref_up_bound): Moved to tree.h. (assemble_alias): Moved to cgraph.h. (bit_from_pos): Moved to stor-layout.h. (build_addr): Moved to tree-nested.h. (build_duplicate_type): Moved to tree-inline.h. (build_fold_addr_expr): Moved to fold-const.h. (build_fold_addr_expr_with_type): Moved to fold-const.h. (build_fold_addr_expr_with_type_loc): Moved to fold-const.h. (build_fold_indirect_ref): Moved to fold-const.h. (build_fold_indirect_ref_loc): Moved to fold-const.h. (build_personality_function): Moved to tree.h. (build_range_check): Moved to fold-const.h. (build_simple_mem_ref): Moved to fold-const.h. (build_simple_mem_ref_loc): Moved to fold-const.h. (build_tm_abort_call): Moved to trans-mem.h. (byte_from_pos): Moved to stor-layout.h. (call_expr_flags): Moved to calls.h. (can_move_by_pieces): Moved to expr.h. (categorize_ctor_elements): Moved to expr.h. (change_decl_assembler_name): Moved to gcc-symtab.h. (combine_comparisons): Moved to fold-const.h. (complete_ctor_at_level_p): Moved to tree.h. (component_ref_field_offset): Moved to tree-dfa.h. (compute_builtin_object_size): Moved to tree-object-size.h. (compute_record_mode): Moved to stor-layout.h. (constant_boolean_node): Moved to fold-const.h. (constructor_static_from_elts_p): Moved to varasm.h. (cxx11_attribute_p): Moved to attribs.h. (debug_body): Moved to print-tree.h. (debug_find_tree): Moved to tree-inline.h. (debug_fold_checksum): Moved to fold-const.h. (debug_head): Moved to print-tree.h. (debug_head): Moved to print-tree.h. (debug_raw): Moved to print-tree.h. (debug_tree): Moved to print-tree.h. (debug_vec_tree): Moved to print-tree.h. (debug_verbose): Moved to print-tree.h. (debug_verbose): Moved to print-tree.h. (decl_attributes): Moved to attribs.h. (decl_binds_to_current_def_p): Moved to varasm.h. (decl_default_tls_model): Moved to varasm.h. (decl_replaceable_p): Moved to varasm.h. (div_if_zero_remainder): Moved to fold-const.h. (double_int mem_ref_offset): Moved to fold-const.h. (dump_addr): Moved to print-tree.h. (element_precision): Moved to machmode.h. (expand_dummy_function_end): Moved to function.h. (expand_function_end): Moved to function.h. (expand_function_start): Moved to function.h. (expand_label): Moved to stmt.h. (expr_first): Moved to tree-iterator.h. (expr_last): Moved to tree-iterator.h. (finalize_size_functions): Moved to stor-layout.h. (finish_builtin_struct): Moved to stor-layout.h. (finish_record_layout): Moved to stor-layout.h. (fixup_signed_type): Moved to stor-layout.h. (fixup_unsigned_type): Moved to stor-layout.h. (flags_from_decl_or_type): Moved to calls.h. (fold): Moved to fold-const.h. (fold_abs_const): Moved to fold-const.h. (fold_binary): Moved to fold-const.h. (fold_binary_loc): Moved to fold-const.h. (fold_binary_to_constant): Moved to fold-const.h. (fold_build1): Moved to fold-const.h. (fold_build1_initializer_loc): Moved to fold-const.h. (fold_build1_loc): Moved to fold-const.h. (fold_build1_stat_loc): Moved to fold-const.h. (fold_build2): Moved to fold-const.h. (fold_build2_initializer_loc): Moved to fold-const.h. (fold_build2_loc): Moved to fold-const.h. (fold_build2_stat_loc): Moved to fold-const.h. (fold_build3): Moved to fold-const.h. (fold_build3_loc): Moved to fold-const.h. (fold_build3_stat_loc): Moved to fold-const.h. (fold_build_call_array): Moved to fold-const.h. (fold_build_call_array_initializer): Moved to fold-const.h. (fold_build_call_array_initializer_loc): Moved to fold-const.h. (fold_build_call_array_loc): Moved to fold-const.h. (fold_build_cleanup_point_expr): Moved to fold-const.h. (fold_convert): Moved to fold-const.h. (fold_convert_loc): Moved to fold-const.h. (fold_convertible_p): Moved to fold-const.h. (fold_defer_overflow_warnings): Moved to fold-const.h. (fold_deferring_overflow_warnings_p): Moved to fold-const.h. (fold_fma): Moved to fold-const.h. (fold_ignored_result): Moved to fold-const.h. (fold_indirect_ref): Moved to fold-const.h. (fold_indirect_ref_1): Moved to fold-const.h. (fold_indirect_ref_loc): Moved to fold-const.h. (fold_read_from_constant_string): Moved to fold-const.h. (fold_real_zero_addition_p): Moved to fold-const.h. (fold_single_bit_test): Moved to fold-const.h. (fold_strip_sign_ops): Moved to fold-const.h. (fold_ternary): Moved to fold-const.h. (fold_ternary_loc): Moved to fold-const.h. (fold_unary): Moved to tree-data-ref.h. (fold_unary_ignore_overflow): Moved to fold-const.h. (fold_unary_ignore_overflow_loc): Moved to fold-const.h. (fold_unary_loc): Moved to fold-const.h. (fold_unary_to_constant): Moved to fold-const.h. (fold_undefer_and_ignore_overflow_warnings): Moved to fold-const.h. (fold_undefer_overflow_warnings): Moved to fold-const.h. (folding_initializer): Moved to fold-const.h. (free_temp_slots): Moved to function.h. (generate_setjmp_warnings): Moved to function.h. (get_attribute_name): Moved to attribs.h. (get_identifier): Moved to stringpool.h. (get_identifier_with_length): Moved to stringpool.h. (get_inner_reference): Moved to tree.h. (gimple_alloca_call_p): Moved to calls.h. (gimplify_parameters): Moved to function.h. (highest_pow2_factor): Moved to expr.h. (indent_to): Moved to print-tree.h. (init_attributes): Moved to attribs.h. (init_dummy_function_start): Moved to function.h. (init_function_start): Moved to function.h. (init_inline_once): Moved to tree-inline.h. (init_object_sizes): Moved to tree-object-size.h. (init_temp_slots): Moved to function.h. (init_tree_optimization_optabs): Moved to optabs.h. (initialize_sizetypes): Moved to stor-layout.h. (initializer_constant_valid_for_bitfield_p): Moved to varasm.h. (initializer_constant_valid_p): Moved to varasm.h. (int_const_binop): Moved to fold-const.h. (internal_reference_types): Moved to stor-layout.h. (invert_tree_comparison): Moved to fold-const.h. (invert_truthvalue): Moved to fold-const.h. (invert_truthvalue_loc): Moved to fold-const.h. (is_tm_ending_fndecl): Moved to trans-mem.h. (is_tm_may_cancel_outer): Moved to trans-mem.h. (is_tm_pure): Moved to trans-mem.h. (is_tm_safe): Moved to trans-mem.h. (layout_decl): Moved to stor-layout.h. (layout_type): Moved to stor-layout.h. (lookup_attribute_spec): Moved to attribs.h. (make_accum_type): Moved to stor-layout.h. (make_decl_one_only): Moved to varasm.h. (make_decl_rtl): Moved to tree.h. (make_decl_rtl_for_debug): Moved to varasm.h. (make_fract_type): Moved to stor-layout.h. (make_or_reuse_sat_signed_accum_type): Moved to stor-layout.h. (make_or_reuse_sat_signed_fract_type): Moved to stor-layout.h. (make_or_reuse_sat_unsigned_accum_type): Moved to stor-layout.h. (make_or_reuse_sat_unsigned_fract_type): Moved to stor-layout.h. (make_or_reuse_signed_accum_type): Moved to stor-layout.h. (make_or_reuse_signed_fract_type): Moved to stor-layout.h. (make_or_reuse_unsigned_accum_type): Moved to stor-layout.h. (make_or_reuse_unsigned_fract_type): Moved to stor-layout.h. (make_range): Moved to fold-const.h. (make_range_step): Moved to fold-const.h. (make_sat_signed_accum_type): Moved to stor-layout.h. (make_sat_signed_fract_type): Moved to stor-layout.h. (make_sat_unsigned_accum_type): Moved to stor-layout.h. (make_sat_unsigned_fract_type): Moved to stor-layout.h. (make_signed_accum_type): Moved to stor-layout.h. (make_signed_fract_type): Moved to stor-layout.h. (make_signed_type): Moved to stor-layout.h. (make_unsigned_accum_type): Moved to stor-layout.h. (make_unsigned_fract_type): Moved to stor-layout.h. (make_unsigned_type): Moved to stor-layout.h. (mark_decl_referenced): Moved to varasm.h. (mark_referenced): Moved to varasm.h. (may_negate_without_overflow_p): Moved to fold-const.h. (maybe_get_identifier): Moved to stringpool.h. (merge_ranges): Moved to fold-const.h. (merge_weak): Moved to varasm.h. (mode_for_size_tree): Moved to stor-layout.h. (multiple_of_p): Moved to fold-const.h. (must_pass_in_stack_var_size): Moved to calls.h. (must_pass_in_stack_var_size_or_pad): Moved to calls.h. (native_encode_expr): Moved to fold-const.h. (native_interpret_expr): Moved to fold-const.h. (non_lvalue): Moved to fold-const.h. (non_lvalue_loc): Moved to fold-const.h. (normalize_offset): Moved to stor-layout.h. (normalize_rli): Moved to stor-layout.h. (notice_global_symbol): Moved to varasm.h. (omit_one_operand): Moved to fold-const.h. (omit_one_operand_loc): Moved to fold-const.h. (omit_two_operands): Moved to fold-const.h. (omit_two_operands_loc): Moved to fold-const.h. (operand_equal_p): Moved to tree-data-ref.h. (parse_input_constraint): Moved to stmt.h. (parse_output_constraint): Moved to stmt.h. (place_field): Moved to stor-layout.h. (pop_function_context): Moved to function.h. (pop_temp_slots): Moved to function.h. (pos_from_bit): Moved to stor-layout.h. (preserve_temp_slots): Moved to function.h. (print_node): Moved to print-tree.h. (print_node_brief): Moved to print-tree.h. (print_rtl): Moved to rtl.h. (process_pending_assemble_externals): Moved to varasm.h. (ptr_difference_const): Moved to fold-const.h. (push_function_context): Moved to function.h. (push_struct_function): Moved to function.h. (push_temp_slots): Moved to function.h. (record_tm_replacement): Moved to trans-mem.h. (relayout_decl): Moved to stor-layout.h. (resolve_asm_operand_names): Moved to stmt.h. (resolve_unique_section): Moved to varasm.h. (rli_size_so_far): Moved to stor-layout.h. (rli_size_unit_so_far): Moved to stor-layout.h. (round_down): Moved to fold-const.h. (round_down_loc): Moved to fold-const.h. (round_up): Moved to fold-const.h. (round_up_loc): Moved to fold-const.h. (set_decl_incoming_rtl): Moved to emit-rtl.h. (set_decl_rtl): Moved to tree.h. (set_min_and_max_values_for_integral_type): Moved to stor-layout.h. (set_user_assembler_name): Moved to varasm.h. (setjmp_call_p): Moved to calls.h. (size_binop): Moved to fold-const.h. (size_binop_loc): Moved to fold-const.h. (size_diffop): Moved to fold-const.h. (size_diffop_loc): Moved to fold-const.h. (size_int_kind): Moved to fold-const.h. (stack_protect_epilogue): Moved to function.h. (start_record_layout): Moved to stor-layout.h. (supports_one_only): Moved to varasm.h. (swap_tree_comparison): Moved to fold-const.h. (tm_malloc_replacement): Moved to trans-mem.h. (tree build_fold_addr_expr_loc): Moved to fold-const.h. (tree build_invariant_address): Moved to fold-const.h. (tree_binary_nonnegative_warnv_p): Moved to fold-const.h. (tree_binary_nonzero_warnv_p): Moved to fold-const.h. (tree_call_nonnegative_warnv_p): Moved to fold-const.h. (tree_expr_nonnegative_p): Moved to fold-const.h. (tree_expr_nonnegative_warnv_p): Moved to fold-const.h. (tree_output_constant_def): Moved to varasm.h. (tree_overlaps_hard_reg_set): Moved to stmt.h. (tree_single_nonnegative_warnv_p): Moved to fold-const.h. (tree_single_nonzero_warnv_p): Moved to fold-const.h. (tree_swap_operands_p): Moved to fold-const.h. (tree_unary_nonnegative_warnv_p): Moved to fold-const.h. (tree_unary_nonzero_warnv_p): Moved to fold-const.h. (update_alignment_for_field): Moved to stor-layout.h. (use_register_for_decl): Moved to function.h. (variable_size): Moved to rtl.h. (vector_type_mode): Moved to stor-layout.h. * cgraph.h: Corresponding changes. * emit-rtl.h: Corresponding changes. * expr.h: Corresponding changes. * function.h: Corresponding changes. * optabs.h: Corresponding changes. * trans-mem.h: Corresponding changes. Protect against multiple inclusion. * tree-inline.h: Corresponding changes. * tree-iterator.h: Corresponding changes. * tree-dfa.h: Include expr.h. * tree-ssanames.h: Include stringpool.h. * attribs.h: New file. * calls.h: New file. * fold-const.h: New file. * gcc-symtab.h: New file. * print-rtl.h: New file. * print-tree.h: New file. * stmt.h: New file. * stor-layout.h: New file. * strinpool.h: New file. * tree-nested.h: New file * tree-object-size.h: New file. * varasm.h: New file. * Makefile.in (PLUGIN_HEADERS): Add stringpool.h. * alias.c: Include varasm.h. Include expr.h. * asan.c: Include calls.h. Include stor-layout.h. Include varasm.h. * attribs.c: Include stringpool.h. Include attribs.h. Include stor-layout.h. * builtins.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. Include tree-object-size.h. * calls.c: Include stor-layout.h. Include varasm.h. Include stringpool.h. Include attribs.h. * cfgexpand.c: Include stringpool.h. Include varasm.h. Include stor-layout.h. Include stmt.h. Include print-tree.h. * cgraph.c: Include varasm.h. Include calls.h. Include print-tree.h. * cgraphclones.c: Include stringpool.h. Include function.h. Include emit-rtl.h. Move inclusion of rtl.h earlier in the file. * cgraphunit.c: Include varasm.h. Include stor-layout.h. Include stringpool.h. * cilk-common.c: Include stringpool.h. Include stor-layout.h. * combine.c: Include stor-layout.h. * config/aarch64/aarch64-builtins.c: Include stor-layout.h. Include stringpool.h. Include calls.h. * config/aarch64/aarch64.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * config/alpha/alpha.c: Include stor-layout.h. Include calls.h. Include varasm.h. * config/arc/arc.c: Include varasm.h. Include stor-layout.h. Include stringpool.h. Include calls.h. * config/arm/arm.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * config/avr/avr-c.c: Include stor-layout.h. * config/avr/avr-log.c: Include print-tree.h. * config/avr/avr.c: Include print-tree.h. Include calls.h. Include stor-layout.h. Include stringpool.h. * config/bfin/bfin.c: Include varasm.h. Include calls.h. * config/c6x/c6x.c: Include stor-layout.h. Include varasm.h. Include calls.h. Include stringpool.h. * config/cr16/cr16.c: Include stor-layout.h. Include calls.h. * config/cris/cris.c: Include varasm.h. Include stor-layout.h. Include calls.h. Include stmt.h. * config/darwin.c: Include stringpool.h. Include varasm.h. Include stor-layout.h. * config/epiphany/epiphany.c: Include stor-layout.h. Include varasm.h. Include calls.h. Include stringpool.h. * config/fr30/fr30.c: Include stor-layout.h. Include varasm.h. * config/frv/frv.c: Include varasm.h. Include stor-layout.h. Include stringpool.h. * config/h8300/h8300.c: Include stor-layout.h. Include varasm.h. Include calls.h. Include stringpool.h. * config/i386/i386.c: Include stringpool.h. Include attribs.h. Include calls.h. Include stor-layout.h. Include varasm.h. * config/i386/winnt-cxx.c: Include stringpool.h. Include attribs.h. * config/i386/winnt.c: Include stringpool.h. Include varasm.h. * config/ia64/ia64-c.c: Include stringpool.h. * config/ia64/ia64.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * config/iq2000/iq2000.c: Include stor-layout.h. Include calls.h. Include varasm.h. * config/lm32/lm32.c: Include calls.h. * config/m32c/m32c.c: Include stor-layout.h. Include varasm.h. Include calls.h. * config/m32r/m32r.c: Include stor-layout.h. Include varasm.h. Include stringpool.h. Include calls.h. * config/m68k/m68k.c: Include calls.h. Include stor-layout.h. Include varasm.h. * config/mcore/mcore.c: Include stor-layout.h. Include varasm.h. Include stringpool.h. Include calls.h. * config/mep/mep.c: Include varasm.h. Include calls.h. Include stringpool.h. Include stor-layout.h. * config/microblaze/microblaze.c: Include varasm.h. Include stor-layout.h. Include calls.h. * config/mips/mips.c: Include varasm.h. Include stringpool.h. Include stor-layout.h. Include calls.h. * config/mmix/mmix.c: Include varasm.h. Include stor-layout.h. Include calls.h. * config/mn10300/mn10300.c: Include stor-layout.h. Include varasm.h. Include calls.h. * config/moxie/moxie.c: Include stor-layout.h. Include varasm.h. Include calls.h. * config/msp430/msp430.c: Include stor-layout.h. Include calls.h. * config/nds32/nds32.c: Include stor-layout.h. Include varasm.h. Include calls.h. * config/pa/pa.c: Include stor-layout.h. Include stringpool.h. Include varasm.h. Include calls.h. * config/pdp11/pdp11.c: Include stor-layout.h. Include varasm.h. Include calls.h. * config/picochip/picochip.c: Include calls.h. Include stor-layout.h. Include stringpool.h. Include varasm.h. * config/rl78/rl78.c: Include varasm.h. Include stor-layout.h. Include calls.h. * config/rs6000/rs6000-c.c: Include stor-layout.h. Include stringpool.h. * config/rs6000/rs6000.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include print-tree.h. Include varasm.h. * config/rx/rx.c: Include varasm.h. Include stor-layout.h. Include calls.h. * config/s390/s390.c: Include print-tree.h. Include stringpool.h. Include stor-layout.h. Include varasm.h. Include calls.h. * config/score/score.c: Include stringpool.h. Include calls.h. Include varasm.h. Include stor-layout.h. * config/sh/sh-c.c: Include stringpool.h. Include attribs.h.h. * config/sh/sh.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * config/sol2-c.c: Include stringpool.h. Include attribs.h. * config/sol2-cxx.c: Include stringpool.h. * config/sol2.c: Include stringpool.h. Include varasm.h. * config/sparc/sparc.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * config/spu/spu-c.c: Include stringpool.h. * config/spu/spu.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * config/stormy16/stormy16.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. Include calls.h. * config/tilegx/tilegx.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. Include calls.h. * config/tilepro/tilepro.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. Include calls.h. * config/v850/v850-c.c: Include stringpool.h. Include attribs.h. * config/v850/v850.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. Include calls.h. * config/vax/vax.c: Include calls.h. Include varasm.h. * config/vms/vms.c: Include stringpool.h. * config/vxworks.c: Include stringpool.h. * config/xtensa/xtensa.c: Include stringpool.h. Include stor-layout.h. Include calls.h. Include varasm.h. * convert.c: Include stor-layout.h. * coverage.c: Include stringpool.h. Include stor-layout.h. * dbxout.c: Include varasm.h. Include stor-layout.h. * dojump.c: Include stor-layout.h. * dse.c: Include stor-layout.h. * dwarf2asm.c: Include stringpool.h. Include varasm.h. * dwarf2cfi.c: Include stor-layout.h. * dwarf2out.c: Include rtl.h. Include stringpool.h. Include stor-layout.h. Include varasm.h. Include function.h. Include emit-rtl.h. Move inclusion of rtl.h earlier in the file. * emit-rtl.c: Include varasm.h. * except.c: Include stringpool.h. Include stor-layout.h. * explow.c: Include stor-layout.h. * expmed.c: Include stor-layout.h. * expr.c: Include stringpool.h. Include stor-layout.h. Include attribs.h. Include varasm.h. * final.c: Include varasm.h. * fold-const.c: Include stor-layout.h. Include calls.h. Include tree-iterator.h. * function.c: Include stor-layout.h. Include varasm.h. Include stringpool.h. * genattrtab.c (write_header): Emit includes for varasm.h, stor-layout.h and calls.h. * genautomata.c (main): Likewise. * genemit.c: Likewise. * genopinit.c: Likewise. * genoutput.c (output_prologue): Likewise. * genpeep.c: Likewise. * genpreds.c (write_insn_preds_c): Likewise. * gengtype.c (open_base_files): Add stringpool.h. * gimple-expr.c: Include stringpool.h. Include stor-layout.h. * gimple-fold.c: Include stringpool.h. Include expr.h. Include stmt.h. Include stor-layout.h. * gimple-low.c: Include tree-nested.h. Include calls.h. * gimple-pretty-print.c: Include stringpool.h. * gimple-ssa-strength-reduction.c: Include stor-layout.h. Include expr.h. * gimple-walk.c: Include stmt.h. * gimple.c: Include calls.h. Include stmt.h. Include stor-layout.h. * gimplify.c: Include stringpool.h. Include calls.h. Include varasm.h. Include stor-layout.h. Include stmt.h. Include print-tree.h. Include expr.h. * gimplify-me.c: Include stmt.h Include stor-layout.h * internal-fn.c: Include stor-layout.h. * ipa-devirt.c: Include print-tree.h. Include calls.h. * ipa-inline-analysis.c: Include stor-layout.h. Include stringpool.h. Include print-tree.h. * ipa-inline.c: Include trans-mem.h. Include calls.h. * ipa-prop.c: Include expr.h. Include stor-layout.h. Include print-tree.h. * ipa-pure-const.c: Include print-tree.h. Include calls.h. * ipa-reference.c: Include calls.h. * ipa-split.c: Include stringpool.h. Include expr.h. Include calls.h. * ipa.c: Include calls.h. Include stringpool.h. * langhooks.c: Include stringpool.h. Include attribs.h. * lto-cgraph.c: Include stringpool.h. * lto-streamer-in.c: Include stringpool.h. * lto-streamer-out.c: Include stor-layout.h. Include stringpool.h. * omp-low.c: Include stringpool.h. Include stor-layout.h. Include expr.h. * optabs.c: Include stor-layout.h. Include stringpool.h. Include varasm.h. * passes.c: Include varasm.h. * predict.c: Include calls.h. * print-rtl.c: Include print-tree.h. * print-tree.c: Include varasm.h. Include print-rtl.h. Include stor-layout.h. * realmpfr.c: Include stor-layout.h. * reg-stack.c: Include varasm.h. * sdbout.c: Include varasm.h. Include stor-layout.h. * simplify-rtx.c: Include varasm.h. * stmt.c: Include varasm.h. Include stor-layout.h. * stor-layout.c: Include stor-layout.h. Include stringpool.h. Include varasm.h. Include print-tree.h. * symtab.c: Include rtl.h. Include print-tree.h. Include varasm.h. Include function.h. Include emit-rtl.h. * targhooks.c: Include stor-layout.h. Include varasm.h. * toplev.c: Include varasm.h. Include tree-inline.h. * trans-mem.c: Include calls.h. Include function.h. Include rtl.h. Include emit-rtl.h. * tree-affine.c: Include expr.h. * tree-browser.c: Include print-tree.h. * tree-call-cdce.c: Include stor-layout.h. * tree-cfg.c: Include trans-mem.h. Include stor-layout.h. Include print-tree.h. * tree-complex.c: Include stor-layout.h. * tree-data-ref.c: Include expr.h. * tree-dfa.c: Include stor-layout.h. * tree-eh.c: Include expr.h. Include calls.h. * tree-emutls.c: Include stor-layout.h. Include varasm.h. * tree-if-conv.c: Include stor-layout.h. * tree-inline.c: Include stor-layout.h. Include calls.h. * tree-loop-distribution.c: Include stor-layout.h. * tree-nested.c: Include stringpool.h. Include stor-layout.h. * tree-object-size.c: Include tree-object-size.h. * tree-outof-ssa.c: Include stor-layout.h. * tree-parloops.c: Include stor-layout.h. Include tree-nested.h. * tree-pretty-print.c: Include stor-layout.h. Include expr.h. * tree-profile.c: Include varasm.h. Include tree-nested.h. * tree-scalar-evolution.c: Include expr.h. * tree-sra.c: Include stor-layout.h. * tree-ssa-address.c: Include stor-layout.h. * tree-ssa-ccp.c: Include stor-layout.h. * tree-ssa-dce.c: Include calls.h. * tree-ssa-dom.c: Include stor-layout.h. * tree-ssa-forwprop.c: Include stor-layout.h. * tree-ssa-ifcombine.c: Include stor-layout.h. * tree-ssa-loop-ivopts.c: Include stor-layout.h. * tree-ssa-loop-niter.c: Include calls.h. Include expr.h. * tree-ssa-loop-prefetch.c: Include stor-layout.h. * tree-ssa-math-opts.c: Include stor-layout.h. * tree-ssa-operands.c: Include stmt.h. Include print-tree.h. * tree-ssa-phiopt.c: Include stor-layout.h. * tree-ssa-reassoc.c: Include stor-layout.h. * tree-ssa-sccvn.c: Include stor-layout.h. * tree-ssa-sink.c: Include stor-layout.h. * tree-ssa-strlen.c: Include stor-layout.h. * tree-ssa-structalias.c: Include stor-layout.h. Include stmt.h. * tree-ssa-tail-merge.c: Include stor-layout.h. Include trans-mem.h. * tree-ssa-uncprop.c: Include stor-layout.h. * tree-ssa.c: Include stor-layout.h. * tree-ssanames.c: Include stor-layout.h. * tree-streamer-in.c: Include stringpool.h. * tree-streamer-out.c: Include stor-layout.h. * tree-switch-conversion.c: Include varasm.h. Include stor-layout.h. * tree-tailcall.c: Include stor-layout.h. * tree-vect-data-refs.c: Include stor-layout.h. * tree-vect-generic.c: Include stor-layout.h. * tree-vect-loop.c: Include stor-layout.h. * tree-vect-patterns.c: Include stor-layout.h. * tree-vect-slp.c: Include stor-layout.h. * tree-vect-stmts.c: Include stor-layout.h. * tree-vectorizer.c: Include stor-layout.h. * tree-vrp.c: Include stor-layout.h. Include calls.h. * tree.c: Include stor-layout.h. Include calls.h. Include attribs.h. Include varasm.h. * tsan.c: Include expr.h. * ubsan.c: Include stor-layout.h. Include stringpool.h. * value-prof.c: Include tree-nested.h. Include calls.h. * var-tracking.c: Include varasm.h. Include stor-layout.h. * varasm.c: Include stor-layout.h. Include stringpool.h. Include gcc-symtab.h. Include varasm.h. * varpool.c: Include varasm.h. * vmsdbgout.c: Include varasm.h. * xcoffout.c: Include varasm.h. ada/ChangeLog * gcc-interface/decl.c: Include stringpool.h Include stor-layout.h * gcc-interface/misc.c: Include stor-layout.h Include print-tree.h * gcc-interface/trans.c: Include stringpool.h Include stor-layout.h Include stmt.h Include varasm.h * gcc-interface/utils.c: Include stringpool.h Include stor-layout.h Include attribs.h Include varasm.h * gcc-interface/utils2.c: Include stringpool.h Include stor-layout.h Include attribs.h Include varasm.h c-family/ChangeLog * c-common.c: Include fold-const.h. Include stor-layout.h. Include calls.h. Include stringpool.h. Include attribs.h. Include varasm.h. Include trans-mem.h. * c-cppbuiltin.c: Include stor-layout.h. Include stringpool.h. * c-format.c: Include stringpool.h. * c-lex.c: Include stringpool.h. Include stor-layout.h. * c-pragma.c: Include stringpool.h. Include attribs.h. Include varasm.h. Include gcc-symtab.h. * c-pretty-print.c: Include stor-layout.h. Include attribs.h. * cilk.c: Include stringpool.h. Include calls.h. c/ChangeLog * c-decl.c: Include print-tree.h. Include stor-layout.h. Include varasm.h. Include attribs.h. Include stringpool.h. * c-lang.c: Include fold-const.h. * c-parser.c: Include stringpool.h. Include attribs.h. Include stor-layout.h. Include varasm.h. Include trans-mem.h. * c-typeck.c: Include stor-layout.h. Include trans-mem.h. Include varasm.h. Include stmt.h. cp/ChangeLog * call.c: Include stor-layout.h. Include trans-mem.h. Include stringpool.h. * class.c: Include stringpool.h. Include stor-layout.h. Include attribs.h. * cp-gimplify.c: Include stor-layout.h. * cvt.c: Include stor-layout.h. * decl.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. Include attribs.h. Include calls.h. * decl2.c: Include stringpool.h. Include varasm.h. Include attribs.h. Include stor-layout.h. Include calls.h. * error.c: Include stringpool.h. * except.c: Include stringpool.h. Include trans-mem.h. Include attribs.h. * init.c: Include stringpool.h. Include varasm.h. * lambda.c: Include stringpool.h. * lex.c: Include stringpool.h. * mangle.c: Include stor-layout.h. Include stringpool.h. * method.c: Include stringpool.h. Include varasm.h. * name-lookup.c: Include stringpool.h. Include print-tree.h. Include attribs.h. * optimize.c: Include stringpool.h. * parser.c: Include print-tree.h. Include stringpool.h. Include attribs.h. Include trans-mem.h. * pt.c: Include stringpool.h. Include varasm.h. Include attribs.h. Include stor-layout.h. * ptree.c: Include print-tree.h. * repo.c: Include stringpool.h. * rtti.c: Include stringpool.h. Include stor-layout.h. * semantics.c: Include stmt.h. Include varasm.h. Include stor-layout.h. Include stringpool.h. * tree.c: Include stor-layout.h. Include print-tree.h. Include tree-iterator.h. * typeck.c: Include stor-layout.h. Include varasm.h. * typeck2.c: Include stor-layout.h. Include varasm.h. * vtable-class-hierarchy.c: Include stringpool.h. Include stor-layout.h. fortran/ChangeLog * decl.c: Include stringpool.h. * iresolve.c: Include stringpool.h. * match.c: Include stringpool.h. * module.c: Include stringpool.h. * target-memory.c: Include stor-layout.h. * trans-common.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. * trans-const.c: Include stor-layout.h. * trans-decl.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. Include attribs.h. * trans-expr.c: Include stringpool.h. * trans-intrinsic.c: Include stringpool.h. Include tree-nested.h. Include stor-layout.h. * trans-io.c: Include stringpool.h. Include stor-layout.h. * trans-openmp.c: Include stringpool.h. * trans-stmt.c: Include stringpool.h. * trans-types.c: Include stor-layout.h. Include stringpool.h. * trans.c: Include stringpool.h. go/ChangeLog * go-backend.c: Include stor-layout.h. * go-gcc.cc: Include stringpool.h. Include stor-layout.h. Include varasm.h. * go-lang.c: Include stor-layout.h. java/ChangeLog * builtins.c: Include stor-layout.h. Include stringpool.h. * class.c: Include stringpool.h. Include stor-layout.h. Include varasm.h. * constants.c: Include stringpool.h. Include stor-layout.h. * decl.c: Include stor-layout.h. Include stringpool.h. Include varasm.h. * except.c: Include stringpool.h. Include stor-layout.h. * expr.c: Include stringpool.h. Include stor-layout.h. * jcf-parse.c: Include stringpool.h. * mangle.c: Include stringpool.h. * resource.c: Include stringpool.h. Include stor-layout.h. * typeck.c: Include stor-layout.h. Include stringpool.h. * verify-glue.c: Include stringpool.h. lto/ChangeLog * lto-lang.c: Include stringpool.h. Include stor-layout.h. * lto-partition.c: Include gcc-symtab.h. * lto.c: Include stor-layout.h. objc/ChangeLog * objc-act.c: Include stringpool.h. Include stor-layout.h. Include attribs.h. * objc-encoding.c: Include stringpool.h. Include stor-layout.h. * objc-gnu-runtime-abi-01.c: Include stringpool.h. * objc-next-runtime-abi-01.c: Include stringpool.h. * objc-next-runtime-abi-02.c: Include stringpool.h. * objc-runtime-shared-support.c: Include stringpool.h. testsuite/ChangeLog * gcc.dg/plugin/selfassign.c: Include stringpool.h. * gcc.dg/plugin/start_unit_plugin.c: Likewise. From-SVN: r205023
2013-11-19 13:31:09 +01:00
#include "stringpool.h"
#include "expr.h"
#include "stmt.h"
#include "stor-layout.h"
#include "flags.h"
function.h: Flatten file. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * function.h: Flatten file. Remove includes, adjust prototypes to reflect only what is in function.h. (enum direction, struct args_size, struct locate_and_pad_arg_data, ADD_PARM_SIZE, SUB_PARM_SIZE, ARGS_SIZE_TREE, ARGS_SIZE_RTX): Relocate from expr.h. (ASLK_REDUCE_ALIGN, ASLK_RECORD_PAD): Relocate from rtl.h. (optimize_function_for_size_p, optimize_function_for_speed_p): Move prototypes to predict.h. (init_varasm_status): Move prototype to varasm.h. * expr.h: Adjust include files. (enum direction, struct args_size, struct locate_and_pad_arg_data, ADD_PARM_SIZE, SUB_PARM_SIZE, ARGS_SIZE_TREE, ARGS_SIZE_RTX): Move to function.h. (locate_and_pad_parm): Move prototype to function.h. * rtl.h: (assign_stack_local, ASLK_REDUCE_ALIGN, ASLK_RECORD_PAD, assign_stack_local_1, assign_stack_temp, assign_stack_temp_for_type, assign_temp, reposition_prologue_and_epilogue_notes, prologue_epilogue_contains, sibcall_epilogue_contains, update_temp_slot_address, maybe_copy_prologue_epilogue_insn, set_return_jump_label): Move prototypes to function.h. * predict.h (optimize_function_for_size_p, optimize_function_for_speed_p): Relocate prototypes from function.h. * shrink-wrap.h (emit_return_into_block, active_insn_between, convert_jumps_to_returns, emit_return_for_exit): Move prototypes to function.h. * varasm.h (init_varasm_status): Relocate prototype from function.h. * genattrtab.c (write_header): Add predict.h to include list. * genconditions.c (write_header): Add predict.h to include list. * genemit.c (main): Adjust header file includes. * gengtype.c (ifiles): Add flattened function.h header files. * genoutput.c (output_prologue): Add predict.h to include list. * genpreds.c (write_insn_preds_c): Adjust header file includes. * genrecog.c (write_header): Add flattened function.h header files. * alias.c: Adjust include files. * auto-inc-dec.c: Likewise. * basic-block.h: Likewise. * bb-reorder.c: Likewise. * bt-load.c: Likewise. * builtins.c: Likewise. * caller-save.c: Likewise. * calls.c: Likewise. * cfgbuild.c: Likewise. * cfgcleanup.c: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloop.h: Likewise. * cfgrtl.c: Likewise. * cgraph.h: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * combine-stack-adj.c: Likewise. * combine.c: Likewise. * coverage.c: Likewise. * cprop.c: Likewise. * cse.c: Likewise. * cselib.c: Likewise. * dbxout.c: Likewise. * ddg.c: Likewise. * df-core.c: Likewise. * df-problems.c: Likewise. * df-scan.c: Likewise. * dojump.c: Likewise. * dwarf2cfi.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * explow.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * function.c: Likewise. * gcse.c: Likewise. * gimple-fold.c: Likewise. * gimple-low.c: Likewise. * gimple-streamer.h: Likewise. * haifa-sched.c: Likewise. * ifcvt.c: Likewise. * ira.c: Likewise. * jump.c: Likewise. * lcm.c: Likewise. * loop-invariant.c: Likewise. * lra-assigns.c: Likewise. * lra-coalesce.c: Likewise. * lra-constraints.c: Likewise. * lra-eliminations.c: Likewise. * lra-lives.c: Likewise. * lra-spills.c: Likewise. * lra.c: Likewise. * lto-cgraph.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * mode-switching.c: Likewise. * modulo-sched.c: Likewise. * omp-low.c: Likewise. * optabs.c: Likewise. * passes.c: Likewise. * postreload-gcse.c: Likewise. * postreload.c: Likewise. * predict.c: Likewise. * profile.c: Likewise. * recog.c: Likewise. * ree.c: Likewise. * reg-stack.c: Likewise. * regcprop.c: Likewise. * reginfo.c: Likewise. * regrename.c: Likewise. * reload.c: Likewise. * reload1.c: Likewise. * reorg.c: Likewise. * resource.c: Likewise. * rtlanal.c: Likewise. * sched-deps.c: Likewise. * sched-ebb.c: Likewise. * sched-rgn.c: Likewise. * sel-sched-dump.c: Likewise. * sel-sched-ir.c: Likewise. * sel-sched.c: Likewise. * shrink-wrap.c: Likewise. * simplify-rtx.c: Likewise. * statistics.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * store-motion.c: Likewise. * symtab.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * trans-mem.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-profile.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-stdarg.c: Likewise. * tree-tailcall.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * valtrack.c: Likewise. * varasm.c: Likewise. * vmsdbgout.c: Likewise. * web.c: Likewise. * testsuite/g++.dg/plugin/pragma_plugin.c: Adjust include files. * config/aarch64/aarch64.c: Add flattened includes from function.h. * config/alpha/alpha.c: Likewise. * config/arc/arc.c: Likewise. * config/arm/arm.c: Likewise. * config/avr/avr-log.c: Likewise. * config/avr/avr.c: Likewise. * config/bfin/bfin.c: Likewise. * config/c6x/c6x.c: Likewise. * config/cr16/cr16.c: Likewise. * config/cris/cris.c: Likewise. * config/darwin.c: Likewise. * config/epiphany/epiphany.c: Likewise. * config/epiphany/mode-switch-use.c: Likewise. * config/epiphany/resolve-sw-modes.c: Likewise. * config/fr30/fr30.c: Likewise. * config/frv/frv.c: Likewise. * config/h8300/h8300.c: Likewise. * config/i386/i386.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/lm32/lm32.c: Likewise. * config/m32c/m32c.c: Likewise. * config/m32r/m32r.c: Likewise. * config/m68k/m68k.c: Likewise. * config/mcore/mcore.c: Likewise. * config/mep/mep-pragma.c: Likewise. * config/mep/mep.c: Likewise. * config/microblaze/microblaze.c: Likewise. * config/mips/mips.c: Likewise. * config/mmix/mmix.c: Likewise. * config/mn10300/mn10300.c: Likewise. * config/moxie/moxie.c: Likewise. * config/msp430/msp430.c: Likewise. * config/nds32/nds32-cost.c: Likewise. * config/nds32/nds32-fp-as-gp.c: Likewise. * config/nds32/nds32-intrinsic.c: Likewise. * config/nds32/nds32-isr.c: Likewise. * config/nds32/nds32-md-auxiliary.c: Likewise. * config/nds32/nds32-memory-manipulation.c: Likewise. * config/nds32/nds32-pipelines-auxiliary.c: Likewise. * config/nds32/nds32-predicates.c: Likewise. * config/nds32/nds32.c: Likewise. * config/nios2/nios2.c: Likewise. * config/pa/pa.c: Likewise. * config/pdp11/pdp11.c: Likewise. * config/rl78/rl78.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/rx/rx.c: Likewise. * config/s390/s390.c: Likewise. * config/score/score.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/v850/v850.c: Likewise. * config/vax/vax.c: Likewise. * config/xtensa/xtensa.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * ada/gcc-interface/misc.c: Adjust include files. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * c/c-decl.c: Adjust include files. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * c-family/c-pragma.c: Adjust include files. * c-family/c-semantics.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * cp/cp-tree.h: Adjust include files. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * fortran/f95-lang.c: Adjust include files. * fortran/trans-decl.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * java/class.c: Adjust include files. * java/resource.c: Likewise. 2014-10-16 Andrew MacLeod <amacleod@redhat.com> * objc/objc-act.c: Adjust include files. From-SVN: r216337
2014-10-16 18:37:19 +02:00
#include "hashtab.h"
#include "hash-set.h"
#include "vec.h"
#include "machmode.h"
#include "hard-reg-set.h"
#include "input.h"
#include "function.h"
system.h (dump_file): Do not define. gcc/ * system.h (dump_file): Do not define. * tree-pass.h: Include dumpfile.h, which is a new file containing... (enum tree_dump_index, TDF_*, get_dump_file_name, dump_enabled_p, dump_initialized_p, dump_begin, dump_end, dump_node, dump_switch_p, dump_flag_name, dump_file, dump_flags, dump_file_name, get_dump_file_info, struct dump_file_info): all of this, moved to... * dumpfile.h: Here, new file. * tree-dump.h: Include dumpfile.h, but not tree-pass.h. (dump_stmt): Remove prototype for C++ specific function. (dump_enumerated_decls): Move prototype from here... * tree-flow.h (dump_enumerated_decls): ... to here. (get_ref_base_and_extent) Move prototype from here ... * tree.h (get_ref_base_and_extent) ... to here. * tree-ssa-live.c: Do not inclde tree-pretty-print.h, because gimple-pretty-print.h is enough. Do not include tree-dump.h, include timevar.h and dumpfile.h instead. (struct numbered_tree_d, compare_decls_by_uid, dump_enumerated_decls_push, dump_enumerated_decls): Move from here ... * tree-dfa.c:(struct numbered_tree_d, compare_decls_by_uid, dump_enumerated_decls_push, dump_enumerated_decls):... to here. Do not include timevar.h. * tree.c: Do not include timevar.h. * tree-cfg.c: Do not include langhooks.h, tree-pretty-print.h, and timevar.h. (dump_cfg_stats): Use current_function_name. (gimple_cfg2vcg): Likewise. (dump_function_to_file): Likewise. * df-scan.c: Do not include tree-pass.h and timevar.h. Include dumpfile.h. (df_entry_block_bitmap_verify, df_exit_block_bitmap_verify): Do not use print_current_pass. * df-problems.c: Include dumpfile.h. Always define REG_DEAD_DEBUGGING, avoid #ifdef code, because it leads to errors in the code not selected. (df_note_compute): Do not print_rtl_with_bb here. Fix compilation bug if REG_DEAD_DEBUGGING is not 0, get_insns is not available here. * lcm.c: Include dumpfile.h. Remove obsolete include of insn-attr.h. * dojump.c (do_compare_rtx_and_jump): Remove failure printing for missing probability notes. * stmt.c: Include dumpfile.h. (emit_case_decision_tree): Re-enable printing expand details only if TDF_DETAILS. * alias.c, auto-inc-dec.c, bb-reorder.c, caller-save.c, cfg.c, cfgcleanup.c, cfgexpand.c, cfgloop.c, cfgloopmanip.c, cgraph.c, cgraphclones.c, cgraphunit.c, combine.c, combine-stack-adj.c, coverage.c, cprop.c, cse.c, cselib.c, dbgcnt.c, dce.c, df-core.c, dse.c, dwarf2out.c, emit-rtl.c, except.c, expr.c, final.c, function.c, fwprop.c, gcse.c, gimple-fold.c, gimple-pretty-print.c, gimple-ssa-strength-reduction.c, gimplify.c, graphite-blocking.c, graphite-clast-to-gimple.c, graphite-dependences.c, graphite-interchange.c, graphite-optimize-isl.c, graphite-poly.c, graphite-sese-to-poly.c, haifa-sched.c, hw-doloop.c, ifcvt.c, ipa.c, ipa-cp.c, ipa-inline-analysis.c, ipa-inline.c, ipa-inline-transform.c, ipa-prop.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa-utils.c, ira.c, ira-emit.c, jump.c, loop-doloop.c, loop-init.c, loop-invariant.c, loop-iv.c, loop-unroll.c, loop-unswitch.c, lower-subreg.c, lto-section-out.c, lto-streamer-in.c, matrix-reorg.c, mcf.c, mode-switching.c, modulo-sched.c, omega.c, omp-low.c, passes.c, plugin.c, postreload.c, postreload-gcse.c, predict.c, print-rtl.c, print-tree.c, profile.c, recog.c, ree.c, regcprop.c, reginfo.c, regmove.c, regrename.c, reg-stack.c, reload1.c, reorg.c, sched-rgn.c, sched-vis.c, sel-sched.c, sel-sched-ir.c, store-motion.c, tracer.c, trans-mem.c, tree-affine.c, tree-call-cdce.c, tree-cfgcleanup.c, tree-chrec.c, tree-data-ref.c, tree-diagnostic.c, tree-dump.c, tree-eh.c, tree-flow-inline.h, tree-if-conv.c, tree-into-ssa.c, tree-mudflap.c, tree-nrv.c, tree-object-size.c, tree-optimize.c, tree-outof-ssa.c, tree-predcom.c, tree-pretty-print.c, tree-profile.c, tree-scalar-evolution.c, tree-sra.c, tree-ssa-address.c, tree-ssa-alias.c, tree-ssa.c, tree-ssa-ccp.c, tree-ssa-coalesce.c, tree-ssa-copy.c, tree-ssa-copyrename.c,, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-loop.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-manip.c, tree-ssa-loop-niter.c, tree-ssa-loop-prefetch.c, tree-ssa-loop-unswitch.c, tree-ssa-math-opts.c, tree-ssa-operands.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-propagate.c, tree-ssa-reassoc.c, tree-ssa-sccvn.c, tree-ssa-sink.c, tree-ssa-structalias.c, tree-ssa-tail-merge.c, tree-ssa-ter.c, tree-ssa-threadedge.c, tree-ssa-threadupdate.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-data-refs.c, tree-vect-loop.c, tree-vect-loop-manip.c, tree-vectorizer.c, tree-vect-patterns.c, tree-vect-slp.c, tree-vect-stmts.c, tree-vrp.c, value-prof.c, var-tracking.c, web.c: Include tree-pass.h only if needed. If tree-pass.h is included, do not include timevar.h and dumpfile.h. If tree-pass.h is not included but dump_file, or dump_flags, or the TDF_* flags are used, include dumpfile.h. If gimple-pretty-print.h is included, don't include tree-pretty-print.h. Remove assorted unnecessary includes. * config/mn10300/mn10300.c, config/c6x/c6x.c, config/ia64/ia64.c, config/arm/arm.c, config/bfin/bfin.c, config/frv/frv.c, config/spu/spu.c, config/mep/mep.c, config/i386/i386.c: Include dumpfile.h. * config/rl78/rl78.c: Include dumpfile.h instead of tree-pass.h. * arm/t-arm, avr/t-avr, i386/t-i386, ia64/t-ia64, mep/t-mep, spu/t-spu-elf: Fix dependencies. c-family/ * c-gimplify.c: Include dumpfile.h instead of tree-dump.h. * c-ada-spec.c: Likewise. * c-dump.c (dump_stmt): Move to cp/dump.c, the only user. c/ * c-decl.c: Include dumpfile.h instead of tree-dump.h. * Make-lang.in: Fix dependencies. cp/ * dump.c (dump_stmt): Moved here from c-dump.c. * optimize.c: Include dumpfile.h instead of tree-dump.h. * class.c: Likewise. * decl2.c: Likewise. * Make-lang.in: Fix dependencies. fortran/ * f95-lang.c: Include dumpfile.h instead of tree-dump.h. * Make-lang.in: Fix dependencies. java/ * java-gimplify.c Include dumpfile.h instead of tree-dump.h * Make-lang.in: Fix dependencies. lto/ * lto.c: Do not include timevar.h. * Make-lang.in: Fix dependencies. ada/ * gcc-interface/utils.c: Include timevar.h. * Make-lang.in: Fix dependencies. From-SVN: r189519
2012-07-16 13:32:42 +02:00
#include "dumpfile.h"
tree-ssa.h: Remove all #include's * tree-ssa.h: Remove all #include's * gengtype.c (open_base_files): Adjust include list for gtype-desc.c. * alias.c: Move required includes from tree-ssa.h. * asan.c: Likewise. * builtins.c: Likewise. * calls.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * dse.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fold-const.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimplify.c: Likewise. * graphite-blocking.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * ipa-cp.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * loop-init.c: Likewise. * lto-cgraph.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * omp-low.c: Likewise. * passes.c: Likewise. * predict.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * sese.c: Likewise. * targhooks.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-mudflap.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varpool.c: Likewise. * vtable-verify.c: Likewise. From-SVN: r203967
2013-10-23 14:16:58 +02:00
#include "bitmap.h"
gimple.h: Remove all includes. * gimple.h: Remove all includes. (recalculate_side_effects): Move prototype to gimplify.h. * Makefile.in (PLUGIN_HEADERS): Add flattened gimple.h includes. * gengtype.c (open_base_files): Add gimple.h include list. * gimplify.h (recalculate_side_effects): Relocate prototype here. * gimple.c: Adjust include list. (recalculate_side_effects): Move to gimplify.c. * gimplify.c: Adjust include list. (recalculate_side_effects): Relocate from gimple.c. * alias.c: Add required include files removed from gimple.h. * asan.c: Likewise. * builtins.c: Likewise. * calls.c: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraphbuild.c: Likewise. * cgraph.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * data-streamer.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * dse.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimplify-me.c: Likewise. * graphite-blocking.c: Likewise. * graphite.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * internal-fn.c: Likewise. * ipa.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * langhooks.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * omp-low.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * predict.c: Likewise. * profile.c: Likewise. * sese.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * symtab.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssanames.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vrp.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * varpool.c: Likewise. * var-tracking.c: Likewise. * vtable-verify.c: Likewise. * ada/gcc-interface/trans.c: Add required include files from gimple.h. * c/c-typeck.c: Add required include files from gimple.h. * c-family/c-common.c: Add required include files from gimple.h. * c-family/c-gimplify.c: Likewise * c-family/cilk.c: Likewise * cp/class.c: Add required include files from gimple.h. * cp/cp-gimplify.c: Likewise * cp/decl2.c: Likewise * cp/init.c: Likewise * cp/optimize.c: Likewise * cp/pt.c: Likewise * cp/semantics.c: Likewise * cp/tree.c: Likewise * cp/typeck.c: Likewise * cp/vtable-class-hierarchy.c: Likewise * fortran/trans.c: Add required include files from gimple.h. * fortran/trans-expr.c: Likewise * fortran/trans-openmp.c: Likewise * go/gofrontend/expressions.cc: Add required include files from gimple.h. * go/gofrontend/gogo-tree.cc: Likewise * go/gofrontend/types.cc: Likewise * go/go-gcc.cc: Likewise * go/go-lang.c: Likewise * java/java-gimplify.c: Add required include files from gimple.h. * lto/lto.c: Add required include files from gimple.h. * lto/lto-lang.c: Likewise * lto/lto-object.c: Likewise * lto/lto-partition.c: Likewise * lto/lto-symtab.c: Likewise * objc/objc-act.c: Add required include files from gimple.h. * config/darwin.c: Add required include files removed from gimple.h. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/alpha/alpha.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64.c: Likewise. * config/m32c/m32c.c: Likewise. * config/mep/mep.c: Likewise. * config/mips/mips.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/xtensa/xtensa.c: Likewise. * testsuite/gcc.dg/plugin/finish_unit_plugin.c: Add required include files removed from gimple.h. * testsuite/gcc.dg/plugin/ggcplug.c: Likewise. * testsuite/gcc.dg/plugin/one_time_plugin.c: Likewise. * testsuite/gcc.dg/plugin/selfassign.c: Likewise. * testsuite/gcc.dg/plugin/start_unit_plugin.c: Likewise. * testsuite/g++.dg/plugin/selfassign.c: Likewise. From-SVN: r205272
2013-11-22 16:58:51 +01:00
#include "basic-block.h"
#include "tree-ssa-alias.h"
#include "internal-fn.h"
#include "gimple-fold.h"
#include "gimple-expr.h"
#include "is-a.h"
gimplify-be.h: New file. * gimplify-be.h: New file. Add prototypes. * gimplify.h: Don't include gimple.h. (struct gimplify_hasher, struct gimplify_ctx, is_gimple_sizepos, gimplify_hasher::hash, gimplify_hasher::equal): Relocate from gimple.h. * gimple.h (struct gimplify_hasher, gimplify_hasher::hash, gimplify_hasher::equal, struct gimplify_ctx, is_gimple_sizepos): Move to gimplify.h. (enum gsi_iterator_update): Move to gimple-iterator.h. * gimple-iterator.h (enum gsi_iterator_update): Relocate from gimple.h. * gimplify-be.c: New File. (force_gimple_operand_1, force_gimple_operand, force_gimple_operand_gsi_1, force_gimple_operand_gsi): Relocate from gimplify.c. * gimplify.c (force_gimple_operand_1, force_gimple_operand, force_gimple_operand_gsi_1, force_gimple_operand_gsi): Move to gimplify-be.c. * Makefile.in (OBJS): Add gimplify-be.o * asan.c: Include only gimplify.h, gimplify-be.h, and/or gimple.h as required. * cfgloopmanip.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-sese-to-poly.c: Likewise. * ipa-prop.c: Likewise. * ipa-split.c: Likewise. * ipa.c: Likewise. * langhooks.c: Likewise. * omp-low.c: Likewise. * sese.c: Likewise. * stor-layout.c: Likewise. * targhooks.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-complex.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-parloops.c: Likewise. * tree-predcom.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-stmts.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * value-prof.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/alpha/alpha.c: Likewise. * config/darwin.c: Likewise. * config/i386/i386.c: Likewise. * config/ia64/ia64.c: Likewise. * config/mep/mep.c: Likewise. * config/mips/mips.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/xtensa/xtensa.c: Likewise. * c/c-typeck.c: Include only gimplify.h and gimple.h as needed. * c-family/c-common.c: Likewise. * c-family/c-gimplify.c: Likewise. * c-family/cilk.c: Likewise. * cp/class.c: Include only gimplify.h and gimple.h as needed. * cp/cp-gimplify.c: Likewise. * cp/error.c: Likewise. * cp/init.c: Likewise. * cp/optimize.c: Likewise. * cp/pt.c: Likewise. * cp/semantics.c: Likewise. * cp/tree.c: Likewise. * cp/vtable-class-hierarchy.c: Likewise. * fortran/trans-expr.c: Include only gimplify.h and gimple.h as needed. * fortran/trans-openmp.c: Likewise. * go/go-lang.c: Include only gimplify.h and gimple.h as needed. * java/java-gimplify.c: Include only gimplify.h and gimple.h as needed. * objc/objc-act.c: Include only gimplify.h and gimple.h as needed. From-SVN: r204812
2013-11-14 20:39:38 +01:00
#include "gimple.h"
gimple-expr.h (create_tmp_var_name, [...]): Relocate prototypes from gimple.h. 2013-11-12 Andrew MacLeod <amacleod@redhat.com> * gimple-expr.h (create_tmp_var_name, create_tmp_var_raw, create_tmp_var, create_tmp_reg, mark_addressable, is_gimple_reg_rhs): Relocate prototypes from gimple.h. * gimplify.h: New File. Relocate some prototypes from gimple.h here. (gimple_predicate, enum fallback, enum gimplify_status): Relocate from gimple.h. * gimple.h: Move some prototypes to gimplify.h. (gimple_predicate, enum fallback, enum gimplify_status): Move to gimplify.h. (gimple_do_not_emit_location_p, gimple_set_do_not_emit_location): Relocate from gimpify.c. * gimple-expr.c (remove_suffix, tmp_var_id_num, create_tmp_var_name, create_tmp_var_raw, create_tmp_var, create_tmp_reg, mark_addressable, is_gimple_reg_rhs) Relocate from gimplify.c. * gimplify.c (mark_addressable): Move to gimple-expr.c. (gimple_seq_add_stmt_without_update): Move to gimple.c. (remove_suffix, tmp_var_id_num, create_tmp_var_name, create_tmp_var_raw, create_tmp_var, create_tmp_reg, is_gimple_reg_rhs): Move to gimple-expr.c. (should_carry_location_p): Move to gimple.c. (gimple_do_not_emit_location_p, gimple_set_do_not_emit_location): Move to gimple.h. (annotate_one_with_location, annotate_all_with_location_after, annotate_all_with_location): Move to gimple.c. (compare_case_labels, sort_case_labels, preprocess_case_label_vec_for_gimple): Move to gimple.c. (rhs_predicate_for): Make static. (gimplify_assign): Relocate from gimple.c. * gimple.c (gimplify_assign): Move to gimplify.c. (gimple_seq_add_stmt_without_update, should_carry_location_p, annotate_one_with_location, annotate_all_with_location_after, annotate_all_with_location, compare_case_labels, sort_case_labels, preprocess_case_label_vec_for_gimple): Relocate from gimplify.c. * tree.h (unshare_expr, unshare_expr_without_location, mark_addressable): Move prototypes to gimplify.h. * Makefile.in (GTFILES): gimple-expr.c now has the GTY tag for tmp_var_id_num * asan.c: Include gimplify.h rather than gimple.h. * cfgloopmanip.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * dwarf2out.c: Dont include gimple.h. * fold-const.c: Include gimplify.h rather than gimple.h. * function.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-sese-to-poly.c: Likewise. * ipa-prop.c: Likewise. * ipa-split.c: Likewise. * ipa.c: Likewise. * langhooks.c: Dont include gimple.h. * loop-init.c: Include gimplify.h rather than gimple.h. * omp-low.c: Likewise. * sese.c: Likewise. * stor-layout.c: Likewise. * targhooks.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-complex.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-iterator.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-parloops.c: Likewise. * tree-predcom.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa.c: Likewise. * tree-switch-conversio: Likewise.n.c * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-stmts.c: Likewise. * tsan.c: Likewise. * value-prof.c: Likewise. * config/aarch64/aarch64.c: Include gimplify.h instead of gimple.h. * config/alpha/alpha.c: Likewise. * config/darwin.c: Likewise. * config/i386/i386.c: Likewise. * config/ia64/ia64.c: Likewise. * config/mep/mep.c: Likewise. * config/mips/mips.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/xtensa/xtensa.c: Likewise. * ada/gcc-interface/trans.c: Include gimplify.h. * c/c-typeck.c: Include gimplify.h. * c-family/c-common.c: Include gimplify.h. * c-family/c-gimplify.c: Likewise. * c-family/cilk.c: Likewise. * c-family/c-omp.c: Include gimple-expr.h instead of gimple.h. * c-family/c-ubsan.c: Don't include gimple.h. * cp/class.c: Include gimplify.h. * cp/cp-gimplify.c: Likewise. * cp/error.c: Likewise. * cp/init.c: Likewise. * cp/optimize.c: Likewise. * cp/pt.c: Likewise. * cp/semantics.c: Likewise. * cp/tree.c: Likewise. * cp/vtable-class-hierarchy.c: Likewise. * cp/decl2.c: Don't include gimple.h. * cp/except.c: Likewise. * cp/method.c: Include pointer-set.h instead of gimple.h. * fortran/f95-lang.c: Don't include gimple.h. * fortran/trans-array.c: Include gimple-expr.h instead of gimple.h. * fortran/trans.c: Likewise. * fortran/trans-decl.c: Likewise. * fortran/trans-expr.c: Include gimplify.h. * fortran/trans-openmp.c: Likewise. * go/go-lang.c: Include gimplify.h. * java/java-gimplify.c: Include gimplify.h. * objc/objc-act.c: Include gimplify.h. From-SVN: r204717
2013-11-12 21:26:43 +01:00
#include "gimplify.h"
gimple-walk.h: New File. * gimple-walk.h: New File. Relocate prototypes from gimple.h. (struct walk_stmt_info): Relocate here from gimple.h. * gimple-iterator.h: New File. Relocate prototypes from gimple.h. (struct gimple_stmt_iterator_d): Relocate here from gimple.h. (gsi_start_1, gsi_none, gsi_start_bb, gsi_last_1, gsi_last_bb, gsi_end_p, gsi_one_before_end_p, gsi_next, gsi_prev, gsi_stmt, gsi_after_labels, gsi_next_nondebug, gsi_prev_nondebug, gsi_start_nondebug_bb, gsi_start_nondebug_after_labels_bb, gsi_last_nondebug_bb, gsi_bb, gsi_seq): Relocate here from gimple.h. * gimple.h (struct gimple_stmt_iterator_d): Move to gimple-iterator.h. (gsi_start_1, gsi_none, gsi_start_bb, gsi_last_1, gsi_last_bb, gsi_end_p, gsi_one_before_end_p, gsi_next, gsi_prev, gsi_stmt, gsi_after_labels, gsi_next_nondebug, gsi_prev_nondebug, gsi_start_nondebug_bb, gsi_start_nondebug_after_labels_bb, gsi_last_nondebug_bb, gsi_bb, gsi_seq): Move to gimple-iterator.h. (struct walk_stmt_info): Move to gimple-walk.h. (gimple_seq_set_location): Move to gimple.c * gimple-walk.c: New File. (walk_gimple_seq_mod, walk_gimple_seq, walk_gimple_asm, walk_gimple_op, walk_gimple_stmt, get_base_loadstore, walk_stmt_load_store_addr_ops, walk_stmt_load_store_ops): Relocate here from gimple.c. * gimple-iterator.c: Include gimple-iterator.h. * gimple.c (walk_gimple_seq_mod, walk_gimple_seq, walk_gimple_asm, walk_gimple_op, walk_gimple_stmt, get_base_loadstore, walk_stmt_load_store_addr_ops, walk_stmt_load_store_ops): Move to gimple-walk.c. (gimple_seq_set_location): Relocate from gimple.h. * tree-phinodes.h (set_phi_nodes): Move to tree-phinodes.c. * tree-phinodes.c (set_phi_nodes): Relocate from tree-phinodes.h. * gengtype.c (open_base_files): Add gimple-iterator.h to include list. * Makefile.in (OBJS): Add gimple-walk.o * asan.c: Update Include list as required for gimple-iterator.h and gimple-walk.h. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphunit.c: Likewise. * gimple-fold.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimplify.c: Likewise. * graphite-blocking.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-split.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * omp-low.c: Likewise. * predict.c: Likewise. * profile.c: Likewise. * sese.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-predcom.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-stdarg.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * value-prof.c: Likewise. * vtable-verify.c: Likewise. * config/aarch64/aarch64-builtins.c: Include gimple-iterator.h. * config/rs6000/rs6000.c: Include gimple-iterator.h and gimple-walk.h. * testsuite/g++.dg/plugin/selfassign.c: Include gimple-iterator.h. * testsuite/gcc.dg/plugin/selfassign.c: Likewise. From-SVN: r204763
2013-11-14 00:54:17 +01:00
#include "gimple-iterator.h"
tree-ssa.h: Remove all #include's * tree-ssa.h: Remove all #include's * gengtype.c (open_base_files): Adjust include list for gtype-desc.c. * alias.c: Move required includes from tree-ssa.h. * asan.c: Likewise. * builtins.c: Likewise. * calls.c: Likewise. * cfgexpand.c: Likewise. * cfghooks.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraph.c: Likewise. * cgraphbuild.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * dse.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * final.c: Likewise. * fold-const.c: Likewise. * ggc-page.c: Likewise. * gimple-builder.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimplify.c: Likewise. * graphite-blocking.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * graphite.c: Likewise. * ipa-cp.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline-transform.c: Likewise. * ipa-inline.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * loop-init.c: Likewise. * lto-cgraph.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * lto-streamer.c: Likewise. * omp-low.c: Likewise. * passes.c: Likewise. * predict.c: Likewise. * print-tree.c: Likewise. * profile.c: Likewise. * sese.c: Likewise. * targhooks.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-mudflap.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-ssa.c: Likewise. * tree-ssanames.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer-in.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * tsan.c: Likewise. * value-prof.c: Likewise. * var-tracking.c: Likewise. * varpool.c: Likewise. * vtable-verify.c: Likewise. From-SVN: r203967
2013-10-23 14:16:58 +02:00
#include "gimple-ssa.h"
#include "tree-ssanames.h"
#include "tree-into-ssa.h"
#include "tree-dfa.h"
tree-ssa.h: New. * tree-ssa.h: New. Move content from tree-flow.h and tree-flow-inline.h. * tree-flow.h (_edge_var_map, edge_var_map_vector): Move to tree-ssa.h. Move prototypes belonging to tree-ssa.c. * tree-flow-inline.h (redirect_edge_var_map_def, redirect_edge_var_map_result, redirect_edge_var_map_location): Move to tree-ssa.h. * gimple.h: Adjust prototypes. * tree-ssa.c (useless_type_conversion_p, types_compatible_p): Move to... * gimple.c (useless_type_conversion_p, types_compatible_p): Here. * tree.h: Move prototype to tree-ssa.h. * gengtype.c (open_base_files): Replace tree-flow.h with tree-ssa.h. * Makefile.in: (TREE_SSA_H, TREE_FLOW_H): Adjust dependencies. * alias.c, asan.c, builtins.c, calls.c, cfgexpand.c, cfghooks.c, cfgloop.c, cfgloopmanip.c, cgraph.c, cgraphbuild.c, cgraphclones.c, cgraphunit.c, dse.c, except.c, expr.c, final.c, fold-const.c, ggc-page.c, gimple-fold.c, gimple-iterator.c, gimple-low.c, gimple-pretty-print.c, gimple-ssa-strength-reduction.c, gimple-streamer-in.c, gimple-streamer-out.c, gimple.c, gimplify.c, graphite-blocking.c, graphite-clast-to-gimple.c, graphite-dependences.c, graphite-interchange.c, graphite-optimize-isl.c, graphite-poly.c, graphite-scop-detection.c, graphite-sese-to-poly.c, graphite.c, ipa-cp.c, ipa-inline-analysis.c, ipa-inline-transform.c, ipa-inline.c, ipa-prop.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa-utils.c, loop-init.c, lto-cgraph.c, lto-section-in.c, lto-section-out.c, lto-streamer-in.c, lto-streamer-out.c, lto-streamer.c, omp-low.c, passes.c, predict.c, print-tree.c, profile.c, sese.c, targhooks.c, tracer.c, trans-mem.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-chrec.c, tree-complex.c, tree-data-ref.c, tree-dfa.c, tree-eh.c, tree-emutls.c, tree-if-conv.c, tree-inline.c, tree-into-ssa.c, tree-loop-distribution.c, tree-mudflap.c, tree-nested.c, tree-nrv.c, tree-object-size.c, tree-optimize.c, tree-outof-ssa.c, tree-parloops.c, tree-phinodes.c, tree-predcom.c, tree-pretty-print.c, tree-profile.c, tree-scalar-evolution.c, tree-sra.c, tree-ssa*.c, tree-stdarg.c, tree-streamer-in.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop-manip.c, tree-vect-loop.c, tree-vect-patterns.c, tree-vect-slp.c, tree-vect-stmts.c, tree-vectorizer.c, tree-vrp.c, tsan.c, value-prof.c, var-tracking.c, varpool.c, vtable-verify.c: Replace tree-flow.h with tree-ssa.h From-SVN: r202523
2013-09-12 15:03:18 +02:00
#include "tree-ssa.h"
#include "tree-ssa-propagate.h"
#include "target.h"
#include "ipa-utils.h"
#include "gimple-pretty-print.h"
tree-ssa.h: Don't include gimple-low.h... * tree-ssa.h: Don't include gimple-low.h, tree-ssa-address.h, sbitmap.h, tree-ssa-threadedge.h, tree-ssa-dom.h, and tree-cfgcleanup.h. * gimple-low.c (gimple_check_call_arg, gimple_check_call_matching_types): Move to cgraph.c. * gimple-low.h: Remove prototype. * cgraph.c: (gimple_check_call_arg, gimple_check_call_matching_types): Relocate from gimple-low.c. * cgraph.h: Add prototype. Don't include basic-block.h. * gimplify.c: Add gimple-low to include list. * omp-low.c: Add gimple-low and tree-cfgcleanup.h to include list. * tree-eh.c: Add gimple-low to include list. * tree-nested.c: Likewise. * cfgexpand.c: Add tree-ssa-address.h to include list. * expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * trans-mem.c: Likewise. * tree-mudflap.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-dom.c: Include tree-ssa-threadedge.h and tree-ssa-dom.h. (degenerate_phi_result): Move to tree-phinodes.c. * tree-ssa-loop-ch.c: Include tree-ssa-threadedge.h. * tree-ssa-threadedge.c: Likewise. * tree-vrp.c: Likewise. * tree-phinodes.c (degenerate_phi_result): Relocate here. * tree-ssa-dom.h (degenerate_phi_result): Remove Prototype. * tree-phinodes.h (degenerate_phi_result): Add prototype. * tree-ssa-copy.c: Include tree-ssa-dom.h. * tree-ssa-forwprop.c: Likewise. * tree-cfgcleanup.c (execute_cleanup_cfg_post_optimizing, pass_data_cleanup_cfg_post_optimizing, make_pass_cleanup_cfg_post_optimizing): Relocate from tree-optimize.c. * tree-optimize.c: Delete File. * graphite.c: Include tree-cfgcleanup.h. * passes.c: Likewise. * tree-cfg.c: Likewise. * tree-profile.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-switch-conversion.c: Don't include tree-ssa-operands.h. * tree-outof-ssa.c: Include sbitmap.h. * tree-ssa-live.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-stdarg.c: Likewise. * Makefile.in (OBJS): Delete tree-optimize.o. * basic-block.h (gcov_type, gcov_type_unsigned): Move to coretypes.h. * coretypes.h (gcov_type, gcov_type_unsigned): Relocate here. * varasm.c: Include basic-block.h. * cfgloop.h: Include function.h instead of basic-block.h (bb_loop_depth): Move to cfgloop.c. * cfgloop.c (bb_loop_depth): Relocate from cfgloop.h. From-SVN: r203833
2013-10-18 21:35:40 +02:00
#include "tree-ssa-address.h"
Re-factor tree.h - Part 1. This is the first patch in a series of patches to cleanup tree.h to reduce the exposure it has all over the compiler. In this patch, I'm moving functions that are used once into the files that use them, and make them private to that file. These functions were declared extern in tree.h and called from exactly one place. The patch does not move EVERY function. This usually happens when the function uses private state from its original file, and moving that private state would mean moving other functions that made no sense to move. Additionally, the patch removes functions that were never used. In subsequent patches, I will be moving out of tree.h extern definitions that should be grouped in other files (e.g., all functions defined in some FOO.c will be moved to the corresponding FOO.h). This will allow me to remove the inclusion of tree.h from some files. * attribs.c (lookup_scoped_attribute_spec): Make static. (get_attribute_namespace): Likewise. * builtins.c (more_const_call_expr_args_p): Move from tree.h. (validate_arglist): Move earlier in the file. Make static. (expand_stack_restore): Move from stmt.c (expand_stack_save): Move from stmt.c (rewrite_call_expr_array): Move earlier in the file. (rewrite_call_expr_valist): Likewise. * cfgexpand.c: Include hard-reg-set.h before tree.h Include recog.h. Include output.h. (expand_asm_loc): Move from stmt.c. (n_occurrences): Move from stmt.c. (check_operand_nalternatives): Move from stmt.c. (tree_conflicts_with_clobbers_p): Move from stmt.c. (expand_asm_operands): Move from stmt.c (expand_asm_stmt): Move from stmt.c (expand_computed_goto): Move from stmt.c (expand_goto): Move from stmt.c (expand_null_return_1): Move from stmt.c (expand_null_return): Move from stmt.c (expand_value_return): Move from stmt.c (expand_return): Move from stmt.c (expand_main_function): Move from function.c (stack_protect_prologue): Move from function.c * cgraphclones.c (build_function_type_skip_args): Move from tree.c. (build_function_decl_skip_args): Move from tree.c. * explow.c (tree_expr_size): Move from tree.c. * expr.c (addr_expr_of_non_mem_decl_p): Remove. (fields_length): Move from tree.c. * fold-const.c (size_low_cst): Move from tree.c. (tree_expr_nonzero_warnv_p): Make static. Move earlier in the file. (tree_expr_nonzero_p): Make static. Move earlier in the file. (fold_build3_initializer_loc): Remove. (tree_invalid_nonnegative_warnv_p): Make static. * function.c (expand_main_function): Move to cfgexpand.c. (stack_protect_prologue): Move to cfgexpand.c. (set_insn_locations): Move earlier in the file. * gimple-fold.c: Include langhooks.h. (truth_type_for): Move from tree.c. * print-tree.c (print_vec_tree): Remove. * stmt.c (expand_computed_goto): Move to cfgexpand.c. (expand_goto): Move to cfgexpand.c. (n_occurrences): Move to cfgexpand.c. (expand_asm_loc): Move to cfgexpand.c (tree_conflicts_with_clobbers_p): Move to cfgexpand.c. (expand_asm_operands): Move to cfgexpand.c. (expand_asm_stmt): Move to cfgexpand.c. (check_operand_nalternatives): Move to cfgexpand.c (expand_null_return): Move to cfgexpand.c. (expand_value_return): Move to cfgexpand.c. (expand_null_return_1): Move to cfgexpand.c. (expand_return): Move to cfgexpand.c. (expand_stack_save): Move to builtins.c. (expand_stack_restore): Move to builtins.c * symtab.c: Include output.h. (decl_assembler_name_hash): Move from tree.c. (decl_assembler_name_equal): Move from tree.c. * trans-mem.c (is_tm_safe_or_pure): Move from tree.h. * tree-eh.c (in_array_bounds_p): Move from tree.c. (range_in_array_bounds_p): Move from tree.c. * tree-object-size.c (fini_object_sizes): Make static. * tree-ssa-dom.c (iterative_hash_exprs_commutative): Move from tree.h. * tree-vrp.c (ssa_name_nonnegative_p): Remove. * tree.c (decl_assembler_name_equal): Move to symtab.c. (tree_expr_size): Move to explow.c. (decl_assembler_name_hash): Move to symtab.c. (real_twop): Remove. (tree_expr_size): Move to explow.c. (stabilize_reference_1): Move earlier in the file. Make static. (omp_remove_redundant_declare_simd_attrs): Remove. (simple_cst_list_equal): Move earlier in the file. Make static. (size_low_cst): Move to fold-const.c. (build_type_no_quals): Remove. (build_function_type_skip_args): Move to cgraphclones.c. (build_function_decl_skip_args): Move to cgraphclones.c. (in_array_bounds_p): Move to tree-eh.c. (range_in_array_bounds_p): Move to tree-eh.c. (truth_type_for): Move to gimple-fold.c. (list_equal_p): remove. * tree.h (decl_assembler_name_equal): Remove. (decl_assembler_name_hash): Remove. (truth_type_for): Remove. (build_type_no_quals): Remove. (build_function_decl_skip_args): Remove. (in_array_bounds_p): Remove. (range_in_array_bounds_p): Remove. (size_low_cst): Remove. (omp_remove_redundant_declare_simd_attrs): Remove. (tree_expr_size): Remove. (fields_length): Remove. (stabilize_reference_1): Remove. (expand_goto): Remove. (expand_stack_save): Remove. (expand_stack_restore): Remove. (expand_return): Remove. (fold_build3_initializer_loc): Remove. (tree_expr_nonzero_p): Remove. (tree_invalid_nonnegative_warnv_p): Remove. (tree_expr_nonzero_warnv_p): Remove. (fold_builtin_snprintf_chk): Remove. (validate_arglist): Remove. (iterative_hash_exprs_commutative): Move to tree-ssa-dom.c. (simple_cst_list_equal): Remove. (real_twop): Remove. (expand_main_function): Remove. (stack_protect_prologue): Remove. (print_vec_tree): Remove. (lookup_scoped_attribute_spec): Remove. (get_attribute_namespace): Remove. (expand_computed_goto): Remove. (expand_asm_stmt): Remove. (list_equal_p): Remove. (ssa_name_nonnegative_p): Remove. (fini_object_sizes): Remove. (addr_expr_of_non_mem_decl_p): Remove. (is_tm_safe_or_pure): Move to trans-mem.c. (more_const_call_expr_args_p): Remove. (save_vtable_map_decl): Remove. From-SVN: r204606
2013-11-08 23:46:16 +01:00
#include "langhooks.h"
#include "gimplify-me.h"
#include "dbgcnt.h"
expr.h: Remove prototypes of functions defined in builtins.c. * expr.h: Remove prototypes of functions defined in builtins.c. * tree.h: (build_call_expr_*, build_string_literal): Add prototypes. Remove prototypes of functions defined in builtins.c. * builtins.h: Update prototype list to include all exported functions. * builtins.c: (default_libc_has_function, gnu_libc_has_function, no_c99_libc_has_function): Move to targhooks.c (build_string_literal, build_call_expr_loc_array, build_call_expr_loc_vec, build_call_expr_loc, build_call_expr): Move to tree.c. (expand_builtin_object_size, fold_builtin_object_size): Make static. * targhooks.c (default_libc_has_function, gnu_libc_has_function, no_c99_libc_has_function): Relocate from builtins.c. * tree.c: Include builtins.h. (build_call_expr_loc_array, build_call_expr_loc_vec, build_call_expr_loc, build_call_expr, build_string_literal): Relocate from builtins.c. * fold-const.h (fold_fma): Move prototype to builtins.h. * realmpfr.h (do_mpc_arg2): Move prototype to builtins.h. * fortran/trans.c (trans_runtime_error_vararg): Call fold_build_call_array_loc instead of fold_builtin_call_array. * asan.c: Include builtins.h. * cfgexpand.c: Likewise. * convert.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * fold-const.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimplify.c: Likewise. * ipa-inline.c: Likewise. * ipa-prop.c: Likewise. * lto-streamer-out.c: Likewise. * stmt.c: Likewise. * tree-inline.c: Likewise. * tree-object-size.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-streamer-in.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-stmts.c: Likewise. c * c-decl.c: Include builtins.h. * c-parser.c: Likewise. cp * decl.c: Include builtins.h. * semantics.c: Likewise. go * go-gcc.cc: Include builtins.h. lto * lto-symtab.c: Include builtins.h. config * aarch64/aarch64.c: Include builtins.h. * alpha/alpha.c: Likewise. * arc/arc.c: Likewise. * arm/arm.c: Likewise. * avr/avr.c: Likewise. * bfin/bfin.c: Likewise. * c6x/c6x.c: Likewise. * cr16/cr16.c: Likewise. * cris/cris.c: Likewise. * epiphany/epiphany.c: Likewise. * fr30/fr30.c: Likewise. * frv/frv.c: Likewise. * h8300/h8300.c: Likewise. * i386/i386.c: Likewise. * i386/winnt.c: Likewise. * ia64/ia64.c: Likewise. * iq2000/iq2000.c: Likewise. * lm32/lm32.c: Likewise. * m32c/m32c.c: Likewise. * m32r/m32r.c: Likewise. * m68k/m68k.c: Likewise. * mcore/mcore.c: Likewise. * mep/mep.c: Likewise. * microblaze/microblaze.c: Likewise. * mips/mips.c: Likewise. * mmix/mmix.c: Likewise. * mn10300/mn10300.c: Likewise. * moxie/moxie.c: Likewise. * msp430/msp430.c: Likewise. * nds32/nds32.c: Likewise. * pa/pa.c: Likewise. * pdp11/pdp11.c: Likewise. * picochip/picochip.c: Likewise. * rl78/rl78.c: Likewise. * rs6000/rs6000.c: Likewise. * rx/rx.c: Likewise. * s390/s390.c: Likewise. * score/score.c: Likewise. * sh/sh.c: Likewise. * sparc/sparc.c: Likewise. * spu/spu.c: Likewise. * stormy16/stormy16.c: Likewise. * tilegx/tilegx.c: Likewise. * tilepro/tilepro.c: Likewise. * v850/v850.c: Likewise. * vax/vax.c: Likewise. * xtensa/xtensa.c: Likewise. From-SVN: r211145
2014-06-02 22:13:44 +02:00
#include "builtins.h"
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
#include "output.h"
/* Return true when DECL can be referenced from current unit.
FROM_DECL (if non-null) specify constructor of variable DECL was taken from.
We can get declarations that are not possible to reference for various
reasons:
1) When analyzing C++ virtual tables.
C++ virtual tables do have known constructors even
when they are keyed to other compilation unit.
Those tables can contain pointers to methods and vars
in other units. Those methods have both STATIC and EXTERNAL
set.
2) In WHOPR mode devirtualization might lead to reference
to method that was partitioned elsehwere.
In this case we have static VAR_DECL or FUNCTION_DECL
that has no corresponding callgraph/varpool node
declaring the body.
3) COMDAT functions referred by external vtables that
2013-11-06 15:37:46 +01:00
we devirtualize only during final compilation stage.
At this time we already decided that we will not output
the function body and thus we can't reference the symbol
directly. */
static bool
can_refer_decl_in_current_unit_p (tree decl, tree from_decl)
{
varpool_node *vnode;
struct cgraph_node *node;
Automated part of renaming of symtab_node_base to symtab_node. gcc/ Patch autogenerated by rename_symtab.py from https://github.com/davidmalcolm/gcc-refactoring-scripts revision 58bb219cc090b2f4516a9297d868c245495ee622 with ChangeLog entry fixed up by hand. * cgraph.c (x_cgraph_nodes_queue): Rename symtab_node_base to symtab_node. (cgraph_node_for_asm): Likewise. * cgraph.h (symtab_node_base): Likewise. (cgraph_node): Likewise. (varpool_node): Likewise. (is_a_helper <cgraph_node>::test): Likewise. (is_a_helper <varpool_node>::test): Likewise. (symtab_nodes): Likewise. (symtab_register_node): Likewise. (symtab_unregister_node): Likewise. (symtab_remove_node): Likewise. (symtab_get_node): Likewise. (symtab_node_for_asm): Likewise. (symtab_node_asm_name): Likewise. (symtab_node_name): Likewise. (symtab_insert_node_to_hashtable): Likewise. (symtab_add_to_same_comdat_group): Likewise. (symtab_dissolve_same_comdat_group_list): Likewise. (dump_symtab_node): Likewise. (debug_symtab_node): Likewise. (dump_symtab_base): Likewise. (verify_symtab_node): Likewise. (verify_symtab_base): Likewise. (symtab_used_from_object_file_p): Likewise. (symtab_alias_ultimate_target): Likewise. (symtab_resolve_alias): Likewise. (fixup_same_cpp_alias_visibility): Likewise. (symtab_for_node_and_aliases): Likewise. (symtab_nonoverwritable_alias): Likewise. (availability symtab_node_availability): Likewise. (symtab_semantically_equivalent_p): Likewise. (fixup_same_cpp_alias_visibility): Likewise. (symtab_prevail_in_asm_name_hash): Likewise. (cgraph): Likewise. (varpool): Likewise. (varpool_first_variable): Likewise. (varpool_next_variable): Likewise. (varpool_first_static_initializer): Likewise. (varpool_next_static_initializer): Likewise. (varpool_first_defined_variable): Likewise. (varpool_next_defined_variable): Likewise. (cgraph_first_defined_function): Likewise. (cgraph_next_defined_function): Likewise. (cgraph_first_function): Likewise. (cgraph_next_function): Likewise. (cgraph_first_function_with_gimple_body): Likewise. (cgraph_next_function_with_gimple_body): Likewise. (symtab_alias_target): Likewise. (symtab_real_symbol_p): Likewise. (symtab_can_be_discarded): Likewise. * cgraphbuild.c (mark_address): Likewise. (mark_load): Likewise. (mark_store): Likewise. * cgraphunit.c (decide_is_symbol_needed): Likewise. (first): Likewise. (enqueue_node): Likewise. (referred_to_p): Likewise. (cgraph_process_same_body_aliases): Likewise. (analyze_functions): Likewise. (handle_alias_pairs): Likewise. (output_weakrefs): Likewise. (compile): Likewise. * gimple-fold.c (can_refer_decl_in_current_unit_p): Likewise. * ipa-inline-analysis.c (inline_write_summary): Likewise. * ipa-prop.c (remove_described_reference): Likewise. (try_decrement_rdesc_refcount): Likewise. (ipa_edge_duplication_hook): Likewise. * ipa-ref.c (ipa_record_reference): Likewise. (ipa_maybe_record_reference): Likewise. (ipa_clone_ref): Likewise. (ipa_clone_references): Likewise. (ipa_clone_referring): Likewise. (ipa_find_reference): Likewise. (ipa_remove_stmt_references): Likewise. (ipa_clear_stmts_in_references): Likewise. * ipa-ref.h (symtab_node_base): Likewise. (ipa_ref): Likewise. (ipa_record_reference): Likewise. (ipa_maybe_record_reference): Likewise. (ipa_clone_references): Likewise. (ipa_clone_referring): Likewise. (ipa_clone_ref): Likewise. (ipa_find_reference): Likewise. (ipa_remove_stmt_references): Likewise. (ipa_clear_stmts_in_references): Likewise. * ipa-reference.c (ipa_reference_write_optimization_summary): Likewise. * ipa.c (enqueue_node): Likewise. (process_references): Likewise. (walk_polymorphic_call_targets): Likewise. (symtab_remove_unreachable_nodes): Likewise. (address_taken_from_non_vtable_p): Likewise. (comdat_can_be_unshared_p_1): Likewise. (comdat_can_be_unshared_p): Likewise. (can_replace_by_local_alias): Likewise. (function_and_variable_visibility): Likewise. * is-a.h: Likewise (within example in comment). * lto-cgraph.c (input_cgraph_opt_summary): Likewise. (lto_symtab_encoder_encode): Likewise. (lto_symtab_encoder_delete_node): Likewise. (lto_symtab_encoder_in_partition_p): Likewise. (lto_set_symtab_encoder_in_partition): Likewise. (output_refs): Likewise. (compute_ltrans_boundary): Likewise. (output_symtab): Likewise. (input_node): Likewise. (input_ref): Likewise. (input_edge): Likewise. (input_cgraph_1): Likewise. (input_refs): Likewise. (output_cgraph_opt_summary): Likewise. (input_node_opt_summary): Likewise. (input_cgraph_opt_section): Likewise. * lto-section-in.c (lto_free_function_in_decl_state_for_node): Likewise. * lto-streamer-out.c (lto_output): Likewise. (output_symbol_p): Likewise. (produce_symtab): Likewise. * lto-streamer.h (lto_encoder_entry): Likewise. (lto_free_function_in_decl_state_for_node): Likewise. (lto_symtab_encoder_encode): Likewise. (lto_symtab_encoder_delete_node): Likewise. (lto_symtab_encoder_in_partition_p): Likewise. (lto_set_symtab_encoder_in_partition): Likewise. (lto_symtab_encoder_lookup): Likewise. (lsei_node): Likewise. (lto_symtab_encoder_deref): Likewise. * symtab.c (symtab_hash): Likewise. (assembler_name_hash): Likewise. (symtab_nodes): Likewise. (hash_node): Likewise. (eq_node): Likewise. (hash_node_by_assembler_name): Likewise. (eq_assembler_name): Likewise. (insert_to_assembler_name_hash): Likewise. (unlink_from_assembler_name_hash): Likewise. (symtab_prevail_in_asm_name_hash): Likewise. (symtab_register_node): Likewise. (symtab_insert_node_to_hashtable): Likewise. (symtab_unregister_node): Likewise. (symtab_get_node): Likewise. (symtab_remove_node): Likewise. (symtab_initialize_asm_name_hash): Likewise. (symtab_node_for_asm): Likewise. (symtab_add_to_same_comdat_group): Likewise. (symtab_dissolve_same_comdat_group_list): Likewise. (symtab_node_asm_name): Likewise. (symtab_node_name): Likewise. (dump_symtab_base): Likewise. (dump_symtab_node): Likewise. (dump_symtab): Likewise. (debug_symtab_node): Likewise. (verify_symtab_base): Likewise. (verify_symtab_node): Likewise. (verify_symtab): Likewise. (symtab_used_from_object_file_p): Likewise. (symtab_node_availability): Likewise. (symtab_alias_ultimate_target): Likewise. (fixup_same_cpp_alias_visibility): Likewise. (symtab_resolve_alias): Likewise. (symtab_for_node_and_aliases): Likewise. (symtab_for_node_and_aliases): Likewise. (symtab_nonoverwritable_alias_1): Likewise. (symtab_nonoverwritable_alias): Likewise. (symtab_semantically_equivalent_p): Likewise. * value-prof.c (init_node_map): Likewise. * varasm.c (find_decl): Likewise. * varpool.c (varpool_node_for_asm): Likewise. (varpool_remove_unreferenced_decls): Likewise. gcc/c-family/ Patch autogenerated by rename_symtab.py from https://github.com/davidmalcolm/gcc-refactoring-scripts revision 58bb219cc090b2f4516a9297d868c245495ee622 * c-pragma.c (maybe_apply_pending_pragma_weaks): Rename symtab_node_base to symtab_node. gcc/lto/ Patch autogenerated by rename_symtab.py from https://github.com/davidmalcolm/gcc-refactoring-scripts revision 58bb219cc090b2f4516a9297d868c245495ee622 * lto-partition.c (add_symbol_to_partition): Rename symtab_node_base to symtab_node. (get_symbol_class): Likewise. (symbol_partitioned_p): Likewise. (add_references_to_partition): Likewise. (add_symbol_to_partition_1): Likewise. (contained_in_symbol): Likewise. (add_symbol_to_partition): Likewise. (lto_1_to_1_map): Likewise. (lto_max_map): Likewise. (lto_balanced_map): Likewise. (privatize_symbol_name): Likewise. (promote_symbol): Likewise. (may_need_named_section_p): Likewise. (rename_statics): Likewise. (lto_promote_statics_nonwpa): Likewise. * lto-symtab.c (lto_symtab_merge): Likewise. (lto_symtab_resolve_replaceable_p): Likewise. (lto_symtab_symbol_p): Likewise. (lto_symtab_resolve_can_prevail_p): Likewise. (lto_symtab_resolve_symbols): Likewise. (lto_symtab_merge_decls_2): Likewise. (lto_symtab_merge_decls_1): Likewise. (lto_symtab_merge_decls): Likewise. (lto_symtab_merge_symbols_1): Likewise. (lto_symtab_merge_symbols): Likewise. (lto_symtab_prevailing_decl): Likewise. * lto.c (lto_wpa_write_files): Likewise. (read_cgraph_and_symbols): Likewise. (do_whole_program_analysis): Likewise. From-SVN: r204279
2013-10-31 22:26:14 +01:00
symtab_node *snode;
if (DECL_ABSTRACT_P (decl))
return false;
/* We are concerned only about static/external vars and functions. */
if ((!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
|| (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL))
return true;
/* Static objects can be referred only if they was not optimized out yet. */
if (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
{
/* Before we start optimizing unreachable code we can be sure all
static objects are defined. */
IPA C++ refactoring 4/N * cgraph.h (symtab_node): (bool needed_p (void)): created from decide_is_symbol_needed (bool referred_to_p (void)): created from referred_to_p (static cgraph_node *get_for_asmname (tree asmname)): created from symtab_node_for_asm * cgraph.h (cgraph_node): (void assemble_thunks_and_aliases (void)): created from assemble_thunks_and_aliases (void expand (void)): created from expand_function (static void finalize_function (tree, bool)): created from cgraph_finalize_function (static cgraph_local_info *local_info (tree decl)): created from cgraph_local_info (static cgraph_global_info *global_info (tree)): created from cgraph_global_info (static cgraph_rtl_info *rtl_info (tree)): created from cgraph_rtl_info * cgraph.h (varpool_node): (static void add (tree decl): created from varpool_add_new_variable * cgraph.h (cgraph_edge): void remove (void); (void remove_caller (void)): created from cgraph_edge_remove_caller (void remove_callee (void)): created from cgraph_edge_remove_callee (void set_call_stmt (gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt (void redirect_callee (cgraph_node *n)): created from cgraph_redirect_edge_callee (cgraph_edge *make_direct (cgraph_node *callee)): created from cgraph_make_edge_direct (cgraph_edge *make_speculative (cgraph_node *n2, gcov_type direct_count, gimple redirect_call_stmt_to_callee (void)): created from cgraph_turn_edge_to_speculative (void speculative_call_info (cgraph_edge *&direct, cgraph_edge *&indirect, ipa_ref *&reference)): created from cgraph_speculative_call_info (cgraph_edge * clone (cgraph_node *n, gimple call_stmt, unsigned stmt_uid, gcov_type count_scale, int freq_scale, bool update_original)): created from cgraph_clone_edge (cgraph_edge *resolve_speculation (tree callee_decl)): created from cgraph_resolve_speculation (bool cannot_lead_to_return_p (void)): created from cannot_lead_to_return_p (bool recursive_p (void)): created from cgraph_edge_recursive_p (bool maybe_hot_p (void)): created from cgraph_maybe_hot_edge_p (static unsigned int rebuild_edges (void)): created from rebuild_cgraph_edges (static void rebuild_references (void)): created from cgraph_rebuild_references * cgraph.h (symbol_table): (create_reference): renamed from add_reference (maybe_create_reference): renamed from maybe_add_reference (void register_symbol (symtab_node *node)): new function (void clear_asm_symbols (void)): new function (void unregister (symtab_node *node)): new function (void release_symbol (cgraph_node *node, int uid)): new function (cgraph_node * allocate_cgraph_symbol (void)): new function (void initialize (void)): created from cgraph_init (symtab_node *first_symbol (void)):new function (asm_node *first_asm_symbol (void)):new function (symtab_node *first_defined_symbol (void)):new function (varpool_node *first_variable (void)):new function (varpool_node *next_variable (varpool_node *node)):new function (varpool_node *first_static_initializer (void)):new function (varpool_node *next_static_initializer (varpool_node *node)):new function (varpool_node *first_defined_variable (void)):new function (varpool_node *next_defined_variable (varpool_node *node)):new function (cgraph_node *first_defined_function (void)):new function (cgraph_node *next_defined_function (cgraph_node *node)):new function (cgraph_node *first_function (void)):new function (cgraph_node *next_function (cgraph_node *node)):new function (cgraph_node *first_function_with_gimple_body (void)):new function (asm_node *finalize_toplevel_asm (tree asm_str)): created from add_asm_node (bool remove_unreachable_nodes (bool before_inlining_p, FILE *file)): created from symtab_remove_unreachable_nodes (void remove_unreferenced_decls (void)): created from varpool_remove_unreferenced_decls (void process_new_functions (void)): created from cgraph_process_new_functions (void process_same_body_aliases (void)): created from cgraph_process_same_body_aliases (bool output_variables (void)): created from varpool_node::output_variables (void output_asm_statements (void)): created from output_asm_statements (void finalize_compilation_unit (void)): created from finalize_compilation_unit (void compile (void)): created from compile (void output_weakrefs (void)): created from output_weakrefs (cgraph_node *create_empty (void)): created from cgraph_node::create_empty (cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_node::create_edge (void free_edge (cgraph_edge *e)): created from cgraph_free_edge (cgraph_node *next_function_with_gimple_body (cgraph_node *node)): created from cgraph_next_function_with_gimple_body (void remove_edge_removal_hook (cgraph_edge_hook_list *)): created from cgraph_remove_edge_removal_hook (cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook, void *)): created from cgraph_add_node_removal_hook (void remove_cgraph_removal_hook (cgraph_node_hook_list *)): created from cgraph_remove_node_removal_hook (varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook, void *)): created from varpool_add_node_removal_hook (void remove_varpool_removal_hook (varpool_node_hook_list *)): created from varpool_remove_node_removal_hook (cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook, void *)): created from cgraph_add_function_insertion_hook (void remove_cgraph_insertion_hook (cgraph_node_hook_list *)): created from cgraph_remove_function_insertion_hook (varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook, void *)): created from varpool_add_variable_insertion_hook (void remove_varpool_insertion_hook (varpool_node_hook_list *)): created from varpool_remove_variable_insertion_hook (cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook, void *)): created from cgraph_add_edge_duplication_hook (void remove_edge_duplication_hook (cgraph_2edge_hook_list *)): created from cgraph_remove_edge_duplication_hook (cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook, void *)): created from cgraph_add_node_duplication_hook (void remove_cgraph_duplication_hook (cgraph_2node_hook_list *)): created from cgraph_remove_node_duplication_hook (void call_edge_removal_hooks (cgraph_edge *e)): created from cgraph_call_edge_removal_hooks (void call_cgraph_insertion_hooks (cgraph_node *node)): created from call_function_insertion_hooks (void call_cgraph_removal_hooks (cgraph_node *node)): created from cgraph_call_node_removal_hooks (void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2)): created from cgraph_node::call_duplication_hooks (void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)): created from cgraph_call_edge_duplication_hooks (void call_varpool_removal_hooks (varpool_node *node)): created from varpool_call_node_removal_hooks (void call_varpool_insertion_hooks (varpool_node *node)): created from varpool_call_variable_insertion_hooks (void insert_to_assembler_name_hash (symtab_node *node, bool with_clones)): created from insert_to_assembler_name_hash (void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones)): created from unlink_from_assembler_name_hash (void symtab_prevail_in_asm_name_hash (symtab_node *node)): created from symtab_prevail_in_asm_name_hash (void symtab_initialize_asm_name_hash (void)): created from symtab_initialize_asm_name_hash (void change_decl_assembler_name (tree decl, tree name)): created from change_decl_assembler_name (void materialize_all_clones (void)): created from cgraph_materialize_all_clones (static hashval_t decl_assembler_name_hash (const_tree asmname)): created from decl_assembler_name_hash (static bool decl_assembler_name_equal (tree decl, const_tree asmname)): created from decl_assembler_name_equal (static hashval_t hash_node_by_assembler_name (const void *p)): created from hash_node_by_assembler_name (static int eq_assembler_name (const void *p1, const void *p2)): created from eq_assembler_name From-SVN: r214422
2014-08-25 15:01:47 +02:00
if (symtab->function_flags_ready)
return true;
IPA C++ refactoring 1/N * cgraph.h (symtab_node): (void register_symbol (void)): created from symtab_register_node (void remove (void)): created from symtab_remove_node (void dump (FILE *f)): created from dump_symtab_node (void DEBUG_FUNCTION debug (void)): created from debug_symtab_node (void DEBUG_FUNCTION verify (void)): created from verify_symtab_node (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type)): created from add_reference (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type, gimple stmt)): created from add_reference (struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type, gimple stmt)): created from maybe_add_reference (bool semantically_equivalent_p (symtab_node *target)): created from symtab_semantically_equivalent_p (void remove_from_same_comdat_group (void)): created from remove_from_same_comdat_group (void add_to_same_comdat_group (symtab_node *old_node)): created from symtab_add_to_same_comdat_group (void dissolve_same_comdat_group_list (void)): created from symtab_dissolve_same_comdat_group_list (bool used_from_object_file_p (void)): created from symtab_used_from_object_file_p (symtab_node *ultimate_alias_target (enum availability *avail = NULL)): created from symtab_alias_ultimate_target (inline symtab_node *next_defined_symbol (void)): created from symtab_next_defined_symbol (bool resolve_alias (symtab_node *target)): created from symtab_resolve_alias (bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), void *data, bool include_overwrite)): created from symtab_for_node_and_aliases (symtab_node *noninterposable_alias (void)): created from symtab_nonoverwritable_alias (inline symtab_node *get_alias_target (void)): created from symtab_alias_target (void set_section (const char *section)): created from set_section_1 (enum availability get_availability (void)): created from symtab_node_availability (void make_decl_local (void)): created from symtab_make_decl_local (bool real_symbol_p (void)): created from symtab_read_node (can_be_discarded_p (void)): created from symtab_can_be_discarded (inline bool comdat_local_p (void)): created from symtab_comdat_local_p (inline bool in_same_comdat_group_p (symtab_node *target)): created from symtab_in_same_comdat_p; (bool address_taken_from_non_vtable_p (void)): created from address_taken_from_non_vtable_p (static inline symtab_node *get (const_tree decl)): created from symtab_get_node (static void dump_table (FILE *)): created from dump_symtab (static inline DEBUG_FUNCTION void debug_symtab (void)): created from debug_symtab (static DEBUG_FUNCTION void verify_symtab_nodes (void)): created from verify_symtab (static bool used_from_object_file_p_worker (symtab_node *node)): created from symtab_used_from_object_file_p (void dump_base (FILE *)): created from dump_symtab_base (bool DEBUG_FUNCTION verify_base (void)): created from verify_symtab_base (void unregister (void)): created from symtab_unregister_node (struct symbol_priority_map *priority_info (void)): created from symtab_priority_info (static bool set_implicit_section (symtab_node *n, void *)): created from set_implicit_section (static bool noninterposable_alias (symtab_node *node, void *data)): created from symtab_nonoverwritable_alias_1 * cgraph.h (cgraph_node): (bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL)): created from cgraph_remove_node_and_inline_clones (void record_stmt_references (gimple stmt)): created from ipa_record_stmt_references (void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt_including_clones (cgraph_node *function_symbol (enum availability *avail = NULL)): created from cgraph_function_node (cgraph_node *create_clone (tree decl, gcov_type count, int freq, bool update_original, vec<cgraph_edge *> redirect_callers, bool call_duplication_hook, struct cgraph_node *new_inlined_to, bitmap args_to_skip)): created from cgraph_create_clone (cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, const char * suffix)): created from cgraph_create_virtual_clone (cgraph_node *find_replacement (void)): created from cgraph_find_replacement_node (cgraph_node *create_version_clone (tree new_decl, vec<cgraph_edge *> redirect_callers, bitmap bbs_to_copy)): created from cgraph_copy_node_for_versioning (cgraph_node *create_version_clone_with_body (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name)): created from cgraph_function_version_info (struct cgraph_function_version_info *insert_new_function_version (void)): created from insert_new_cgraph_node_version (struct cgraph_function_version_info *function_version (void)): created from get_cgraph_node_version (void analyze (void)): created from analyze_function (cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value, tree virtual_offset, tree real_alias) cgraph_add_thunk (inline cgraph_node *get_alias_target (void)): created from cgraph_alias_target (cgraph_node *ultimate_alias_target (availability *availability = NULL)): created from cgraph_function_or_thunk_node (bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)): created from expand_thunk (void reset (void)): created from cgraph_reset_node (void create_wrapper (cgraph_node *target)): created from cgraph_make_wrapper (void DEBUG_FUNCTION verify_node (void)): created from verify_cgraph_node (void remove (void)): created from cgraph_remove_node (void dump (FILE *f)): created from dump_cgraph_node (void DEBUG_FUNCTION debug (void)): created from debug_cgraph_node (bool get_body (void)): created from cgraph_get_body (void release_body (void)): created from cgraph_release_function_body (void unnest (void)): created from cgraph_unnest_node (void make_local (void)): created from cgraph_make_node_local (void mark_address_taken (void)): created from cgraph_mark_address_taken_node (struct cgraph_edge *create_edge (cgraph_node *callee, gimple call_stmt, gcov_type count, int freq)): created from cgraph_create_edge (struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, gcov_type count, int freq)): created from cgraph_create_indirect_edge (void create_edge_including_clones (struct cgraph_node *callee, gimple old_stmt, gimple stmt, gcov_type count, int freq, cgraph_inline_failed_t reason)): created from cgraph_create_edge_including_clones (cgraph_edge *get_edge (gimple call_stmt)): created from cgraph_edge (vec<cgraph_edge *> collect_callers (void)): created from collect_callers_of_node (void remove_callers (void)): created from cgraph_node_remove_callers (void remove_callees (void)): created from cgraph_node_remove_callees (enum availability get_availability (void)): created from cgraph_function_body_availability (void set_nothrow_flag (bool nothrow)): created from cgraph_set_nothrow_flag (void set_const_flag (bool readonly, bool looping)): created from cgraph_set_const_flag (void set_pure_flag (bool pure, bool looping)): created from cgraph_set_pure_flag (void call_duplication_hooks (cgraph_node *node2)): created from cgraph_call_node_duplication_hooks (bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, void *), void *data, bool include_overwritable)): created from cgraph_for_node_and_aliases (bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, void *data), void *data, bool include_overwritable)): created from cgraph_for_node_thunks_and_aliases (void call_function_insertion_hooks (void)): created from cgraph_call_function_insertion_hooks (inline void mark_force_output (void)): created from cgraph_mark_force_output_node (bool local_p (void)): created from cgraph_local_node (bool can_be_local_p (void)): created from cgraph_node_can_be_local_p (bool cannot_return_p (void)): created from cgraph_node_cannot_return (bool only_called_directly_p (void)): created from cgraph_only_called_directly_p (inline bool only_called_directly_or_aliased_p (void)): created from cgraph_only_called_directly_or_aliased_p (bool will_be_removed_from_program_if_no_direct_calls_p (void)): created from cgraph_will_be_removed_from_program_if_no_direct_calls (bool can_remove_if_no_direct_calls_and_refs_p (void)): created from cgraph_can_remove_if_no_direct_calls_and_refs_p (bool can_remove_if_no_direct_calls_p (void)): created from cgraph_can_remove_if_no_direct_calls_p (inline bool has_gimple_body_p (void)): created from cgraph_function_with_gimple_body_p (bool optimize_for_size_p (void)): created from cgraph_optimize_for_size_p (static void dump_cgraph (FILE *f)): created from dump_cgraph (static inline void debug_cgraph (void)): created from debug_cgraph (static void record_function_versions (tree decl1, tree decl2)): created from record_function_versions (static void delete_function_version (tree decl)): created from delete_function_version (static void add_new_function (tree fndecl, bool lowered)): created from cgraph_add_new_function (static inline cgraph_node *get (const_tree decl)): created from cgraph_get_node (static cgraph_node * create (tree decl)): created from cgraph_create_node (static cgraph_node * create_empty (void)): created from cgraph_create_empty_node (static cgraph_node * get_create (tree)): created from cgraph_get_create_node (static cgraph_node *get_for_asmname (tree asmname)): created from cgraph_node_for_asm (static cgraph_node * create_same_body_alias (tree alias, tree decl)): created from cgraph_same_body_alias (static bool used_from_object_file_p_worker (cgraph_node *node, void *): new function (static bool non_local_p (cgraph_node *node, void *)): created from cgraph_non_local_node_p_1 (static void DEBUG_FUNCTION verify_cgraph_nodes (void)): created from verify_cgraph (static bool make_local (cgraph_node *node, void *)): created from cgraph_make_node_local (static cgraph_node *create_alias (tree alias, tree target)): created from cgraph_create_function_alias (static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_create_edge_1 * cgraph.h (varpool_node): (void remove (void)): created from varpool_remove_node (void dump (FILE *f)): created from dump_varpool_node From-SVN: r212982
2014-07-24 14:07:13 +02:00
snode = symtab_node::get (decl);
if (!snode || !snode->definition)
return false;
Change is-a.h to support typedefs of pointers gcc/ * is-a.h: Update comments to reflect the following changes to the "pointerness" of the API, making the template parameter match the return type, allowing use of is-a.h with typedefs of pointers. (is_a_helper::cast): Return a T rather then a pointer to a T, so that the return type matches the parameter to the is_a_helper. (as_a): Likewise. (dyn_cast): Likewise. * cgraph.c (cgraph_node_for_asm): Update for removal of implicit pointer from the is-a.h API. * cgraph.h (is_a_helper <cgraph_node>::test): Convert to... (is_a_helper <cgraph_node *>::test): ...this, matching change to is-a.h API. (is_a_helper <varpool_node>::test): Likewise, convert to... (is_a_helper <varpool_node *>::test): ...this. (varpool_first_variable): Update for removal of implicit pointer from the is-a.h API. (varpool_next_variable): Likewise. (varpool_first_static_initializer): Likewise. (varpool_next_static_initializer): Likewise. (varpool_first_defined_variable): Likewise. (varpool_next_defined_variable): Likewise. (cgraph_first_defined_function): Likewise. (cgraph_next_defined_function): Likewise. (cgraph_first_function): Likewise. (cgraph_next_function): Likewise. (cgraph_first_function_with_gimple_body): Likewise. (cgraph_next_function_with_gimple_body): Likewise. (cgraph_alias_target): Likewise. (varpool_alias_target): Likewise. (cgraph_function_or_thunk_node): Likewise. (varpool_variable_node): Likewise. (symtab_real_symbol_p): Likewise. * cgraphunit.c (referred_to_p): Likewise. (analyze_functions): Likewise. (handle_alias_pairs): Likewise. * gimple-fold.c (can_refer_decl_in_current_unit_p): Likewise. * gimple-ssa.h (gimple_vuse_op): Likewise. (gimple_vdef_op): Likewise. * gimple-streamer-in.c (input_gimple_stmt): Likewise. * gimple.c (gimple_build_asm_1): Likewise. (gimple_build_try): Likewise. (gimple_build_resx): Likewise. (gimple_build_eh_dispatch): Likewise. (gimple_build_omp_for): Likewise. (gimple_omp_for_set_clauses): Likewise. * gimple.h (is_a_helper <gimple_statement_asm>::test): Convert to... (is_a_helper <gimple_statement_asm *>::test): ...this. (is_a_helper <gimple_statement_bind>::test): Convert to... (is_a_helper <gimple_statement_bind *>::test): ...this. (is_a_helper <gimple_statement_call>::test): Convert to... (is_a_helper <gimple_statement_call *>::test): ...this. (is_a_helper <gimple_statement_catch>::test): Convert to... (is_a_helper <gimple_statement_catch *>::test): ...this. (is_a_helper <gimple_statement_resx>::test): Convert to... (is_a_helper <gimple_statement_resx *>::test): ...this. (is_a_helper <gimple_statement_eh_dispatch>::test): Convert to... (is_a_helper <gimple_statement_eh_dispatch *>::test): ...this. (is_a_helper <gimple_statement_eh_else>::test): Convert to... (is_a_helper <gimple_statement_eh_else *>::test): ...this. (is_a_helper <gimple_statement_eh_filter>::test): Convert to... (is_a_helper <gimple_statement_eh_filter *>::test): ...this. (is_a_helper <gimple_statement_eh_mnt>::test): Convert to... (is_a_helper <gimple_statement_eh_mnt *>::test): ...this. (is_a_helper <gimple_statement_omp_atomic_load>::test): Convert to... (is_a_helper <gimple_statement_omp_atomic_load *>::test): ...this. (is_a_helper <gimple_statement_omp_atomic_store>::test): Convert to... (is_a_helper <gimple_statement_omp_atomic_store *>::test): ...this. (is_a_helper <gimple_statement_omp_return>::test): Convert to... (is_a_helper <gimple_statement_omp_return *>::test): ...this. (is_a_helper <gimple_statement_omp_continue>::test): Convert to... (is_a_helper <gimple_statement_omp_continue *>::test): ...this. (is_a_helper <gimple_statement_omp_critical>::test): Convert to... (is_a_helper <gimple_statement_omp_critical *>::test): ...this. (is_a_helper <gimple_statement_omp_for>::test): Convert to... (is_a_helper <gimple_statement_omp_for *>::test): ...this. (is_a_helper <gimple_statement_omp_taskreg>::test): Convert to... (is_a_helper <gimple_statement_omp_taskreg *>::test): ...this. (is_a_helper <gimple_statement_omp_parallel>::test): Convert to... (is_a_helper <gimple_statement_omp_parallel *>::test): ...this. (is_a_helper <gimple_statement_omp_target>::test): Convert to... (is_a_helper <gimple_statement_omp_target *>::test): ...this. (is_a_helper <gimple_statement_omp_sections>::test): Convert to... (is_a_helper <gimple_statement_omp_sections *>::test): ...this. (is_a_helper <gimple_statement_omp_single>::test): Convert to... (is_a_helper <gimple_statement_omp_single *>::test): ...this. (is_a_helper <gimple_statement_omp_teams>::test): Convert to... (is_a_helper <gimple_statement_omp_teams *>::test): ...this. (is_a_helper <gimple_statement_omp_task>::test): Convert to... (is_a_helper <gimple_statement_omp_task *>::test): ...this. (is_a_helper <gimple_statement_phi>::test): Convert to... (is_a_helper <gimple_statement_phi *>::test): ...this. (is_a_helper <gimple_statement_transaction>::test): Convert to... (is_a_helper <gimple_statement_transaction *>::test): ...this. (is_a_helper <gimple_statement_try>::test): Convert to... (is_a_helper <gimple_statement_try *>::test): ...this. (is_a_helper <gimple_statement_wce>::test): Convert to... (is_a_helper <gimple_statement_wce *>::test): ...this. (is_a_helper <const gimple_statement_asm>::test): Convert to... (is_a_helper <const gimple_statement_asm *>::test): ...this. (is_a_helper <const gimple_statement_bind>::test): Convert to... (is_a_helper <const gimple_statement_bind *>::test): ...this. (is_a_helper <const gimple_statement_call>::test): Convert to... (is_a_helper <const gimple_statement_call *>::test): ...this. (is_a_helper <const gimple_statement_catch>::test): Convert to... (is_a_helper <const gimple_statement_catch *>::test): ...this. (is_a_helper <const gimple_statement_resx>::test): Convert to... (is_a_helper <const gimple_statement_resx *>::test): ...this. (is_a_helper <const gimple_statement_eh_dispatch>::test): Convert to... (is_a_helper <const gimple_statement_eh_dispatch *>::test): ...this. (is_a_helper <const gimple_statement_eh_filter>::test): Convert to... (is_a_helper <const gimple_statement_eh_filter *>::test): ...this. (is_a_helper <const gimple_statement_omp_atomic_load>::test): Convert to... (is_a_helper <const gimple_statement_omp_atomic_load *>::test): ...this. (is_a_helper <const gimple_statement_omp_atomic_store>::test): Convert to... (is_a_helper <const gimple_statement_omp_atomic_store *>::test): ...this. (is_a_helper <const gimple_statement_omp_return>::test): Convert to... (is_a_helper <const gimple_statement_omp_return *>::test): ...this. (is_a_helper <const gimple_statement_omp_continue>::test): Convert to... (is_a_helper <const gimple_statement_omp_continue *>::test): ...this. (is_a_helper <const gimple_statement_omp_critical>::test): Convert to... (is_a_helper <const gimple_statement_omp_critical *>::test): ...this. (is_a_helper <const gimple_statement_omp_for>::test): Convert to... (is_a_helper <const gimple_statement_omp_for *>::test): ...this. (is_a_helper <const gimple_statement_omp_taskreg>::test): Convert to... (is_a_helper <const gimple_statement_omp_taskreg *>::test): ...this. (is_a_helper <const gimple_statement_omp_parallel>::test): Convert to... (is_a_helper <const gimple_statement_omp_parallel *>::test): ...this. (is_a_helper <const gimple_statement_omp_target>::test): Convert to... (is_a_helper <const gimple_statement_omp_target *>::test): ...this. (is_a_helper <const gimple_statement_omp_sections>::test): Convert to... (is_a_helper <const gimple_statement_omp_sections *>::test): ...this. (is_a_helper <const gimple_statement_omp_single>::test): Convert to... (is_a_helper <const gimple_statement_omp_single *>::test): ...this. (is_a_helper <const gimple_statement_omp_teams>::test): Convert to... (is_a_helper <const gimple_statement_omp_teams *>::test): ...this. (is_a_helper <const gimple_statement_omp_task>::test): Convert to... (is_a_helper <const gimple_statement_omp_task *>::test): ...this. (is_a_helper <const gimple_statement_phi>::test): Convert to... (is_a_helper <const gimple_statement_phi *>::test): ...this. (is_a_helper <const gimple_statement_transaction>::test): Convert to... (is_a_helper <const gimple_statement_transaction *>::test): ...this. (is_a_helper <const gimple_statement_with_ops>::test): Convert to... (is_a_helper <const gimple_statement_with_ops *>::test): ...this. (is_a_helper <gimple_statement_with_ops>::test): Convert to... (is_a_helper <gimple_statement_with_ops *>::test): ...this. (is_a_helper <const gimple_statement_with_memory_ops>::test): Convert to... (is_a_helper <const gimple_statement_with_memory_ops *>::test): ...this. (is_a_helper <gimple_statement_with_memory_ops>::test): Convert to... (is_a_helper <gimple_statement_with_memory_ops *>::test): ...this. (gimple_use_ops): Update for removal of implicit pointer from the is-a.h API. (gimple_set_use_ops): Likewise. (gimple_vuse): Likewise. (gimple_vdef): Likewise. (gimple_vuse_ptr): Likewise. (gimple_vdef_ptr): Likewise. (gimple_set_vuse): Likewise. (gimple_set_vdef): Likewise. (gimple_omp_return_set_lhs): Likewise. (gimple_omp_return_lhs): Likewise. (gimple_omp_return_lhs_ptr): Likewise. (gimple_call_fntype): Likewise. (gimple_call_set_fntype): Likewise. (gimple_call_set_internal_fn): Likewise. (gimple_call_use_set): Likewise. (gimple_call_clobber_set): Likewise. (gimple_bind_vars): Likewise. (gimple_bind_set_vars): Likewise. (gimple_bind_body_ptr): Likewise. (gimple_bind_set_body): Likewise. (gimple_bind_add_stmt): Likewise. (gimple_bind_block): Likewise. (gimple_bind_set_block): Likewise. (gimple_asm_ninputs): Likewise. (gimple_asm_noutputs): Likewise. (gimple_asm_nclobbers): Likewise. (gimple_asm_nlabels): Likewise. (gimple_asm_input_op): Likewise. (gimple_asm_input_op_ptr): Likewise. (gimple_asm_output_op): Likewise. (gimple_asm_output_op_ptr): Likewise. (gimple_asm_set_output_op): Likewise. (gimple_asm_clobber_op): Likewise. (gimple_asm_set_clobber_op): Likewise. (gimple_asm_label_op): Likewise. (gimple_asm_set_label_op): Likewise. (gimple_asm_string): Likewise. (gimple_catch_types): Likewise. (gimple_catch_types_ptr): Likewise. (gimple_catch_handler_ptr): Likewise. (gimple_catch_set_types): Likewise. (gimple_catch_set_handler): Likewise. (gimple_eh_filter_types): Likewise. (gimple_eh_filter_types_ptr): Likewise. (gimple_eh_filter_failure_ptr): Likewise. (gimple_eh_filter_set_types): Likewise. (gimple_eh_filter_set_failure): Likewise. (gimple_eh_must_not_throw_fndecl): Likewise. (gimple_eh_must_not_throw_set_fndecl): Likewise. (gimple_eh_else_n_body_ptr): Likewise. (gimple_eh_else_e_body_ptr): Likewise. (gimple_eh_else_set_n_body): Likewise. (gimple_eh_else_set_e_body): Likewise. (gimple_try_eval_ptr): Likewise. (gimple_try_cleanup_ptr): Likewise. (gimple_try_set_eval): Likewise. (gimple_try_set_cleanup): Likewise. (gimple_wce_cleanup_ptr): Likewise. (gimple_wce_set_cleanup): Likewise. (gimple_phi_capacity): Likewise. (gimple_phi_num_args): Likewise. (gimple_phi_result): Likewise. (gimple_phi_result_ptr): Likewise. (gimple_phi_set_result): Likewise. (gimple_phi_arg): Likewise. (gimple_phi_set_arg): Likewise. (gimple_resx_region): Likewise. (gimple_resx_set_region): Likewise. (gimple_eh_dispatch_region): Likewise. (gimple_eh_dispatch_set_region): Likewise. (gimple_omp_critical_name): Likewise. (gimple_omp_critical_name_ptr): Likewise. (gimple_omp_critical_set_name): Likewise. (gimple_omp_for_clauses): Likewise. (gimple_omp_for_clauses_ptr): Likewise. (gimple_omp_for_set_clauses): Likewise. (gimple_omp_for_collapse): Likewise. (gimple_omp_for_index): Likewise. (gimple_omp_for_index_ptr): Likewise. (gimple_omp_for_set_index): Likewise. (gimple_omp_for_initial): Likewise. (gimple_omp_for_initial_ptr): Likewise. (gimple_omp_for_set_initial): Likewise. (gimple_omp_for_final): Likewise. (gimple_omp_for_final_ptr): Likewise. (gimple_omp_for_set_final): Likewise. (gimple_omp_for_incr): Likewise. (gimple_omp_for_incr_ptr): Likewise. (gimple_omp_for_set_incr): Likewise. (gimple_omp_for_pre_body_ptr): Likewise. (gimple_omp_for_set_pre_body): Likewise. (gimple_omp_parallel_clauses): Likewise. (gimple_omp_parallel_clauses_ptr): Likewise. (gimple_omp_parallel_set_clauses): Likewise. (gimple_omp_parallel_child_fn): Likewise. (gimple_omp_parallel_child_fn_ptr): Likewise. (gimple_omp_parallel_set_child_fn): Likewise. (gimple_omp_parallel_data_arg): Likewise. (gimple_omp_parallel_data_arg_ptr): Likewise. (gimple_omp_parallel_set_data_arg): Likewise. (gimple_omp_task_clauses): Likewise. (gimple_omp_task_clauses_ptr): Likewise. (gimple_omp_task_set_clauses): Likewise. (gimple_omp_task_child_fn): Likewise. (gimple_omp_task_child_fn_ptr): Likewise. (gimple_omp_task_set_child_fn): Likewise. (gimple_omp_task_data_arg): Likewise. (gimple_omp_task_data_arg_ptr): Likewise. (gimple_omp_task_set_data_arg): Likewise. (gimple_omp_taskreg_clauses): Likewise. (gimple_omp_taskreg_clauses_ptr): Likewise. (gimple_omp_taskreg_set_clauses): Likewise. (gimple_omp_taskreg_child_fn): Likewise. (gimple_omp_taskreg_child_fn_ptr): Likewise. (gimple_omp_taskreg_set_child_fn): Likewise. (gimple_omp_taskreg_data_arg): Likewise. (gimple_omp_taskreg_data_arg_ptr): Likewise. (gimple_omp_taskreg_set_data_arg): Likewise. (gimple_omp_task_copy_fn): Likewise. (gimple_omp_task_copy_fn_ptr): Likewise. (gimple_omp_task_set_copy_fn): Likewise. (gimple_omp_task_arg_size): Likewise. (gimple_omp_task_arg_size_ptr): Likewise. (gimple_omp_task_set_arg_size): Likewise. (gimple_omp_task_arg_align): Likewise. (gimple_omp_task_arg_align_ptr): Likewise. (gimple_omp_task_set_arg_align): Likewise. (gimple_omp_single_clauses): Likewise. (gimple_omp_single_clauses_ptr): Likewise. (gimple_omp_single_set_clauses): Likewise. (gimple_omp_target_clauses): Likewise. (gimple_omp_target_clauses_ptr): Likewise. (gimple_omp_target_set_clauses): Likewise. (gimple_omp_target_child_fn): Likewise. (gimple_omp_target_child_fn_ptr): Likewise. (gimple_omp_target_set_child_fn): Likewise. (gimple_omp_target_data_arg): Likewise. (gimple_omp_target_data_arg_ptr): Likewise. (gimple_omp_target_set_data_arg): Likewise. (gimple_omp_teams_clauses): Likewise. (gimple_omp_teams_clauses_ptr): Likewise. (gimple_omp_teams_set_clauses): Likewise. (gimple_omp_sections_clauses): Likewise. (gimple_omp_sections_clauses_ptr): Likewise. (gimple_omp_sections_set_clauses): Likewise. (gimple_omp_sections_control): Likewise. (gimple_omp_sections_control_ptr): Likewise. (gimple_omp_sections_set_control): Likewise. (gimple_omp_for_set_cond): Likewise. (gimple_omp_for_cond): Likewise. (gimple_omp_atomic_store_set_val): Likewise. (gimple_omp_atomic_store_val): Likewise. (gimple_omp_atomic_store_val_ptr): Likewise. (gimple_omp_atomic_load_set_lhs): Likewise. (gimple_omp_atomic_load_lhs): Likewise. (gimple_omp_atomic_load_lhs_ptr): Likewise. (gimple_omp_atomic_load_set_rhs): Likewise. (gimple_omp_atomic_load_rhs): Likewise. (gimple_omp_atomic_load_rhs_ptr): Likewise. (gimple_omp_continue_control_def): Likewise. (gimple_omp_continue_control_def_ptr): Likewise. (gimple_omp_continue_set_control_def): Likewise. (gimple_omp_continue_control_use): Likewise. (gimple_omp_continue_control_use_ptr): Likewise. (gimple_omp_continue_set_control_use): Likewise. (gimple_transaction_body_ptr): Likewise. (gimple_transaction_label): Likewise. (gimple_transaction_label_ptr): Likewise. (gimple_transaction_set_body): Likewise. (gimple_transaction_set_label): Likewise. * ipa-devirt.c (build_type_inheritance_graph): Likewise. * ipa-inline-analysis.c (inline_write_summary): Likewise. * ipa-ref.c (ipa_record_reference): Likewise. * ipa-reference.c (analyze_function): Likewise. (ipa_reference_write_optimization_summary): Likewise. * ipa.c (symtab_remove_unreachable_nodes): Likewise. (address_taken_from_non_vtable_p): Likewise. (comdat_can_be_unshared_p_1): Likewise. * lto-cgraph.c (lto_output_ref): Likewise. (add_references): Likewise. (compute_ltrans_boundary): Likewise. (output_symtab): Likewise. (input_ref): Likewise. (input_cgraph_1): Likewise. (output_cgraph_opt_summary): Likewise. * lto-streamer-out.c (lto_output): Likewise. (output_symbol_p): Likewise. * lto-streamer.h (lsei_next_function_in_partition): Likewise. (lsei_start_function_in_partition): Likewise. (lsei_next_variable_in_partition): Likewise. (lsei_start_variable_in_partition): Likewise. * symtab.c (insert_to_assembler_name_hash): Likewise. (unlink_from_assembler_name_hash): Likewise. (symtab_unregister_node): Likewise. (symtab_remove_node): Likewise. (dump_symtab_node): Likewise. (verify_symtab_base): Likewise. (verify_symtab_node): Likewise. (symtab_make_decl_local): Likewise. (symtab_alias_ultimate_target): Likewise. (symtab_resolve_alias): Likewise. (symtab_get_symbol_partitioning_class): Likewise. * tree-phinodes.c (allocate_phi_node): Likewise. (reserve_phi_args_for_new_edge): Likewise. (remove_phi_args): Likewise. * varpool.c (varpool_node_for_asm): Likewise. (varpool_remove_unreferenced_decls): Likewise. gcc/lto/ * lto-partition.c (add_references_to_partition): Update for removal of implicit pointer from the is-a.h API. (add_symbol_to_partition_1): Likewise. (contained_in_symbol): Likewise. (undo_partition): Likewise. (lto_balanced_map): Likewise. (promote_symbol): Likewise. * lto-symtab.c (lto_symtab_merge_symbols_1): Likewise. (lto_symtab_merge_symbols): Likewise. * lto.c (lto_wpa_write_files): Likewise. From-SVN: r209719
2014-04-23 21:06:40 +02:00
node = dyn_cast <cgraph_node *> (snode);
return !node || !node->global.inlined_to;
}
/* We will later output the initializer, so we can refer to it.
So we are concerned only when DECL comes from initializer of
external var or var that has been optimized out. */
if (!from_decl
|| TREE_CODE (from_decl) != VAR_DECL
|| (!DECL_EXTERNAL (from_decl)
IPA C++ refactoring 2/N * cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
2014-07-24 14:25:27 +02:00
&& (vnode = varpool_node::get (from_decl)) != NULL
&& vnode->definition)
|| (flag_ltrans
IPA C++ refactoring 2/N * cgraph.h (varpool_node): (availability get_availability (void)): created from cgraph_variable_initializer_availability (inline varpool_node *ultimate_alias_target (availability *availability = NULL) creted from: cgraph_variable_initializer_availability (inline varpool_node *get_alias_target (void)): created from varpool_alias_target (void finalize_named_section_flags (void)): created from varpool_finalize_named_section_flags (bool assemble_decl (void)): created from varpool_assemble_decl (void analyze (void)): created from varpool_analyze_node (bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), void *data, bool include_overwritable)): created fromvarpool_for_node_and_aliases (void remove_initializer (void)): created from varpool_remove_initializer (tree get_constructor (void)): created from varpool_get_constructor (bool externally_visible_p (void)): created from varpool_externally_visible_p (bool ctor_useable_for_folding_p (void)): created from varpool_ctor_useable_for_folding_p (inline bool all_refs_explicit_p ()): created from varpool_all_refs_explicit_p (inline bool can_remove_if_no_refs_p (void)): created from varpool_can_remove_if_no_refs (static inline varpool_node *get (const_tree decl)): created from varpool_get_node (static void finalize_decl (tree decl)): created from varpool_finalize_decl (static bool output_variables (void)): created from varpool_output_variables (static varpool_node * create_extra_name_alias (tree alias, tree decl)): created from varpool_extra_name_alias (static varpool_node * create_alias (tree, tree)): created from varpool_create_variable_alias (static void dump_varpool (FILE *f)): created from dump_varpool (static void DEBUG_FUNCTION debug_varpool (void)): created from debug_varpool (static varpool_node *create_empty (void)): created from varpool_create_empty_node (static varpool_node *get_create (tree decl)): created from varpool_node_for_decl (static varpool_node *get_for_asmname (tree asmname)): created from varpool_node_for_asm (void assemble_aliases (void)): created from assemble_aliases From-SVN: r212984
2014-07-24 14:25:27 +02:00
&& (vnode = varpool_node::get (from_decl)) != NULL
&& vnode->in_other_partition))
return true;
/* We are folding reference from external vtable. The vtable may reffer
to a symbol keyed to other compilation unit. The other compilation
unit may be in separate DSO and the symbol may be hidden. */
if (DECL_VISIBILITY_SPECIFIED (decl)
&& DECL_EXTERNAL (decl)
&& DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT
IPA C++ refactoring 1/N * cgraph.h (symtab_node): (void register_symbol (void)): created from symtab_register_node (void remove (void)): created from symtab_remove_node (void dump (FILE *f)): created from dump_symtab_node (void DEBUG_FUNCTION debug (void)): created from debug_symtab_node (void DEBUG_FUNCTION verify (void)): created from verify_symtab_node (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type)): created from add_reference (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type, gimple stmt)): created from add_reference (struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type, gimple stmt)): created from maybe_add_reference (bool semantically_equivalent_p (symtab_node *target)): created from symtab_semantically_equivalent_p (void remove_from_same_comdat_group (void)): created from remove_from_same_comdat_group (void add_to_same_comdat_group (symtab_node *old_node)): created from symtab_add_to_same_comdat_group (void dissolve_same_comdat_group_list (void)): created from symtab_dissolve_same_comdat_group_list (bool used_from_object_file_p (void)): created from symtab_used_from_object_file_p (symtab_node *ultimate_alias_target (enum availability *avail = NULL)): created from symtab_alias_ultimate_target (inline symtab_node *next_defined_symbol (void)): created from symtab_next_defined_symbol (bool resolve_alias (symtab_node *target)): created from symtab_resolve_alias (bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), void *data, bool include_overwrite)): created from symtab_for_node_and_aliases (symtab_node *noninterposable_alias (void)): created from symtab_nonoverwritable_alias (inline symtab_node *get_alias_target (void)): created from symtab_alias_target (void set_section (const char *section)): created from set_section_1 (enum availability get_availability (void)): created from symtab_node_availability (void make_decl_local (void)): created from symtab_make_decl_local (bool real_symbol_p (void)): created from symtab_read_node (can_be_discarded_p (void)): created from symtab_can_be_discarded (inline bool comdat_local_p (void)): created from symtab_comdat_local_p (inline bool in_same_comdat_group_p (symtab_node *target)): created from symtab_in_same_comdat_p; (bool address_taken_from_non_vtable_p (void)): created from address_taken_from_non_vtable_p (static inline symtab_node *get (const_tree decl)): created from symtab_get_node (static void dump_table (FILE *)): created from dump_symtab (static inline DEBUG_FUNCTION void debug_symtab (void)): created from debug_symtab (static DEBUG_FUNCTION void verify_symtab_nodes (void)): created from verify_symtab (static bool used_from_object_file_p_worker (symtab_node *node)): created from symtab_used_from_object_file_p (void dump_base (FILE *)): created from dump_symtab_base (bool DEBUG_FUNCTION verify_base (void)): created from verify_symtab_base (void unregister (void)): created from symtab_unregister_node (struct symbol_priority_map *priority_info (void)): created from symtab_priority_info (static bool set_implicit_section (symtab_node *n, void *)): created from set_implicit_section (static bool noninterposable_alias (symtab_node *node, void *data)): created from symtab_nonoverwritable_alias_1 * cgraph.h (cgraph_node): (bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL)): created from cgraph_remove_node_and_inline_clones (void record_stmt_references (gimple stmt)): created from ipa_record_stmt_references (void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt_including_clones (cgraph_node *function_symbol (enum availability *avail = NULL)): created from cgraph_function_node (cgraph_node *create_clone (tree decl, gcov_type count, int freq, bool update_original, vec<cgraph_edge *> redirect_callers, bool call_duplication_hook, struct cgraph_node *new_inlined_to, bitmap args_to_skip)): created from cgraph_create_clone (cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, const char * suffix)): created from cgraph_create_virtual_clone (cgraph_node *find_replacement (void)): created from cgraph_find_replacement_node (cgraph_node *create_version_clone (tree new_decl, vec<cgraph_edge *> redirect_callers, bitmap bbs_to_copy)): created from cgraph_copy_node_for_versioning (cgraph_node *create_version_clone_with_body (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name)): created from cgraph_function_version_info (struct cgraph_function_version_info *insert_new_function_version (void)): created from insert_new_cgraph_node_version (struct cgraph_function_version_info *function_version (void)): created from get_cgraph_node_version (void analyze (void)): created from analyze_function (cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value, tree virtual_offset, tree real_alias) cgraph_add_thunk (inline cgraph_node *get_alias_target (void)): created from cgraph_alias_target (cgraph_node *ultimate_alias_target (availability *availability = NULL)): created from cgraph_function_or_thunk_node (bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)): created from expand_thunk (void reset (void)): created from cgraph_reset_node (void create_wrapper (cgraph_node *target)): created from cgraph_make_wrapper (void DEBUG_FUNCTION verify_node (void)): created from verify_cgraph_node (void remove (void)): created from cgraph_remove_node (void dump (FILE *f)): created from dump_cgraph_node (void DEBUG_FUNCTION debug (void)): created from debug_cgraph_node (bool get_body (void)): created from cgraph_get_body (void release_body (void)): created from cgraph_release_function_body (void unnest (void)): created from cgraph_unnest_node (void make_local (void)): created from cgraph_make_node_local (void mark_address_taken (void)): created from cgraph_mark_address_taken_node (struct cgraph_edge *create_edge (cgraph_node *callee, gimple call_stmt, gcov_type count, int freq)): created from cgraph_create_edge (struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, gcov_type count, int freq)): created from cgraph_create_indirect_edge (void create_edge_including_clones (struct cgraph_node *callee, gimple old_stmt, gimple stmt, gcov_type count, int freq, cgraph_inline_failed_t reason)): created from cgraph_create_edge_including_clones (cgraph_edge *get_edge (gimple call_stmt)): created from cgraph_edge (vec<cgraph_edge *> collect_callers (void)): created from collect_callers_of_node (void remove_callers (void)): created from cgraph_node_remove_callers (void remove_callees (void)): created from cgraph_node_remove_callees (enum availability get_availability (void)): created from cgraph_function_body_availability (void set_nothrow_flag (bool nothrow)): created from cgraph_set_nothrow_flag (void set_const_flag (bool readonly, bool looping)): created from cgraph_set_const_flag (void set_pure_flag (bool pure, bool looping)): created from cgraph_set_pure_flag (void call_duplication_hooks (cgraph_node *node2)): created from cgraph_call_node_duplication_hooks (bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, void *), void *data, bool include_overwritable)): created from cgraph_for_node_and_aliases (bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, void *data), void *data, bool include_overwritable)): created from cgraph_for_node_thunks_and_aliases (void call_function_insertion_hooks (void)): created from cgraph_call_function_insertion_hooks (inline void mark_force_output (void)): created from cgraph_mark_force_output_node (bool local_p (void)): created from cgraph_local_node (bool can_be_local_p (void)): created from cgraph_node_can_be_local_p (bool cannot_return_p (void)): created from cgraph_node_cannot_return (bool only_called_directly_p (void)): created from cgraph_only_called_directly_p (inline bool only_called_directly_or_aliased_p (void)): created from cgraph_only_called_directly_or_aliased_p (bool will_be_removed_from_program_if_no_direct_calls_p (void)): created from cgraph_will_be_removed_from_program_if_no_direct_calls (bool can_remove_if_no_direct_calls_and_refs_p (void)): created from cgraph_can_remove_if_no_direct_calls_and_refs_p (bool can_remove_if_no_direct_calls_p (void)): created from cgraph_can_remove_if_no_direct_calls_p (inline bool has_gimple_body_p (void)): created from cgraph_function_with_gimple_body_p (bool optimize_for_size_p (void)): created from cgraph_optimize_for_size_p (static void dump_cgraph (FILE *f)): created from dump_cgraph (static inline void debug_cgraph (void)): created from debug_cgraph (static void record_function_versions (tree decl1, tree decl2)): created from record_function_versions (static void delete_function_version (tree decl)): created from delete_function_version (static void add_new_function (tree fndecl, bool lowered)): created from cgraph_add_new_function (static inline cgraph_node *get (const_tree decl)): created from cgraph_get_node (static cgraph_node * create (tree decl)): created from cgraph_create_node (static cgraph_node * create_empty (void)): created from cgraph_create_empty_node (static cgraph_node * get_create (tree)): created from cgraph_get_create_node (static cgraph_node *get_for_asmname (tree asmname)): created from cgraph_node_for_asm (static cgraph_node * create_same_body_alias (tree alias, tree decl)): created from cgraph_same_body_alias (static bool used_from_object_file_p_worker (cgraph_node *node, void *): new function (static bool non_local_p (cgraph_node *node, void *)): created from cgraph_non_local_node_p_1 (static void DEBUG_FUNCTION verify_cgraph_nodes (void)): created from verify_cgraph (static bool make_local (cgraph_node *node, void *)): created from cgraph_make_node_local (static cgraph_node *create_alias (tree alias, tree target)): created from cgraph_create_function_alias (static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_create_edge_1 * cgraph.h (varpool_node): (void remove (void)): created from varpool_remove_node (void dump (FILE *f)): created from dump_varpool_node From-SVN: r212982
2014-07-24 14:07:13 +02:00
&& (!(snode = symtab_node::get (decl)) || !snode->in_other_partition))
return false;
/* When function is public, we always can introduce new reference.
Exception are the COMDAT functions where introducing a direct
reference imply need to include function body in the curren tunit. */
if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
return true;
/* We have COMDAT. We are going to check if we still have definition
or if the definition is going to be output in other partition.
Bypass this when gimplifying; all needed functions will be produced.
As observed in PR20991 for already optimized out comdat virtual functions
LANGUAGES: Fix typos. * LANGUAGES: Fix typos. * Makefile.in: Fix typos. * alias.c: Fix typos. * auto-inc-dec.c: Fix typos. * bb-reorder.c: Fix typos. * cfgcleanup.c: Fix typos. * cgraph.c: Fix typos. * cgraph.h: Fix typos. * cgraphunit.c: Fix typos. * collect2-aix.h: Fix typos. * collect2.c: Fix typos. * compare-elim.c: Fix typos. * config/alpha/vms.h: Fix typos. * config/arm/README-interworking: Fix typos. * config/arm/arm.c: Fix typos. * config/arm/iterators.md: Fix typos. * config/arm/vxworks.h: Fix typos. * config/avr/avr.c: Fix typos. * config/avr/avr.h: Fix typos. * config/avr/avr.md: Fix typos. * config/avr/builtins.def: Fix typos. * config/c6x/c6x.c: Fix typos. * config/cr16/cr16.c: Fix typos. * config/cr16/cr16.md: Fix typos. * config/cris/cris.md: Fix typos. * config/darwin.c: Fix typos. * config/darwin.opt: Fix typos. * config/i386/i386-c.c: Fix typos. * config/i386/i386.c: Fix typos. * config/ia64/ia64.c: Fix typos. * config/m68k/cf.md: Fix typos. * config/mep/mep.c: Fix typos. * config/microblaze/microblaze.c: Fix typos. * config/microblaze/microblaze.h: Fix typos. * config/mn10300/mn10300.c: Fix typos. * config/mn10300/mn10300.md: Fix typos. * config/pa/pa.c: Fix typos. * config/picochip/picochip.h: Fix typos. * config/rs6000/a2.md: Fix typos. * config/rs6000/rs6000.c: Fix typos. * config/rs6000/vector.md: Fix typos. * config/rx/rx.md: Fix typos. * config/rx/rx.opt: Fix typos. * config/s390/2097.md: Fix typos. * config/s390/s390.c: Fix typos. * config/s390/s390.h: Fix typos. * config/sh/sh.c: Fix typos. * config/sh/sh.md: Fix typos. * config/sparc/sync.md: Fix typos. * config/spu/spu.c: Fix typos. * config/spu/spu.md: Fix typos. * config/vms/vms.c: Fix typos. * config/vxworks-dummy.h: Fix typos. * config/vxworks.h: Fix typos. * cselib.c: Fix typos. * df-scan.c: Fix typos. * df.h: Fix typos. * doc/extend.texi: Fix typos. * doc/install.texi: Fix typos. * doc/invoke.texi: Fix typos. * doc/md.texi: Fix typos. * doc/plugins.texi: Fix typos. * doc/rtl.texi: Fix typos. * dse.c: Fix typos. * dwarf2asm.c: Fix typos. * dwarf2out.c: Fix typos. * except.h: Fix typos. * expr.c: Fix typos. * fold-const.c: Fix typos. * gcc.c: Fix typos. * gcse.c: Fix typos. * genautomata.c: Fix typos. * gengtype-state.c: Fix typos. * gengtype.c: Fix typos. * genhooks.c: Fix typos. * gimple-fold.c: Fix typos. * gimple-pretty-print.c: Fix typos. * gimple.c: Fix typos. * gimple.h: Fix typos. * gimplify.c: Fix typos. * graphite-interchange.c: Fix typos. * graphite-sese-to-poly.c: Fix typos. * ifcvt.c: Fix typos. * input.c: Fix typos. * ipa-cp.c: Fix typos. * ipa-inline-analysis.c: Fix typos. * ipa-inline-transform.c: Fix typos. * ipa-inline.c: Fix typos. * ipa-pure-const.c: Fix typos. * ipa-ref.h: Fix typos. * ipa-reference.c: Fix typos. * ipa-utils.c: Fix typos. * ipa.c: Fix typos. * ira-emit.c: Fix typos. * ira-lives.c: Fix typos. * lto-streamer.c: Fix typos. * lto-streamer.h: Fix typos. * lto-wrapper.c: Fix typos. * mcf.c: Fix typos. * mode-switching.c: Fix typos. * modulo-sched.c: Fix typos. * plugin.c: Fix typos. * postreload.c: Fix typos. * sched-deps.c: Fix typos. * sel-sched-ir.c: Fix typos. * sel-sched-ir.h: Fix typos. * sel-sched.c: Fix typos. * sese.c: Fix typos. * stor-layout.c: Fix typos. * target-hooks-macros.h: Fix typos. * target.def: Fix typos. * trans-mem.c: Fix typos. * tree-eh.c: Fix typos. * tree-predcom.c: Fix typos. * tree-sra.c: Fix typos. * tree-ssa-address.c: Fix typos. * tree-ssa-loop-ivopts.c: Fix typos. * tree-ssa-loop-niter.c: Fix typos. * tree-ssa-math-opts.c: Fix typos. * tree-ssa-pre.c: Fix typos. * tree-ssa-propagate.c: Fix typos. * tree-ssa-reassoc.c: Fix typos. * tree-ssa-sccvn.c: Fix typos. * tree-ssa-ter.c: Fix typos. * tree-ssa-uninit.c: Fix typos. * tree-ssanames.c: Fix typos. * tree-vect-generic.c: Fix typos. * tree-vect-slp.c: Fix typos. * tree.c: Fix typos. * tree.h: Fix typos. * varasm.c: Fix typos. * varpool.c: Fix typos. From-SVN: r187959
2012-05-29 16:14:06 +02:00
it may be tempting to not necessarily give up because the copy will be
output elsewhere when corresponding vtable is output.
This is however not possible - ABI specify that COMDATs are output in
units where they are used and when the other unit was compiled with LTO
it is possible that vtable was kept public while the function itself
was privatized. */
IPA C++ refactoring 4/N * cgraph.h (symtab_node): (bool needed_p (void)): created from decide_is_symbol_needed (bool referred_to_p (void)): created from referred_to_p (static cgraph_node *get_for_asmname (tree asmname)): created from symtab_node_for_asm * cgraph.h (cgraph_node): (void assemble_thunks_and_aliases (void)): created from assemble_thunks_and_aliases (void expand (void)): created from expand_function (static void finalize_function (tree, bool)): created from cgraph_finalize_function (static cgraph_local_info *local_info (tree decl)): created from cgraph_local_info (static cgraph_global_info *global_info (tree)): created from cgraph_global_info (static cgraph_rtl_info *rtl_info (tree)): created from cgraph_rtl_info * cgraph.h (varpool_node): (static void add (tree decl): created from varpool_add_new_variable * cgraph.h (cgraph_edge): void remove (void); (void remove_caller (void)): created from cgraph_edge_remove_caller (void remove_callee (void)): created from cgraph_edge_remove_callee (void set_call_stmt (gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt (void redirect_callee (cgraph_node *n)): created from cgraph_redirect_edge_callee (cgraph_edge *make_direct (cgraph_node *callee)): created from cgraph_make_edge_direct (cgraph_edge *make_speculative (cgraph_node *n2, gcov_type direct_count, gimple redirect_call_stmt_to_callee (void)): created from cgraph_turn_edge_to_speculative (void speculative_call_info (cgraph_edge *&direct, cgraph_edge *&indirect, ipa_ref *&reference)): created from cgraph_speculative_call_info (cgraph_edge * clone (cgraph_node *n, gimple call_stmt, unsigned stmt_uid, gcov_type count_scale, int freq_scale, bool update_original)): created from cgraph_clone_edge (cgraph_edge *resolve_speculation (tree callee_decl)): created from cgraph_resolve_speculation (bool cannot_lead_to_return_p (void)): created from cannot_lead_to_return_p (bool recursive_p (void)): created from cgraph_edge_recursive_p (bool maybe_hot_p (void)): created from cgraph_maybe_hot_edge_p (static unsigned int rebuild_edges (void)): created from rebuild_cgraph_edges (static void rebuild_references (void)): created from cgraph_rebuild_references * cgraph.h (symbol_table): (create_reference): renamed from add_reference (maybe_create_reference): renamed from maybe_add_reference (void register_symbol (symtab_node *node)): new function (void clear_asm_symbols (void)): new function (void unregister (symtab_node *node)): new function (void release_symbol (cgraph_node *node, int uid)): new function (cgraph_node * allocate_cgraph_symbol (void)): new function (void initialize (void)): created from cgraph_init (symtab_node *first_symbol (void)):new function (asm_node *first_asm_symbol (void)):new function (symtab_node *first_defined_symbol (void)):new function (varpool_node *first_variable (void)):new function (varpool_node *next_variable (varpool_node *node)):new function (varpool_node *first_static_initializer (void)):new function (varpool_node *next_static_initializer (varpool_node *node)):new function (varpool_node *first_defined_variable (void)):new function (varpool_node *next_defined_variable (varpool_node *node)):new function (cgraph_node *first_defined_function (void)):new function (cgraph_node *next_defined_function (cgraph_node *node)):new function (cgraph_node *first_function (void)):new function (cgraph_node *next_function (cgraph_node *node)):new function (cgraph_node *first_function_with_gimple_body (void)):new function (asm_node *finalize_toplevel_asm (tree asm_str)): created from add_asm_node (bool remove_unreachable_nodes (bool before_inlining_p, FILE *file)): created from symtab_remove_unreachable_nodes (void remove_unreferenced_decls (void)): created from varpool_remove_unreferenced_decls (void process_new_functions (void)): created from cgraph_process_new_functions (void process_same_body_aliases (void)): created from cgraph_process_same_body_aliases (bool output_variables (void)): created from varpool_node::output_variables (void output_asm_statements (void)): created from output_asm_statements (void finalize_compilation_unit (void)): created from finalize_compilation_unit (void compile (void)): created from compile (void output_weakrefs (void)): created from output_weakrefs (cgraph_node *create_empty (void)): created from cgraph_node::create_empty (cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_node::create_edge (void free_edge (cgraph_edge *e)): created from cgraph_free_edge (cgraph_node *next_function_with_gimple_body (cgraph_node *node)): created from cgraph_next_function_with_gimple_body (void remove_edge_removal_hook (cgraph_edge_hook_list *)): created from cgraph_remove_edge_removal_hook (cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook, void *)): created from cgraph_add_node_removal_hook (void remove_cgraph_removal_hook (cgraph_node_hook_list *)): created from cgraph_remove_node_removal_hook (varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook, void *)): created from varpool_add_node_removal_hook (void remove_varpool_removal_hook (varpool_node_hook_list *)): created from varpool_remove_node_removal_hook (cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook, void *)): created from cgraph_add_function_insertion_hook (void remove_cgraph_insertion_hook (cgraph_node_hook_list *)): created from cgraph_remove_function_insertion_hook (varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook, void *)): created from varpool_add_variable_insertion_hook (void remove_varpool_insertion_hook (varpool_node_hook_list *)): created from varpool_remove_variable_insertion_hook (cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook, void *)): created from cgraph_add_edge_duplication_hook (void remove_edge_duplication_hook (cgraph_2edge_hook_list *)): created from cgraph_remove_edge_duplication_hook (cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook, void *)): created from cgraph_add_node_duplication_hook (void remove_cgraph_duplication_hook (cgraph_2node_hook_list *)): created from cgraph_remove_node_duplication_hook (void call_edge_removal_hooks (cgraph_edge *e)): created from cgraph_call_edge_removal_hooks (void call_cgraph_insertion_hooks (cgraph_node *node)): created from call_function_insertion_hooks (void call_cgraph_removal_hooks (cgraph_node *node)): created from cgraph_call_node_removal_hooks (void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2)): created from cgraph_node::call_duplication_hooks (void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)): created from cgraph_call_edge_duplication_hooks (void call_varpool_removal_hooks (varpool_node *node)): created from varpool_call_node_removal_hooks (void call_varpool_insertion_hooks (varpool_node *node)): created from varpool_call_variable_insertion_hooks (void insert_to_assembler_name_hash (symtab_node *node, bool with_clones)): created from insert_to_assembler_name_hash (void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones)): created from unlink_from_assembler_name_hash (void symtab_prevail_in_asm_name_hash (symtab_node *node)): created from symtab_prevail_in_asm_name_hash (void symtab_initialize_asm_name_hash (void)): created from symtab_initialize_asm_name_hash (void change_decl_assembler_name (tree decl, tree name)): created from change_decl_assembler_name (void materialize_all_clones (void)): created from cgraph_materialize_all_clones (static hashval_t decl_assembler_name_hash (const_tree asmname)): created from decl_assembler_name_hash (static bool decl_assembler_name_equal (tree decl, const_tree asmname)): created from decl_assembler_name_equal (static hashval_t hash_node_by_assembler_name (const void *p)): created from hash_node_by_assembler_name (static int eq_assembler_name (const void *p1, const void *p2)): created from eq_assembler_name From-SVN: r214422
2014-08-25 15:01:47 +02:00
if (!symtab->function_flags_ready)
return true;
IPA C++ refactoring 1/N * cgraph.h (symtab_node): (void register_symbol (void)): created from symtab_register_node (void remove (void)): created from symtab_remove_node (void dump (FILE *f)): created from dump_symtab_node (void DEBUG_FUNCTION debug (void)): created from debug_symtab_node (void DEBUG_FUNCTION verify (void)): created from verify_symtab_node (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type)): created from add_reference (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type, gimple stmt)): created from add_reference (struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type, gimple stmt)): created from maybe_add_reference (bool semantically_equivalent_p (symtab_node *target)): created from symtab_semantically_equivalent_p (void remove_from_same_comdat_group (void)): created from remove_from_same_comdat_group (void add_to_same_comdat_group (symtab_node *old_node)): created from symtab_add_to_same_comdat_group (void dissolve_same_comdat_group_list (void)): created from symtab_dissolve_same_comdat_group_list (bool used_from_object_file_p (void)): created from symtab_used_from_object_file_p (symtab_node *ultimate_alias_target (enum availability *avail = NULL)): created from symtab_alias_ultimate_target (inline symtab_node *next_defined_symbol (void)): created from symtab_next_defined_symbol (bool resolve_alias (symtab_node *target)): created from symtab_resolve_alias (bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), void *data, bool include_overwrite)): created from symtab_for_node_and_aliases (symtab_node *noninterposable_alias (void)): created from symtab_nonoverwritable_alias (inline symtab_node *get_alias_target (void)): created from symtab_alias_target (void set_section (const char *section)): created from set_section_1 (enum availability get_availability (void)): created from symtab_node_availability (void make_decl_local (void)): created from symtab_make_decl_local (bool real_symbol_p (void)): created from symtab_read_node (can_be_discarded_p (void)): created from symtab_can_be_discarded (inline bool comdat_local_p (void)): created from symtab_comdat_local_p (inline bool in_same_comdat_group_p (symtab_node *target)): created from symtab_in_same_comdat_p; (bool address_taken_from_non_vtable_p (void)): created from address_taken_from_non_vtable_p (static inline symtab_node *get (const_tree decl)): created from symtab_get_node (static void dump_table (FILE *)): created from dump_symtab (static inline DEBUG_FUNCTION void debug_symtab (void)): created from debug_symtab (static DEBUG_FUNCTION void verify_symtab_nodes (void)): created from verify_symtab (static bool used_from_object_file_p_worker (symtab_node *node)): created from symtab_used_from_object_file_p (void dump_base (FILE *)): created from dump_symtab_base (bool DEBUG_FUNCTION verify_base (void)): created from verify_symtab_base (void unregister (void)): created from symtab_unregister_node (struct symbol_priority_map *priority_info (void)): created from symtab_priority_info (static bool set_implicit_section (symtab_node *n, void *)): created from set_implicit_section (static bool noninterposable_alias (symtab_node *node, void *data)): created from symtab_nonoverwritable_alias_1 * cgraph.h (cgraph_node): (bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL)): created from cgraph_remove_node_and_inline_clones (void record_stmt_references (gimple stmt)): created from ipa_record_stmt_references (void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt_including_clones (cgraph_node *function_symbol (enum availability *avail = NULL)): created from cgraph_function_node (cgraph_node *create_clone (tree decl, gcov_type count, int freq, bool update_original, vec<cgraph_edge *> redirect_callers, bool call_duplication_hook, struct cgraph_node *new_inlined_to, bitmap args_to_skip)): created from cgraph_create_clone (cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, const char * suffix)): created from cgraph_create_virtual_clone (cgraph_node *find_replacement (void)): created from cgraph_find_replacement_node (cgraph_node *create_version_clone (tree new_decl, vec<cgraph_edge *> redirect_callers, bitmap bbs_to_copy)): created from cgraph_copy_node_for_versioning (cgraph_node *create_version_clone_with_body (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name)): created from cgraph_function_version_info (struct cgraph_function_version_info *insert_new_function_version (void)): created from insert_new_cgraph_node_version (struct cgraph_function_version_info *function_version (void)): created from get_cgraph_node_version (void analyze (void)): created from analyze_function (cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value, tree virtual_offset, tree real_alias) cgraph_add_thunk (inline cgraph_node *get_alias_target (void)): created from cgraph_alias_target (cgraph_node *ultimate_alias_target (availability *availability = NULL)): created from cgraph_function_or_thunk_node (bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)): created from expand_thunk (void reset (void)): created from cgraph_reset_node (void create_wrapper (cgraph_node *target)): created from cgraph_make_wrapper (void DEBUG_FUNCTION verify_node (void)): created from verify_cgraph_node (void remove (void)): created from cgraph_remove_node (void dump (FILE *f)): created from dump_cgraph_node (void DEBUG_FUNCTION debug (void)): created from debug_cgraph_node (bool get_body (void)): created from cgraph_get_body (void release_body (void)): created from cgraph_release_function_body (void unnest (void)): created from cgraph_unnest_node (void make_local (void)): created from cgraph_make_node_local (void mark_address_taken (void)): created from cgraph_mark_address_taken_node (struct cgraph_edge *create_edge (cgraph_node *callee, gimple call_stmt, gcov_type count, int freq)): created from cgraph_create_edge (struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, gcov_type count, int freq)): created from cgraph_create_indirect_edge (void create_edge_including_clones (struct cgraph_node *callee, gimple old_stmt, gimple stmt, gcov_type count, int freq, cgraph_inline_failed_t reason)): created from cgraph_create_edge_including_clones (cgraph_edge *get_edge (gimple call_stmt)): created from cgraph_edge (vec<cgraph_edge *> collect_callers (void)): created from collect_callers_of_node (void remove_callers (void)): created from cgraph_node_remove_callers (void remove_callees (void)): created from cgraph_node_remove_callees (enum availability get_availability (void)): created from cgraph_function_body_availability (void set_nothrow_flag (bool nothrow)): created from cgraph_set_nothrow_flag (void set_const_flag (bool readonly, bool looping)): created from cgraph_set_const_flag (void set_pure_flag (bool pure, bool looping)): created from cgraph_set_pure_flag (void call_duplication_hooks (cgraph_node *node2)): created from cgraph_call_node_duplication_hooks (bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, void *), void *data, bool include_overwritable)): created from cgraph_for_node_and_aliases (bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, void *data), void *data, bool include_overwritable)): created from cgraph_for_node_thunks_and_aliases (void call_function_insertion_hooks (void)): created from cgraph_call_function_insertion_hooks (inline void mark_force_output (void)): created from cgraph_mark_force_output_node (bool local_p (void)): created from cgraph_local_node (bool can_be_local_p (void)): created from cgraph_node_can_be_local_p (bool cannot_return_p (void)): created from cgraph_node_cannot_return (bool only_called_directly_p (void)): created from cgraph_only_called_directly_p (inline bool only_called_directly_or_aliased_p (void)): created from cgraph_only_called_directly_or_aliased_p (bool will_be_removed_from_program_if_no_direct_calls_p (void)): created from cgraph_will_be_removed_from_program_if_no_direct_calls (bool can_remove_if_no_direct_calls_and_refs_p (void)): created from cgraph_can_remove_if_no_direct_calls_and_refs_p (bool can_remove_if_no_direct_calls_p (void)): created from cgraph_can_remove_if_no_direct_calls_p (inline bool has_gimple_body_p (void)): created from cgraph_function_with_gimple_body_p (bool optimize_for_size_p (void)): created from cgraph_optimize_for_size_p (static void dump_cgraph (FILE *f)): created from dump_cgraph (static inline void debug_cgraph (void)): created from debug_cgraph (static void record_function_versions (tree decl1, tree decl2)): created from record_function_versions (static void delete_function_version (tree decl)): created from delete_function_version (static void add_new_function (tree fndecl, bool lowered)): created from cgraph_add_new_function (static inline cgraph_node *get (const_tree decl)): created from cgraph_get_node (static cgraph_node * create (tree decl)): created from cgraph_create_node (static cgraph_node * create_empty (void)): created from cgraph_create_empty_node (static cgraph_node * get_create (tree)): created from cgraph_get_create_node (static cgraph_node *get_for_asmname (tree asmname)): created from cgraph_node_for_asm (static cgraph_node * create_same_body_alias (tree alias, tree decl)): created from cgraph_same_body_alias (static bool used_from_object_file_p_worker (cgraph_node *node, void *): new function (static bool non_local_p (cgraph_node *node, void *)): created from cgraph_non_local_node_p_1 (static void DEBUG_FUNCTION verify_cgraph_nodes (void)): created from verify_cgraph (static bool make_local (cgraph_node *node, void *)): created from cgraph_make_node_local (static cgraph_node *create_alias (tree alias, tree target)): created from cgraph_create_function_alias (static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_create_edge_1 * cgraph.h (varpool_node): (void remove (void)): created from varpool_remove_node (void dump (FILE *f)): created from dump_varpool_node From-SVN: r212982
2014-07-24 14:07:13 +02:00
snode = symtab_node::get (decl);
if (!snode
|| ((!snode->definition || DECL_EXTERNAL (decl))
&& (!snode->in_other_partition
|| (!snode->forced_by_abi && !snode->force_output))))
return false;
node = dyn_cast <cgraph_node *> (snode);
return !node || !node->global.inlined_to;
}
/* CVAL is value taken from DECL_INITIAL of variable. Try to transform it into
acceptable form for is_gimple_min_invariant.
FROM_DECL (if non-NULL) specify variable whose constructor contains CVAL. */
tree
canonicalize_constructor_val (tree cval, tree from_decl)
{
tree orig_cval = cval;
STRIP_NOPS (cval);
if (TREE_CODE (cval) == POINTER_PLUS_EXPR
&& TREE_CODE (TREE_OPERAND (cval, 1)) == INTEGER_CST)
{
tree ptr = TREE_OPERAND (cval, 0);
if (is_gimple_min_invariant (ptr))
cval = build1_loc (EXPR_LOCATION (cval),
ADDR_EXPR, TREE_TYPE (ptr),
fold_build2 (MEM_REF, TREE_TYPE (TREE_TYPE (ptr)),
ptr,
fold_convert (ptr_type_node,
TREE_OPERAND (cval, 1))));
}
if (TREE_CODE (cval) == ADDR_EXPR)
{
tree base = NULL_TREE;
if (TREE_CODE (TREE_OPERAND (cval, 0)) == COMPOUND_LITERAL_EXPR)
{
base = COMPOUND_LITERAL_EXPR_DECL (TREE_OPERAND (cval, 0));
if (base)
TREE_OPERAND (cval, 0) = base;
}
else
base = get_base_address (TREE_OPERAND (cval, 0));
if (!base)
return NULL_TREE;
if ((TREE_CODE (base) == VAR_DECL
|| TREE_CODE (base) == FUNCTION_DECL)
&& !can_refer_decl_in_current_unit_p (base, from_decl))
return NULL_TREE;
if (TREE_CODE (base) == VAR_DECL)
tree-dfa.c (referenced_var_lookup): Remove. 2012-08-02 Richard Guenther <rguenther@suse.de> * tree-dfa.c (referenced_var_lookup): Remove. (find_referenced_vars): Remove. (pass_referenced_vars): Likewise. (make_rename_temp): Do not add referenced vars. (dump_referenced_vars): Remove. (debug_referenced_vars): Likewise. (dump_dfa_stats): Do not dump referenced var stats. (find_vars_r): Remove. (find_referenced_vars_in): Likewise. (referenced_var_check_and_insert): Likewise. (add_referenced_var_1): Likewise. (remove_referenced_var): Likewise. * tree-flow.h (referenced_var_lookup): Likewise. (struct gimple_df): Remove referenced_vars member. (typedef referenced_var_iterator): Remove. (FOR_EACH_REFERENCED_VAR): Likewise. (num_referenced_vars): Likewise. (debug_referenced_vars, dump_referenced_vars): Likewise. (add_referenced_var_1, add_referenced_var): Likewise. (remove_referenced_var): Likewise. (find_referenced_vars_in): Likewise. * tree-flow-inline.h (gimple_referenced_vars): Remove. (first_referenced_var): Likewise. (end_referenced_vars_p): Likewise. (next_referenced_var): Likewise. * cfgexpand.c (update_alias_info_with_stack_vars): Remove assert. * gimple-pretty-print.c (pp_points_to_solution): Dump UIDs unconditionally. * tree-into-ssa.c (dump_decl_set): Likewise. (pass_build_ssa): Do not require PROP_referenced_vars. * tree-ssa.c (target_for_debug_bind): Virtual operands are not suitable, but all register type vars are. (init_tree_ssa): Do not allocate referenced vars. (delete_tree_ssa): Do not free referenced vars. * cgraphunit.c (init_lowered_empty_function): Do not set PROP_referenced_vars. (assemble_thunk): Do not add referenced vars. * gimple-fold.c (canonicalize_constructor_val): Likewise. (gimplify_and_update_call_from_tree): Likewise. * gimple-streamer-in.c (input_bb): Likewise. * passes.c (init_optimization_passes): Do not run pass_referenced_vars. (dump_properties): Do not dump PROP_referenced_vars. * tree-inline.c (remap_decl): Do not add referenced vars. (remap_gimple_op_r): Likewise. (copy_tree_body_r): Likewise. (copy_bb): Likewise. (setup_one_parameter): Likewise. (declare_return_variable): Likewise. (copy_decl_for_dup_finish): Likewise. (copy_arguments_for_versioning): Likewise. (tree_function_versioning): Likewise. * tree-pass.h (PROP_referenced_vars): Remove. (pass_referenced_vars): Likewise. * tree-profile.c (gimple_gen_edge_profiler): Do not add referenced vars. (gimple_gen_interval_profiler): Likewise. (gimple_gen_pow2_profiler): Likewise. (gimple_gen_one_value_profiler): Likewise. (gimple_gen_ic_profiler): Likewise. (gimple_gen_average_profiler): Likewise. (gimple_gen_ior_profiler): Likewise. * tree-ssa-live.c (remove_unused_locals): Do not touch referenced vars. * tree-cfg.c (replace_ssa_name): Do not add referenced vars. (move_stmt_op): Likewise. * tree-ssa-operands.c (create_vop_var): Likewise. * gimple-low.c (record_vars_into): Likewise. * gimplify.c (gimple_regimplify_operands): Likewise. (force_gimple_operand_1): Likewise. * omp-low.c (expand_omp_for_generic): Likewise. (expand_omp_for_static_chunk): Likewise. (expand_omp_atomic_pipeline): Likewise. * graphite-clast-to-gimple.c (graphite_create_new_loop): Likewise. (translate_clast_assignment): Likewise. * graphite-sese-to-poly.c (create_zero_dim_array): Likewise. (handle_scalar_deps_crossing_scop_limits): Likewise. * ipa-prop.c (ipa_modify_formal_parameters): Likewise. * ipa-split.c (split_function): Likewise. * matrix-reorg.c (transform_access_sites): Likewise. * trans-mem.c (tm_log_add): Likewise. (ipa_tm_insert_gettmclone_call): Likewise. * tree-complex.c (create_one_component_var): Likewise. * tree-if-conv.c (ifc_temp_var): Likewise. * tree-parloops.c (take_address_of): Likewise. (initialize_reductions): Likewise. (separate_decls_in_region_name): Likewise. (create_call_for_reduction_1): Likewise. (separate_decls_in_region): Likewise. * tree-predcom.c (predcom_tmp_var): Likewise. (reassociate_to_the_same_stmt): Likewise. * tree-sra.c (build_ref_for_offset): Likewise. (create_access_replacement): Likewise. (get_replaced_param_substitute): Likewise. (sra_ipa_reset_debug_stmts): Likewise. * tree-ssa-loop-im.c (rewrite_reciprocal): Likewise. (rewrite_bittest): Likewise. * tree-ssa-loop-ivopts.c (create_new_iv): Likewise. * tree-ssa-loop-manip.c (create_iv): Likewise. (tree_transform_and_unroll_loop): Likewise. * tree-ssa-math-opts.c (powi_as_mults): Likewise. (build_and_insert_call): Likewise. (gimple_expand_builtin_cabs): Likewise. (execute_optimize_bswap): Likewise. * tree-ssa-phiopt.c (conditional_replacement): Likewise. (abs_replacement): Likewise. (cond_store_replacement): Likewise. (cond_if_else_store_replacement_1): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise. * tree-ssa-pre.c (get_representative_for): Likewise. (create_expression_by_pieces): Likewise. (insert_into_preds_of_block): Likewise. * tree-ssa-propagate.c (update_call_from_tree): Likewise. * tree-ssa-reassoc.c (undistribute_ops_list): Likewise. (eliminate_redundant_comparison): Likewise. (rewrite_expr_tree_parallel): Likewise. (get_reassoc_pow_ssa_name): Likewise. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-switch-conversion.c (emit_case_bit_tests): Likewise. (build_arrays): Likewise. * tree-tailcall.c (adjust_return_value_with_ops): Likewise. (create_tailcall_accumulator): Likewise. * tree-vect-data-refs.c (vect_get_new_vect_var): Likewise. (vect_create_addr_base_for_vector_ref): Likewise. (vect_permute_store_chain): Likewise. (vect_permute_load_chain): Likewise. * tree-vect-generic.c (expand_vector_divmod): Likewise. * tree-vect-loop-manip.c (set_prologue_iterations): Likewise. (vect_build_loop_niters): Likewise. (vect_generate_tmps_on_preheader): Likewise. (vect_update_ivs_after_vectorizer): Likewise. (vect_gen_niters_for_prolog_loop): Likewise. (vect_do_peeling_for_alignment): Likewise. (vect_create_cond_for_align_checks): Likewise. * tree-vect-patterns.c (vect_recog_temp_ssa_var): Likewise. (vect_handle_widen_op_by_const): Likewise. (vect_operation_fits_smaller_type): Likewise. (vect_recog_over_widening_pattern): Likewise. * tree-vect-stmts.c (vect_init_vector): Likewise. * gcc.dg/torture/pta-callused-1.c: Adjust. * gcc.dg/torture/pta-ptrarith-3.c: Likewise. * gcc.dg/torture/ssa-pta-fn-1.c: Likewise. * gcc.dg/tree-ssa/alias-19.c: Likewise. * gcc.dg/tree-ssa/pta-escape-1.c: Likewise. * gcc.dg/tree-ssa/pta-escape-2.c: Likewise. * gcc.dg/tree-ssa/pta-escape-3.c: Likewise. * gcc.dg/tree-ssa/pta-ptrarith-1.c: Likewise. * gcc.dg/tree-ssa/pta-ptrarith-2.c: Likewise. From-SVN: r190067
2012-08-02 10:14:54 +02:00
TREE_ADDRESSABLE (base) = 1;
else if (TREE_CODE (base) == FUNCTION_DECL)
{
/* Make sure we create a cgraph node for functions we'll reference.
They can be non-existent if the reference comes from an entry
of an external vtable for example. */
IPA C++ refactoring 1/N * cgraph.h (symtab_node): (void register_symbol (void)): created from symtab_register_node (void remove (void)): created from symtab_remove_node (void dump (FILE *f)): created from dump_symtab_node (void DEBUG_FUNCTION debug (void)): created from debug_symtab_node (void DEBUG_FUNCTION verify (void)): created from verify_symtab_node (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type)): created from add_reference (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type, gimple stmt)): created from add_reference (struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type, gimple stmt)): created from maybe_add_reference (bool semantically_equivalent_p (symtab_node *target)): created from symtab_semantically_equivalent_p (void remove_from_same_comdat_group (void)): created from remove_from_same_comdat_group (void add_to_same_comdat_group (symtab_node *old_node)): created from symtab_add_to_same_comdat_group (void dissolve_same_comdat_group_list (void)): created from symtab_dissolve_same_comdat_group_list (bool used_from_object_file_p (void)): created from symtab_used_from_object_file_p (symtab_node *ultimate_alias_target (enum availability *avail = NULL)): created from symtab_alias_ultimate_target (inline symtab_node *next_defined_symbol (void)): created from symtab_next_defined_symbol (bool resolve_alias (symtab_node *target)): created from symtab_resolve_alias (bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), void *data, bool include_overwrite)): created from symtab_for_node_and_aliases (symtab_node *noninterposable_alias (void)): created from symtab_nonoverwritable_alias (inline symtab_node *get_alias_target (void)): created from symtab_alias_target (void set_section (const char *section)): created from set_section_1 (enum availability get_availability (void)): created from symtab_node_availability (void make_decl_local (void)): created from symtab_make_decl_local (bool real_symbol_p (void)): created from symtab_read_node (can_be_discarded_p (void)): created from symtab_can_be_discarded (inline bool comdat_local_p (void)): created from symtab_comdat_local_p (inline bool in_same_comdat_group_p (symtab_node *target)): created from symtab_in_same_comdat_p; (bool address_taken_from_non_vtable_p (void)): created from address_taken_from_non_vtable_p (static inline symtab_node *get (const_tree decl)): created from symtab_get_node (static void dump_table (FILE *)): created from dump_symtab (static inline DEBUG_FUNCTION void debug_symtab (void)): created from debug_symtab (static DEBUG_FUNCTION void verify_symtab_nodes (void)): created from verify_symtab (static bool used_from_object_file_p_worker (symtab_node *node)): created from symtab_used_from_object_file_p (void dump_base (FILE *)): created from dump_symtab_base (bool DEBUG_FUNCTION verify_base (void)): created from verify_symtab_base (void unregister (void)): created from symtab_unregister_node (struct symbol_priority_map *priority_info (void)): created from symtab_priority_info (static bool set_implicit_section (symtab_node *n, void *)): created from set_implicit_section (static bool noninterposable_alias (symtab_node *node, void *data)): created from symtab_nonoverwritable_alias_1 * cgraph.h (cgraph_node): (bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL)): created from cgraph_remove_node_and_inline_clones (void record_stmt_references (gimple stmt)): created from ipa_record_stmt_references (void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt_including_clones (cgraph_node *function_symbol (enum availability *avail = NULL)): created from cgraph_function_node (cgraph_node *create_clone (tree decl, gcov_type count, int freq, bool update_original, vec<cgraph_edge *> redirect_callers, bool call_duplication_hook, struct cgraph_node *new_inlined_to, bitmap args_to_skip)): created from cgraph_create_clone (cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, const char * suffix)): created from cgraph_create_virtual_clone (cgraph_node *find_replacement (void)): created from cgraph_find_replacement_node (cgraph_node *create_version_clone (tree new_decl, vec<cgraph_edge *> redirect_callers, bitmap bbs_to_copy)): created from cgraph_copy_node_for_versioning (cgraph_node *create_version_clone_with_body (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name)): created from cgraph_function_version_info (struct cgraph_function_version_info *insert_new_function_version (void)): created from insert_new_cgraph_node_version (struct cgraph_function_version_info *function_version (void)): created from get_cgraph_node_version (void analyze (void)): created from analyze_function (cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value, tree virtual_offset, tree real_alias) cgraph_add_thunk (inline cgraph_node *get_alias_target (void)): created from cgraph_alias_target (cgraph_node *ultimate_alias_target (availability *availability = NULL)): created from cgraph_function_or_thunk_node (bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)): created from expand_thunk (void reset (void)): created from cgraph_reset_node (void create_wrapper (cgraph_node *target)): created from cgraph_make_wrapper (void DEBUG_FUNCTION verify_node (void)): created from verify_cgraph_node (void remove (void)): created from cgraph_remove_node (void dump (FILE *f)): created from dump_cgraph_node (void DEBUG_FUNCTION debug (void)): created from debug_cgraph_node (bool get_body (void)): created from cgraph_get_body (void release_body (void)): created from cgraph_release_function_body (void unnest (void)): created from cgraph_unnest_node (void make_local (void)): created from cgraph_make_node_local (void mark_address_taken (void)): created from cgraph_mark_address_taken_node (struct cgraph_edge *create_edge (cgraph_node *callee, gimple call_stmt, gcov_type count, int freq)): created from cgraph_create_edge (struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, gcov_type count, int freq)): created from cgraph_create_indirect_edge (void create_edge_including_clones (struct cgraph_node *callee, gimple old_stmt, gimple stmt, gcov_type count, int freq, cgraph_inline_failed_t reason)): created from cgraph_create_edge_including_clones (cgraph_edge *get_edge (gimple call_stmt)): created from cgraph_edge (vec<cgraph_edge *> collect_callers (void)): created from collect_callers_of_node (void remove_callers (void)): created from cgraph_node_remove_callers (void remove_callees (void)): created from cgraph_node_remove_callees (enum availability get_availability (void)): created from cgraph_function_body_availability (void set_nothrow_flag (bool nothrow)): created from cgraph_set_nothrow_flag (void set_const_flag (bool readonly, bool looping)): created from cgraph_set_const_flag (void set_pure_flag (bool pure, bool looping)): created from cgraph_set_pure_flag (void call_duplication_hooks (cgraph_node *node2)): created from cgraph_call_node_duplication_hooks (bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, void *), void *data, bool include_overwritable)): created from cgraph_for_node_and_aliases (bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, void *data), void *data, bool include_overwritable)): created from cgraph_for_node_thunks_and_aliases (void call_function_insertion_hooks (void)): created from cgraph_call_function_insertion_hooks (inline void mark_force_output (void)): created from cgraph_mark_force_output_node (bool local_p (void)): created from cgraph_local_node (bool can_be_local_p (void)): created from cgraph_node_can_be_local_p (bool cannot_return_p (void)): created from cgraph_node_cannot_return (bool only_called_directly_p (void)): created from cgraph_only_called_directly_p (inline bool only_called_directly_or_aliased_p (void)): created from cgraph_only_called_directly_or_aliased_p (bool will_be_removed_from_program_if_no_direct_calls_p (void)): created from cgraph_will_be_removed_from_program_if_no_direct_calls (bool can_remove_if_no_direct_calls_and_refs_p (void)): created from cgraph_can_remove_if_no_direct_calls_and_refs_p (bool can_remove_if_no_direct_calls_p (void)): created from cgraph_can_remove_if_no_direct_calls_p (inline bool has_gimple_body_p (void)): created from cgraph_function_with_gimple_body_p (bool optimize_for_size_p (void)): created from cgraph_optimize_for_size_p (static void dump_cgraph (FILE *f)): created from dump_cgraph (static inline void debug_cgraph (void)): created from debug_cgraph (static void record_function_versions (tree decl1, tree decl2)): created from record_function_versions (static void delete_function_version (tree decl)): created from delete_function_version (static void add_new_function (tree fndecl, bool lowered)): created from cgraph_add_new_function (static inline cgraph_node *get (const_tree decl)): created from cgraph_get_node (static cgraph_node * create (tree decl)): created from cgraph_create_node (static cgraph_node * create_empty (void)): created from cgraph_create_empty_node (static cgraph_node * get_create (tree)): created from cgraph_get_create_node (static cgraph_node *get_for_asmname (tree asmname)): created from cgraph_node_for_asm (static cgraph_node * create_same_body_alias (tree alias, tree decl)): created from cgraph_same_body_alias (static bool used_from_object_file_p_worker (cgraph_node *node, void *): new function (static bool non_local_p (cgraph_node *node, void *)): created from cgraph_non_local_node_p_1 (static void DEBUG_FUNCTION verify_cgraph_nodes (void)): created from verify_cgraph (static bool make_local (cgraph_node *node, void *)): created from cgraph_make_node_local (static cgraph_node *create_alias (tree alias, tree target)): created from cgraph_create_function_alias (static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_create_edge_1 * cgraph.h (varpool_node): (void remove (void)): created from varpool_remove_node (void dump (FILE *f)): created from dump_varpool_node From-SVN: r212982
2014-07-24 14:07:13 +02:00
cgraph_node::get_create (base);
}
/* Fixup types in global initializers. */
if (TREE_TYPE (TREE_TYPE (cval)) != TREE_TYPE (TREE_OPERAND (cval, 0)))
cval = build_fold_addr_expr (TREE_OPERAND (cval, 0));
if (!useless_type_conversion_p (TREE_TYPE (orig_cval), TREE_TYPE (cval)))
cval = fold_convert (TREE_TYPE (orig_cval), cval);
return cval;
}
if (TREE_OVERFLOW_P (cval))
return drop_tree_overflow (cval);
return orig_cval;
}
/* If SYM is a constant variable with known value, return the value.
NULL_TREE is returned otherwise. */
tree
get_symbol_constant_value (tree sym)
{
tree val = ctor_for_folding (sym);
if (val != error_mark_node)
{
if (val)
{
val = canonicalize_constructor_val (unshare_expr (val), sym);
if (val && is_gimple_min_invariant (val))
return val;
else
return NULL_TREE;
}
/* Variables declared 'const' without an initializer
have zero as the initializer if they may not be
overridden at link or run time. */
if (!val
&& (INTEGRAL_TYPE_P (TREE_TYPE (sym))
|| SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
builtins.c (fold_builtin_signbit): Use build_zero_cst instead of fold_convert. gcc/ * builtins.c (fold_builtin_signbit): Use build_zero_cst instead of fold_convert. * c-typeck.c (build_function_call_vec): Likewise. * cfgexpand.c (expand_debug_expr): Likewise. * cgraphunit.c (assemble_thunk): Likewise. * config/sparc/sparc.c (sparc_fold_builtin): Likewise. * fold-const.c (fold_unary_loc, fold_mult_zconjz): Likewise. (fold_binary_loc, fold_ternary_loc): Likewise. * gimple-fold.c (get_symbol_constant_value): Likewise. * gimple-low.c (lower_builtin_setjmp): Likewise. * gimple.c (gimple_cond_get_ops_from_tree): Likewise. * gimplify.c (gimplify_init_constructor): Likewise. * lambda.h (build_linear_expr): Likewise. * omp-low.c (omp_reduction_init): Likewise. * tree-inline.c (remap_ssa_name): Likewise. * tree-object-size.c (compute_object_sizes): Likewise. * tree-sra.c (init_subtree_with_zero): Likewise. (sra_ipa_modify_assign): Likewise. * tree-ssa-copy.c (propagate_tree_value_into_stmt): Likewise. * tree-ssa-reassoc.c (eliminate_duplicate_pair): Likewise. (eliminate_plus_minus_pair, eliminate_not_pairs): Likewise. (undistribute_ops_list): Likewise. * tree-ssa-sccvn.c (vn_reference_lookup_3): Likewise. * tree-vect-stmts.c (vectorizable_call): Likewise. * tree.c (build_vector_from_ctor, build_one_cst): Likewise. (build_zero_cst): Handle more cases directly. Update comment. gcc/cp/ * class.c (build_base_path, add_vcall_offset): Use build_zero_cst instead of fold_convert. * init.c (build_zero_init): Likewise. * typeck.c (cp_build_binary_op): Likewise. gcc/fortran/ * trans-decl.c (add_argument_checking): Use build_zero_cst instead of fold_convert. * trans-expr.c (gfc_conv_missing_dummy, fill_with_spaces): Likewise. * trans-stmt.c (gfc_trans_do): Likewise. From-SVN: r166227
2010-11-03 01:49:00 +01:00
return build_zero_cst (TREE_TYPE (sym));
}
return NULL_TREE;
}
/* Subroutine of fold_stmt. We perform several simplifications of the
memory reference tree EXPR and make sure to re-gimplify them properly
after propagation of constant addresses. IS_LHS is true if the
reference is supposed to be an lvalue. */
static tree
maybe_fold_reference (tree expr, bool is_lhs)
{
tree result;
if ((TREE_CODE (expr) == VIEW_CONVERT_EXPR
|| TREE_CODE (expr) == REALPART_EXPR
|| TREE_CODE (expr) == IMAGPART_EXPR)
&& CONSTANT_CLASS_P (TREE_OPERAND (expr, 0)))
return fold_unary_loc (EXPR_LOCATION (expr),
TREE_CODE (expr),
TREE_TYPE (expr),
TREE_OPERAND (expr, 0));
else if (TREE_CODE (expr) == BIT_FIELD_REF
&& CONSTANT_CLASS_P (TREE_OPERAND (expr, 0)))
return fold_ternary_loc (EXPR_LOCATION (expr),
TREE_CODE (expr),
TREE_TYPE (expr),
TREE_OPERAND (expr, 0),
TREE_OPERAND (expr, 1),
TREE_OPERAND (expr, 2));
if (!is_lhs
&& (result = fold_const_aggregate_ref (expr))
&& is_gimple_min_invariant (result))
return result;
return NULL_TREE;
}
/* Attempt to fold an assignment statement pointed-to by SI. Returns a
replacement rhs for the statement or NULL_TREE if no simplification
could be made. It is assumed that the operands have been previously
folded. */
static tree
fold_gimple_assign (gimple_stmt_iterator *si)
{
gimple stmt = gsi_stmt (*si);
enum tree_code subcode = gimple_assign_rhs_code (stmt);
location_t loc = gimple_location (stmt);
tree result = NULL_TREE;
switch (get_gimple_rhs_class (subcode))
{
case GIMPLE_SINGLE_RHS:
{
tree rhs = gimple_assign_rhs1 (stmt);
if (REFERENCE_CLASS_P (rhs))
return maybe_fold_reference (rhs, false);
else if (TREE_CODE (rhs) == OBJ_TYPE_REF)
{
tree val = OBJ_TYPE_REF_EXPR (rhs);
if (is_gimple_min_invariant (val))
return val;
else if (flag_devirtualize && virtual_method_call_p (rhs))
{
bool final;
vec <cgraph_node *>targets
= possible_polymorphic_call_targets (rhs, stmt, &final);
if (final && targets.length () <= 1 && dbg_cnt (devirt))
{
if (dump_enabled_p ())
{
location_t loc = gimple_location_safe (stmt);
dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
"resolving virtual function address "
"reference to function %s\n",
targets.length () == 1
? targets[0]->name ()
: "NULL");
}
if (targets.length () == 1)
{
val = fold_convert (TREE_TYPE (val),
build_fold_addr_expr_loc
(loc, targets[0]->decl));
STRIP_USELESS_TYPE_CONVERSION (val);
}
else
/* We can not use __builtin_unreachable here because it
can not have address taken. */
val = build_int_cst (TREE_TYPE (val), 0);
return val;
}
}
}
else if (TREE_CODE (rhs) == ADDR_EXPR)
{
re PR middle-end/42834 (memcpy folding overeager) 2010-07-01 Richard Guenther <rguenther@suse.de> PR middle-end/42834 PR middle-end/44468 * doc/gimple.texi (is_gimple_mem_ref_addr): Document. * doc/generic.texi (References to storage): Document MEM_REF. * tree-pretty-print.c (dump_generic_node): Handle MEM_REF. (print_call_name): Likewise. * tree.c (recompute_tree_invariant_for_addr_expr): Handle MEM_REF. (build_simple_mem_ref_loc): New function. (mem_ref_offset): Likewise. * tree.h (build_simple_mem_ref_loc): Declare. (build_simple_mem_ref): Define. (mem_ref_offset): Declare. * fold-const.c: Include tree-flow.h. (operand_equal_p): Handle MEM_REF. (build_fold_addr_expr_with_type_loc): Likewise. (fold_comparison): Likewise. (fold_unary_loc): Fold VIEW_CONVERT_EXPR <T1, MEM_REF <T2, ...>> to MEM_REF <T1, ...>. (fold_binary_loc): Fold MEM[&MEM[p, CST1], CST2] to MEM[p, CST1 + CST2], fold MEM[&a.b, CST2] to MEM[&a, offsetof (a, b) + CST2]. * tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Handle MEM_REF. (ptr_deref_may_alias_ref_p_1): Likewise. (ao_ref_base_alias_set): Properly differentiate base object for offset and TBAA. (ao_ref_init_from_ptr_and_size): Use MEM_REF. (indirect_ref_may_alias_decl_p): Handle MEM_REFs properly. (indirect_refs_may_alias_p): Likewise. (refs_may_alias_p_1): Likewise. Remove pointer SSA name def chasing code. (ref_maybe_used_by_call_p_1): Handle MEM_REF. (call_may_clobber_ref_p_1): Likewise. * dwarf2out.c (loc_list_from_tree): Handle MEM_REF. * expr.c (expand_assignment): Handle MEM_REF. (store_expr): Handle MEM_REFs from STRING_CSTs. (store_field): If expanding a MEM_REF of a non-addressable decl use bitfield operations. (get_inner_reference): Handle MEM_REF. (expand_expr_addr_expr_1): Likewise. (expand_expr_real_1): Likewise. * tree-eh.c (tree_could_trap_p): Handle MEM_REF. * alias.c (ao_ref_from_mem): Handle MEM_REF. (get_alias_set): Likewise. Properly handle VIEW_CONVERT_EXPRs. * tree-data-ref.c (dr_analyze_innermost): Handle MEM_REF. (dr_analyze_indices): Likewise. (dr_analyze_alias): Likewise. (object_address_invariant_in_loop_p): Likewise. * gimplify.c (mark_addressable): Handle MEM_REF. (gimplify_cond_expr): Build MEM_REFs. (gimplify_modify_expr_to_memcpy): Likewise. (gimplify_init_ctor_preeval_1): Handle MEM_REF. (gimple_fold_indirect_ref): Adjust. (gimplify_expr): Handle MEM_REF. Gimplify INDIRECT_REF to MEM_REF. * tree.def (MEM_REF): New tree code. * tree-dfa.c: Include toplev.h. (get_ref_base_and_extent): Handle MEM_REF. (get_addr_base_and_unit_offset): New function. * emit-rtl.c (set_mem_attributes_minus_bitpos): Handle MEM_REF. * gimple-fold.c (may_propagate_address_into_dereference): Handle MEM_REF. (maybe_fold_offset_to_array_ref): Allow possibly out-of bounds accesses if the array has just one dimension. Remove always true parameter. Do not require type compatibility here. (maybe_fold_offset_to_component_ref): Remove. (maybe_fold_stmt_indirect): Remove. (maybe_fold_reference): Remove INDIRECT_REF handling. Fold back to non-MEM_REF. (maybe_fold_offset_to_address): Simplify. Deal with type mismatches here. (maybe_fold_reference): Likewise. (maybe_fold_stmt_addition): Likewise. Also handle &ARRAY + I in addition to &ARRAY[0] + I. (fold_gimple_assign): Handle ADDR_EXPR of MEM_REFs. (gimple_get_relevant_ref_binfo): Handle MEM_REF. * cfgexpand.c (expand_debug_expr): Handle MEM_REF. * tree-ssa.c (useless_type_conversion_p): Make most pointer conversions useless. (warn_uninitialized_var): Handle MEM_REF. (maybe_rewrite_mem_ref_base): New function. (execute_update_addresses_taken): Implement re-writing of MEM_REFs to SSA form. * tree-inline.c (remap_gimple_op_r): Handle MEM_REF, remove INDIRECT_REF handling. (copy_tree_body_r): Handle MEM_REF. * gimple.c (is_gimple_addressable): Adjust. (is_gimple_address): Likewise. (is_gimple_invariant_address): ADDR_EXPRs of MEM_REFs with invariant base are invariant. (is_gimple_min_lval): Adjust. (is_gimple_mem_ref_addr): New function. (get_base_address): Handle MEM_REF. (count_ptr_derefs): Likewise. (get_base_loadstore): Likewise. * gimple.h (is_gimple_mem_ref_addr): Declare. (gimple_call_fndecl): Handle invariant MEM_REF addresses. * tree-cfg.c (verify_address): New function, split out from ... (verify_expr): ... here. Use for verifying ADDR_EXPRs and the address operand of MEM_REFs. Verify MEM_REFs. Reject INDIRECT_REFs. (verify_types_in_gimple_min_lval): Handle MEM_REF. Disallow INDIRECT_REF. Allow conversions. (verify_types_in_gimple_reference): Verify VIEW_CONVERT_EXPR of a register does not change its size. (verify_types_in_gimple_reference): Verify MEM_REF. (verify_gimple_assign_single): Disallow INDIRECT_REF. Handle MEM_REF. * tree-ssa-operands.c (opf_non_addressable, opf_not_non_addressable): New. (mark_address_taken): Handle MEM_REF. (get_indirect_ref_operands): Pass through opf_not_non_addressable. (get_asm_expr_operands): Pass opf_not_non_addressable. (get_expr_operands): Handle opf_[not_]non_addressable. Handle MEM_REF. Remove INDIRECT_REF handling. * tree-vrp.c: (check_array_ref): Handle MEM_REF. (search_for_addr_array): Likewise. (check_array_bounds): Likewise. (vrp_stmt_computes_nonzero): Adjust for MEM_REF. * tree-ssa-loop-im.c (for_each_index): Handle MEM_REF. (ref_always_accessed_p): Likewise. (gen_lsm_tmp_name): Likewise. Handle ADDR_EXPR. * tree-complex.c (extract_component): Do not handle INDIRECT_REF. Handle MEM_REF. * cgraphbuild.c (mark_load): Properly check for NULL result from get_base_address. (mark_store): Likewise. * tree-ssa-loop-niter.c (array_at_struct_end_p): Handle MEM_REF. * tree-loop-distribution.c (generate_builtin): Exchange INDIRECT_REF handling for MEM_REF. * tree-scalar-evolution.c (follow_ssa_edge_expr): Handle &MEM[ptr + CST] similar to POINTER_PLUS_EXPR. * builtins.c (stabilize_va_list_loc): Use the function ABI valist type if we couldn't canonicalize the argument type. Always dereference with the canonical va-list type. (maybe_emit_free_warning): Handle MEM_REF. (fold_builtin_memory_op): Simplify and handle MEM_REFs in folding memmove to memcpy. * builtins.c (fold_builtin_memory_op): Use ref-all types for all memcpy foldings. * omp-low.c (build_receiver_ref): Adjust for MEM_REF. (build_outer_var_ref): Likewise. (scan_omp_1_op): Likewise. (lower_rec_input_clauses): Likewise. (lower_lastprivate_clauses): Likewise. (lower_reduction_clauses): Likewise. (lower_copyprivate_clauses): Likewise. (expand_omp_atomic_pipeline): Likewise. (expand_omp_atomic_mutex): Likewise. (create_task_copyfn): Likewise. * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Handle MEM_REF. Remove old union trick. Initialize constant offsets. (ao_ref_init_from_vn_reference): Likewise. Do not handle INDIRECT_REF. Init base_alias_set properly. (vn_reference_lookup_3): Replace INDIRECT_REF handling with MEM_REF. (vn_reference_fold_indirect): Adjust for MEM_REFs. (valueize_refs): Fold MEM_REFs. Re-evaluate constant offset for ARRAY_REFs. (may_insert): Remove. (visit_reference_op_load): Do not test may_insert. (run_scc_vn): Remove parameter, do not fiddle with may_insert. * tree-ssa-sccvn.h (struct vn_reference_op_struct): Add a field to store the constant offset this op applies. (run_scc_vn): Adjust prototype. * cgraphunit.c (thunk_adjust): Adjust for MEM_REF. * tree-ssa-ccp.c (ccp_fold): Replace INDIRECT_REF folding with MEM_REF. Propagate &foo + CST as &MEM[&foo, CST]. Do not bother about volatile qualifiers on pointers. (fold_const_aggregate_ref): Handle MEM_REF, do not handle INDIRECT_REF. * tree-ssa-loop-ivopts.c * tree-ssa-loop-ivopts.c (determine_base_object): Adjust for MEM_REF. (strip_offset_1): Likewise. (find_interesting_uses_address): Replace INDIRECT_REF handling with MEM_REF handling. (get_computation_cost_at): Likewise. * ipa-pure-const.c (check_op): Handle MEM_REF. * tree-stdarg.c (check_all_va_list_escapes): Adjust for MEM_REF. * tree-ssa-sink.c (is_hidden_global_store): Handle MEM_REF and constants. * ipa-inline.c (likely_eliminated_by_inlining_p): Handle MEM_REF. * tree-parloops.c (take_address_of): Adjust for MEM_REF. (eliminate_local_variables_1): Likewise. (create_call_for_reduction_1): Likewise. (create_loads_for_reductions): Likewise. (create_loads_and_stores_for_name): Likewise. * matrix-reorg.c (may_flatten_matrices_1): Sanitize. (ssa_accessed_in_tree): Handle MEM_REF. (ssa_accessed_in_assign_rhs): Likewise. (update_type_size): Likewise. (analyze_accesses_for_call_stmt): Likewise. (analyze_accesses_for_assign_stmt): Likewise. (transform_access_sites): Likewise. (transform_allocation_sites): Likewise. * tree-affine.c (tree_to_aff_combination): Handle MEM_REF. * tree-vect-data-refs.c (vect_create_addr_base_for_vector_ref): Do not handle INDIRECT_REF. * tree-ssa-phiopt.c (add_or_mark_expr): Handle MEM_REF. (cond_store_replacement): Likewise. * tree-ssa-pre.c (create_component_ref_by_pieces_1): Handle MEM_REF, no not handle INDIRECT_REFs. (insert_into_preds_of_block): Properly initialize avail. (phi_translate_1): Fold MEM_REFs. Re-evaluate constant offset for ARRAY_REFs. Properly handle reference lookups that require a bit re-interpretation. (can_PRE_operation): Do not handle INDIRECT_REF. Handle MEM_REF. * tree-sra.c * tree-sra.c (build_access_from_expr_1): Handle MEM_REF. (build_ref_for_offset_1): Remove. (build_ref_for_offset): Build MEM_REFs. (gate_intra_sra): Disable for now. (sra_ipa_modify_expr): Handle MEM_REF. (ipa_early_sra_gate): Disable for now. * tree-sra.c (create_access): Swap INDIRECT_REF handling for MEM_REF handling. (disqualify_base_of_expr): Likewise. (ptr_parm_has_direct_uses): Swap INDIRECT_REF handling for MEM_REF handling. (sra_ipa_modify_expr): Remove INDIRECT_REF handling. Use mem_ref_offset. Remove bogus folding. (build_access_from_expr_1): Properly handle MEM_REF for non IPA-SRA. (make_fancy_name_1): Add support for MEM_REF. * tree-predcom.c (ref_at_iteration): Handle MEM_REFs. * tree-mudflap.c (mf_xform_derefs_1): Adjust for MEM_REF. * ipa-prop.c (compute_complex_assign_jump_func): Handle MEM_REF. (compute_complex_ancestor_jump_func): Likewise. (ipa_analyze_virtual_call_uses): Likewise. * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Replace INDIRECT_REF folding with more generalized MEM_REF folding. (tree_ssa_forward_propagate_single_use_vars): Adjust accordingly. (forward_propagate_addr_into_variable_array_index): Also handle &ARRAY + I in addition to &ARRAY[0] + I. * tree-ssa-dce.c (ref_may_be_aliased): Handle MEM_REF. * tree-ssa-ter.c (find_replaceable_in_bb): Avoid TER if that creates assignments with overlap. * tree-nested.c (get_static_chain): Adjust for MEM_REF. (get_frame_field): Likewise. (get_nonlocal_debug_decl): Likewise. (convert_nonlocal_reference_op): Likewise. (struct nesting_info): Add mem_refs pointer-set. (create_nesting_tree): Allocate it. (convert_local_reference_op): Insert to be folded mem-refs. (fold_mem_refs): New function. (finalize_nesting_tree_1): Perform defered folding of mem-refs (free_nesting_tree): Free the pointer-set. * tree-vect-stmts.c (vectorizable_store): Adjust for MEM_REF. (vectorizable_load): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Adjust for MEM_REF. (propagate_with_phi): Likewise. * tree-object-size.c (addr_object_size): Handle MEM_REFs instead of INDIRECT_REFs. (compute_object_offset): Handle MEM_REF. (plus_stmt_object_size): Handle MEM_REF. (collect_object_sizes_for): Dispatch to plus_stmt_object_size for &MEM_REF. * tree-flow.h (get_addr_base_and_unit_offset): Declare. (symbol_marked_for_renaming): Likewise. * Makefile.in (tree-dfa.o): Add $(TOPLEV_H). (fold-const.o): Add $(TREE_FLOW_H). * tree-ssa-structalias.c (get_constraint_for_1): Handle MEM_REF. (find_func_clobbers): Likewise. * ipa-struct-reorg.c (decompose_indirect_ref_acc): Handle MEM_REF. (decompose_access): Likewise. (replace_field_acc): Likewise. (replace_field_access_stmt): Likewise. (insert_new_var_in_stmt): Likewise. (get_stmt_accesses): Likewise. (reorg_structs_drive): Disable. * config/i386/i386.c (ix86_va_start): Adjust for MEM_REF. (ix86_canonical_va_list_type): Likewise. cp/ * cp-gimplify.c (cp_gimplify_expr): Open-code the rhs predicate we are looking for, allow non-gimplified INDIRECT_REFs. testsuite/ * gcc.c-torture/execute/20100316-1.c: New testcase. * gcc.c-torture/execute/pr44468.c: Likewise. * gcc.c-torture/compile/20100609-1.c: Likewise. * gcc.dg/volatile2.c: Adjust. * gcc.dg/plugin/selfassign.c: Likewise. * gcc.dg/pr36902.c: Likewise. * gcc.dg/tree-ssa/foldaddr-2.c: Remove. * gcc.dg/tree-ssa/foldaddr-3.c: Likewise. * gcc.dg/tree-ssa/forwprop-8.c: Adjust. * gcc.dg/tree-ssa/pr17141-1.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-13.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-14.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-21.c: Likewise. * gcc.dg/tree-ssa/pta-ptrarith-1.c: Likewise. * gcc.dg/tree-ssa/20030807-7.c: Likewise. * gcc.dg/tree-ssa/forwprop-10.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-1.c: Likewise. * gcc.dg/tree-ssa/pta-ptrarith-2.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-23.c: Likewise. * gcc.dg/tree-ssa/forwprop-1.c: Likewise. * gcc.dg/tree-ssa/forwprop-2.c: Likewise. * gcc.dg/tree-ssa/struct-aliasing-1.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-25.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-26.c: Likewise. * gcc.dg/tree-ssa/struct-aliasing-2.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-26.c: Likewise. * gcc.dg/tree-ssa/ssa-sccvn-4.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-7.c: Likewise. * gcc.dg/tree-ssa/forwprop-5.c: Likewise. * gcc.dg/struct/w_prof_two_strs.c: XFAIL. * gcc.dg/struct/wo_prof_escape_arg_to_local.c: Likewise. * gcc.dg/struct/wo_prof_global_var.c: Likewise. * gcc.dg/struct/wo_prof_malloc_size_var.c: Likewise. * gcc.dg/struct/w_prof_local_array.c: Likewise. * gcc.dg/struct/w_prof_single_str_global.c: Likewise. * gcc.dg/struct/wo_prof_escape_str_init.c: Likewise. * gcc.dg/struct/wo_prof_array_through_pointer.c: Likewise. * gcc.dg/struct/w_prof_global_array.c: Likewise. * gcc.dg/struct/wo_prof_array_field.c: Likewise. * gcc.dg/struct/wo_prof_single_str_local.c: Likewise. * gcc.dg/struct/w_prof_local_var.c: Likewise. * gcc.dg/struct/wo_prof_two_strs.c: Likewise. * gcc.dg/struct/wo_prof_empty_str.c: Likewise. * gcc.dg/struct/wo_prof_local_array.c: Likewise. * gcc.dg/struct/w_prof_global_var.c: Likewise. * gcc.dg/struct/wo_prof_single_str_global.c: Likewise. * gcc.dg/struct/wo_prof_escape_substr_value.c: Likewise. * gcc.dg/struct/wo_prof_global_array.c: Likewise. * gcc.dg/struct/wo_prof_escape_return.c: Likewise. * gcc.dg/struct/wo_prof_escape_substr_array.c: Likewise. * gcc.dg/struct/wo_prof_double_malloc.c: Likewise. * gcc.dg/struct/w_ratio_cold_str.c: Likewise. * gcc.dg/struct/wo_prof_escape_substr_pointer.c: Likewise. * gcc.dg/struct/wo_prof_local_var.c: Likewise. * gcc.dg/tree-prof/stringop-1.c: Adjust. * g++.dg/tree-ssa/pr31146.C: Likewise. * g++.dg/tree-ssa/copyprop-1.C: Likewise. * g++.dg/tree-ssa/pr33604.C: Likewise. * g++.dg/plugin/selfassign.c: Likewise. * gfortran.dg/array_memcpy_3.f90: Likewise. * gfortran.dg/array_memcpy_4.f90: Likewise. * c-c++-common/torture/pr42834.c: New testcase. From-SVN: r161655
2010-07-01 10:49:19 +02:00
tree ref = TREE_OPERAND (rhs, 0);
tree tem = maybe_fold_reference (ref, true);
if (tem
&& TREE_CODE (tem) == MEM_REF
&& integer_zerop (TREE_OPERAND (tem, 1)))
result = fold_convert (TREE_TYPE (rhs), TREE_OPERAND (tem, 0));
else if (tem)
result = fold_convert (TREE_TYPE (rhs),
build_fold_addr_expr_loc (loc, tem));
re PR middle-end/42834 (memcpy folding overeager) 2010-07-01 Richard Guenther <rguenther@suse.de> PR middle-end/42834 PR middle-end/44468 * doc/gimple.texi (is_gimple_mem_ref_addr): Document. * doc/generic.texi (References to storage): Document MEM_REF. * tree-pretty-print.c (dump_generic_node): Handle MEM_REF. (print_call_name): Likewise. * tree.c (recompute_tree_invariant_for_addr_expr): Handle MEM_REF. (build_simple_mem_ref_loc): New function. (mem_ref_offset): Likewise. * tree.h (build_simple_mem_ref_loc): Declare. (build_simple_mem_ref): Define. (mem_ref_offset): Declare. * fold-const.c: Include tree-flow.h. (operand_equal_p): Handle MEM_REF. (build_fold_addr_expr_with_type_loc): Likewise. (fold_comparison): Likewise. (fold_unary_loc): Fold VIEW_CONVERT_EXPR <T1, MEM_REF <T2, ...>> to MEM_REF <T1, ...>. (fold_binary_loc): Fold MEM[&MEM[p, CST1], CST2] to MEM[p, CST1 + CST2], fold MEM[&a.b, CST2] to MEM[&a, offsetof (a, b) + CST2]. * tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Handle MEM_REF. (ptr_deref_may_alias_ref_p_1): Likewise. (ao_ref_base_alias_set): Properly differentiate base object for offset and TBAA. (ao_ref_init_from_ptr_and_size): Use MEM_REF. (indirect_ref_may_alias_decl_p): Handle MEM_REFs properly. (indirect_refs_may_alias_p): Likewise. (refs_may_alias_p_1): Likewise. Remove pointer SSA name def chasing code. (ref_maybe_used_by_call_p_1): Handle MEM_REF. (call_may_clobber_ref_p_1): Likewise. * dwarf2out.c (loc_list_from_tree): Handle MEM_REF. * expr.c (expand_assignment): Handle MEM_REF. (store_expr): Handle MEM_REFs from STRING_CSTs. (store_field): If expanding a MEM_REF of a non-addressable decl use bitfield operations. (get_inner_reference): Handle MEM_REF. (expand_expr_addr_expr_1): Likewise. (expand_expr_real_1): Likewise. * tree-eh.c (tree_could_trap_p): Handle MEM_REF. * alias.c (ao_ref_from_mem): Handle MEM_REF. (get_alias_set): Likewise. Properly handle VIEW_CONVERT_EXPRs. * tree-data-ref.c (dr_analyze_innermost): Handle MEM_REF. (dr_analyze_indices): Likewise. (dr_analyze_alias): Likewise. (object_address_invariant_in_loop_p): Likewise. * gimplify.c (mark_addressable): Handle MEM_REF. (gimplify_cond_expr): Build MEM_REFs. (gimplify_modify_expr_to_memcpy): Likewise. (gimplify_init_ctor_preeval_1): Handle MEM_REF. (gimple_fold_indirect_ref): Adjust. (gimplify_expr): Handle MEM_REF. Gimplify INDIRECT_REF to MEM_REF. * tree.def (MEM_REF): New tree code. * tree-dfa.c: Include toplev.h. (get_ref_base_and_extent): Handle MEM_REF. (get_addr_base_and_unit_offset): New function. * emit-rtl.c (set_mem_attributes_minus_bitpos): Handle MEM_REF. * gimple-fold.c (may_propagate_address_into_dereference): Handle MEM_REF. (maybe_fold_offset_to_array_ref): Allow possibly out-of bounds accesses if the array has just one dimension. Remove always true parameter. Do not require type compatibility here. (maybe_fold_offset_to_component_ref): Remove. (maybe_fold_stmt_indirect): Remove. (maybe_fold_reference): Remove INDIRECT_REF handling. Fold back to non-MEM_REF. (maybe_fold_offset_to_address): Simplify. Deal with type mismatches here. (maybe_fold_reference): Likewise. (maybe_fold_stmt_addition): Likewise. Also handle &ARRAY + I in addition to &ARRAY[0] + I. (fold_gimple_assign): Handle ADDR_EXPR of MEM_REFs. (gimple_get_relevant_ref_binfo): Handle MEM_REF. * cfgexpand.c (expand_debug_expr): Handle MEM_REF. * tree-ssa.c (useless_type_conversion_p): Make most pointer conversions useless. (warn_uninitialized_var): Handle MEM_REF. (maybe_rewrite_mem_ref_base): New function. (execute_update_addresses_taken): Implement re-writing of MEM_REFs to SSA form. * tree-inline.c (remap_gimple_op_r): Handle MEM_REF, remove INDIRECT_REF handling. (copy_tree_body_r): Handle MEM_REF. * gimple.c (is_gimple_addressable): Adjust. (is_gimple_address): Likewise. (is_gimple_invariant_address): ADDR_EXPRs of MEM_REFs with invariant base are invariant. (is_gimple_min_lval): Adjust. (is_gimple_mem_ref_addr): New function. (get_base_address): Handle MEM_REF. (count_ptr_derefs): Likewise. (get_base_loadstore): Likewise. * gimple.h (is_gimple_mem_ref_addr): Declare. (gimple_call_fndecl): Handle invariant MEM_REF addresses. * tree-cfg.c (verify_address): New function, split out from ... (verify_expr): ... here. Use for verifying ADDR_EXPRs and the address operand of MEM_REFs. Verify MEM_REFs. Reject INDIRECT_REFs. (verify_types_in_gimple_min_lval): Handle MEM_REF. Disallow INDIRECT_REF. Allow conversions. (verify_types_in_gimple_reference): Verify VIEW_CONVERT_EXPR of a register does not change its size. (verify_types_in_gimple_reference): Verify MEM_REF. (verify_gimple_assign_single): Disallow INDIRECT_REF. Handle MEM_REF. * tree-ssa-operands.c (opf_non_addressable, opf_not_non_addressable): New. (mark_address_taken): Handle MEM_REF. (get_indirect_ref_operands): Pass through opf_not_non_addressable. (get_asm_expr_operands): Pass opf_not_non_addressable. (get_expr_operands): Handle opf_[not_]non_addressable. Handle MEM_REF. Remove INDIRECT_REF handling. * tree-vrp.c: (check_array_ref): Handle MEM_REF. (search_for_addr_array): Likewise. (check_array_bounds): Likewise. (vrp_stmt_computes_nonzero): Adjust for MEM_REF. * tree-ssa-loop-im.c (for_each_index): Handle MEM_REF. (ref_always_accessed_p): Likewise. (gen_lsm_tmp_name): Likewise. Handle ADDR_EXPR. * tree-complex.c (extract_component): Do not handle INDIRECT_REF. Handle MEM_REF. * cgraphbuild.c (mark_load): Properly check for NULL result from get_base_address. (mark_store): Likewise. * tree-ssa-loop-niter.c (array_at_struct_end_p): Handle MEM_REF. * tree-loop-distribution.c (generate_builtin): Exchange INDIRECT_REF handling for MEM_REF. * tree-scalar-evolution.c (follow_ssa_edge_expr): Handle &MEM[ptr + CST] similar to POINTER_PLUS_EXPR. * builtins.c (stabilize_va_list_loc): Use the function ABI valist type if we couldn't canonicalize the argument type. Always dereference with the canonical va-list type. (maybe_emit_free_warning): Handle MEM_REF. (fold_builtin_memory_op): Simplify and handle MEM_REFs in folding memmove to memcpy. * builtins.c (fold_builtin_memory_op): Use ref-all types for all memcpy foldings. * omp-low.c (build_receiver_ref): Adjust for MEM_REF. (build_outer_var_ref): Likewise. (scan_omp_1_op): Likewise. (lower_rec_input_clauses): Likewise. (lower_lastprivate_clauses): Likewise. (lower_reduction_clauses): Likewise. (lower_copyprivate_clauses): Likewise. (expand_omp_atomic_pipeline): Likewise. (expand_omp_atomic_mutex): Likewise. (create_task_copyfn): Likewise. * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Handle MEM_REF. Remove old union trick. Initialize constant offsets. (ao_ref_init_from_vn_reference): Likewise. Do not handle INDIRECT_REF. Init base_alias_set properly. (vn_reference_lookup_3): Replace INDIRECT_REF handling with MEM_REF. (vn_reference_fold_indirect): Adjust for MEM_REFs. (valueize_refs): Fold MEM_REFs. Re-evaluate constant offset for ARRAY_REFs. (may_insert): Remove. (visit_reference_op_load): Do not test may_insert. (run_scc_vn): Remove parameter, do not fiddle with may_insert. * tree-ssa-sccvn.h (struct vn_reference_op_struct): Add a field to store the constant offset this op applies. (run_scc_vn): Adjust prototype. * cgraphunit.c (thunk_adjust): Adjust for MEM_REF. * tree-ssa-ccp.c (ccp_fold): Replace INDIRECT_REF folding with MEM_REF. Propagate &foo + CST as &MEM[&foo, CST]. Do not bother about volatile qualifiers on pointers. (fold_const_aggregate_ref): Handle MEM_REF, do not handle INDIRECT_REF. * tree-ssa-loop-ivopts.c * tree-ssa-loop-ivopts.c (determine_base_object): Adjust for MEM_REF. (strip_offset_1): Likewise. (find_interesting_uses_address): Replace INDIRECT_REF handling with MEM_REF handling. (get_computation_cost_at): Likewise. * ipa-pure-const.c (check_op): Handle MEM_REF. * tree-stdarg.c (check_all_va_list_escapes): Adjust for MEM_REF. * tree-ssa-sink.c (is_hidden_global_store): Handle MEM_REF and constants. * ipa-inline.c (likely_eliminated_by_inlining_p): Handle MEM_REF. * tree-parloops.c (take_address_of): Adjust for MEM_REF. (eliminate_local_variables_1): Likewise. (create_call_for_reduction_1): Likewise. (create_loads_for_reductions): Likewise. (create_loads_and_stores_for_name): Likewise. * matrix-reorg.c (may_flatten_matrices_1): Sanitize. (ssa_accessed_in_tree): Handle MEM_REF. (ssa_accessed_in_assign_rhs): Likewise. (update_type_size): Likewise. (analyze_accesses_for_call_stmt): Likewise. (analyze_accesses_for_assign_stmt): Likewise. (transform_access_sites): Likewise. (transform_allocation_sites): Likewise. * tree-affine.c (tree_to_aff_combination): Handle MEM_REF. * tree-vect-data-refs.c (vect_create_addr_base_for_vector_ref): Do not handle INDIRECT_REF. * tree-ssa-phiopt.c (add_or_mark_expr): Handle MEM_REF. (cond_store_replacement): Likewise. * tree-ssa-pre.c (create_component_ref_by_pieces_1): Handle MEM_REF, no not handle INDIRECT_REFs. (insert_into_preds_of_block): Properly initialize avail. (phi_translate_1): Fold MEM_REFs. Re-evaluate constant offset for ARRAY_REFs. Properly handle reference lookups that require a bit re-interpretation. (can_PRE_operation): Do not handle INDIRECT_REF. Handle MEM_REF. * tree-sra.c * tree-sra.c (build_access_from_expr_1): Handle MEM_REF. (build_ref_for_offset_1): Remove. (build_ref_for_offset): Build MEM_REFs. (gate_intra_sra): Disable for now. (sra_ipa_modify_expr): Handle MEM_REF. (ipa_early_sra_gate): Disable for now. * tree-sra.c (create_access): Swap INDIRECT_REF handling for MEM_REF handling. (disqualify_base_of_expr): Likewise. (ptr_parm_has_direct_uses): Swap INDIRECT_REF handling for MEM_REF handling. (sra_ipa_modify_expr): Remove INDIRECT_REF handling. Use mem_ref_offset. Remove bogus folding. (build_access_from_expr_1): Properly handle MEM_REF for non IPA-SRA. (make_fancy_name_1): Add support for MEM_REF. * tree-predcom.c (ref_at_iteration): Handle MEM_REFs. * tree-mudflap.c (mf_xform_derefs_1): Adjust for MEM_REF. * ipa-prop.c (compute_complex_assign_jump_func): Handle MEM_REF. (compute_complex_ancestor_jump_func): Likewise. (ipa_analyze_virtual_call_uses): Likewise. * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Replace INDIRECT_REF folding with more generalized MEM_REF folding. (tree_ssa_forward_propagate_single_use_vars): Adjust accordingly. (forward_propagate_addr_into_variable_array_index): Also handle &ARRAY + I in addition to &ARRAY[0] + I. * tree-ssa-dce.c (ref_may_be_aliased): Handle MEM_REF. * tree-ssa-ter.c (find_replaceable_in_bb): Avoid TER if that creates assignments with overlap. * tree-nested.c (get_static_chain): Adjust for MEM_REF. (get_frame_field): Likewise. (get_nonlocal_debug_decl): Likewise. (convert_nonlocal_reference_op): Likewise. (struct nesting_info): Add mem_refs pointer-set. (create_nesting_tree): Allocate it. (convert_local_reference_op): Insert to be folded mem-refs. (fold_mem_refs): New function. (finalize_nesting_tree_1): Perform defered folding of mem-refs (free_nesting_tree): Free the pointer-set. * tree-vect-stmts.c (vectorizable_store): Adjust for MEM_REF. (vectorizable_load): Likewise. * tree-ssa-phiprop.c (phiprop_insert_phi): Adjust for MEM_REF. (propagate_with_phi): Likewise. * tree-object-size.c (addr_object_size): Handle MEM_REFs instead of INDIRECT_REFs. (compute_object_offset): Handle MEM_REF. (plus_stmt_object_size): Handle MEM_REF. (collect_object_sizes_for): Dispatch to plus_stmt_object_size for &MEM_REF. * tree-flow.h (get_addr_base_and_unit_offset): Declare. (symbol_marked_for_renaming): Likewise. * Makefile.in (tree-dfa.o): Add $(TOPLEV_H). (fold-const.o): Add $(TREE_FLOW_H). * tree-ssa-structalias.c (get_constraint_for_1): Handle MEM_REF. (find_func_clobbers): Likewise. * ipa-struct-reorg.c (decompose_indirect_ref_acc): Handle MEM_REF. (decompose_access): Likewise. (replace_field_acc): Likewise. (replace_field_access_stmt): Likewise. (insert_new_var_in_stmt): Likewise. (get_stmt_accesses): Likewise. (reorg_structs_drive): Disable. * config/i386/i386.c (ix86_va_start): Adjust for MEM_REF. (ix86_canonical_va_list_type): Likewise. cp/ * cp-gimplify.c (cp_gimplify_expr): Open-code the rhs predicate we are looking for, allow non-gimplified INDIRECT_REFs. testsuite/ * gcc.c-torture/execute/20100316-1.c: New testcase. * gcc.c-torture/execute/pr44468.c: Likewise. * gcc.c-torture/compile/20100609-1.c: Likewise. * gcc.dg/volatile2.c: Adjust. * gcc.dg/plugin/selfassign.c: Likewise. * gcc.dg/pr36902.c: Likewise. * gcc.dg/tree-ssa/foldaddr-2.c: Remove. * gcc.dg/tree-ssa/foldaddr-3.c: Likewise. * gcc.dg/tree-ssa/forwprop-8.c: Adjust. * gcc.dg/tree-ssa/pr17141-1.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-13.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-14.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-21.c: Likewise. * gcc.dg/tree-ssa/pta-ptrarith-1.c: Likewise. * gcc.dg/tree-ssa/20030807-7.c: Likewise. * gcc.dg/tree-ssa/forwprop-10.c: Likewise. * gcc.dg/tree-ssa/ssa-fre-1.c: Likewise. * gcc.dg/tree-ssa/pta-ptrarith-2.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-23.c: Likewise. * gcc.dg/tree-ssa/forwprop-1.c: Likewise. * gcc.dg/tree-ssa/forwprop-2.c: Likewise. * gcc.dg/tree-ssa/struct-aliasing-1.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-25.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-26.c: Likewise. * gcc.dg/tree-ssa/struct-aliasing-2.c: Likewise. * gcc.dg/tree-ssa/ssa-ccp-26.c: Likewise. * gcc.dg/tree-ssa/ssa-sccvn-4.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-7.c: Likewise. * gcc.dg/tree-ssa/forwprop-5.c: Likewise. * gcc.dg/struct/w_prof_two_strs.c: XFAIL. * gcc.dg/struct/wo_prof_escape_arg_to_local.c: Likewise. * gcc.dg/struct/wo_prof_global_var.c: Likewise. * gcc.dg/struct/wo_prof_malloc_size_var.c: Likewise. * gcc.dg/struct/w_prof_local_array.c: Likewise. * gcc.dg/struct/w_prof_single_str_global.c: Likewise. * gcc.dg/struct/wo_prof_escape_str_init.c: Likewise. * gcc.dg/struct/wo_prof_array_through_pointer.c: Likewise. * gcc.dg/struct/w_prof_global_array.c: Likewise. * gcc.dg/struct/wo_prof_array_field.c: Likewise. * gcc.dg/struct/wo_prof_single_str_local.c: Likewise. * gcc.dg/struct/w_prof_local_var.c: Likewise. * gcc.dg/struct/wo_prof_two_strs.c: Likewise. * gcc.dg/struct/wo_prof_empty_str.c: Likewise. * gcc.dg/struct/wo_prof_local_array.c: Likewise. * gcc.dg/struct/w_prof_global_var.c: Likewise. * gcc.dg/struct/wo_prof_single_str_global.c: Likewise. * gcc.dg/struct/wo_prof_escape_substr_value.c: Likewise. * gcc.dg/struct/wo_prof_global_array.c: Likewise. * gcc.dg/struct/wo_prof_escape_return.c: Likewise. * gcc.dg/struct/wo_prof_escape_substr_array.c: Likewise. * gcc.dg/struct/wo_prof_double_malloc.c: Likewise. * gcc.dg/struct/w_ratio_cold_str.c: Likewise. * gcc.dg/struct/wo_prof_escape_substr_pointer.c: Likewise. * gcc.dg/struct/wo_prof_local_var.c: Likewise. * gcc.dg/tree-prof/stringop-1.c: Adjust. * g++.dg/tree-ssa/pr31146.C: Likewise. * g++.dg/tree-ssa/copyprop-1.C: Likewise. * g++.dg/tree-ssa/pr33604.C: Likewise. * g++.dg/plugin/selfassign.c: Likewise. * gfortran.dg/array_memcpy_3.f90: Likewise. * gfortran.dg/array_memcpy_4.f90: Likewise. * c-c++-common/torture/pr42834.c: New testcase. From-SVN: r161655
2010-07-01 10:49:19 +02:00
else if (TREE_CODE (ref) == MEM_REF
&& integer_zerop (TREE_OPERAND (ref, 1)))
result = fold_convert (TREE_TYPE (rhs), TREE_OPERAND (ref, 0));
}
else if (TREE_CODE (rhs) == CONSTRUCTOR
&& TREE_CODE (TREE_TYPE (rhs)) == VECTOR_TYPE
&& (CONSTRUCTOR_NELTS (rhs)
== TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs))))
{
/* Fold a constant vector CONSTRUCTOR to VECTOR_CST. */
unsigned i;
tree val;
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)
if (TREE_CODE (val) != INTEGER_CST
&& TREE_CODE (val) != REAL_CST
&& TREE_CODE (val) != FIXED_CST)
return NULL_TREE;
return build_vector_from_ctor (TREE_TYPE (rhs),
CONSTRUCTOR_ELTS (rhs));
}
else if (DECL_P (rhs))
return get_symbol_constant_value (rhs);
/* If we couldn't fold the RHS, hand over to the generic
fold routines. */
if (result == NULL_TREE)
result = fold (rhs);
/* Strip away useless type conversions. Both the NON_LVALUE_EXPR
that may have been added by fold, and "useless" type
conversions that might now be apparent due to propagation. */
STRIP_USELESS_TYPE_CONVERSION (result);
if (result != rhs && valid_gimple_rhs_p (result))
return result;
return NULL_TREE;
}
break;
case GIMPLE_UNARY_RHS:
{
tree rhs = gimple_assign_rhs1 (stmt);
result = fold_unary_loc (loc, subcode, gimple_expr_type (stmt), rhs);
if (result)
{
/* If the operation was a conversion do _not_ mark a
resulting constant with TREE_OVERFLOW if the original
constant was not. These conversions have implementation
defined behavior and retaining the TREE_OVERFLOW flag
here would confuse later passes such as VRP. */
if (CONVERT_EXPR_CODE_P (subcode)
&& TREE_CODE (result) == INTEGER_CST
&& TREE_CODE (rhs) == INTEGER_CST)
TREE_OVERFLOW (result) = TREE_OVERFLOW (rhs);
STRIP_USELESS_TYPE_CONVERSION (result);
if (valid_gimple_rhs_p (result))
return result;
}
}
break;
case GIMPLE_BINARY_RHS:
/* Try to canonicalize for boolean-typed X the comparisons
X == 0, X == 1, X != 0, and X != 1. */
if (gimple_assign_rhs_code (stmt) == EQ_EXPR
|| gimple_assign_rhs_code (stmt) == NE_EXPR)
{
tree lhs = gimple_assign_lhs (stmt);
tree op1 = gimple_assign_rhs1 (stmt);
tree op2 = gimple_assign_rhs2 (stmt);
tree type = TREE_TYPE (op1);
/* Check whether the comparison operands are of the same boolean
type as the result type is.
Check that second operand is an integer-constant with value
one or zero. */
if (TREE_CODE (op2) == INTEGER_CST
&& (integer_zerop (op2) || integer_onep (op2))
&& useless_type_conversion_p (TREE_TYPE (lhs), type))
{
enum tree_code cmp_code = gimple_assign_rhs_code (stmt);
bool is_logical_not = false;
/* X == 0 and X != 1 is a logical-not.of X
X == 1 and X != 0 is X */
if ((cmp_code == EQ_EXPR && integer_zerop (op2))
|| (cmp_code == NE_EXPR && integer_onep (op2)))
is_logical_not = true;
if (is_logical_not == false)
result = op1;
/* Only for one-bit precision typed X the transformation
!X -> ~X is valied. */
else if (TYPE_PRECISION (type) == 1)
result = build1_loc (gimple_location (stmt), BIT_NOT_EXPR,
type, op1);
/* Otherwise we use !X -> X ^ 1. */
else
result = build2_loc (gimple_location (stmt), BIT_XOR_EXPR,
type, op1, build_int_cst (type, 1));
}
}
if (!result)
result = fold_binary_loc (loc, subcode,
TREE_TYPE (gimple_assign_lhs (stmt)),
gimple_assign_rhs1 (stmt),
gimple_assign_rhs2 (stmt));
if (result)
{
STRIP_USELESS_TYPE_CONVERSION (result);
if (valid_gimple_rhs_p (result))
return result;
}
break;
With large parts from Jim Wilson: PR target/43902 * tree-pretty-print.c (dump_generic_node, op_code_prio): Add WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * optabs.c (optab_for_tree_code): Likewise. (expand_widen_pattern_expr): Likewise. * tree-ssa-math-opts.c (convert_mult_to_widen): New function, broken out of execute_optimize_widening_mul. (convert_plusminus_to_widen): New function. (execute_optimize_widening_mul): Use the two new functions. * expr.c (expand_expr_real_2): Add support for GIMPLE_TERNARY_RHS. Remove code to generate widening multiply-accumulate. Add support for WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * gimple-pretty-print.c (dump_ternary_rhs): New function. (dump_gimple_assign): Call it when appropriate. * tree.def (WIDEN_MULT_PLUS_EXPR, WIDEN_MULT_MINUS_EXPR): New codes. * cfgexpand.c (gimple_assign_rhs_to_tree): Likewise. (expand_gimple_stmt_1): Likewise. (expand_debug_expr): Support WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * tree-ssa-operands.c (get_expr_operands): Likewise. * tree-inline.c (estimate_operator_cost): Likewise. * gimple.c (extract_ops_from_tree_1): Renamed from extract_ops_from_tree. Add new arg for a third operand; fill it. (gimple_build_assign_stat): Support operations with three operands. (gimple_build_assign_with_ops_stat): Likewise. (gimple_assign_set_rhs_from_tree): Likewise. (gimple_assign_set_rhs_with_ops_1): Renamed from gimple_assign_set_rhs_with_ops. Add new arg for a third operand. (get_gimple_rhs_num_ops): Support GIMPLE_TERNARY_RHS. (get_gimple_rhs_num_ops): Handle WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * gimple.h (enum gimple_rhs_class): Add GIMPLE_TERNARY_RHS. (extract_ops_from_tree_1): Adjust declaration. (gimple_assign_set_rhs_with_ops_1): Likewise. (gimple_build_assign_with_ops): Pass NULL for last operand. (gimple_build_assign_with_ops3): New macro. (gimple_assign_rhs3, gimple_assign_rhs3_ptr, gimple_assign_set_rhs3, gimple_assign_set_rhs_with_ops, extract_ops_from_tree): New inline functions. * tree-cfg.c (verify_gimple_assign_ternary): New static function. (verify_gimple_assign): Call it. * doc/gimple.texi (Manipulating operands): Document GIMPLE_TERNARY_RHS. (Tuple specific accessors, subsection GIMPLE_ASSIGN): Document new functions for dealing with three-operand statements. * tree.c (commutative_ternary_tree_code): New function. * tree.h (commutative_ternary_tree_code): Declare it. * tree-vrp.c (gimple_assign_nonnegative_warnv_p): Return false for ternary statements. (gimple_assign_nonzero_warnv_p): Likewise. * tree-ssa-sccvn.c (stmt_has_constants): Handle GIMPLE_TERNARY_RHS. * tree-ssa-ccp.c (get_rhs_assign_op_for_ccp): New static function. (ccp_fold): Use it. Handle GIMPLE_TERNARY_RHS. * tree-ssa-dom.c (enum expr_kind): Add EXPR_TERNARY. (struct hashtable_expr): New member ternary in the union. (initialize_hash_element): Handle GIMPLE_TERNARY_RHS. (hashable_expr_equal_p): Fix indentation. Handle EXPR_TERNARY. (iterative_hash_hashable_expr): Likewise. (print_expr_hash_elt): Handle EXPR_TERNARY. * gimple-fold.c (fold_gimple_assign): Handle GIMPLE_TERNARY_RHS. * tree-ssa-threadedge.c (fold_assignment_stmt): Remove useless break statements. Handle GIMPLE_TERNARY_RHS. testsuite/ PR target/43902 * gcc.target/mips/madd-9.c: New test. From-SVN: r161366
2010-06-25 10:56:24 +02:00
case GIMPLE_TERNARY_RHS:
/* Try to fold a conditional expression. */
if (gimple_assign_rhs_code (stmt) == COND_EXPR)
{
tree op0 = gimple_assign_rhs1 (stmt);
tree tem;
bool set = false;
location_t cond_loc = gimple_location (stmt);
if (COMPARISON_CLASS_P (op0))
{
fold_defer_overflow_warnings ();
tem = fold_binary_loc (cond_loc,
TREE_CODE (op0), TREE_TYPE (op0),
TREE_OPERAND (op0, 0),
TREE_OPERAND (op0, 1));
/* This is actually a conditional expression, not a GIMPLE
conditional statement, however, the valid_gimple_rhs_p
test still applies. */
set = (tem && is_gimple_condexpr (tem)
&& valid_gimple_rhs_p (tem));
fold_undefer_overflow_warnings (set, stmt, 0);
}
else if (is_gimple_min_invariant (op0))
{
tem = op0;
set = true;
}
else
return NULL_TREE;
if (set)
result = fold_build3_loc (cond_loc, COND_EXPR,
TREE_TYPE (gimple_assign_lhs (stmt)), tem,
gimple_assign_rhs2 (stmt),
gimple_assign_rhs3 (stmt));
}
if (!result)
result = fold_ternary_loc (loc, subcode,
TREE_TYPE (gimple_assign_lhs (stmt)),
gimple_assign_rhs1 (stmt),
gimple_assign_rhs2 (stmt),
gimple_assign_rhs3 (stmt));
With large parts from Jim Wilson: PR target/43902 * tree-pretty-print.c (dump_generic_node, op_code_prio): Add WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * optabs.c (optab_for_tree_code): Likewise. (expand_widen_pattern_expr): Likewise. * tree-ssa-math-opts.c (convert_mult_to_widen): New function, broken out of execute_optimize_widening_mul. (convert_plusminus_to_widen): New function. (execute_optimize_widening_mul): Use the two new functions. * expr.c (expand_expr_real_2): Add support for GIMPLE_TERNARY_RHS. Remove code to generate widening multiply-accumulate. Add support for WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * gimple-pretty-print.c (dump_ternary_rhs): New function. (dump_gimple_assign): Call it when appropriate. * tree.def (WIDEN_MULT_PLUS_EXPR, WIDEN_MULT_MINUS_EXPR): New codes. * cfgexpand.c (gimple_assign_rhs_to_tree): Likewise. (expand_gimple_stmt_1): Likewise. (expand_debug_expr): Support WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * tree-ssa-operands.c (get_expr_operands): Likewise. * tree-inline.c (estimate_operator_cost): Likewise. * gimple.c (extract_ops_from_tree_1): Renamed from extract_ops_from_tree. Add new arg for a third operand; fill it. (gimple_build_assign_stat): Support operations with three operands. (gimple_build_assign_with_ops_stat): Likewise. (gimple_assign_set_rhs_from_tree): Likewise. (gimple_assign_set_rhs_with_ops_1): Renamed from gimple_assign_set_rhs_with_ops. Add new arg for a third operand. (get_gimple_rhs_num_ops): Support GIMPLE_TERNARY_RHS. (get_gimple_rhs_num_ops): Handle WIDEN_MULT_PLUS_EXPR and WIDEN_MULT_MINUS_EXPR. * gimple.h (enum gimple_rhs_class): Add GIMPLE_TERNARY_RHS. (extract_ops_from_tree_1): Adjust declaration. (gimple_assign_set_rhs_with_ops_1): Likewise. (gimple_build_assign_with_ops): Pass NULL for last operand. (gimple_build_assign_with_ops3): New macro. (gimple_assign_rhs3, gimple_assign_rhs3_ptr, gimple_assign_set_rhs3, gimple_assign_set_rhs_with_ops, extract_ops_from_tree): New inline functions. * tree-cfg.c (verify_gimple_assign_ternary): New static function. (verify_gimple_assign): Call it. * doc/gimple.texi (Manipulating operands): Document GIMPLE_TERNARY_RHS. (Tuple specific accessors, subsection GIMPLE_ASSIGN): Document new functions for dealing with three-operand statements. * tree.c (commutative_ternary_tree_code): New function. * tree.h (commutative_ternary_tree_code): Declare it. * tree-vrp.c (gimple_assign_nonnegative_warnv_p): Return false for ternary statements. (gimple_assign_nonzero_warnv_p): Likewise. * tree-ssa-sccvn.c (stmt_has_constants): Handle GIMPLE_TERNARY_RHS. * tree-ssa-ccp.c (get_rhs_assign_op_for_ccp): New static function. (ccp_fold): Use it. Handle GIMPLE_TERNARY_RHS. * tree-ssa-dom.c (enum expr_kind): Add EXPR_TERNARY. (struct hashtable_expr): New member ternary in the union. (initialize_hash_element): Handle GIMPLE_TERNARY_RHS. (hashable_expr_equal_p): Fix indentation. Handle EXPR_TERNARY. (iterative_hash_hashable_expr): Likewise. (print_expr_hash_elt): Handle EXPR_TERNARY. * gimple-fold.c (fold_gimple_assign): Handle GIMPLE_TERNARY_RHS. * tree-ssa-threadedge.c (fold_assignment_stmt): Remove useless break statements. Handle GIMPLE_TERNARY_RHS. testsuite/ PR target/43902 * gcc.target/mips/madd-9.c: New test. From-SVN: r161366
2010-06-25 10:56:24 +02:00
if (result)
{
STRIP_USELESS_TYPE_CONVERSION (result);
if (valid_gimple_rhs_p (result))
return result;
}
break;
case GIMPLE_INVALID_RHS:
gcc_unreachable ();
}
return NULL_TREE;
}
/* Attempt to fold a conditional statement. Return true if any changes were
made. We only attempt to fold the condition expression, and do not perform
any transformation that would require alteration of the cfg. It is
assumed that the operands have been previously folded. */
static bool
fold_gimple_cond (gimple stmt)
{
tree result = fold_binary_loc (gimple_location (stmt),
gimple_cond_code (stmt),
boolean_type_node,
gimple_cond_lhs (stmt),
gimple_cond_rhs (stmt));
if (result)
{
STRIP_USELESS_TYPE_CONVERSION (result);
if (is_gimple_condexpr (result) && valid_gimple_rhs_p (result))
{
gimple_cond_set_condition_from_tree (stmt, result);
return true;
}
}
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Replace a statement at *SI_P with a sequence of statements in STMTS,
adjusting the replacement stmts location and virtual operands.
If the statement has a lhs the last stmt in the sequence is expected
to assign to that lhs. */
static void
gsi_replace_with_seq_vops (gimple_stmt_iterator *si_p, gimple_seq stmts)
{
gimple stmt = gsi_stmt (*si_p);
if (gimple_has_location (stmt))
annotate_all_with_location (stmts, gimple_location (stmt));
/* First iterate over the replacement statements backward, assigning
virtual operands to their defining statements. */
gimple laststore = NULL;
for (gimple_stmt_iterator i = gsi_last (stmts);
!gsi_end_p (i); gsi_prev (&i))
{
gimple new_stmt = gsi_stmt (i);
if ((gimple_assign_single_p (new_stmt)
&& !is_gimple_reg (gimple_assign_lhs (new_stmt)))
|| (is_gimple_call (new_stmt)
&& (gimple_call_flags (new_stmt)
& (ECF_NOVOPS | ECF_PURE | ECF_CONST | ECF_NORETURN)) == 0))
{
tree vdef;
if (!laststore)
vdef = gimple_vdef (stmt);
else
vdef = make_ssa_name (gimple_vop (cfun), new_stmt);
gimple_set_vdef (new_stmt, vdef);
if (vdef && TREE_CODE (vdef) == SSA_NAME)
SSA_NAME_DEF_STMT (vdef) = new_stmt;
laststore = new_stmt;
}
}
/* Second iterate over the statements forward, assigning virtual
operands to their uses. */
tree reaching_vuse = gimple_vuse (stmt);
for (gimple_stmt_iterator i = gsi_start (stmts);
!gsi_end_p (i); gsi_next (&i))
{
gimple new_stmt = gsi_stmt (i);
/* If the new statement possibly has a VUSE, update it with exact SSA
name we know will reach this one. */
if (gimple_has_mem_ops (new_stmt))
gimple_set_vuse (new_stmt, reaching_vuse);
gimple_set_modified (new_stmt, true);
if (gimple_vdef (new_stmt))
reaching_vuse = gimple_vdef (new_stmt);
}
/* If the new sequence does not do a store release the virtual
definition of the original statement. */
if (reaching_vuse
&& reaching_vuse == gimple_vuse (stmt))
{
tree vdef = gimple_vdef (stmt);
if (vdef
&& TREE_CODE (vdef) == SSA_NAME)
{
unlink_stmt_vdef (stmt);
release_ssa_name (vdef);
}
}
/* Finally replace the original statement with the sequence. */
gsi_replace_with_seq (si_p, stmts, false);
}
/* Convert EXPR into a GIMPLE value suitable for substitution on the
RHS of an assignment. Insert the necessary statements before
iterator *SI_P. The statement at *SI_P, which must be a GIMPLE_CALL
is replaced. If the call is expected to produces a result, then it
is replaced by an assignment of the new RHS to the result variable.
If the result is to be ignored, then the call is replaced by a
GIMPLE_NOP. A proper VDEF chain is retained by making the first
VUSE and the last VDEF of the whole sequence be the same as the replaced
statement and using new SSA names for stores in between. */
void
gimplify_and_update_call_from_tree (gimple_stmt_iterator *si_p, tree expr)
{
tree lhs;
gimple stmt, new_stmt;
gimple_stmt_iterator i;
coretypes.h (gimple_seq, [...]): Typedef as gimple. * coretypes.h (gimple_seq, const_gimple_seq): Typedef as gimple. * gimple.h (struct gimple_seq_node_d, struct gimple_seq_d): Remove. (const_gimple_seq_node): Remove. (gimple_seq_node): Typedef as gimple. (struct gimple_statement_base): Add next and prev members, adjust all WORD markers in using structs. (union gimple_statement_d): Link via gsbase.next field for GC and PCH. (gimple_seq_first, gimple_seq_first_stmt, gimple_seq_last, gimple_seq_last_stmt): Adjust as gimple_seq, gimple_seq_node and gimple are the same. (gimple_seq_set_last, gimple_seq_set_first): Don't allocate gimple_seq, adjust. (gimple_init_singleton): New function. (gsi_start_1, gsi_last_1, gsi_end_p, gsi_one_before_end_p): Adjust. (gsi_next, gsi_prev): Adjust, handle prev cyclic list correctly. (gsi_stmt): Adjust. (gsi_stmt_ptr): Remove. (enum gimple_alloc_kind): Remove gimple_alloc_kind_seq member. * gimple-iterator.c (update_bb_for_stmts): Take last parameter again, adjust for above changes. (update_call_edge_frequencies): Adjust for above changes. (gsi_insert_seq_nodes_before): Rewrite for new data structure. (gsi_insert_seq_nodes_after): Ditto. (gsi_split_seq_after): Ditto. (gsi_set_stmt): Ditto. (gsi_split_seq_before): Ditto. (gsi_remove): Ditto. (gsi_insert_seq_before_without_update): Don't free sequence. (gsi_insert_seq_after_without_update): Ditto. (gsi_replace): Assert some more invariants. (gsi_insert_before_without_update, gsi_insert_after_without_update): Tidy. (gsi_for_stmt): Don't search for stmt. (gsi_insert_on_edge_immediate): Tidy. * gimple.c (gimple_alloc_k): Remove "sequences". (gimple_seq_cache): Remove. (gimple_alloc_stat): Make stmt a singleton sequence. (gimple_seq_alloc, gimple_seq_free): Remove. (gimple_assign_set_rhs_with_ops_1): Ensure new stmt is a singleton. (gimple_copy): Ditto. * gimplify.c (gimplify_cleanup_point_expr): Use gsi_set_stmt, create iterator from correct sequence. * tree-phinodes.c (make_phi_node): Make stmt a singleton. * gimple.h (gimple_stmt_iterator <seq>): Make it be pointer to gimple_seq. (gimple_seq_set_last, gimple_seq_set_first): Take pointer to sequence, lazily allocate it. (bb_seq_addr): New function. (gsi_start_1): Rename from gsi_start, but take pointer to sequence. (gsi_start): Macro to wrap gsi_start_1 taking pointer of argument. (gsi_none): New function. (gsi_start_bb): Adjust. (gsi_last_1): Rename from gsi_last, but take pointer to sequence. (gsi_last): Macro to wrap gsi_last_1 taking pointer of argument. (gsi_last_bb): Adjust. (gsi_seq): Adjust. * tree-flow-inline.h (phi_nodes_ptr): New function. * gimple-iterator.c (gsi_insert_seq_nodes_before): Adjust to datastructure and interface change. (gsi_insert_seq_before_without_update): Ditto. (gsi_insert_seq_nodes_after): Ditto. (gsi_insert_seq_after_without_update): Ditto. (gsi_split_seq_after): Ditto, don't use gimple_seq_alloc. (gsi_split_seq_before): Ditto. (gsi_start_phis): Adjust. * tree-vect-loop.c (vect_determine_vectorization_factor): Use gsi_none. (vect_transform_loop): Ditto. * gimple.c (gimple_seq_add_stmt, gimple_seq_add_seq, gimple_seq_copy): Don't use gimple_seq_alloc. * gimplify.c (gimple_seq_add_stmt_without_update): Ditto. (gimplify_seq_add_seq): Ditto. * lto-streamer-in.c (make_new_block): Ditto. * tree-cfg.c (create_bb): Ditto. * tree-sra.c (initialize_parameter_reductions): Ditto. * gimple.h (gimple_seq_first, gimple_seq_first_stmt, gimple_seq_last, gimple_seq_last_stmt, gimple_seq_set_last, gimple_seq_set_first, gimple_seq_empty_p, gimple_seq_alloc_with_stmt, bb_seq, set_bb_seq): Move down to after gimple_statement_d definition. * gimple-fold.c (gimplify_and_update_call_from_tree): Use gsi_replace_with_seq, instead of inserting itself. * gimple-iterator.c (gsi_replace_with_seq): New function. * tree-ssa-forwprop.c (forward_propagate_comparison): Take iterator instead of statement, advance it. (ssa_forward_propagate_and_combine): Adjust call to above. * tree-phinodes.c (add_phi_node_to_bb): Tidy, don't use gimple_seq_alloc. * omp-low.c (finalize_task_copyfn): Don't use gimple_seq_alloc. * tree-nested.c (walk_gimple_omp_for): Ditto. * trans-mem.c (lower_transaction): Ditto. * tree-eh.c (do_return_redirection): Ditto. (do_goto_redirection): Ditto. (lower_try_finally_switch): Ditto. * gimplify.c (gimplify_stmt): Ditto. (gimplify_scan_omp_clauses): Ditto. (gimplify_omp_for): Ditto. (gimplify_function_tree): Ditto. * gimple-fold.c (gimplify_and_update_call_from_tree): Ditto. * tree-mudflap.c (mf_decl_cache_locals): Ditto. (mf_build_check_statement_for): Ditto. (mx_register_decls): Ditto. * graphite-sese-to-poly.c (remove_invariant_phi): Ditto, and don't use itertors to append. (insert_stmts): Ditto. (insert_out_of_ssa_copy): Ditto. (insert_out_of_ssa_copy_on_edge): Ditto. * gimple.h (gimple_bind_body_ptr): New function. (gimple_bind_body): Use it. (gimple_catch_handler): Use gimple_catch_handler_ptr. (gimple_eh_filter_failure_ptr): New function. (gimple_eh_filter_failure): Use it. (gimple_eh_else_n_body_ptr): New function. (gimple_eh_else_n_body): Use it. (gimple_eh_else_e_body_ptr): New function. (gimple_eh_else_e_body): Use it. (gimple_try_eval_ptr): New function. (gimple_try_eval): Use it. (gimple_try_cleanup_ptr): New function. (gimple_try_cleanup): Use it. (gimple_wce_cleanup_ptr): New function. (gimple_wce_cleanup): Use it. (gimple_omp_body_ptr): New function. (gimple_omp_body): Use it. (gimple_omp_for_pre_body_ptr): New function. (gimple_omp_for_pre_body): Use it. (gimple_transaction_body_ptr): New function. (gimple_transaction_body): Use it. (gsi_split_seq_before): Adjust to return nothing and take pointer to sequence. (gsi_set_stmt): Declare. (gsi_replace_with_seq): Declare. (walk_gimple_seq_mod): Declare. * function.h (struct function <gimple_body>): Use typedef gimple_seq. * gimple-iterator.c (gsi_set_stmt): New function. (gsi_split_seq_before): Return new sequence via pointer argument. (gsi_replace): Use gsi_set_stmt. * tree-ssa-loop-im.c (move_computations_stmt): First remove then insert stmt. * tree-complex.c (update_complex_components_on_edge): Don't copy gsi. * tree-phinodes.c (resize_phi_node): Don't resize stmt in-place, return new stmt. (reserve_phi_args_for_new_edge): Change call to above, use gsi_set_stmt. * omp-low.c (lower_omp): Change prototype to take pointer to sequence. (lower_rec_input_clauses): Use gimple_seq_add_seq instead of iterators. Adjust call to lower_omp. (lower_lastprivate_clauses): Adjust call to lower_omp. (lower_reduction_clauses): Ditto. (expand_omp_taskreg): Nullify non-cfg body of child_fn. (lower_omp_sections): Don't explicitely count sequence length, nullify lowered bodies earlier, ensure stmts are part of only one sequence, adjust call to lower_omp. (lower_omp_single): Ensure stmts are part of only one sequence, adjust call to lower_omp. (lower_omp_master): Ditto. (lower_omp_ordered): Ditto. (lower_omp_critical): Ditto. (lower_omp_for): Ditto. (lower_omp_taskreg): Ditto, tidy. (lower_omp_1): Adjust calls to lower_omp. (execute_lower_omp): Ditto. (lower_omp): Adjust to take pointer to sequence. (diagnose_sb_2): Use walk_gimple_seq_mod. (diagnose_omp_structured_block_errors): Ditto and set possibly changed function body. * gimple-low.c (lower_function_body): Set function body after it stabilizes. (lower_sequence): Adjust to take pointer to sequence. (lower_omp_directive): Ensure stmt isn't put twice into the sequence, adjust call to lower_sequence. (lower_stmt): Adjust calls to lower_sequence. (lower_gimple_bind): Ditto. (gimple_try_catch_may_fallthru): Call gsi_start with lvalue. * tree-nested.c (walk_body): Take pointer to sequence, use walk_gimple_seq_mod. (walk_function): Adjust call to walk_body, set possibly changed body. (walk_gimple_omp_for): Adjust calls to walk_body. (convert_nonlocal_omp_clauses): Ditto. (convert_nonlocal_reference_stmt): Ditto. (convert_local_omp_clauses): Ditto. (convert_local_reference_stmt): Ditto. (convert_tramp_reference_stmt): Ditto. (convert_gimple_call): Ditto. (convert_nl_goto_reference): Use local iterator copy. * gimple.c (walk_gimple_seq_mod): Renamed from walk_gimple_seq, but taking pointer to sequence, ensure gsi_start is called with callers lvalue. (walk_gimple_seq): New wrapper around walk_gimple_seq_mod, asserting that the sequence head didn't change. (walk_gimple_stmt): Replace all calls to walk_gimple_seq with walk_gimple_seq_mod. * trans-mem.c (lower_transaction): Use walk_gimple_seq_mod. (execute_lower_tm): Ditto, and set possibly changed body. * tree-eh.c (lower_eh_constructs_1): Take pointer to sequence, call gsi_start with that lvalue. (replace_goto_queue_stmt_list): Ditto. (replace_goto_queue_1): Adjust calls to replace_goto_queue_stmt_list. (replace_goto_queue): Ditto. (lower_try_finally_nofallthru): Adjust calls to lower_eh_constructs_1. (lower_try_finally_onedest): Ditto. (lower_try_finally_copy): Ditto. (lower_try_finally_switch): Ditto. (lower_try_finally): Ditto. (lower_eh_filter): Ditto. (lower_eh_must_not_throw): Ditto. (lower_cleanup): Ditto. (lower_eh_constructs_2): Ditto. (lower_catch): Ditto, and ensure gsi_start is called with lvalue. (lower_eh_constructs): Adjust calls to lower_eh_constructs_1, and set possibly changed body. (optimize_double_finally): Call gsi_start with lvalue. * tree-cfg.c (make_blocks): Adjust call to gsi_split_seq_before. (gimple_split_block): Ditto. (gimple_merge_blocks): Use gsi_start_phis. (move_stmt_r): Use walk_gimple_seq_mod. * tree-ssa-dse.c (dse_enter_block): Use gsi_last_bb. * cgraphbuild.c (build_cgraph_edges): Use gsi_start_phis. (rebuild_cgraph_edges): Ditto. (cgraph_rebuild_references): Ditto. * ipa-prop.c (ipa_analyze_params_uses): Ditto. * tree-inline.c (copy_phis_for_bb): Ditto. * tree-ssa-dce.c: Ditto. * cgraphunit.c (cgraph_analyze_function): Use gimple_has_body_p. From-SVN: r187053
2012-05-02 18:41:48 +02:00
gimple_seq stmts = NULL;
stmt = gsi_stmt (*si_p);
gcc_assert (is_gimple_call (stmt));
push_gimplify_context (gimple_in_ssa_p (cfun));
lhs = gimple_call_lhs (stmt);
if (lhs == NULL_TREE)
{
gimplify_and_add (expr, &stmts);
/* We can end up with folding a memcpy of an empty class assignment
which gets optimized away by C++ gimplification. */
if (gimple_seq_empty_p (stmts))
{
pop_gimplify_context (NULL);
if (gimple_in_ssa_p (cfun))
{
unlink_stmt_vdef (stmt);
release_defs (stmt);
}
gsi_replace (si_p, gimple_build_nop (), true);
return;
}
}
else
{
tree tmp = get_initialized_tmp_var (expr, &stmts, NULL);
new_stmt = gimple_build_assign (lhs, tmp);
i = gsi_last (stmts);
gsi_insert_after_without_update (&i, new_stmt,
GSI_CONTINUE_LINKING);
}
pop_gimplify_context (NULL);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gsi_replace_with_seq_vops (si_p, stmts);
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Replace the call at *GSI with the gimple value VAL. */
static void
replace_call_with_value (gimple_stmt_iterator *gsi, tree val)
{
gimple stmt = gsi_stmt (*gsi);
tree lhs = gimple_call_lhs (stmt);
gimple repl;
if (lhs)
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (val)))
val = fold_convert (TREE_TYPE (lhs), val);
repl = gimple_build_assign (lhs, val);
}
else
repl = gimple_build_nop ();
tree vdef = gimple_vdef (stmt);
if (vdef && TREE_CODE (vdef) == SSA_NAME)
{
unlink_stmt_vdef (stmt);
release_ssa_name (vdef);
}
gsi_replace (gsi, repl, true);
}
/* Replace the call at *GSI with the new call REPL and fold that
again. */
static void
replace_call_with_call_and_fold (gimple_stmt_iterator *gsi, gimple repl)
{
gimple stmt = gsi_stmt (*gsi);
gimple_call_set_lhs (repl, gimple_call_lhs (stmt));
gimple_set_location (repl, gimple_location (stmt));
if (gimple_vdef (stmt)
&& TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
{
gimple_set_vdef (repl, gimple_vdef (stmt));
gimple_set_vuse (repl, gimple_vuse (stmt));
SSA_NAME_DEF_STMT (gimple_vdef (repl)) = repl;
}
gsi_replace (gsi, repl, true);
fold_stmt (gsi);
}
/* Return true if VAR is a VAR_DECL or a component thereof. */
static bool
var_decl_component_p (tree var)
{
tree inner = var;
while (handled_component_p (inner))
inner = TREE_OPERAND (inner, 0);
return SSA_VAR_P (inner);
}
/* Fold function call to builtin mem{{,p}cpy,move}. Return
NULL_TREE if no simplification can be made.
If ENDP is 0, return DEST (like memcpy).
If ENDP is 1, return DEST+LEN (like mempcpy).
If ENDP is 2, return DEST+LEN-1 (like stpcpy).
If ENDP is 3, return DEST, additionally *SRC and *DEST may overlap
(memmove). */
static bool
gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
tree dest, tree src, int endp)
{
gimple stmt = gsi_stmt (*gsi);
tree lhs = gimple_call_lhs (stmt);
tree len = gimple_call_arg (stmt, 2);
tree destvar, srcvar;
location_t loc = gimple_location (stmt);
/* If the LEN parameter is zero, return DEST. */
if (integer_zerop (len))
{
gimple repl;
if (gimple_call_lhs (stmt))
repl = gimple_build_assign (gimple_call_lhs (stmt), dest);
else
repl = gimple_build_nop ();
tree vdef = gimple_vdef (stmt);
if (vdef && TREE_CODE (vdef) == SSA_NAME)
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
unlink_stmt_vdef (stmt);
release_ssa_name (vdef);
}
gsi_replace (gsi, repl, true);
return true;
}
/* If SRC and DEST are the same (and not volatile), return
DEST{,+LEN,+LEN-1}. */
if (operand_equal_p (src, dest, 0))
{
unlink_stmt_vdef (stmt);
if (gimple_vdef (stmt) && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
release_ssa_name (gimple_vdef (stmt));
if (!lhs)
{
gsi_replace (gsi, gimple_build_nop (), true);
return true;
}
goto done;
}
else
{
tree srctype, desttype;
unsigned int src_align, dest_align;
tree off0;
/* Build accesses at offset zero with a ref-all character type. */
off0 = build_int_cst (build_pointer_type_for_mode (char_type_node,
ptr_mode, true), 0);
/* If we can perform the copy efficiently with first doing all loads
and then all stores inline it that way. Currently efficiently
means that we can load all the memory into a single integer
register which is what MOVE_MAX gives us. */
src_align = get_pointer_alignment (src);
dest_align = get_pointer_alignment (dest);
if (tree_fits_uhwi_p (len)
&& compare_tree_int (len, MOVE_MAX) <= 0
/* ??? Don't transform copies from strings with known length this
confuses the tree-ssa-strlen.c. This doesn't handle
the case in gcc.dg/strlenopt-8.c which is XFAILed for that
reason. */
&& !c_strlen (src, 2))
{
unsigned ilen = tree_to_uhwi (len);
if (exact_log2 (ilen) != -1)
{
tree type = lang_hooks.types.type_for_size (ilen * 8, 1);
if (type
&& TYPE_MODE (type) != BLKmode
&& (GET_MODE_SIZE (TYPE_MODE (type)) * BITS_PER_UNIT
== ilen * 8)
/* If the destination pointer is not aligned we must be able
to emit an unaligned store. */
&& (dest_align >= GET_MODE_ALIGNMENT (TYPE_MODE (type))
|| !SLOW_UNALIGNED_ACCESS (TYPE_MODE (type), dest_align)))
{
tree srctype = type;
tree desttype = type;
if (src_align < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
srctype = build_aligned_type (type, src_align);
tree srcmem = fold_build2 (MEM_REF, srctype, src, off0);
tree tem = fold_const_aggregate_ref (srcmem);
if (tem)
srcmem = tem;
else if (src_align < GET_MODE_ALIGNMENT (TYPE_MODE (type))
&& SLOW_UNALIGNED_ACCESS (TYPE_MODE (type),
src_align))
srcmem = NULL_TREE;
if (srcmem)
{
gimple new_stmt;
if (is_gimple_reg_type (TREE_TYPE (srcmem)))
{
new_stmt = gimple_build_assign (NULL_TREE, srcmem);
if (gimple_in_ssa_p (cfun))
srcmem = make_ssa_name (TREE_TYPE (srcmem),
new_stmt);
else
srcmem = create_tmp_reg (TREE_TYPE (srcmem),
NULL);
gimple_assign_set_lhs (new_stmt, srcmem);
gimple_set_vuse (new_stmt, gimple_vuse (stmt));
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
if (dest_align < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
desttype = build_aligned_type (type, dest_align);
new_stmt
= gimple_build_assign (fold_build2 (MEM_REF, desttype,
dest, off0),
srcmem);
gimple_set_vuse (new_stmt, gimple_vuse (stmt));
gimple_set_vdef (new_stmt, gimple_vdef (stmt));
if (gimple_vdef (new_stmt)
&& TREE_CODE (gimple_vdef (new_stmt)) == SSA_NAME)
SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
if (!lhs)
{
gsi_replace (gsi, new_stmt, true);
return true;
}
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
goto done;
}
}
}
}
if (endp == 3)
{
/* Both DEST and SRC must be pointer types.
??? This is what old code did. Is the testing for pointer types
really mandatory?
If either SRC is readonly or length is 1, we can use memcpy. */
if (!dest_align || !src_align)
return false;
if (readonly_data_expr (src)
|| (tree_fits_uhwi_p (len)
&& (MIN (src_align, dest_align) / BITS_PER_UNIT
>= tree_to_uhwi (len))))
{
tree fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (!fn)
return false;
gimple_call_set_fndecl (stmt, fn);
gimple_call_set_arg (stmt, 0, dest);
gimple_call_set_arg (stmt, 1, src);
fold_stmt (gsi);
return true;
}
/* If *src and *dest can't overlap, optimize into memcpy as well. */
if (TREE_CODE (src) == ADDR_EXPR
&& TREE_CODE (dest) == ADDR_EXPR)
{
tree src_base, dest_base, fn;
HOST_WIDE_INT src_offset = 0, dest_offset = 0;
HOST_WIDE_INT size = -1;
HOST_WIDE_INT maxsize = -1;
srcvar = TREE_OPERAND (src, 0);
src_base = get_ref_base_and_extent (srcvar, &src_offset,
&size, &maxsize);
destvar = TREE_OPERAND (dest, 0);
dest_base = get_ref_base_and_extent (destvar, &dest_offset,
&size, &maxsize);
if (tree_fits_uhwi_p (len))
maxsize = tree_to_uhwi (len);
else
maxsize = -1;
src_offset /= BITS_PER_UNIT;
dest_offset /= BITS_PER_UNIT;
if (SSA_VAR_P (src_base)
&& SSA_VAR_P (dest_base))
{
if (operand_equal_p (src_base, dest_base, 0)
&& ranges_overlap_p (src_offset, maxsize,
dest_offset, maxsize))
return false;
}
else if (TREE_CODE (src_base) == MEM_REF
&& TREE_CODE (dest_base) == MEM_REF)
{
if (! operand_equal_p (TREE_OPERAND (src_base, 0),
TREE_OPERAND (dest_base, 0), 0))
return false;
offset_int off = mem_ref_offset (src_base) + src_offset;
if (!wi::fits_shwi_p (off))
return false;
src_offset = off.to_shwi ();
off = mem_ref_offset (dest_base) + dest_offset;
if (!wi::fits_shwi_p (off))
return false;
dest_offset = off.to_shwi ();
if (ranges_overlap_p (src_offset, maxsize,
dest_offset, maxsize))
return false;
}
else
return false;
fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (!fn)
return false;
gimple_call_set_fndecl (stmt, fn);
gimple_call_set_arg (stmt, 0, dest);
gimple_call_set_arg (stmt, 1, src);
fold_stmt (gsi);
return true;
}
/* If the destination and source do not alias optimize into
memcpy as well. */
if ((is_gimple_min_invariant (dest)
|| TREE_CODE (dest) == SSA_NAME)
&& (is_gimple_min_invariant (src)
|| TREE_CODE (src) == SSA_NAME))
{
ao_ref destr, srcr;
ao_ref_init_from_ptr_and_size (&destr, dest, len);
ao_ref_init_from_ptr_and_size (&srcr, src, len);
if (!refs_may_alias_p_1 (&destr, &srcr, false))
{
tree fn;
fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (!fn)
return false;
gimple_call_set_fndecl (stmt, fn);
gimple_call_set_arg (stmt, 0, dest);
gimple_call_set_arg (stmt, 1, src);
fold_stmt (gsi);
return true;
}
}
return false;
}
if (!tree_fits_shwi_p (len))
return false;
/* FIXME:
This logic lose for arguments like (type *)malloc (sizeof (type)),
since we strip the casts of up to VOID return value from malloc.
Perhaps we ought to inherit type from non-VOID argument here? */
STRIP_NOPS (src);
STRIP_NOPS (dest);
if (!POINTER_TYPE_P (TREE_TYPE (src))
|| !POINTER_TYPE_P (TREE_TYPE (dest)))
return false;
/* In the following try to find a type that is most natural to be
used for the memcpy source and destination and that allows
the most optimization when memcpy is turned into a plain assignment
using that type. In theory we could always use a char[len] type
but that only gains us that the destination and source possibly
no longer will have their address taken. */
/* As we fold (void *)(p + CST) to (void *)p + CST undo this here. */
if (TREE_CODE (src) == POINTER_PLUS_EXPR)
{
tree tem = TREE_OPERAND (src, 0);
STRIP_NOPS (tem);
if (tem != TREE_OPERAND (src, 0))
src = build1 (NOP_EXPR, TREE_TYPE (tem), src);
}
if (TREE_CODE (dest) == POINTER_PLUS_EXPR)
{
tree tem = TREE_OPERAND (dest, 0);
STRIP_NOPS (tem);
if (tem != TREE_OPERAND (dest, 0))
dest = build1 (NOP_EXPR, TREE_TYPE (tem), dest);
}
srctype = TREE_TYPE (TREE_TYPE (src));
if (TREE_CODE (srctype) == ARRAY_TYPE
&& !tree_int_cst_equal (TYPE_SIZE_UNIT (srctype), len))
{
srctype = TREE_TYPE (srctype);
STRIP_NOPS (src);
src = build1 (NOP_EXPR, build_pointer_type (srctype), src);
}
desttype = TREE_TYPE (TREE_TYPE (dest));
if (TREE_CODE (desttype) == ARRAY_TYPE
&& !tree_int_cst_equal (TYPE_SIZE_UNIT (desttype), len))
{
desttype = TREE_TYPE (desttype);
STRIP_NOPS (dest);
dest = build1 (NOP_EXPR, build_pointer_type (desttype), dest);
}
if (TREE_ADDRESSABLE (srctype)
|| TREE_ADDRESSABLE (desttype))
return false;
/* Make sure we are not copying using a floating-point mode or
a type whose size possibly does not match its precision. */
if (FLOAT_MODE_P (TYPE_MODE (desttype))
|| TREE_CODE (desttype) == BOOLEAN_TYPE
|| TREE_CODE (desttype) == ENUMERAL_TYPE)
desttype = bitwise_type_for_mode (TYPE_MODE (desttype));
if (FLOAT_MODE_P (TYPE_MODE (srctype))
|| TREE_CODE (srctype) == BOOLEAN_TYPE
|| TREE_CODE (srctype) == ENUMERAL_TYPE)
srctype = bitwise_type_for_mode (TYPE_MODE (srctype));
if (!srctype)
srctype = desttype;
if (!desttype)
desttype = srctype;
if (!srctype)
return false;
src_align = get_pointer_alignment (src);
dest_align = get_pointer_alignment (dest);
if (dest_align < TYPE_ALIGN (desttype)
|| src_align < TYPE_ALIGN (srctype))
return false;
destvar = dest;
STRIP_NOPS (destvar);
if (TREE_CODE (destvar) == ADDR_EXPR
&& var_decl_component_p (TREE_OPERAND (destvar, 0))
&& tree_int_cst_equal (TYPE_SIZE_UNIT (desttype), len))
destvar = fold_build2 (MEM_REF, desttype, destvar, off0);
else
destvar = NULL_TREE;
srcvar = src;
STRIP_NOPS (srcvar);
if (TREE_CODE (srcvar) == ADDR_EXPR
&& var_decl_component_p (TREE_OPERAND (srcvar, 0))
&& tree_int_cst_equal (TYPE_SIZE_UNIT (srctype), len))
{
if (!destvar
|| src_align >= TYPE_ALIGN (desttype))
srcvar = fold_build2 (MEM_REF, destvar ? desttype : srctype,
srcvar, off0);
else if (!STRICT_ALIGNMENT)
{
srctype = build_aligned_type (TYPE_MAIN_VARIANT (desttype),
src_align);
srcvar = fold_build2 (MEM_REF, srctype, srcvar, off0);
}
else
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
srcvar = NULL_TREE;
}
else
srcvar = NULL_TREE;
if (srcvar == NULL_TREE && destvar == NULL_TREE)
return false;
if (srcvar == NULL_TREE)
{
STRIP_NOPS (src);
if (src_align >= TYPE_ALIGN (desttype))
srcvar = fold_build2 (MEM_REF, desttype, src, off0);
else
{
if (STRICT_ALIGNMENT)
return false;
srctype = build_aligned_type (TYPE_MAIN_VARIANT (desttype),
src_align);
srcvar = fold_build2 (MEM_REF, srctype, src, off0);
}
}
else if (destvar == NULL_TREE)
{
STRIP_NOPS (dest);
if (dest_align >= TYPE_ALIGN (srctype))
destvar = fold_build2 (MEM_REF, srctype, dest, off0);
else
{
if (STRICT_ALIGNMENT)
return false;
desttype = build_aligned_type (TYPE_MAIN_VARIANT (srctype),
dest_align);
destvar = fold_build2 (MEM_REF, desttype, dest, off0);
}
}
gimple new_stmt;
if (is_gimple_reg_type (TREE_TYPE (srcvar)))
{
new_stmt = gimple_build_assign (NULL_TREE, srcvar);
if (gimple_in_ssa_p (cfun))
srcvar = make_ssa_name (TREE_TYPE (srcvar), new_stmt);
else
srcvar = create_tmp_reg (TREE_TYPE (srcvar), NULL);
gimple_assign_set_lhs (new_stmt, srcvar);
gimple_set_vuse (new_stmt, gimple_vuse (stmt));
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
new_stmt = gimple_build_assign (destvar, srcvar);
gimple_set_vuse (new_stmt, gimple_vuse (stmt));
gimple_set_vdef (new_stmt, gimple_vdef (stmt));
if (gimple_vdef (new_stmt)
&& TREE_CODE (gimple_vdef (new_stmt)) == SSA_NAME)
SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
if (!lhs)
{
gsi_replace (gsi, new_stmt, true);
return true;
}
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
done:
if (endp == 0 || endp == 3)
len = NULL_TREE;
else if (endp == 2)
len = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (len), len,
ssize_int (1));
if (endp == 2 || endp == 1)
dest = fold_build_pointer_plus_loc (loc, dest, len);
dest = force_gimple_operand_gsi (gsi, dest, false, NULL_TREE, true,
GSI_SAME_STMT);
gimple repl = gimple_build_assign (lhs, dest);
gsi_replace (gsi, repl, true);
return true;
}
/* Fold function call to builtin memset or bzero at *GSI setting the
memory of size LEN to VAL. Return whether a simplification was made. */
static bool
gimple_fold_builtin_memset (gimple_stmt_iterator *gsi, tree c, tree len)
{
gimple stmt = gsi_stmt (*gsi);
tree etype;
unsigned HOST_WIDE_INT length, cval;
/* If the LEN parameter is zero, return DEST. */
if (integer_zerop (len))
{
replace_call_with_value (gsi, gimple_call_arg (stmt, 0));
return true;
}
if (! tree_fits_uhwi_p (len))
return false;
if (TREE_CODE (c) != INTEGER_CST)
return false;
tree dest = gimple_call_arg (stmt, 0);
tree var = dest;
if (TREE_CODE (var) != ADDR_EXPR)
return false;
var = TREE_OPERAND (var, 0);
if (TREE_THIS_VOLATILE (var))
return false;
etype = TREE_TYPE (var);
if (TREE_CODE (etype) == ARRAY_TYPE)
etype = TREE_TYPE (etype);
if (!INTEGRAL_TYPE_P (etype)
&& !POINTER_TYPE_P (etype))
return NULL_TREE;
if (! var_decl_component_p (var))
return NULL_TREE;
length = tree_to_uhwi (len);
if (GET_MODE_SIZE (TYPE_MODE (etype)) != length
|| get_pointer_alignment (dest) / BITS_PER_UNIT < length)
return NULL_TREE;
if (length > HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT)
return NULL_TREE;
if (integer_zerop (c))
cval = 0;
else
{
if (CHAR_BIT != 8 || BITS_PER_UNIT != 8 || HOST_BITS_PER_WIDE_INT > 64)
return NULL_TREE;
cval = TREE_INT_CST_LOW (c);
cval &= 0xff;
cval |= cval << 8;
cval |= cval << 16;
cval |= (cval << 31) << 1;
}
var = fold_build2 (MEM_REF, etype, dest, build_int_cst (ptr_type_node, 0));
gimple store = gimple_build_assign (var, build_int_cst_type (etype, cval));
gimple_set_vuse (store, gimple_vuse (stmt));
tree vdef = gimple_vdef (stmt);
if (vdef && TREE_CODE (vdef) == SSA_NAME)
{
gimple_set_vdef (store, gimple_vdef (stmt));
SSA_NAME_DEF_STMT (gimple_vdef (stmt)) = store;
}
gsi_insert_before (gsi, store, GSI_SAME_STMT);
if (gimple_call_lhs (stmt))
{
gimple asgn = gimple_build_assign (gimple_call_lhs (stmt), dest);
gsi_replace (gsi, asgn, true);
}
else
{
gimple_stmt_iterator gsi2 = *gsi;
gsi_prev (gsi);
gsi_remove (&gsi2, true);
}
return true;
}
/* Return the string length, maximum string length or maximum value of
ARG in LENGTH.
If ARG is an SSA name variable, follow its use-def chains. If LENGTH
is not NULL and, for TYPE == 0, its value is not equal to the length
we determine or if we are unable to determine the length or value,
return false. VISITED is a bitmap of visited variables.
TYPE is 0 if string length should be returned, 1 for maximum string
length and 2 for maximum value ARG can have. */
static bool
get_maxval_strlen (tree arg, tree *length, bitmap *visited, int type)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
{
tree var, val;
gimple def_stmt;
if (TREE_CODE (arg) != SSA_NAME)
{
/* We can end up with &(*iftmp_1)[0] here as well, so handle it. */
if (TREE_CODE (arg) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF
&& integer_zerop (TREE_OPERAND (TREE_OPERAND (arg, 0), 1)))
{
tree aop0 = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
if (TREE_CODE (aop0) == INDIRECT_REF
&& TREE_CODE (TREE_OPERAND (aop0, 0)) == SSA_NAME)
return get_maxval_strlen (TREE_OPERAND (aop0, 0),
length, visited, type);
}
if (type == 2)
{
val = arg;
if (TREE_CODE (val) != INTEGER_CST
|| tree_int_cst_sgn (val) < 0)
return false;
}
else
val = c_strlen (arg, 1);
if (!val)
return false;
if (*length)
{
if (type > 0)
{
if (TREE_CODE (*length) != INTEGER_CST
|| TREE_CODE (val) != INTEGER_CST)
return false;
if (tree_int_cst_lt (*length, val))
*length = val;
return true;
}
else if (simple_cst_equal (val, *length) != 1)
return false;
}
*length = val;
return true;
}
/* If ARG is registered for SSA update we cannot look at its defining
statement. */
if (name_registered_for_update_p (arg))
return false;
/* If we were already here, break the infinite cycle. */
if (!*visited)
*visited = BITMAP_ALLOC (NULL);
if (!bitmap_set_bit (*visited, SSA_NAME_VERSION (arg)))
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
return true;
var = arg;
def_stmt = SSA_NAME_DEF_STMT (var);
switch (gimple_code (def_stmt))
{
case GIMPLE_ASSIGN:
/* The RHS of the statement defining VAR must either have a
constant length or come from another SSA_NAME with a constant
length. */
if (gimple_assign_single_p (def_stmt)
|| gimple_assign_unary_nop_p (def_stmt))
{
tree rhs = gimple_assign_rhs1 (def_stmt);
return get_maxval_strlen (rhs, length, visited, type);
}
else if (gimple_assign_rhs_code (def_stmt) == COND_EXPR)
{
tree op2 = gimple_assign_rhs2 (def_stmt);
tree op3 = gimple_assign_rhs3 (def_stmt);
return get_maxval_strlen (op2, length, visited, type)
&& get_maxval_strlen (op3, length, visited, type);
}
return false;
case GIMPLE_PHI:
{
/* All the arguments of the PHI node must have the same constant
length. */
unsigned i;
for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
{
tree arg = gimple_phi_arg (def_stmt, i)->def;
/* If this PHI has itself as an argument, we cannot
determine the string length of this argument. However,
if we can find a constant string length for the other
PHI args then we can still be sure that this is a
constant string length. So be optimistic and just
continue with the next argument. */
if (arg == gimple_phi_result (def_stmt))
continue;
if (!get_maxval_strlen (arg, length, visited, type))
return false;
}
}
return true;
default:
return false;
}
}
tree
get_maxval_strlen (tree arg, int type)
{
bitmap visited = NULL;
tree len = NULL_TREE;
if (!get_maxval_strlen (arg, &len, &visited, type))
len = NULL_TREE;
if (visited)
BITMAP_FREE (visited);
return len;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Fold function call to builtin strcpy with arguments DEST and SRC.
If LEN is not NULL, it represents the length of the string to be
copied. Return NULL_TREE if no simplification can be made. */
static bool
gimple_fold_builtin_strcpy (gimple_stmt_iterator *gsi,
tree dest, tree src)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
{
location_t loc = gimple_location (gsi_stmt (*gsi));
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
tree fn;
/* If SRC and DEST are the same (and not volatile), return DEST. */
if (operand_equal_p (src, dest, 0))
{
replace_call_with_value (gsi, dest);
return true;
}
if (optimize_function_for_size_p (cfun))
return false;
fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (!fn)
return false;
tree len = get_maxval_strlen (src, 0);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (!len)
return false;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
len = fold_convert_loc (loc, size_type_node, len);
len = size_binop_loc (loc, PLUS_EXPR, len, build_int_cst (size_type_node, 1));
len = force_gimple_operand_gsi (gsi, len, true,
NULL_TREE, true, GSI_SAME_STMT);
gimple repl = gimple_build_call (fn, 3, dest, src, len);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
/* Fold function call to builtin strncpy with arguments DEST, SRC, and LEN.
If SLEN is not NULL, it represents the length of the source string.
Return NULL_TREE if no simplification can be made. */
static bool
gimple_fold_builtin_strncpy (gimple_stmt_iterator *gsi,
tree dest, tree src, tree len)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
{
location_t loc = gimple_location (gsi_stmt (*gsi));
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
tree fn;
/* If the LEN parameter is zero, return DEST. */
if (integer_zerop (len))
{
replace_call_with_value (gsi, dest);
return true;
}
/* We can't compare slen with len as constants below if len is not a
constant. */
if (TREE_CODE (len) != INTEGER_CST)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
return false;
/* Now, we must be passed a constant src ptr parameter. */
tree slen = get_maxval_strlen (src, 0);
if (!slen || TREE_CODE (slen) != INTEGER_CST)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
return false;
slen = size_binop_loc (loc, PLUS_EXPR, slen, ssize_int (1));
/* We do not support simplification of this case, though we do
support it when expanding trees into RTL. */
/* FIXME: generate a call to __builtin_memset. */
if (tree_int_cst_lt (slen, len))
return false;
/* OK transform into builtin memcpy. */
fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (!fn)
return false;
len = fold_convert_loc (loc, size_type_node, len);
len = force_gimple_operand_gsi (gsi, len, true,
NULL_TREE, true, GSI_SAME_STMT);
gimple repl = gimple_build_call (fn, 3, dest, src, len);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
/* Simplify a call to the strcat builtin. DST and SRC are the arguments
to the call.
Return NULL_TREE if no simplification was possible, otherwise return the
simplified form of the call as a tree.
The simplified form may be a constant or other expression which
computes the same value, but in a more efficient manner (including
calls to other builtin functions).
The call may contain arguments which need to be evaluated, but
which are not useful to determine the result of the call. In
this case we return a chain of COMPOUND_EXPRs. The LHS of each
COMPOUND_EXPR will be an argument which must be evaluated.
COMPOUND_EXPRs are chained through their RHS. The RHS of the last
COMPOUND_EXPR in the chain will contain the tree for the simplified
form of the builtin function call. */
static bool
gimple_fold_builtin_strcat (gimple_stmt_iterator *gsi, tree dst, tree src)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
{
gimple stmt = gsi_stmt (*gsi);
location_t loc = gimple_location (stmt);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
const char *p = c_getstr (src);
/* If the string length is zero, return the dst parameter. */
if (p && *p == '\0')
{
replace_call_with_value (gsi, dst);
return true;
}
if (!optimize_bb_for_speed_p (gimple_bb (stmt)))
return false;
/* See if we can store by pieces into (dst + strlen(dst)). */
tree newdst;
tree strlen_fn = builtin_decl_implicit (BUILT_IN_STRLEN);
tree memcpy_fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (!strlen_fn || !memcpy_fn)
return false;
/* If the length of the source string isn't computable don't
split strcat into strlen and memcpy. */
tree len = get_maxval_strlen (src, 0);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! len)
return false;
/* Create strlen (dst). */
gimple_seq stmts = NULL, stmts2;
gimple repl = gimple_build_call (strlen_fn, 1, dst);
gimple_set_location (repl, loc);
if (gimple_in_ssa_p (cfun))
newdst = make_ssa_name (size_type_node, NULL);
else
newdst = create_tmp_reg (size_type_node, NULL);
gimple_call_set_lhs (repl, newdst);
gimple_seq_add_stmt_without_update (&stmts, repl);
/* Create (dst p+ strlen (dst)). */
newdst = fold_build_pointer_plus_loc (loc, dst, newdst);
newdst = force_gimple_operand (newdst, &stmts2, true, NULL_TREE);
gimple_seq_add_seq_without_update (&stmts, stmts2);
len = fold_convert_loc (loc, size_type_node, len);
len = size_binop_loc (loc, PLUS_EXPR, len,
build_int_cst (size_type_node, 1));
len = force_gimple_operand (len, &stmts2, true, NULL_TREE);
gimple_seq_add_seq_without_update (&stmts, stmts2);
repl = gimple_build_call (memcpy_fn, 3, newdst, src, len);
gimple_seq_add_stmt_without_update (&stmts, repl);
if (gimple_call_lhs (stmt))
{
repl = gimple_build_assign (gimple_call_lhs (stmt), dst);
gimple_seq_add_stmt_without_update (&stmts, repl);
gsi_replace_with_seq_vops (gsi, stmts);
/* gsi now points at the assignment to the lhs, get a
stmt iterator to the memcpy call.
??? We can't use gsi_for_stmt as that doesn't work when the
CFG isn't built yet. */
gimple_stmt_iterator gsi2 = *gsi;
gsi_prev (&gsi2);
fold_stmt (&gsi2);
}
else
{
gsi_replace_with_seq_vops (gsi, stmts);
fold_stmt (gsi);
}
return true;
}
/* Fold a call to the __strcat_chk builtin FNDECL. DEST, SRC, and SIZE
are the arguments to the call. */
static bool
gimple_fold_builtin_strcat_chk (gimple_stmt_iterator *gsi)
{
gimple stmt = gsi_stmt (*gsi);
tree dest = gimple_call_arg (stmt, 0);
tree src = gimple_call_arg (stmt, 1);
tree size = gimple_call_arg (stmt, 2);
tree fn;
const char *p;
p = c_getstr (src);
/* If the SRC parameter is "", return DEST. */
if (p && *p == '\0')
{
replace_call_with_value (gsi, dest);
return true;
}
if (! tree_fits_uhwi_p (size) || ! integer_all_onesp (size))
return false;
/* If __builtin_strcat_chk is used, assume strcat is available. */
fn = builtin_decl_explicit (BUILT_IN_STRCAT);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 2, dest, src);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
/* Fold a call to the __strncat_chk builtin with arguments DEST, SRC,
LEN, and SIZE. */
static bool
gimple_fold_builtin_strncat_chk (gimple_stmt_iterator *gsi)
{
gimple stmt = gsi_stmt (*gsi);
tree dest = gimple_call_arg (stmt, 0);
tree src = gimple_call_arg (stmt, 1);
tree len = gimple_call_arg (stmt, 2);
tree size = gimple_call_arg (stmt, 3);
tree fn;
const char *p;
p = c_getstr (src);
/* If the SRC parameter is "" or if LEN is 0, return DEST. */
if ((p && *p == '\0')
|| integer_zerop (len))
{
replace_call_with_value (gsi, dest);
return true;
}
if (! tree_fits_uhwi_p (size))
return false;
if (! integer_all_onesp (size))
{
tree src_len = c_strlen (src, 1);
if (src_len
&& tree_fits_uhwi_p (src_len)
&& tree_fits_uhwi_p (len)
&& ! tree_int_cst_lt (len, src_len))
{
/* If LEN >= strlen (SRC), optimize into __strcat_chk. */
fn = builtin_decl_explicit (BUILT_IN_STRCAT_CHK);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 3, dest, src, size);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
return false;
}
/* If __builtin_strncat_chk is used, assume strncat is available. */
fn = builtin_decl_explicit (BUILT_IN_STRNCAT);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 3, dest, src, len);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Fold a call to the fputs builtin. ARG0 and ARG1 are the arguments
to the call. IGNORE is true if the value returned
by the builtin will be ignored. UNLOCKED is true is true if this
actually a call to fputs_unlocked. If LEN in non-NULL, it represents
the known length of the string. Return NULL_TREE if no simplification
was possible. */
static bool
gimple_fold_builtin_fputs (gimple_stmt_iterator *gsi,
tree arg0, tree arg1,
bool unlocked)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
{
gimple stmt = gsi_stmt (*gsi);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If we're using an unlocked function, assume the other unlocked
functions exist explicitly. */
tree const fn_fputc = (unlocked
? builtin_decl_explicit (BUILT_IN_FPUTC_UNLOCKED)
: builtin_decl_implicit (BUILT_IN_FPUTC));
tree const fn_fwrite = (unlocked
? builtin_decl_explicit (BUILT_IN_FWRITE_UNLOCKED)
: builtin_decl_implicit (BUILT_IN_FWRITE));
/* If the return value is used, don't do the transformation. */
if (gimple_call_lhs (stmt))
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
return false;
/* Get the length of the string passed to fputs. If the length
can't be determined, punt. */
tree len = get_maxval_strlen (arg0, 0);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (!len
|| TREE_CODE (len) != INTEGER_CST)
return false;
switch (compare_tree_int (len, 1))
{
case -1: /* length is 0, delete the call entirely . */
replace_call_with_value (gsi, integer_zero_node);
return true;
case 0: /* length is 1, call fputc. */
{
const char *p = c_getstr (arg0);
if (p != NULL)
{
if (!fn_fputc)
return false;
gimple repl = gimple_build_call (fn_fputc, 2,
build_int_cst
(integer_type_node, p[0]), arg1);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
}
/* FALLTHROUGH */
case 1: /* length is greater than 1, call fwrite. */
{
/* If optimizing for size keep fputs. */
if (optimize_function_for_size_p (cfun))
return false;
/* New argument list transforming fputs(string, stream) to
fwrite(string, 1, len, stream). */
if (!fn_fwrite)
return false;
gimple repl = gimple_build_call (fn_fwrite, 4, arg0,
size_one_node, len, arg1);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
default:
gcc_unreachable ();
}
return false;
}
/* Fold a call to the __mem{cpy,pcpy,move,set}_chk builtin.
DEST, SRC, LEN, and SIZE are the arguments to the call.
IGNORE is true, if return value can be ignored. FCODE is the BUILT_IN_*
code of the builtin. If MAXLEN is not NULL, it is maximum length
passed as third argument. */
static bool
gimple_fold_builtin_memory_chk (gimple_stmt_iterator *gsi,
tree dest, tree src, tree len, tree size,
enum built_in_function fcode)
{
gimple stmt = gsi_stmt (*gsi);
location_t loc = gimple_location (stmt);
bool ignore = gimple_call_lhs (stmt) == NULL_TREE;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
tree fn;
/* If SRC and DEST are the same (and not volatile), return DEST
(resp. DEST+LEN for __mempcpy_chk). */
if (fcode != BUILT_IN_MEMSET_CHK && operand_equal_p (src, dest, 0))
{
if (fcode != BUILT_IN_MEMPCPY_CHK)
{
replace_call_with_value (gsi, dest);
return true;
}
else
{
tree temp = fold_build_pointer_plus_loc (loc, dest, len);
temp = force_gimple_operand_gsi (gsi, temp,
false, NULL_TREE, true,
GSI_SAME_STMT);
replace_call_with_value (gsi, temp);
return true;
}
}
if (! tree_fits_uhwi_p (size))
return false;
tree maxlen = get_maxval_strlen (len, 2);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! integer_all_onesp (size))
{
if (! tree_fits_uhwi_p (len))
{
/* If LEN is not constant, try MAXLEN too.
For MAXLEN only allow optimizing into non-_ocs function
if SIZE is >= MAXLEN, never convert to __ocs_fail (). */
if (maxlen == NULL_TREE || ! tree_fits_uhwi_p (maxlen))
{
if (fcode == BUILT_IN_MEMPCPY_CHK && ignore)
{
/* (void) __mempcpy_chk () can be optimized into
(void) __memcpy_chk (). */
fn = builtin_decl_explicit (BUILT_IN_MEMCPY_CHK);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 4, dest, src, len, size);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
return false;
}
}
else
maxlen = len;
if (tree_int_cst_lt (size, maxlen))
return false;
}
fn = NULL_TREE;
/* If __builtin_mem{cpy,pcpy,move,set}_chk is used, assume
mem{cpy,pcpy,move,set} is available. */
switch (fcode)
{
case BUILT_IN_MEMCPY_CHK:
fn = builtin_decl_explicit (BUILT_IN_MEMCPY);
break;
case BUILT_IN_MEMPCPY_CHK:
fn = builtin_decl_explicit (BUILT_IN_MEMPCPY);
break;
case BUILT_IN_MEMMOVE_CHK:
fn = builtin_decl_explicit (BUILT_IN_MEMMOVE);
break;
case BUILT_IN_MEMSET_CHK:
fn = builtin_decl_explicit (BUILT_IN_MEMSET);
break;
default:
break;
}
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 3, dest, src, len);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
/* Fold a call to the __st[rp]cpy_chk builtin.
DEST, SRC, and SIZE are the arguments to the call.
IGNORE is true if return value can be ignored. FCODE is the BUILT_IN_*
code of the builtin. If MAXLEN is not NULL, it is maximum length of
strings passed as second argument. */
static bool
gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi,
tree dest,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
tree src, tree size,
enum built_in_function fcode)
{
gimple stmt = gsi_stmt (*gsi);
location_t loc = gimple_location (stmt);
bool ignore = gimple_call_lhs (stmt) == NULL_TREE;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
tree len, fn;
/* If SRC and DEST are the same (and not volatile), return DEST. */
if (fcode == BUILT_IN_STRCPY_CHK && operand_equal_p (src, dest, 0))
{
replace_call_with_value (gsi, dest);
return true;
}
if (! tree_fits_uhwi_p (size))
return false;
tree maxlen = get_maxval_strlen (src, 1);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! integer_all_onesp (size))
{
len = c_strlen (src, 1);
if (! len || ! tree_fits_uhwi_p (len))
{
/* If LEN is not constant, try MAXLEN too.
For MAXLEN only allow optimizing into non-_ocs function
if SIZE is >= MAXLEN, never convert to __ocs_fail (). */
if (maxlen == NULL_TREE || ! tree_fits_uhwi_p (maxlen))
{
if (fcode == BUILT_IN_STPCPY_CHK)
{
if (! ignore)
return false;
/* If return value of __stpcpy_chk is ignored,
optimize into __strcpy_chk. */
fn = builtin_decl_explicit (BUILT_IN_STRCPY_CHK);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 3, dest, src, size);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
if (! len || TREE_SIDE_EFFECTS (len))
return false;
/* If c_strlen returned something, but not a constant,
transform __strcpy_chk into __memcpy_chk. */
fn = builtin_decl_explicit (BUILT_IN_MEMCPY_CHK);
if (!fn)
return false;
len = fold_convert_loc (loc, size_type_node, len);
len = size_binop_loc (loc, PLUS_EXPR, len,
build_int_cst (size_type_node, 1));
len = force_gimple_operand_gsi (gsi, len, true, NULL_TREE,
true, GSI_SAME_STMT);
gimple repl = gimple_build_call (fn, 4, dest, src, len, size);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
else
maxlen = len;
if (! tree_int_cst_lt (maxlen, size))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If __builtin_st{r,p}cpy_chk is used, assume st{r,p}cpy is available. */
fn = builtin_decl_explicit (fcode == BUILT_IN_STPCPY_CHK
? BUILT_IN_STPCPY : BUILT_IN_STRCPY);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 2, dest, src);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
/* Fold a call to the __st{r,p}ncpy_chk builtin. DEST, SRC, LEN, and SIZE
are the arguments to the call. If MAXLEN is not NULL, it is maximum
length passed as third argument. IGNORE is true if return value can be
ignored. FCODE is the BUILT_IN_* code of the builtin. */
static bool
gimple_fold_builtin_stxncpy_chk (gimple_stmt_iterator *gsi,
tree dest, tree src,
tree len, tree size,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
enum built_in_function fcode)
{
gimple stmt = gsi_stmt (*gsi);
bool ignore = gimple_call_lhs (stmt) == NULL_TREE;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
tree fn;
if (fcode == BUILT_IN_STPNCPY_CHK && ignore)
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If return value of __stpncpy_chk is ignored,
optimize into __strncpy_chk. */
fn = builtin_decl_explicit (BUILT_IN_STRNCPY_CHK);
if (fn)
{
gimple repl = gimple_build_call (fn, 4, dest, src, len, size);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! tree_fits_uhwi_p (size))
return false;
tree maxlen = get_maxval_strlen (len, 2);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! integer_all_onesp (size))
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! tree_fits_uhwi_p (len))
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If LEN is not constant, try MAXLEN too.
For MAXLEN only allow optimizing into non-_ocs function
if SIZE is >= MAXLEN, never convert to __ocs_fail (). */
if (maxlen == NULL_TREE || ! tree_fits_uhwi_p (maxlen))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
else
maxlen = len;
if (tree_int_cst_lt (size, maxlen))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If __builtin_st{r,p}ncpy_chk is used, assume st{r,p}ncpy is available. */
fn = builtin_decl_explicit (fcode == BUILT_IN_STPNCPY_CHK
? BUILT_IN_STPNCPY : BUILT_IN_STRNCPY);
if (!fn)
return false;
gimple repl = gimple_build_call (fn, 3, dest, src, len);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Fold a call EXP to {,v}snprintf having NARGS passed as ARGS. Return
NULL_TREE if a normal call should be emitted rather than expanding
the function inline. FCODE is either BUILT_IN_SNPRINTF_CHK or
BUILT_IN_VSNPRINTF_CHK. If MAXLEN is not NULL, it is maximum length
passed as second argument. */
static bool
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple_fold_builtin_snprintf_chk (gimple_stmt_iterator *gsi,
enum built_in_function fcode)
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple stmt = gsi_stmt (*gsi);
tree dest, size, len, fn, fmt, flag;
const char *fmt_str;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Verify the required arguments in the original call. */
if (gimple_call_num_args (stmt) < 5)
return false;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
dest = gimple_call_arg (stmt, 0);
len = gimple_call_arg (stmt, 1);
flag = gimple_call_arg (stmt, 2);
size = gimple_call_arg (stmt, 3);
fmt = gimple_call_arg (stmt, 4);
if (! tree_fits_uhwi_p (size))
return false;
if (! integer_all_onesp (size))
{
tree maxlen = get_maxval_strlen (len, 2);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! tree_fits_uhwi_p (len))
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If LEN is not constant, try MAXLEN too.
For MAXLEN only allow optimizing into non-_ocs function
if SIZE is >= MAXLEN, never convert to __ocs_fail (). */
if (maxlen == NULL_TREE || ! tree_fits_uhwi_p (maxlen))
return false;
}
else
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
maxlen = len;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (tree_int_cst_lt (size, maxlen))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (!init_target_chars ())
return false;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Only convert __{,v}snprintf_chk to {,v}snprintf if flag is 0
or if format doesn't contain % chars or is "%s". */
if (! integer_zerop (flag))
{
fmt_str = c_getstr (fmt);
if (fmt_str == NULL)
return false;
if (strchr (fmt_str, target_percent) != NULL
&& strcmp (fmt_str, target_percent_s))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If __builtin_{,v}snprintf_chk is used, assume {,v}snprintf is
available. */
fn = builtin_decl_explicit (fcode == BUILT_IN_VSNPRINTF_CHK
? BUILT_IN_VSNPRINTF : BUILT_IN_SNPRINTF);
if (!fn)
return false;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Replace the called function and the first 5 argument by 3 retaining
trailing varargs. */
gimple_call_set_fndecl (stmt, fn);
gimple_call_set_fntype (stmt, TREE_TYPE (fn));
gimple_call_set_arg (stmt, 0, dest);
gimple_call_set_arg (stmt, 1, len);
gimple_call_set_arg (stmt, 2, fmt);
for (unsigned i = 3; i < gimple_call_num_args (stmt) - 2; ++i)
gimple_call_set_arg (stmt, i, gimple_call_arg (stmt, i + 2));
gimple_set_num_ops (stmt, gimple_num_ops (stmt) - 2);
fold_stmt (gsi);
return true;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Fold a call EXP to __{,v}sprintf_chk having NARGS passed as ARGS.
Return NULL_TREE if a normal call should be emitted rather than
expanding the function inline. FCODE is either BUILT_IN_SPRINTF_CHK
or BUILT_IN_VSPRINTF_CHK. */
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
static bool
gimple_fold_builtin_sprintf_chk (gimple_stmt_iterator *gsi,
enum built_in_function fcode)
{
gimple stmt = gsi_stmt (*gsi);
tree dest, size, len, fn, fmt, flag;
const char *fmt_str;
unsigned nargs = gimple_call_num_args (stmt);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Verify the required arguments in the original call. */
if (nargs < 4)
return false;
dest = gimple_call_arg (stmt, 0);
flag = gimple_call_arg (stmt, 1);
size = gimple_call_arg (stmt, 2);
fmt = gimple_call_arg (stmt, 3);
if (! tree_fits_uhwi_p (size))
return false;
len = NULL_TREE;
if (!init_target_chars ())
return false;
/* Check whether the format is a literal string constant. */
fmt_str = c_getstr (fmt);
if (fmt_str != NULL)
{
/* If the format doesn't contain % args or %%, we know the size. */
if (strchr (fmt_str, target_percent) == 0)
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (fcode != BUILT_IN_SPRINTF_CHK || nargs == 4)
len = build_int_cstu (size_type_node, strlen (fmt_str));
}
/* If the format is "%s" and first ... argument is a string literal,
we know the size too. */
else if (fcode == BUILT_IN_SPRINTF_CHK
&& strcmp (fmt_str, target_percent_s) == 0)
{
tree arg;
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (nargs == 5)
{
arg = gimple_call_arg (stmt, 4);
if (POINTER_TYPE_P (TREE_TYPE (arg)))
{
len = c_strlen (arg, 1);
if (! len || ! tree_fits_uhwi_p (len))
len = NULL_TREE;
}
}
}
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (! integer_all_onesp (size))
{
if (! len || ! tree_int_cst_lt (len, size))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Only convert __{,v}sprintf_chk to {,v}sprintf if flag is 0
or if format doesn't contain % chars or is "%s". */
if (! integer_zerop (flag))
{
if (fmt_str == NULL)
return false;
if (strchr (fmt_str, target_percent) != NULL
&& strcmp (fmt_str, target_percent_s))
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* If __builtin_{,v}sprintf_chk is used, assume {,v}sprintf is available. */
fn = builtin_decl_explicit (fcode == BUILT_IN_VSPRINTF_CHK
? BUILT_IN_VSPRINTF : BUILT_IN_SPRINTF);
if (!fn)
return false;
/* Replace the called function and the first 4 argument by 2 retaining
trailing varargs. */
gimple_call_set_fndecl (stmt, fn);
gimple_call_set_fntype (stmt, TREE_TYPE (fn));
gimple_call_set_arg (stmt, 0, dest);
gimple_call_set_arg (stmt, 1, fmt);
for (unsigned i = 2; i < gimple_call_num_args (stmt) - 2; ++i)
gimple_call_set_arg (stmt, i, gimple_call_arg (stmt, i + 2));
gimple_set_num_ops (stmt, gimple_num_ops (stmt) - 2);
fold_stmt (gsi);
return true;
}
/* Simplify a call to the sprintf builtin with arguments DEST, FMT, and ORIG.
ORIG may be null if this is a 2-argument call. We don't attempt to
simplify calls with more than 3 arguments.
Return NULL_TREE if no simplification was possible, otherwise return the
simplified form of the call as a tree. If IGNORED is true, it means that
the caller does not use the returned value of the function. */
static bool
gimple_fold_builtin_sprintf (gimple_stmt_iterator *gsi)
{
gimple stmt = gsi_stmt (*gsi);
tree dest = gimple_call_arg (stmt, 0);
tree fmt = gimple_call_arg (stmt, 1);
tree orig = NULL_TREE;
const char *fmt_str = NULL;
/* Verify the required arguments in the original call. We deal with two
types of sprintf() calls: 'sprintf (str, fmt)' and
'sprintf (dest, "%s", orig)'. */
if (gimple_call_num_args (stmt) > 3)
return false;
if (gimple_call_num_args (stmt) == 3)
orig = gimple_call_arg (stmt, 2);
/* Check whether the format is a literal string constant. */
fmt_str = c_getstr (fmt);
if (fmt_str == NULL)
return false;
if (!init_target_chars ())
return false;
/* If the format doesn't contain % args or %%, use strcpy. */
if (strchr (fmt_str, target_percent) == NULL)
{
tree fn = builtin_decl_implicit (BUILT_IN_STRCPY);
if (!fn)
return false;
/* Don't optimize sprintf (buf, "abc", ptr++). */
if (orig)
return false;
/* Convert sprintf (str, fmt) into strcpy (str, fmt) when
'format' is known to contain no % formats. */
gimple_seq stmts = NULL;
gimple repl = gimple_build_call (fn, 2, dest, fmt);
gimple_seq_add_stmt_without_update (&stmts, repl);
if (gimple_call_lhs (stmt))
{
repl = gimple_build_assign (gimple_call_lhs (stmt),
build_int_cst (integer_type_node,
strlen (fmt_str)));
gimple_seq_add_stmt_without_update (&stmts, repl);
gsi_replace_with_seq_vops (gsi, stmts);
/* gsi now points at the assignment to the lhs, get a
stmt iterator to the memcpy call.
??? We can't use gsi_for_stmt as that doesn't work when the
CFG isn't built yet. */
gimple_stmt_iterator gsi2 = *gsi;
gsi_prev (&gsi2);
fold_stmt (&gsi2);
}
else
{
gsi_replace_with_seq_vops (gsi, stmts);
fold_stmt (gsi);
}
return true;
}
/* If the format is "%s", use strcpy if the result isn't used. */
else if (fmt_str && strcmp (fmt_str, target_percent_s) == 0)
{
tree fn;
fn = builtin_decl_implicit (BUILT_IN_STRCPY);
if (!fn)
return false;
/* Don't crash on sprintf (str1, "%s"). */
if (!orig)
return false;
tree orig_len = NULL_TREE;
if (gimple_call_lhs (stmt))
{
orig_len = get_maxval_strlen (orig, 0);
if (!orig_len)
return false;
}
/* Convert sprintf (str1, "%s", str2) into strcpy (str1, str2). */
gimple_seq stmts = NULL;
gimple repl = gimple_build_call (fn, 2, dest, orig);
gimple_seq_add_stmt_without_update (&stmts, repl);
if (gimple_call_lhs (stmt))
{
if (!useless_type_conversion_p (integer_type_node,
TREE_TYPE (orig_len)))
orig_len = fold_convert (integer_type_node, orig_len);
repl = gimple_build_assign (gimple_call_lhs (stmt), orig_len);
gimple_seq_add_stmt_without_update (&stmts, repl);
gsi_replace_with_seq_vops (gsi, stmts);
/* gsi now points at the assignment to the lhs, get a
stmt iterator to the memcpy call.
??? We can't use gsi_for_stmt as that doesn't work when the
CFG isn't built yet. */
gimple_stmt_iterator gsi2 = *gsi;
gsi_prev (&gsi2);
fold_stmt (&gsi2);
}
else
{
gsi_replace_with_seq_vops (gsi, stmts);
fold_stmt (gsi);
}
return true;
}
return false;
}
/* Simplify a call to the snprintf builtin with arguments DEST, DESTSIZE,
FMT, and ORIG. ORIG may be null if this is a 3-argument call. We don't
attempt to simplify calls with more than 4 arguments.
Return NULL_TREE if no simplification was possible, otherwise return the
simplified form of the call as a tree. If IGNORED is true, it means that
the caller does not use the returned value of the function. */
static bool
gimple_fold_builtin_snprintf (gimple_stmt_iterator *gsi)
{
gimple stmt = gsi_stmt (*gsi);
tree dest = gimple_call_arg (stmt, 0);
tree destsize = gimple_call_arg (stmt, 1);
tree fmt = gimple_call_arg (stmt, 2);
tree orig = NULL_TREE;
const char *fmt_str = NULL;
if (gimple_call_num_args (stmt) > 4)
return false;
if (gimple_call_num_args (stmt) == 4)
orig = gimple_call_arg (stmt, 3);
if (!tree_fits_uhwi_p (destsize))
return false;
unsigned HOST_WIDE_INT destlen = tree_to_uhwi (destsize);
/* Check whether the format is a literal string constant. */
fmt_str = c_getstr (fmt);
if (fmt_str == NULL)
return false;
if (!init_target_chars ())
return false;
/* If the format doesn't contain % args or %%, use strcpy. */
if (strchr (fmt_str, target_percent) == NULL)
{
tree fn = builtin_decl_implicit (BUILT_IN_STRCPY);
if (!fn)
return false;
/* Don't optimize snprintf (buf, 4, "abc", ptr++). */
if (orig)
return false;
/* We could expand this as
memcpy (str, fmt, cst - 1); str[cst - 1] = '\0';
or to
memcpy (str, fmt_with_nul_at_cstm1, cst);
but in the former case that might increase code size
and in the latter case grow .rodata section too much.
So punt for now. */
size_t len = strlen (fmt_str);
if (len >= destlen)
return false;
gimple_seq stmts = NULL;
gimple repl = gimple_build_call (fn, 2, dest, fmt);
gimple_seq_add_stmt_without_update (&stmts, repl);
if (gimple_call_lhs (stmt))
{
repl = gimple_build_assign (gimple_call_lhs (stmt),
build_int_cst (integer_type_node, len));
gimple_seq_add_stmt_without_update (&stmts, repl);
gsi_replace_with_seq_vops (gsi, stmts);
/* gsi now points at the assignment to the lhs, get a
stmt iterator to the memcpy call.
??? We can't use gsi_for_stmt as that doesn't work when the
CFG isn't built yet. */
gimple_stmt_iterator gsi2 = *gsi;
gsi_prev (&gsi2);
fold_stmt (&gsi2);
}
else
{
gsi_replace_with_seq_vops (gsi, stmts);
fold_stmt (gsi);
}
return true;
}
/* If the format is "%s", use strcpy if the result isn't used. */
else if (fmt_str && strcmp (fmt_str, target_percent_s) == 0)
{
tree fn = builtin_decl_implicit (BUILT_IN_STRCPY);
if (!fn)
return false;
/* Don't crash on snprintf (str1, cst, "%s"). */
if (!orig)
return false;
tree orig_len = get_maxval_strlen (orig, 0);
if (!orig_len)
return false;
/* We could expand this as
memcpy (str1, str2, cst - 1); str1[cst - 1] = '\0';
or to
memcpy (str1, str2_with_nul_at_cstm1, cst);
but in the former case that might increase code size
and in the latter case grow .rodata section too much.
So punt for now. */
if (compare_tree_int (orig_len, destlen) >= 0)
return false;
/* Convert snprintf (str1, cst, "%s", str2) into
strcpy (str1, str2) if strlen (str2) < cst. */
gimple_seq stmts = NULL;
gimple repl = gimple_build_call (fn, 2, dest, orig);
gimple_seq_add_stmt_without_update (&stmts, repl);
if (gimple_call_lhs (stmt))
{
if (!useless_type_conversion_p (integer_type_node,
TREE_TYPE (orig_len)))
orig_len = fold_convert (integer_type_node, orig_len);
repl = gimple_build_assign (gimple_call_lhs (stmt), orig_len);
gimple_seq_add_stmt_without_update (&stmts, repl);
gsi_replace_with_seq_vops (gsi, stmts);
/* gsi now points at the assignment to the lhs, get a
stmt iterator to the memcpy call.
??? We can't use gsi_for_stmt as that doesn't work when the
CFG isn't built yet. */
gimple_stmt_iterator gsi2 = *gsi;
gsi_prev (&gsi2);
fold_stmt (&gsi2);
}
else
{
gsi_replace_with_seq_vops (gsi, stmts);
fold_stmt (gsi);
}
return true;
}
return false;
}
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
/* Fold a call to __builtin_strlen with known length LEN. */
static bool
gimple_fold_builtin_strlen (gimple_stmt_iterator *gsi)
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
{
gimple stmt = gsi_stmt (*gsi);
tree len = get_maxval_strlen (gimple_call_arg (stmt, 0), 0);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (!len)
return false;
len = force_gimple_operand_gsi (gsi, len, true, NULL, true, GSI_SAME_STMT);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
replace_call_with_value (gsi, len);
return true;
}
/* Fold the non-target builtin at *GSI and return whether any simplification
was made. */
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
static bool
gimple_fold_builtin (gimple_stmt_iterator *gsi)
{
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple stmt = gsi_stmt (*gsi);
tree callee = gimple_call_fndecl (stmt);
/* Give up for always_inline inline builtins until they are
inlined. */
if (avoid_folding_inline_builtin (callee))
return false;
switch (DECL_FUNCTION_CODE (callee))
{
case BUILT_IN_BZERO:
return gimple_fold_builtin_memset (gsi, integer_zero_node,
gimple_call_arg (stmt, 1));
case BUILT_IN_MEMSET:
return gimple_fold_builtin_memset (gsi,
gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2));
case BUILT_IN_BCOPY:
return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 0), 3);
case BUILT_IN_MEMCPY:
return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1), 0);
case BUILT_IN_MEMPCPY:
return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1), 1);
case BUILT_IN_MEMMOVE:
return gimple_fold_builtin_memory_op (gsi, gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1), 3);
case BUILT_IN_SPRINTF_CHK:
case BUILT_IN_VSPRINTF_CHK:
return gimple_fold_builtin_sprintf_chk (gsi, DECL_FUNCTION_CODE (callee));
case BUILT_IN_STRCAT_CHK:
return gimple_fold_builtin_strcat_chk (gsi);
case BUILT_IN_STRNCAT_CHK:
return gimple_fold_builtin_strncat_chk (gsi);
case BUILT_IN_STRLEN:
return gimple_fold_builtin_strlen (gsi);
case BUILT_IN_STRCPY:
return gimple_fold_builtin_strcpy (gsi,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1));
case BUILT_IN_STRNCPY:
return gimple_fold_builtin_strncpy (gsi,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2));
case BUILT_IN_STRCAT:
return gimple_fold_builtin_strcat (gsi, gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1));
case BUILT_IN_FPUTS:
return gimple_fold_builtin_fputs (gsi, gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1), false);
case BUILT_IN_FPUTS_UNLOCKED:
return gimple_fold_builtin_fputs (gsi, gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1), true);
case BUILT_IN_MEMCPY_CHK:
case BUILT_IN_MEMPCPY_CHK:
case BUILT_IN_MEMMOVE_CHK:
case BUILT_IN_MEMSET_CHK:
return gimple_fold_builtin_memory_chk (gsi,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2),
gimple_call_arg (stmt, 3),
DECL_FUNCTION_CODE (callee));
case BUILT_IN_STRCPY_CHK:
case BUILT_IN_STPCPY_CHK:
return gimple_fold_builtin_stxcpy_chk (gsi,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2),
DECL_FUNCTION_CODE (callee));
case BUILT_IN_STRNCPY_CHK:
case BUILT_IN_STPNCPY_CHK:
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
return gimple_fold_builtin_stxncpy_chk (gsi,
gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2),
gimple_call_arg (stmt, 3),
DECL_FUNCTION_CODE (callee));
case BUILT_IN_SNPRINTF_CHK:
case BUILT_IN_VSNPRINTF_CHK:
return gimple_fold_builtin_snprintf_chk (gsi,
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
DECL_FUNCTION_CODE (callee));
case BUILT_IN_SNPRINTF:
return gimple_fold_builtin_snprintf (gsi);
case BUILT_IN_SPRINTF:
return gimple_fold_builtin_sprintf (gsi);
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
default:;
}
/* Try the generic builtin folder. */
bool ignore = (gimple_call_lhs (stmt) == NULL);
tree result = fold_call_stmt (stmt, ignore);
if (result)
{
if (ignore)
STRIP_NOPS (result);
else
result = fold_convert (gimple_call_return_type (stmt), result);
if (!update_call_from_tree (gsi, result))
gimplify_and_update_call_from_tree (gsi, result);
return true;
}
return false;
}
/* Attempt to fold a call statement referenced by the statement iterator GSI.
The statement may be replaced by another statement, e.g., if the call
simplifies to a constant value. Return true if any changes were made.
It is assumed that the operands have been previously folded. */
static bool
re PR tree-optimization/46053 (g++.dg/torture/pr45699.C FAILs with -fno-early-inlining) 2010-12-15 Martin Jambor <mjambor@suse.cz> PR tree-optimization/46053 PR middle-end/46287 PR middle-end/46242 * cgraph.h (cgraph_indirect_call_info): New field thunk_delta. * gimple.h (gimple_fold_obj_type_ref): Declaration removed. (gimple_fold_call): Declare. (gimple_adjust_this_by_delta): Likewise. * cgraph.c (cgraph_make_edge_direct): New parameter delta. Updated all users. (cgraph_clone_edge): Create a copy of indirect_info also for direct edges. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Adjust this parameters. * gimple-fold.c (gimple_fold_obj_type_ref_known_binfo): Renamed to gimple_get_virt_mehtod_for_binfo, new parameter delta. Do not search through thunks, in fact bail out if we encounter one, check that BINFO_VIRTUALS is not NULL. (gimple_adjust_this_by_delta): New function. (gimple_fold_obj_type_ref): Removed. (gimple_fold_obj_type_ref_call): New function. (fold_gimple_call): Renamed to gimple_fold_call, made external. Updated users. Call gimple_fold_obj_type_ref_call instead of gimple_fold_obj_type_ref. * ipa-cp.c (ipcp_process_devirtualization_opportunities): Process thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): New parameter delta. Updated callers. (ipa_write_indirect_edge_info): Stream thunk_delta. (ipa_read_indirect_edge_info): Likewise. * tree-ssa-ccp.c (ccp_fold_stmt): Use gimple_fold_call instead of gimple_fold_obj_type_ref. * testsuite/g++.dg/ipa/pr46053.C: New test. * testsuite/g++.dg/ipa/pr46287-1.C: Likewise. * testsuite/g++.dg/ipa/pr46287-2.C: Likewise. * testsuite/g++.dg/ipa/pr46287-3.C: Likewise. * testsuite/g++.dg/torture/covariant-1.C: Likewise. * testsuite/g++.dg/torture/pr46287.C: Likewise. From-SVN: r167855
2010-12-15 14:19:46 +01:00
gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
{
gimple stmt = gsi_stmt (*gsi);
tree callee;
bool changed = false;
unsigned i;
/* Fold *& in call arguments. */
for (i = 0; i < gimple_call_num_args (stmt); ++i)
if (REFERENCE_CLASS_P (gimple_call_arg (stmt, i)))
{
tree tmp = maybe_fold_reference (gimple_call_arg (stmt, i), false);
if (tmp)
{
gimple_call_set_arg (stmt, i, tmp);
changed = true;
}
}
/* Check for virtual calls that became direct calls. */
callee = gimple_call_fn (stmt);
Makefile.in (INTERNAL_FN_DEF, [...]): Define. gcc/ * Makefile.in (INTERNAL_FN_DEF, INTERNAL_FN_H): Define. (GIMPLE_H): Include $(INTERNAL_FN_H). (OBJS-common): Add internal-fn.o. (internal-fn.o): New rule. * internal-fn.def: New file. * internal-fn.h: Likewise. * internal-fn.c: Likewise. * gimple.h: Include internal-fn.h. (GF_CALL_INTERNAL): New gf_mask. (gimple_statement_call): Put fntype into a union with a new internal_fn field. (gimple_build_call_internal): Declare. (gimple_build_call_internal_vec): Likewise. (gimple_call_same_target_p): Likewise. (gimple_call_internal_p): New function. (gimple_call_internal_fn): Likewise. (gimple_call_fntype): Return null for internal calls. (gimple_call_set_fntype): Assert that the function is not internal. (gimple_call_set_fn): Likewise. (gimple_call_set_fndecl): Likewise. (gimple_call_set_internal_fn): New function. (gimple_call_addr_fndecl): Handle null functions. (gimple_call_return_type): Likewise null types. * gimple.c (gimple_build_call_internal_1): New function. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_call_same_target_p): Likewise. (gimple_call_flags): Handle calls to internal functions. (gimple_call_fnspec): New function. (gimple_call_arg_flags, gimple_call_return_flags): Use it. (gimple_has_side_effects): Handle null functions. (gimple_rhs_has_side_effects): Likewise. (gimple_call_copy_skip_args): Handle calls to internal functions. * cfgexpand.c (expand_call_stmt): Likewise. * expr.c (expand_expr_real_1): Assert that the call isn't internal. * gimple-fold.c (gimple_fold_call): Handle null functions. (gimple_fold_stmt_to_constant_1): Don't fold calls to internal functions. * gimple-low.c (gimple_check_call_args): Handle calls to internal functions. * gimple-pretty-print.c (dump_gimple_call): Likewise. * ipa-prop.c (ipa_analyze_call_uses): Handle null functions. * tree-cfg.c (verify_gimple_call): Handle calls to internal functions. (do_warn_unused_result): Likewise. * tree-eh.c (same_handler_p): Use gimple_call_same_target_p. * tree-ssa-ccp.c (ccp_fold_stmt): Handle calls to internal functions. * tree-ssa-dom.c (hashable_expr): Use the gimple statement to record the target of a call. (initialize_hash_element): Update accordingly. (hashable_expr_equal_p): Use gimple_call_same_target_p. (iterative_hash_hashable_expr): Handle calls to internal functions. (print_expr_hash_elt): Likewise. * tree-ssa-pre.c (can_value_number_call): Likewise. (eliminate): Handle null functions. * tree-ssa-sccvn.c (visit_use): Handle calls to internal functions. * tree-ssa-structalias.c (get_fi_for_callee): Likewise. (find_func_aliases): Likewise. * value-prof.c (gimple_ic_transform): Likewise. (gimple_indirect_call_to_profile): Likewise. * lto-streamer-in.c (input_gimple_stmt): Likewise. * lto-streamer-out.c (output_gimple_stmt): Likewise. From-SVN: r172758
2011-04-20 10:21:25 +02:00
if (callee && TREE_CODE (callee) == OBJ_TYPE_REF)
{
if (gimple_call_addr_fndecl (OBJ_TYPE_REF_EXPR (callee)) != NULL_TREE)
{
if (dump_file && virtual_method_call_p (callee)
&& !possible_polymorphic_call_target_p
(callee, stmt, cgraph_node::get (gimple_call_addr_fndecl
(OBJ_TYPE_REF_EXPR (callee)))))
{
fprintf (dump_file,
"Type inheritance inconsistent devirtualization of ");
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
fprintf (dump_file, " to ");
print_generic_expr (dump_file, callee, TDF_SLIM);
fprintf (dump_file, "\n");
}
gimple_call_set_fn (stmt, OBJ_TYPE_REF_EXPR (callee));
changed = true;
}
else if (flag_devirtualize && !inplace && virtual_method_call_p (callee))
{
bool final;
vec <cgraph_node *>targets
= possible_polymorphic_call_targets (callee, stmt, &final);
if (final && targets.length () <= 1 && dbg_cnt (devirt))
{
tree lhs = gimple_call_lhs (stmt);
if (dump_enabled_p ())
{
location_t loc = gimple_location_safe (stmt);
dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,
"folding virtual function call to %s\n",
targets.length () == 1
? targets[0]->name ()
: "__builtin_unreachable");
}
if (targets.length () == 1)
{
gimple_call_set_fndecl (stmt, targets[0]->decl);
changed = true;
/* If the call becomes noreturn, remove the lhs. */
if (lhs && (gimple_call_flags (stmt) & ECF_NORETURN))
{
if (TREE_CODE (lhs) == SSA_NAME)
{
tree var = create_tmp_var (TREE_TYPE (lhs), NULL);
tree def = get_or_create_ssa_default_def (cfun, var);
gimple new_stmt = gimple_build_assign (lhs, def);
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
gimple_call_set_lhs (stmt, NULL_TREE);
}
}
else
{
tree fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
gimple new_stmt = gimple_build_call (fndecl, 0);
gimple_set_location (new_stmt, gimple_location (stmt));
if (lhs && TREE_CODE (lhs) == SSA_NAME)
{
tree var = create_tmp_var (TREE_TYPE (lhs), NULL);
tree def = get_or_create_ssa_default_def (cfun, var);
/* To satisfy condition for
cgraph_update_edges_for_call_stmt_node,
we need to preserve GIMPLE_CALL statement
at position of GSI iterator. */
update_call_from_tree (gsi, def);
gsi_insert_before (gsi, new_stmt, GSI_NEW_STMT);
}
else
{
gimple_set_vuse (new_stmt, gimple_vuse (stmt));
gimple_set_vdef (new_stmt, gimple_vdef (stmt));
gsi_replace (gsi, new_stmt, false);
}
return true;
}
}
}
}
if (inplace)
return changed;
/* Check for builtins that CCP can handle using information not
available in the generic fold routines. */
builtins.c (c_getstr, [...]): Export. 2014-08-08 Richard Biener <rguenther@suse.de> * builtins.c (c_getstr, readonly_data_expr, init_target_chars, target_percent, target_percent_s): Export. (var_decl_component_p, fold_builtin_memory_op, fold_builtin_memset, fold_builtin_bzero, fold_builtin_strcpy, fold_builtin_strncpy, fold_builtin_strcat, fold_builtin_fputs, fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_stxncpy_chk, fold_builtin_sprintf_chk_1, fold_builtin_snprintf_chk_1): Move to gimple-fold.c. (fold_builtin_2): Remove handling of bzero, fputs, fputs_unlocked, strcat and strcpy. (fold_builtin_3): Remove handling of memset, bcopy, memcpy, mempcpy, memmove, strncpy, strcpy_chk and stpcpy_chk. (fold_builtin_4): Remove handling of memcpy_chk, mempcpy_chk, memmove_chk, memset_chk, strncpy_chk and stpncpy_chk. (rewrite_call_expr_array): Remove. (fold_builtin_sprintf_chk): Likewise. (fold_builtin_snprintf_chk): Likewise. (fold_builtin_varargs): Remove handling of sprintf_chk, vsprintf_chk, snprintf_chk and vsnprintf_chk. (gimple_fold_builtin_sprintf_chk): Remove. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_varargs): Likewise. (fold_call_stmt): Do not call gimple_fold_builtin_varargs. * predict.c (optimize_bb_for_size_p): Handle NULL bb. * gimple.c (gimple_seq_add_seq_without_update): New function. * gimple.h (gimple_seq_add_seq_without_update): Declare. * gimple-fold.c: Include output.h. (gsi_replace_with_seq_vops): New function, split out from ... (gimplify_and_update_call_from_tree): ... here. (replace_call_with_value): New function. (replace_call_with_call_and_fold): Likewise. (var_decl_component_p): Moved from builtins.c. (gimple_fold_builtin_memory_op): Moved from builtins.c fold_builtin_memory_op and rewritten to GIMPLE. (gimple_fold_builtin_memset): Likewise. (gimple_fold_builtin_strcpy): Likewise. (gimple_fold_builtin_strncpy): Likewise. (gimple_fold_builtin_strcat): Likewise. (gimple_fold_builtin_fputs): Likewise. (gimple_fold_builtin_memory_chk): Likewise. (gimple_fold_builtin_stxcpy_chk): Likewise. (gimple_fold_builtin_stxncpy_chk): Likewise. (gimple_fold_builtin_snprintf_chk): Likewise. (gimple_fold_builtin_sprintf_chk): Likewise. (gimple_fold_builtin_strlen): New function. (gimple_fold_builtin_with_strlen): New function split out from gimple_fold_builtin. (gimple_fold_builtin): Change signature and handle bzero, memset, bcopy, memcpy, mempcpy and memmove folding here. Call gimple_fold_builtin_with_strlen. (gimple_fold_call): Adjust. * gcc.dg/strlenopt-8.c: Remove XFAIL. * gcc.dg/tree-prof/stringop-2.c: Adjust. * gfortran.dg/array_memcpy_4.f90: Likewise. * gfortran.dg/trim_optimize_1.f90: Likewise. * gfortran.dg/trim_optimize_2.f90: Likewise. From-SVN: r213753
2014-08-08 11:18:40 +02:00
if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
{
if (gimple_fold_builtin (gsi))
changed = true;
}
else if (gimple_call_builtin_p (stmt, BUILT_IN_MD))
{
changed |= targetm.gimple_fold_builtin (gsi);
}
else if (gimple_call_internal_p (stmt))
re PR ipa/58721 (The subroutine perdida is no longer inlined in fatigue.f90) PR ipa/58721 gcc/ * internal-fn.c: Include diagnostic-core.h. (expand_BUILTIN_EXPECT): New function. * gimplify.c (gimplify_call_expr): Use false instead of FALSE. (gimplify_modify_expr): Gimplify 3 argument __builtin_expect into IFN_BUILTIN_EXPECT call instead of __builtin_expect builtin call. * ipa-inline-analysis.c (find_foldable_builtin_expect): Handle IFN_BUILTIN_EXPECT. * predict.c (expr_expected_value_1): Handle IFN_BUILTIN_EXPECT. Revert 3 argument __builtin_expect code. (strip_predict_hints): Handle IFN_BUILTIN_EXPECT. * gimple-fold.c (gimple_fold_call): Likewise. * tree.h (fold_builtin_expect): New prototype. * builtins.c (build_builtin_expect_predicate): Add predictor argument, if non-NULL, create 3 argument __builtin_expect. (fold_builtin_expect): No longer static. Add ARG2 argument, pass it through to build_builtin_expect_predicate. (fold_builtin_2): Adjust caller. (fold_builtin_3): Handle BUILT_IN_EXPECT. * internal-fn.def (BUILTIN_EXPECT): New. gcc/fortran/ * trans.c (gfc_unlikely, gfc_likely): Don't add __builtin_expect if !optimize. 2014-03-18 Tobias Burnus <burnus@net-b.de> PR ipa/58721 gcc/ * predict.def (PRED_FORTRAN_OVERFLOW, PRED_FORTRAN_FAIL_ALLOC, PRED_FORTRAN_FAIL_IO, PRED_FORTRAN_WARN_ONCE, PRED_FORTRAN_SIZE_ZERO, PRED_FORTRAN_INVALID_BOUND, PRED_FORTRAN_ABSENT_DUMMY): Add. gcc/fortran/ * trans.h (gfc_unlikely, gfc_likely): Add predictor as argument. (gfc_trans_io_runtime_check): Remove. * trans-io.c (gfc_trans_io_runtime_check): Make static; add has_iostat as argument, add predictor to block. (set_parameter_value, gfc_trans_open, gfc_trans_close, build_filepos, gfc_trans_inquire, gfc_trans_wait, build_dt): Update calls. * trans.c (gfc_unlikely, gfc_likely): Add predictor as argument. (gfc_trans_runtime_check, gfc_allocate_using_malloc, gfc_allocate_allocatable, gfc_deallocate_with_status): Set explicitly branch predictor. * trans-expr.c (gfc_conv_procedure_call): Ditto. * trans-stmt.c (gfc_trans_allocate): Ditto. * trans-array.c (gfc_array_init_size, gfc_array_allocate): Ditto. 2014-03-18 Jan Hubicka <hubicka@ucw.cz> PR ipa/58721 gcc/ * predict.c (combine_predictions_for_bb): Fix up formatting. (expr_expected_value_1, expr_expected_value): Add predictor argument, fill what it points to if non-NULL. (tree_predict_by_opcode): Adjust caller, use the predictor. * predict.def (PRED_COMPARE_AND_SWAP): Add. From-SVN: r208641
2014-03-18 12:31:04 +01:00
{
enum tree_code subcode = ERROR_MARK;
tree result = NULL_TREE;
switch (gimple_call_internal_fn (stmt))
{
case IFN_BUILTIN_EXPECT:
result = fold_builtin_expect (gimple_location (stmt),
gimple_call_arg (stmt, 0),
gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2));
break;
case IFN_UBSAN_OBJECT_SIZE:
if (integer_all_onesp (gimple_call_arg (stmt, 2))
|| (TREE_CODE (gimple_call_arg (stmt, 1)) == INTEGER_CST
&& TREE_CODE (gimple_call_arg (stmt, 2)) == INTEGER_CST
&& tree_int_cst_le (gimple_call_arg (stmt, 1),
gimple_call_arg (stmt, 2))))
{
gsi_replace (gsi, gimple_build_nop (), true);
unlink_stmt_vdef (stmt);
release_defs (stmt);
return true;
}
break;
case IFN_UBSAN_CHECK_ADD:
subcode = PLUS_EXPR;
break;
case IFN_UBSAN_CHECK_SUB:
subcode = MINUS_EXPR;
break;
case IFN_UBSAN_CHECK_MUL:
subcode = MULT_EXPR;
break;
default:
break;
}
if (subcode != ERROR_MARK)
{
tree arg0 = gimple_call_arg (stmt, 0);
tree arg1 = gimple_call_arg (stmt, 1);
/* x = y + 0; x = y - 0; x = y * 0; */
if (integer_zerop (arg1))
result = subcode == MULT_EXPR
? build_zero_cst (TREE_TYPE (arg0))
: arg0;
/* x = 0 + y; x = 0 * y; */
else if (subcode != MINUS_EXPR && integer_zerop (arg0))
result = subcode == MULT_EXPR
? build_zero_cst (TREE_TYPE (arg0))
: arg1;
/* x = y - y; */
else if (subcode == MINUS_EXPR && operand_equal_p (arg0, arg1, 0))
result = build_zero_cst (TREE_TYPE (arg0));
/* x = y * 1; x = 1 * y; */
else if (subcode == MULT_EXPR)
{
if (integer_onep (arg1))
result = arg0;
else if (integer_onep (arg0))
result = arg1;
}
}
re PR ipa/58721 (The subroutine perdida is no longer inlined in fatigue.f90) PR ipa/58721 gcc/ * internal-fn.c: Include diagnostic-core.h. (expand_BUILTIN_EXPECT): New function. * gimplify.c (gimplify_call_expr): Use false instead of FALSE. (gimplify_modify_expr): Gimplify 3 argument __builtin_expect into IFN_BUILTIN_EXPECT call instead of __builtin_expect builtin call. * ipa-inline-analysis.c (find_foldable_builtin_expect): Handle IFN_BUILTIN_EXPECT. * predict.c (expr_expected_value_1): Handle IFN_BUILTIN_EXPECT. Revert 3 argument __builtin_expect code. (strip_predict_hints): Handle IFN_BUILTIN_EXPECT. * gimple-fold.c (gimple_fold_call): Likewise. * tree.h (fold_builtin_expect): New prototype. * builtins.c (build_builtin_expect_predicate): Add predictor argument, if non-NULL, create 3 argument __builtin_expect. (fold_builtin_expect): No longer static. Add ARG2 argument, pass it through to build_builtin_expect_predicate. (fold_builtin_2): Adjust caller. (fold_builtin_3): Handle BUILT_IN_EXPECT. * internal-fn.def (BUILTIN_EXPECT): New. gcc/fortran/ * trans.c (gfc_unlikely, gfc_likely): Don't add __builtin_expect if !optimize. 2014-03-18 Tobias Burnus <burnus@net-b.de> PR ipa/58721 gcc/ * predict.def (PRED_FORTRAN_OVERFLOW, PRED_FORTRAN_FAIL_ALLOC, PRED_FORTRAN_FAIL_IO, PRED_FORTRAN_WARN_ONCE, PRED_FORTRAN_SIZE_ZERO, PRED_FORTRAN_INVALID_BOUND, PRED_FORTRAN_ABSENT_DUMMY): Add. gcc/fortran/ * trans.h (gfc_unlikely, gfc_likely): Add predictor as argument. (gfc_trans_io_runtime_check): Remove. * trans-io.c (gfc_trans_io_runtime_check): Make static; add has_iostat as argument, add predictor to block. (set_parameter_value, gfc_trans_open, gfc_trans_close, build_filepos, gfc_trans_inquire, gfc_trans_wait, build_dt): Update calls. * trans.c (gfc_unlikely, gfc_likely): Add predictor as argument. (gfc_trans_runtime_check, gfc_allocate_using_malloc, gfc_allocate_allocatable, gfc_deallocate_with_status): Set explicitly branch predictor. * trans-expr.c (gfc_conv_procedure_call): Ditto. * trans-stmt.c (gfc_trans_allocate): Ditto. * trans-array.c (gfc_array_init_size, gfc_array_allocate): Ditto. 2014-03-18 Jan Hubicka <hubicka@ucw.cz> PR ipa/58721 gcc/ * predict.c (combine_predictions_for_bb): Fix up formatting. (expr_expected_value_1, expr_expected_value): Add predictor argument, fill what it points to if non-NULL. (tree_predict_by_opcode): Adjust caller, use the predictor. * predict.def (PRED_COMPARE_AND_SWAP): Add. From-SVN: r208641
2014-03-18 12:31:04 +01:00
if (result)
{
if (!update_call_from_tree (gsi, result))
gimplify_and_update_call_from_tree (gsi, result);
changed = true;
}
}
return changed;
}
/* Canonicalize MEM_REFs invariant address operand after propagation. */
static bool
maybe_canonicalize_mem_ref_addr (tree *t)
{
bool res = false;
if (TREE_CODE (*t) == ADDR_EXPR)
t = &TREE_OPERAND (*t, 0);
while (handled_component_p (*t))
t = &TREE_OPERAND (*t, 0);
/* Canonicalize MEM [&foo.bar, 0] which appears after propagating
of invariant addresses into a SSA name MEM_REF address. */
if (TREE_CODE (*t) == MEM_REF
|| TREE_CODE (*t) == TARGET_MEM_REF)
{
tree addr = TREE_OPERAND (*t, 0);
if (TREE_CODE (addr) == ADDR_EXPR
&& (TREE_CODE (TREE_OPERAND (addr, 0)) == MEM_REF
|| handled_component_p (TREE_OPERAND (addr, 0))))
{
tree base;
HOST_WIDE_INT coffset;
base = get_addr_base_and_unit_offset (TREE_OPERAND (addr, 0),
&coffset);
if (!base)
gcc_unreachable ();
TREE_OPERAND (*t, 0) = build_fold_addr_expr (base);
TREE_OPERAND (*t, 1) = int_const_binop (PLUS_EXPR,
TREE_OPERAND (*t, 1),
size_int (coffset));
res = true;
}
gcc_checking_assert (TREE_CODE (TREE_OPERAND (*t, 0)) == DEBUG_EXPR_DECL
|| is_gimple_mem_ref_addr (TREE_OPERAND (*t, 0)));
}
/* Canonicalize back MEM_REFs to plain reference trees if the object
accessed is a decl that has the same access semantics as the MEM_REF. */
if (TREE_CODE (*t) == MEM_REF
&& TREE_CODE (TREE_OPERAND (*t, 0)) == ADDR_EXPR
&& integer_zerop (TREE_OPERAND (*t, 1)))
{
tree decl = TREE_OPERAND (TREE_OPERAND (*t, 0), 0);
tree alias_type = TREE_TYPE (TREE_OPERAND (*t, 1));
if (/* Same volatile qualification. */
TREE_THIS_VOLATILE (*t) == TREE_THIS_VOLATILE (decl)
/* Same TBAA behavior with -fstrict-aliasing. */
&& !TYPE_REF_CAN_ALIAS_ALL (alias_type)
&& (TYPE_MAIN_VARIANT (TREE_TYPE (decl))
== TYPE_MAIN_VARIANT (TREE_TYPE (alias_type)))
/* Same alignment. */
&& TYPE_ALIGN (TREE_TYPE (decl)) == TYPE_ALIGN (TREE_TYPE (*t))
/* We have to look out here to not drop a required conversion
from the rhs to the lhs if *t appears on the lhs or vice-versa
if it appears on the rhs. Thus require strict type
compatibility. */
&& types_compatible_p (TREE_TYPE (*t), TREE_TYPE (decl)))
{
*t = TREE_OPERAND (TREE_OPERAND (*t, 0), 0);
res = true;
}
}
/* Canonicalize TARGET_MEM_REF in particular with respect to
the indexes becoming constant. */
else if (TREE_CODE (*t) == TARGET_MEM_REF)
{
tree tem = maybe_fold_tmr (*t);
if (tem)
{
*t = tem;
res = true;
}
}
return res;
}
/* Worker for both fold_stmt and fold_stmt_inplace. The INPLACE argument
distinguishes both cases. */
static bool
fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace)
{
bool changed = false;
gimple stmt = gsi_stmt (*gsi);
unsigned i;
/* First do required canonicalization of [TARGET_]MEM_REF addresses
after propagation.
??? This shouldn't be done in generic folding but in the
propagation helpers which also know whether an address was
propagated. */
switch (gimple_code (stmt))
{
case GIMPLE_ASSIGN:
if (gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
{
tree *rhs = gimple_assign_rhs1_ptr (stmt);
if ((REFERENCE_CLASS_P (*rhs)
|| TREE_CODE (*rhs) == ADDR_EXPR)
&& maybe_canonicalize_mem_ref_addr (rhs))
changed = true;
tree *lhs = gimple_assign_lhs_ptr (stmt);
if (REFERENCE_CLASS_P (*lhs)
&& maybe_canonicalize_mem_ref_addr (lhs))
changed = true;
}
break;
case GIMPLE_CALL:
{
for (i = 0; i < gimple_call_num_args (stmt); ++i)
{
tree *arg = gimple_call_arg_ptr (stmt, i);
if (REFERENCE_CLASS_P (*arg)
&& maybe_canonicalize_mem_ref_addr (arg))
changed = true;
}
tree *lhs = gimple_call_lhs_ptr (stmt);
if (*lhs
&& REFERENCE_CLASS_P (*lhs)
&& maybe_canonicalize_mem_ref_addr (lhs))
changed = true;
break;
}
case GIMPLE_ASM:
{
for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
{
tree link = gimple_asm_output_op (stmt, i);
tree op = TREE_VALUE (link);
if (REFERENCE_CLASS_P (op)
&& maybe_canonicalize_mem_ref_addr (&TREE_VALUE (link)))
changed = true;
}
for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
{
tree link = gimple_asm_input_op (stmt, i);
tree op = TREE_VALUE (link);
if ((REFERENCE_CLASS_P (op)
|| TREE_CODE (op) == ADDR_EXPR)
&& maybe_canonicalize_mem_ref_addr (&TREE_VALUE (link)))
changed = true;
}
}
break;
case GIMPLE_DEBUG:
if (gimple_debug_bind_p (stmt))
{
tree *val = gimple_debug_bind_get_value_ptr (stmt);
if (*val
&& (REFERENCE_CLASS_P (*val)
|| TREE_CODE (*val) == ADDR_EXPR)
&& maybe_canonicalize_mem_ref_addr (val))
changed = true;
}
break;
default:;
}
/* Fold the main computation performed by the statement. */
switch (gimple_code (stmt))
{
case GIMPLE_ASSIGN:
{
unsigned old_num_ops = gimple_num_ops (stmt);
enum tree_code subcode = gimple_assign_rhs_code (stmt);
tree lhs = gimple_assign_lhs (stmt);
tree new_rhs;
/* First canonicalize operand order. This avoids building new
trees if this is the only thing fold would later do. */
if ((commutative_tree_code (subcode)
|| commutative_ternary_tree_code (subcode))
&& tree_swap_operands_p (gimple_assign_rhs1 (stmt),
gimple_assign_rhs2 (stmt), false))
{
tree tem = gimple_assign_rhs1 (stmt);
gimple_assign_set_rhs1 (stmt, gimple_assign_rhs2 (stmt));
gimple_assign_set_rhs2 (stmt, tem);
changed = true;
}
new_rhs = fold_gimple_assign (gsi);
if (new_rhs
&& !useless_type_conversion_p (TREE_TYPE (lhs),
TREE_TYPE (new_rhs)))
new_rhs = fold_convert (TREE_TYPE (lhs), new_rhs);
if (new_rhs
&& (!inplace
|| get_gimple_rhs_num_ops (TREE_CODE (new_rhs)) < old_num_ops))
{
gimple_assign_set_rhs_from_tree (gsi, new_rhs);
changed = true;
}
break;
}
case GIMPLE_COND:
changed |= fold_gimple_cond (stmt);
break;
case GIMPLE_CALL:
re PR tree-optimization/46053 (g++.dg/torture/pr45699.C FAILs with -fno-early-inlining) 2010-12-15 Martin Jambor <mjambor@suse.cz> PR tree-optimization/46053 PR middle-end/46287 PR middle-end/46242 * cgraph.h (cgraph_indirect_call_info): New field thunk_delta. * gimple.h (gimple_fold_obj_type_ref): Declaration removed. (gimple_fold_call): Declare. (gimple_adjust_this_by_delta): Likewise. * cgraph.c (cgraph_make_edge_direct): New parameter delta. Updated all users. (cgraph_clone_edge): Create a copy of indirect_info also for direct edges. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Adjust this parameters. * gimple-fold.c (gimple_fold_obj_type_ref_known_binfo): Renamed to gimple_get_virt_mehtod_for_binfo, new parameter delta. Do not search through thunks, in fact bail out if we encounter one, check that BINFO_VIRTUALS is not NULL. (gimple_adjust_this_by_delta): New function. (gimple_fold_obj_type_ref): Removed. (gimple_fold_obj_type_ref_call): New function. (fold_gimple_call): Renamed to gimple_fold_call, made external. Updated users. Call gimple_fold_obj_type_ref_call instead of gimple_fold_obj_type_ref. * ipa-cp.c (ipcp_process_devirtualization_opportunities): Process thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): New parameter delta. Updated callers. (ipa_write_indirect_edge_info): Stream thunk_delta. (ipa_read_indirect_edge_info): Likewise. * tree-ssa-ccp.c (ccp_fold_stmt): Use gimple_fold_call instead of gimple_fold_obj_type_ref. * testsuite/g++.dg/ipa/pr46053.C: New test. * testsuite/g++.dg/ipa/pr46287-1.C: Likewise. * testsuite/g++.dg/ipa/pr46287-2.C: Likewise. * testsuite/g++.dg/ipa/pr46287-3.C: Likewise. * testsuite/g++.dg/torture/covariant-1.C: Likewise. * testsuite/g++.dg/torture/pr46287.C: Likewise. From-SVN: r167855
2010-12-15 14:19:46 +01:00
changed |= gimple_fold_call (gsi, inplace);
break;
case GIMPLE_ASM:
/* Fold *& in asm operands. */
{
size_t noutputs;
const char **oconstraints;
const char *constraint;
bool allows_mem, allows_reg;
noutputs = gimple_asm_noutputs (stmt);
oconstraints = XALLOCAVEC (const char *, noutputs);
for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
{
tree link = gimple_asm_output_op (stmt, i);
tree op = TREE_VALUE (link);
oconstraints[i]
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
if (REFERENCE_CLASS_P (op)
&& (op = maybe_fold_reference (op, true)) != NULL_TREE)
{
TREE_VALUE (link) = op;
changed = true;
}
}
for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
{
tree link = gimple_asm_input_op (stmt, i);
tree op = TREE_VALUE (link);
constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
parse_input_constraint (&constraint, 0, 0, noutputs, 0,
oconstraints, &allows_mem, &allows_reg);
if (REFERENCE_CLASS_P (op)
&& (op = maybe_fold_reference (op, !allows_reg && allows_mem))
!= NULL_TREE)
{
TREE_VALUE (link) = op;
changed = true;
}
}
}
break;
case GIMPLE_DEBUG:
if (gimple_debug_bind_p (stmt))
{
tree val = gimple_debug_bind_get_value (stmt);
if (val
&& REFERENCE_CLASS_P (val))
{
tree tem = maybe_fold_reference (val, false);
if (tem)
{
gimple_debug_bind_set_value (stmt, tem);
changed = true;
}
}
else if (val
&& TREE_CODE (val) == ADDR_EXPR)
{
tree ref = TREE_OPERAND (val, 0);
tree tem = maybe_fold_reference (ref, false);
if (tem)
{
tem = build_fold_addr_expr_with_type (tem, TREE_TYPE (val));
gimple_debug_bind_set_value (stmt, tem);
changed = true;
}
}
}
break;
default:;
}
stmt = gsi_stmt (*gsi);
/* Fold *& on the lhs. */
if (gimple_has_lhs (stmt))
{
tree lhs = gimple_get_lhs (stmt);
if (lhs && REFERENCE_CLASS_P (lhs))
{
tree new_lhs = maybe_fold_reference (lhs, true);
if (new_lhs)
{
gimple_set_lhs (stmt, new_lhs);
changed = true;
}
}
}
return changed;
}
/* Fold the statement pointed to by GSI. In some cases, this function may
replace the whole statement with a new one. Returns true iff folding
makes any changes.
The statement pointed to by GSI should be in valid gimple form but may
be in unfolded state as resulting from for example constant propagation
which can produce *&x = 0. */
bool
fold_stmt (gimple_stmt_iterator *gsi)
{
return fold_stmt_1 (gsi, false);
}
/* Perform the minimal folding on statement *GSI. Only operations like
*&x created by constant propagation are handled. The statement cannot
be replaced with a new one. Return true if the statement was
changed, false otherwise.
The statement *GSI should be in valid gimple form but may
be in unfolded state as resulting from for example constant propagation
which can produce *&x = 0. */
bool
fold_stmt_inplace (gimple_stmt_iterator *gsi)
{
gimple stmt = gsi_stmt (*gsi);
bool changed = fold_stmt_1 (gsi, true);
gcc_assert (gsi_stmt (*gsi) == stmt);
return changed;
}
/* Canonicalize and possibly invert the boolean EXPR; return NULL_TREE
if EXPR is null or we don't know how.
If non-null, the result always has boolean type. */
static tree
canonicalize_bool (tree expr, bool invert)
{
if (!expr)
return NULL_TREE;
else if (invert)
{
if (integer_nonzerop (expr))
return boolean_false_node;
else if (integer_zerop (expr))
return boolean_true_node;
else if (TREE_CODE (expr) == SSA_NAME)
return fold_build2 (EQ_EXPR, boolean_type_node, expr,
build_int_cst (TREE_TYPE (expr), 0));
else if (TREE_CODE_CLASS (TREE_CODE (expr)) == tcc_comparison)
return fold_build2 (invert_tree_comparison (TREE_CODE (expr), false),
boolean_type_node,
TREE_OPERAND (expr, 0),
TREE_OPERAND (expr, 1));
else
return NULL_TREE;
}
else
{
if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE)
return expr;
if (integer_nonzerop (expr))
return boolean_true_node;
else if (integer_zerop (expr))
return boolean_false_node;
else if (TREE_CODE (expr) == SSA_NAME)
return fold_build2 (NE_EXPR, boolean_type_node, expr,
build_int_cst (TREE_TYPE (expr), 0));
else if (TREE_CODE_CLASS (TREE_CODE (expr)) == tcc_comparison)
return fold_build2 (TREE_CODE (expr),
boolean_type_node,
TREE_OPERAND (expr, 0),
TREE_OPERAND (expr, 1));
else
return NULL_TREE;
}
}
/* Check to see if a boolean expression EXPR is logically equivalent to the
comparison (OP1 CODE OP2). Check for various identities involving
SSA_NAMEs. */
static bool
same_bool_comparison_p (const_tree expr, enum tree_code code,
const_tree op1, const_tree op2)
{
gimple s;
/* The obvious case. */
if (TREE_CODE (expr) == code
&& operand_equal_p (TREE_OPERAND (expr, 0), op1, 0)
&& operand_equal_p (TREE_OPERAND (expr, 1), op2, 0))
return true;
/* Check for comparing (name, name != 0) and the case where expr
is an SSA_NAME with a definition matching the comparison. */
if (TREE_CODE (expr) == SSA_NAME
&& TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE)
{
if (operand_equal_p (expr, op1, 0))
return ((code == NE_EXPR && integer_zerop (op2))
|| (code == EQ_EXPR && integer_nonzerop (op2)));
s = SSA_NAME_DEF_STMT (expr);
if (is_gimple_assign (s)
&& gimple_assign_rhs_code (s) == code
&& operand_equal_p (gimple_assign_rhs1 (s), op1, 0)
&& operand_equal_p (gimple_assign_rhs2 (s), op2, 0))
return true;
}
/* If op1 is of the form (name != 0) or (name == 0), and the definition
of name is a comparison, recurse. */
if (TREE_CODE (op1) == SSA_NAME
&& TREE_CODE (TREE_TYPE (op1)) == BOOLEAN_TYPE)
{
s = SSA_NAME_DEF_STMT (op1);
if (is_gimple_assign (s)
&& TREE_CODE_CLASS (gimple_assign_rhs_code (s)) == tcc_comparison)
{
enum tree_code c = gimple_assign_rhs_code (s);
if ((c == NE_EXPR && integer_zerop (op2))
|| (c == EQ_EXPR && integer_nonzerop (op2)))
return same_bool_comparison_p (expr, c,
gimple_assign_rhs1 (s),
gimple_assign_rhs2 (s));
if ((c == EQ_EXPR && integer_zerop (op2))
|| (c == NE_EXPR && integer_nonzerop (op2)))
return same_bool_comparison_p (expr,
invert_tree_comparison (c, false),
gimple_assign_rhs1 (s),
gimple_assign_rhs2 (s));
}
}
return false;
}
/* Check to see if two boolean expressions OP1 and OP2 are logically
equivalent. */
static bool
same_bool_result_p (const_tree op1, const_tree op2)
{
/* Simple cases first. */
if (operand_equal_p (op1, op2, 0))
return true;
/* Check the cases where at least one of the operands is a comparison.
These are a bit smarter than operand_equal_p in that they apply some
identifies on SSA_NAMEs. */
if (TREE_CODE_CLASS (TREE_CODE (op2)) == tcc_comparison
&& same_bool_comparison_p (op1, TREE_CODE (op2),
TREE_OPERAND (op2, 0),
TREE_OPERAND (op2, 1)))
return true;
if (TREE_CODE_CLASS (TREE_CODE (op1)) == tcc_comparison
&& same_bool_comparison_p (op2, TREE_CODE (op1),
TREE_OPERAND (op1, 0),
TREE_OPERAND (op1, 1)))
return true;
/* Default case. */
return false;
}
/* Forward declarations for some mutually recursive functions. */
static tree
and_comparisons_1 (enum tree_code code1, tree op1a, tree op1b,
enum tree_code code2, tree op2a, tree op2b);
static tree
and_var_with_comparison (tree var, bool invert,
enum tree_code code2, tree op2a, tree op2b);
static tree
and_var_with_comparison_1 (gimple stmt,
enum tree_code code2, tree op2a, tree op2b);
static tree
or_comparisons_1 (enum tree_code code1, tree op1a, tree op1b,
enum tree_code code2, tree op2a, tree op2b);
static tree
or_var_with_comparison (tree var, bool invert,
enum tree_code code2, tree op2a, tree op2b);
static tree
or_var_with_comparison_1 (gimple stmt,
enum tree_code code2, tree op2a, tree op2b);
/* Helper function for and_comparisons_1: try to simplify the AND of the
ssa variable VAR with the comparison specified by (OP2A CODE2 OP2B).
If INVERT is true, invert the value of the VAR before doing the AND.
Return NULL_EXPR if we can't simplify this to a single expression. */
static tree
and_var_with_comparison (tree var, bool invert,
enum tree_code code2, tree op2a, tree op2b)
{
tree t;
gimple stmt = SSA_NAME_DEF_STMT (var);
/* We can only deal with variables whose definitions are assignments. */
if (!is_gimple_assign (stmt))
return NULL_TREE;
/* If we have an inverted comparison, apply DeMorgan's law and rewrite
!var AND (op2a code2 op2b) => !(var OR !(op2a code2 op2b))
Then we only have to consider the simpler non-inverted cases. */
if (invert)
t = or_var_with_comparison_1 (stmt,
invert_tree_comparison (code2, false),
op2a, op2b);
else
t = and_var_with_comparison_1 (stmt, code2, op2a, op2b);
return canonicalize_bool (t, invert);
}
/* Try to simplify the AND of the ssa variable defined by the assignment
STMT with the comparison specified by (OP2A CODE2 OP2B).
Return NULL_EXPR if we can't simplify this to a single expression. */
static tree
and_var_with_comparison_1 (gimple stmt,
enum tree_code code2, tree op2a, tree op2b)
{
tree var = gimple_assign_lhs (stmt);
tree true_test_var = NULL_TREE;
tree false_test_var = NULL_TREE;
enum tree_code innercode = gimple_assign_rhs_code (stmt);
/* Check for identities like (var AND (var == 0)) => false. */
if (TREE_CODE (op2a) == SSA_NAME
&& TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE)
{
if ((code2 == NE_EXPR && integer_zerop (op2b))
|| (code2 == EQ_EXPR && integer_nonzerop (op2b)))
{
true_test_var = op2a;
if (var == true_test_var)
return var;
}
else if ((code2 == EQ_EXPR && integer_zerop (op2b))
|| (code2 == NE_EXPR && integer_nonzerop (op2b)))
{
false_test_var = op2a;
if (var == false_test_var)
return boolean_false_node;
}
}
/* If the definition is a comparison, recurse on it. */
if (TREE_CODE_CLASS (innercode) == tcc_comparison)
{
tree t = and_comparisons_1 (innercode,
gimple_assign_rhs1 (stmt),
gimple_assign_rhs2 (stmt),
code2,
op2a,
op2b);
if (t)
return t;
}
/* If the definition is an AND or OR expression, we may be able to
simplify by reassociating. */
if (TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE
&& (innercode == BIT_AND_EXPR || innercode == BIT_IOR_EXPR))
{
tree inner1 = gimple_assign_rhs1 (stmt);
tree inner2 = gimple_assign_rhs2 (stmt);
gimple s;
tree t;
tree partial = NULL_TREE;
bool is_and = (innercode == BIT_AND_EXPR);
/* Check for boolean identities that don't require recursive examination
of inner1/inner2:
inner1 AND (inner1 AND inner2) => inner1 AND inner2 => var
inner1 AND (inner1 OR inner2) => inner1
!inner1 AND (inner1 AND inner2) => false
!inner1 AND (inner1 OR inner2) => !inner1 AND inner2
Likewise for similar cases involving inner2. */
if (inner1 == true_test_var)
return (is_and ? var : inner1);
else if (inner2 == true_test_var)
return (is_and ? var : inner2);
else if (inner1 == false_test_var)
return (is_and
? boolean_false_node
: and_var_with_comparison (inner2, false, code2, op2a, op2b));
else if (inner2 == false_test_var)
return (is_and
? boolean_false_node
: and_var_with_comparison (inner1, false, code2, op2a, op2b));
/* Next, redistribute/reassociate the AND across the inner tests.
Compute the first partial result, (inner1 AND (op2a code op2b)) */
if (TREE_CODE (inner1) == SSA_NAME
&& is_gimple_assign (s = SSA_NAME_DEF_STMT (inner1))
&& TREE_CODE_CLASS (gimple_assign_rhs_code (s)) == tcc_comparison
&& (t = maybe_fold_and_comparisons (gimple_assign_rhs_code (s),
gimple_assign_rhs1 (s),
gimple_assign_rhs2 (s),
code2, op2a, op2b)))
{
/* Handle the AND case, where we are reassociating:
(inner1 AND inner2) AND (op2a code2 op2b)
=> (t AND inner2)
If the partial result t is a constant, we win. Otherwise
continue on to try reassociating with the other inner test. */
if (is_and)
{
if (integer_onep (t))
return inner2;
else if (integer_zerop (t))
return boolean_false_node;
}
/* Handle the OR case, where we are redistributing:
(inner1 OR inner2) AND (op2a code2 op2b)
=> (t OR (inner2 AND (op2a code2 op2b))) */
else if (integer_onep (t))
return boolean_true_node;
/* Save partial result for later. */
partial = t;
}
/* Compute the second partial result, (inner2 AND (op2a code op2b)) */
if (TREE_CODE (inner2) == SSA_NAME
&& is_gimple_assign (s = SSA_NAME_DEF_STMT (inner2))
&& TREE_CODE_CLASS (gimple_assign_rhs_code (s)) == tcc_comparison
&& (t = maybe_fold_and_comparisons (gimple_assign_rhs_code (s),
gimple_assign_rhs1 (s),
gimple_assign_rhs2 (s),
code2, op2a, op2b)))
{
/* Handle the AND case, where we are reassociating:
(inner1 AND inner2) AND (op2a code2 op2b)
=> (inner1 AND t) */
if (is_and)
{
if (integer_onep (t))
return inner1;
else if (integer_zerop (t))
return boolean_false_node;
/* If both are the same, we can apply the identity
(x AND x) == x. */
else if (partial && same_bool_result_p (t, partial))
return t;
}
/* Handle the OR case. where we are redistributing:
(inner1 OR inner2) AND (op2a code2 op2b)
=> (t OR (inner1 AND (op2a code2 op2b)))
=> (t OR partial) */
else
{
if (integer_onep (t))
return boolean_true_node;
else if (partial)
{
/* We already got a simplification for the other
operand to the redistributed OR expression. The
interesting case is when at least one is false.
Or, if both are the same, we can apply the identity
(x OR x) == x. */
if (integer_zerop (partial))
return t;
else if (integer_zerop (t))
return partial;
else if (same_bool_result_p (t, partial))
return t;
}
}
}
}
return NULL_TREE;
}
/* Try to simplify the AND of two comparisons defined by
(OP1A CODE1 OP1B) and (OP2A CODE2 OP2B), respectively.
If this can be done without constructing an intermediate value,
return the resulting tree; otherwise NULL_TREE is returned.
This function is deliberately asymmetric as it recurses on SSA_DEFs
in the first comparison but not the second. */
static tree
and_comparisons_1 (enum tree_code code1, tree op1a, tree op1b,
enum tree_code code2, tree op2a, tree op2b)
{
tree truth_type = truth_type_for (TREE_TYPE (op1a));
re PR c++/54427 (Expose more vector extensions) 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 gcc/ChangeLog * fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE. (fold_binary_loc): Likewise. * gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE. (or_comparisons_1): Likewise. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE. gcc/testsuite/ChangeLog * g++.dg/other/vector-compare.C: New testcase. * gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase. * gcc.dg/vector-shift.c: Move ... * c-c++-common/vector-shift.c: ... here. * gcc.dg/vector-shift1.c: Move ... * c-c++-common/vector-shift1.c: ... here. * gcc.dg/vector-shift3.c: Move ... * c-c++-common/vector-shift3.c: ... here. * gcc.dg/vector-compare-1.c: Move ... * c-c++-common/vector-compare-1.c: ... here. * gcc.dg/vector-compare-2.c: Move ... * c-c++-common/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-compare-1.c: Move ... * c-c++-common/torture/vector-compare-1.c: ... here. * gcc.c-torture/execute/vector-compare-2.x: Delete. * gcc.c-torture/execute/vector-compare-2.c: Move ... * c-c++-common/torture/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-shift.c: Move ... * c-c++-common/torture/vector-shift.c: ... here. * gcc.c-torture/execute/vector-shift2.c: Move ... * c-c++-common/torture/vector-shift2.c: ... here. * gcc.c-torture/execute/vector-subscript-1.c: Move ... * c-c++-common/torture/vector-subscript-1.c: ... here. * gcc.c-torture/execute/vector-subscript-2.c: Move ... * c-c++-common/torture/vector-subscript-2.c: ... here. * gcc.c-torture/execute/vector-subscript-3.c: Move ... * c-c++-common/torture/vector-subscript-3.c: ... here. From-SVN: r191308
2012-09-14 19:17:01 +02:00
/* First check for ((x CODE1 y) AND (x CODE2 y)). */
if (operand_equal_p (op1a, op2a, 0)
&& operand_equal_p (op1b, op2b, 0))
{
/* Result will be either NULL_TREE, or a combined comparison. */
tree t = combine_comparisons (UNKNOWN_LOCATION,
TRUTH_ANDIF_EXPR, code1, code2,
re PR c++/54427 (Expose more vector extensions) 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 gcc/ChangeLog * fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE. (fold_binary_loc): Likewise. * gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE. (or_comparisons_1): Likewise. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE. gcc/testsuite/ChangeLog * g++.dg/other/vector-compare.C: New testcase. * gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase. * gcc.dg/vector-shift.c: Move ... * c-c++-common/vector-shift.c: ... here. * gcc.dg/vector-shift1.c: Move ... * c-c++-common/vector-shift1.c: ... here. * gcc.dg/vector-shift3.c: Move ... * c-c++-common/vector-shift3.c: ... here. * gcc.dg/vector-compare-1.c: Move ... * c-c++-common/vector-compare-1.c: ... here. * gcc.dg/vector-compare-2.c: Move ... * c-c++-common/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-compare-1.c: Move ... * c-c++-common/torture/vector-compare-1.c: ... here. * gcc.c-torture/execute/vector-compare-2.x: Delete. * gcc.c-torture/execute/vector-compare-2.c: Move ... * c-c++-common/torture/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-shift.c: Move ... * c-c++-common/torture/vector-shift.c: ... here. * gcc.c-torture/execute/vector-shift2.c: Move ... * c-c++-common/torture/vector-shift2.c: ... here. * gcc.c-torture/execute/vector-subscript-1.c: Move ... * c-c++-common/torture/vector-subscript-1.c: ... here. * gcc.c-torture/execute/vector-subscript-2.c: Move ... * c-c++-common/torture/vector-subscript-2.c: ... here. * gcc.c-torture/execute/vector-subscript-3.c: Move ... * c-c++-common/torture/vector-subscript-3.c: ... here. From-SVN: r191308
2012-09-14 19:17:01 +02:00
truth_type, op1a, op1b);
if (t)
return t;
}
/* Likewise the swapped case of the above. */
if (operand_equal_p (op1a, op2b, 0)
&& operand_equal_p (op1b, op2a, 0))
{
/* Result will be either NULL_TREE, or a combined comparison. */
tree t = combine_comparisons (UNKNOWN_LOCATION,
TRUTH_ANDIF_EXPR, code1,
swap_tree_comparison (code2),
re PR c++/54427 (Expose more vector extensions) 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 gcc/ChangeLog * fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE. (fold_binary_loc): Likewise. * gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE. (or_comparisons_1): Likewise. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE. gcc/testsuite/ChangeLog * g++.dg/other/vector-compare.C: New testcase. * gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase. * gcc.dg/vector-shift.c: Move ... * c-c++-common/vector-shift.c: ... here. * gcc.dg/vector-shift1.c: Move ... * c-c++-common/vector-shift1.c: ... here. * gcc.dg/vector-shift3.c: Move ... * c-c++-common/vector-shift3.c: ... here. * gcc.dg/vector-compare-1.c: Move ... * c-c++-common/vector-compare-1.c: ... here. * gcc.dg/vector-compare-2.c: Move ... * c-c++-common/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-compare-1.c: Move ... * c-c++-common/torture/vector-compare-1.c: ... here. * gcc.c-torture/execute/vector-compare-2.x: Delete. * gcc.c-torture/execute/vector-compare-2.c: Move ... * c-c++-common/torture/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-shift.c: Move ... * c-c++-common/torture/vector-shift.c: ... here. * gcc.c-torture/execute/vector-shift2.c: Move ... * c-c++-common/torture/vector-shift2.c: ... here. * gcc.c-torture/execute/vector-subscript-1.c: Move ... * c-c++-common/torture/vector-subscript-1.c: ... here. * gcc.c-torture/execute/vector-subscript-2.c: Move ... * c-c++-common/torture/vector-subscript-2.c: ... here. * gcc.c-torture/execute/vector-subscript-3.c: Move ... * c-c++-common/torture/vector-subscript-3.c: ... here. From-SVN: r191308
2012-09-14 19:17:01 +02:00
truth_type, op1a, op1b);
if (t)
return t;
}
/* If both comparisons are of the same value against constants, we might
be able to merge them. */
if (operand_equal_p (op1a, op2a, 0)
&& TREE_CODE (op1b) == INTEGER_CST
&& TREE_CODE (op2b) == INTEGER_CST)
{
int cmp = tree_int_cst_compare (op1b, op2b);
/* If we have (op1a == op1b), we should either be able to
return that or FALSE, depending on whether the constant op1b
also satisfies the other comparison against op2b. */
if (code1 == EQ_EXPR)
{
bool done = true;
bool val;
switch (code2)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp < 0); break;
case GT_EXPR: val = (cmp > 0); break;
case LE_EXPR: val = (cmp <= 0); break;
case GE_EXPR: val = (cmp >= 0); break;
default: done = false;
}
if (done)
{
if (val)
return fold_build2 (code1, boolean_type_node, op1a, op1b);
else
return boolean_false_node;
}
}
/* Likewise if the second comparison is an == comparison. */
else if (code2 == EQ_EXPR)
{
bool done = true;
bool val;
switch (code1)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp > 0); break;
case GT_EXPR: val = (cmp < 0); break;
case LE_EXPR: val = (cmp >= 0); break;
case GE_EXPR: val = (cmp <= 0); break;
default: done = false;
}
if (done)
{
if (val)
return fold_build2 (code2, boolean_type_node, op2a, op2b);
else
return boolean_false_node;
}
}
/* Same business with inequality tests. */
else if (code1 == NE_EXPR)
{
bool val;
switch (code2)
{
case EQ_EXPR: val = (cmp != 0); break;
case NE_EXPR: val = (cmp == 0); break;
case LT_EXPR: val = (cmp >= 0); break;
case GT_EXPR: val = (cmp <= 0); break;
case LE_EXPR: val = (cmp > 0); break;
case GE_EXPR: val = (cmp < 0); break;
default:
val = false;
}
if (val)
return fold_build2 (code2, boolean_type_node, op2a, op2b);
}
else if (code2 == NE_EXPR)
{
bool val;
switch (code1)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp <= 0); break;
case GT_EXPR: val = (cmp >= 0); break;
case LE_EXPR: val = (cmp < 0); break;
case GE_EXPR: val = (cmp > 0); break;
default:
val = false;
}
if (val)
return fold_build2 (code1, boolean_type_node, op1a, op1b);
}
/* Chose the more restrictive of two < or <= comparisons. */
else if ((code1 == LT_EXPR || code1 == LE_EXPR)
&& (code2 == LT_EXPR || code2 == LE_EXPR))
{
if ((cmp < 0) || (cmp == 0 && code1 == LT_EXPR))
return fold_build2 (code1, boolean_type_node, op1a, op1b);
else
return fold_build2 (code2, boolean_type_node, op2a, op2b);
}
/* Likewise chose the more restrictive of two > or >= comparisons. */
else if ((code1 == GT_EXPR || code1 == GE_EXPR)
&& (code2 == GT_EXPR || code2 == GE_EXPR))
{
if ((cmp > 0) || (cmp == 0 && code1 == GT_EXPR))
return fold_build2 (code1, boolean_type_node, op1a, op1b);
else
return fold_build2 (code2, boolean_type_node, op2a, op2b);
}
/* Check for singleton ranges. */
else if (cmp == 0
&& ((code1 == LE_EXPR && code2 == GE_EXPR)
|| (code1 == GE_EXPR && code2 == LE_EXPR)))
return fold_build2 (EQ_EXPR, boolean_type_node, op1a, op2b);
/* Check for disjoint ranges. */
else if (cmp <= 0
&& (code1 == LT_EXPR || code1 == LE_EXPR)
&& (code2 == GT_EXPR || code2 == GE_EXPR))
return boolean_false_node;
else if (cmp >= 0
&& (code1 == GT_EXPR || code1 == GE_EXPR)
&& (code2 == LT_EXPR || code2 == LE_EXPR))
return boolean_false_node;
}
/* Perhaps the first comparison is (NAME != 0) or (NAME == 1) where
NAME's definition is a truth value. See if there are any simplifications
that can be done against the NAME's definition. */
if (TREE_CODE (op1a) == SSA_NAME
&& (code1 == NE_EXPR || code1 == EQ_EXPR)
&& (integer_zerop (op1b) || integer_onep (op1b)))
{
bool invert = ((code1 == EQ_EXPR && integer_zerop (op1b))
|| (code1 == NE_EXPR && integer_onep (op1b)));
gimple stmt = SSA_NAME_DEF_STMT (op1a);
switch (gimple_code (stmt))
{
case GIMPLE_ASSIGN:
/* Try to simplify by copy-propagating the definition. */
return and_var_with_comparison (op1a, invert, code2, op2a, op2b);
case GIMPLE_PHI:
/* If every argument to the PHI produces the same result when
ANDed with the second comparison, we win.
Do not do this unless the type is bool since we need a bool
result here anyway. */
if (TREE_CODE (TREE_TYPE (op1a)) == BOOLEAN_TYPE)
{
tree result = NULL_TREE;
unsigned i;
for (i = 0; i < gimple_phi_num_args (stmt); i++)
{
tree arg = gimple_phi_arg_def (stmt, i);
/* If this PHI has itself as an argument, ignore it.
If all the other args produce the same result,
we're still OK. */
if (arg == gimple_phi_result (stmt))
continue;
else if (TREE_CODE (arg) == INTEGER_CST)
{
if (invert ? integer_nonzerop (arg) : integer_zerop (arg))
{
if (!result)
result = boolean_false_node;
else if (!integer_zerop (result))
return NULL_TREE;
}
else if (!result)
result = fold_build2 (code2, boolean_type_node,
op2a, op2b);
else if (!same_bool_comparison_p (result,
code2, op2a, op2b))
return NULL_TREE;
}
else if (TREE_CODE (arg) == SSA_NAME
&& !SSA_NAME_IS_DEFAULT_DEF (arg))
{
tree temp;
gimple def_stmt = SSA_NAME_DEF_STMT (arg);
/* In simple cases we can look through PHI nodes,
but we have to be careful with loops.
See PR49073. */
if (! dom_info_available_p (CDI_DOMINATORS)
|| gimple_bb (def_stmt) == gimple_bb (stmt)
|| dominated_by_p (CDI_DOMINATORS,
gimple_bb (def_stmt),
gimple_bb (stmt)))
return NULL_TREE;
temp = and_var_with_comparison (arg, invert, code2,
op2a, op2b);
if (!temp)
return NULL_TREE;
else if (!result)
result = temp;
else if (!same_bool_result_p (result, temp))
return NULL_TREE;
}
else
return NULL_TREE;
}
return result;
}
default:
break;
}
}
return NULL_TREE;
}
/* Try to simplify the AND of two comparisons, specified by
(OP1A CODE1 OP1B) and (OP2B CODE2 OP2B), respectively.
If this can be simplified to a single expression (without requiring
introducing more SSA variables to hold intermediate values),
return the resulting tree. Otherwise return NULL_TREE.
If the result expression is non-null, it has boolean type. */
tree
maybe_fold_and_comparisons (enum tree_code code1, tree op1a, tree op1b,
enum tree_code code2, tree op2a, tree op2b)
{
tree t = and_comparisons_1 (code1, op1a, op1b, code2, op2a, op2b);
if (t)
return t;
else
return and_comparisons_1 (code2, op2a, op2b, code1, op1a, op1b);
}
/* Helper function for or_comparisons_1: try to simplify the OR of the
ssa variable VAR with the comparison specified by (OP2A CODE2 OP2B).
If INVERT is true, invert the value of VAR before doing the OR.
Return NULL_EXPR if we can't simplify this to a single expression. */
static tree
or_var_with_comparison (tree var, bool invert,
enum tree_code code2, tree op2a, tree op2b)
{
tree t;
gimple stmt = SSA_NAME_DEF_STMT (var);
/* We can only deal with variables whose definitions are assignments. */
if (!is_gimple_assign (stmt))
return NULL_TREE;
/* If we have an inverted comparison, apply DeMorgan's law and rewrite
!var OR (op2a code2 op2b) => !(var AND !(op2a code2 op2b))
Then we only have to consider the simpler non-inverted cases. */
if (invert)
t = and_var_with_comparison_1 (stmt,
invert_tree_comparison (code2, false),
op2a, op2b);
else
t = or_var_with_comparison_1 (stmt, code2, op2a, op2b);
return canonicalize_bool (t, invert);
}
/* Try to simplify the OR of the ssa variable defined by the assignment
STMT with the comparison specified by (OP2A CODE2 OP2B).
Return NULL_EXPR if we can't simplify this to a single expression. */
static tree
or_var_with_comparison_1 (gimple stmt,
enum tree_code code2, tree op2a, tree op2b)
{
tree var = gimple_assign_lhs (stmt);
tree true_test_var = NULL_TREE;
tree false_test_var = NULL_TREE;
enum tree_code innercode = gimple_assign_rhs_code (stmt);
/* Check for identities like (var OR (var != 0)) => true . */
if (TREE_CODE (op2a) == SSA_NAME
&& TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE)
{
if ((code2 == NE_EXPR && integer_zerop (op2b))
|| (code2 == EQ_EXPR && integer_nonzerop (op2b)))
{
true_test_var = op2a;
if (var == true_test_var)
return var;
}
else if ((code2 == EQ_EXPR && integer_zerop (op2b))
|| (code2 == NE_EXPR && integer_nonzerop (op2b)))
{
false_test_var = op2a;
if (var == false_test_var)
return boolean_true_node;
}
}
/* If the definition is a comparison, recurse on it. */
if (TREE_CODE_CLASS (innercode) == tcc_comparison)
{
tree t = or_comparisons_1 (innercode,
gimple_assign_rhs1 (stmt),
gimple_assign_rhs2 (stmt),
code2,
op2a,
op2b);
if (t)
return t;
}
/* If the definition is an AND or OR expression, we may be able to
simplify by reassociating. */
if (TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE
&& (innercode == BIT_AND_EXPR || innercode == BIT_IOR_EXPR))
{
tree inner1 = gimple_assign_rhs1 (stmt);
tree inner2 = gimple_assign_rhs2 (stmt);
gimple s;
tree t;
tree partial = NULL_TREE;
bool is_or = (innercode == BIT_IOR_EXPR);
/* Check for boolean identities that don't require recursive examination
of inner1/inner2:
inner1 OR (inner1 OR inner2) => inner1 OR inner2 => var
inner1 OR (inner1 AND inner2) => inner1
!inner1 OR (inner1 OR inner2) => true
!inner1 OR (inner1 AND inner2) => !inner1 OR inner2
*/
if (inner1 == true_test_var)
return (is_or ? var : inner1);
else if (inner2 == true_test_var)
return (is_or ? var : inner2);
else if (inner1 == false_test_var)
return (is_or
? boolean_true_node
: or_var_with_comparison (inner2, false, code2, op2a, op2b));
else if (inner2 == false_test_var)
return (is_or
? boolean_true_node
: or_var_with_comparison (inner1, false, code2, op2a, op2b));
/* Next, redistribute/reassociate the OR across the inner tests.
Compute the first partial result, (inner1 OR (op2a code op2b)) */
if (TREE_CODE (inner1) == SSA_NAME
&& is_gimple_assign (s = SSA_NAME_DEF_STMT (inner1))
&& TREE_CODE_CLASS (gimple_assign_rhs_code (s)) == tcc_comparison
&& (t = maybe_fold_or_comparisons (gimple_assign_rhs_code (s),
gimple_assign_rhs1 (s),
gimple_assign_rhs2 (s),
code2, op2a, op2b)))
{
/* Handle the OR case, where we are reassociating:
(inner1 OR inner2) OR (op2a code2 op2b)
=> (t OR inner2)
If the partial result t is a constant, we win. Otherwise
continue on to try reassociating with the other inner test. */
if (is_or)
{
if (integer_onep (t))
return boolean_true_node;
else if (integer_zerop (t))
return inner2;
}
/* Handle the AND case, where we are redistributing:
(inner1 AND inner2) OR (op2a code2 op2b)
=> (t AND (inner2 OR (op2a code op2b))) */
else if (integer_zerop (t))
return boolean_false_node;
/* Save partial result for later. */
partial = t;
}
/* Compute the second partial result, (inner2 OR (op2a code op2b)) */
if (TREE_CODE (inner2) == SSA_NAME
&& is_gimple_assign (s = SSA_NAME_DEF_STMT (inner2))
&& TREE_CODE_CLASS (gimple_assign_rhs_code (s)) == tcc_comparison
&& (t = maybe_fold_or_comparisons (gimple_assign_rhs_code (s),
gimple_assign_rhs1 (s),
gimple_assign_rhs2 (s),
code2, op2a, op2b)))
{
/* Handle the OR case, where we are reassociating:
(inner1 OR inner2) OR (op2a code2 op2b)
=> (inner1 OR t)
=> (t OR partial) */
if (is_or)
{
if (integer_zerop (t))
return inner1;
else if (integer_onep (t))
return boolean_true_node;
/* If both are the same, we can apply the identity
(x OR x) == x. */
else if (partial && same_bool_result_p (t, partial))
return t;
}
/* Handle the AND case, where we are redistributing:
(inner1 AND inner2) OR (op2a code2 op2b)
=> (t AND (inner1 OR (op2a code2 op2b)))
=> (t AND partial) */
else
{
if (integer_zerop (t))
return boolean_false_node;
else if (partial)
{
/* We already got a simplification for the other
operand to the redistributed AND expression. The
interesting case is when at least one is true.
Or, if both are the same, we can apply the identity
(x AND x) == x. */
if (integer_onep (partial))
return t;
else if (integer_onep (t))
return partial;
else if (same_bool_result_p (t, partial))
return t;
}
}
}
}
return NULL_TREE;
}
/* Try to simplify the OR of two comparisons defined by
(OP1A CODE1 OP1B) and (OP2A CODE2 OP2B), respectively.
If this can be done without constructing an intermediate value,
return the resulting tree; otherwise NULL_TREE is returned.
This function is deliberately asymmetric as it recurses on SSA_DEFs
in the first comparison but not the second. */
static tree
or_comparisons_1 (enum tree_code code1, tree op1a, tree op1b,
enum tree_code code2, tree op2a, tree op2b)
{
tree truth_type = truth_type_for (TREE_TYPE (op1a));
re PR c++/54427 (Expose more vector extensions) 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 gcc/ChangeLog * fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE. (fold_binary_loc): Likewise. * gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE. (or_comparisons_1): Likewise. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE. gcc/testsuite/ChangeLog * g++.dg/other/vector-compare.C: New testcase. * gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase. * gcc.dg/vector-shift.c: Move ... * c-c++-common/vector-shift.c: ... here. * gcc.dg/vector-shift1.c: Move ... * c-c++-common/vector-shift1.c: ... here. * gcc.dg/vector-shift3.c: Move ... * c-c++-common/vector-shift3.c: ... here. * gcc.dg/vector-compare-1.c: Move ... * c-c++-common/vector-compare-1.c: ... here. * gcc.dg/vector-compare-2.c: Move ... * c-c++-common/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-compare-1.c: Move ... * c-c++-common/torture/vector-compare-1.c: ... here. * gcc.c-torture/execute/vector-compare-2.x: Delete. * gcc.c-torture/execute/vector-compare-2.c: Move ... * c-c++-common/torture/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-shift.c: Move ... * c-c++-common/torture/vector-shift.c: ... here. * gcc.c-torture/execute/vector-shift2.c: Move ... * c-c++-common/torture/vector-shift2.c: ... here. * gcc.c-torture/execute/vector-subscript-1.c: Move ... * c-c++-common/torture/vector-subscript-1.c: ... here. * gcc.c-torture/execute/vector-subscript-2.c: Move ... * c-c++-common/torture/vector-subscript-2.c: ... here. * gcc.c-torture/execute/vector-subscript-3.c: Move ... * c-c++-common/torture/vector-subscript-3.c: ... here. From-SVN: r191308
2012-09-14 19:17:01 +02:00
/* First check for ((x CODE1 y) OR (x CODE2 y)). */
if (operand_equal_p (op1a, op2a, 0)
&& operand_equal_p (op1b, op2b, 0))
{
/* Result will be either NULL_TREE, or a combined comparison. */
tree t = combine_comparisons (UNKNOWN_LOCATION,
TRUTH_ORIF_EXPR, code1, code2,
re PR c++/54427 (Expose more vector extensions) 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 gcc/ChangeLog * fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE. (fold_binary_loc): Likewise. * gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE. (or_comparisons_1): Likewise. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE. gcc/testsuite/ChangeLog * g++.dg/other/vector-compare.C: New testcase. * gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase. * gcc.dg/vector-shift.c: Move ... * c-c++-common/vector-shift.c: ... here. * gcc.dg/vector-shift1.c: Move ... * c-c++-common/vector-shift1.c: ... here. * gcc.dg/vector-shift3.c: Move ... * c-c++-common/vector-shift3.c: ... here. * gcc.dg/vector-compare-1.c: Move ... * c-c++-common/vector-compare-1.c: ... here. * gcc.dg/vector-compare-2.c: Move ... * c-c++-common/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-compare-1.c: Move ... * c-c++-common/torture/vector-compare-1.c: ... here. * gcc.c-torture/execute/vector-compare-2.x: Delete. * gcc.c-torture/execute/vector-compare-2.c: Move ... * c-c++-common/torture/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-shift.c: Move ... * c-c++-common/torture/vector-shift.c: ... here. * gcc.c-torture/execute/vector-shift2.c: Move ... * c-c++-common/torture/vector-shift2.c: ... here. * gcc.c-torture/execute/vector-subscript-1.c: Move ... * c-c++-common/torture/vector-subscript-1.c: ... here. * gcc.c-torture/execute/vector-subscript-2.c: Move ... * c-c++-common/torture/vector-subscript-2.c: ... here. * gcc.c-torture/execute/vector-subscript-3.c: Move ... * c-c++-common/torture/vector-subscript-3.c: ... here. From-SVN: r191308
2012-09-14 19:17:01 +02:00
truth_type, op1a, op1b);
if (t)
return t;
}
/* Likewise the swapped case of the above. */
if (operand_equal_p (op1a, op2b, 0)
&& operand_equal_p (op1b, op2a, 0))
{
/* Result will be either NULL_TREE, or a combined comparison. */
tree t = combine_comparisons (UNKNOWN_LOCATION,
TRUTH_ORIF_EXPR, code1,
swap_tree_comparison (code2),
re PR c++/54427 (Expose more vector extensions) 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 gcc/ChangeLog * fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE. (fold_binary_loc): Likewise. * gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE. (or_comparisons_1): Likewise. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR, NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE. gcc/testsuite/ChangeLog * g++.dg/other/vector-compare.C: New testcase. * gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase. * gcc.dg/vector-shift.c: Move ... * c-c++-common/vector-shift.c: ... here. * gcc.dg/vector-shift1.c: Move ... * c-c++-common/vector-shift1.c: ... here. * gcc.dg/vector-shift3.c: Move ... * c-c++-common/vector-shift3.c: ... here. * gcc.dg/vector-compare-1.c: Move ... * c-c++-common/vector-compare-1.c: ... here. * gcc.dg/vector-compare-2.c: Move ... * c-c++-common/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-compare-1.c: Move ... * c-c++-common/torture/vector-compare-1.c: ... here. * gcc.c-torture/execute/vector-compare-2.x: Delete. * gcc.c-torture/execute/vector-compare-2.c: Move ... * c-c++-common/torture/vector-compare-2.c: ... here. * gcc.c-torture/execute/vector-shift.c: Move ... * c-c++-common/torture/vector-shift.c: ... here. * gcc.c-torture/execute/vector-shift2.c: Move ... * c-c++-common/torture/vector-shift2.c: ... here. * gcc.c-torture/execute/vector-subscript-1.c: Move ... * c-c++-common/torture/vector-subscript-1.c: ... here. * gcc.c-torture/execute/vector-subscript-2.c: Move ... * c-c++-common/torture/vector-subscript-2.c: ... here. * gcc.c-torture/execute/vector-subscript-3.c: Move ... * c-c++-common/torture/vector-subscript-3.c: ... here. From-SVN: r191308
2012-09-14 19:17:01 +02:00
truth_type, op1a, op1b);
if (t)
return t;
}
/* If both comparisons are of the same value against constants, we might
be able to merge them. */
if (operand_equal_p (op1a, op2a, 0)
&& TREE_CODE (op1b) == INTEGER_CST
&& TREE_CODE (op2b) == INTEGER_CST)
{
int cmp = tree_int_cst_compare (op1b, op2b);
/* If we have (op1a != op1b), we should either be able to
return that or TRUE, depending on whether the constant op1b
also satisfies the other comparison against op2b. */
if (code1 == NE_EXPR)
{
bool done = true;
bool val;
switch (code2)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp < 0); break;
case GT_EXPR: val = (cmp > 0); break;
case LE_EXPR: val = (cmp <= 0); break;
case GE_EXPR: val = (cmp >= 0); break;
default: done = false;
}
if (done)
{
if (val)
return boolean_true_node;
else
return fold_build2 (code1, boolean_type_node, op1a, op1b);
}
}
/* Likewise if the second comparison is a != comparison. */
else if (code2 == NE_EXPR)
{
bool done = true;
bool val;
switch (code1)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp > 0); break;
case GT_EXPR: val = (cmp < 0); break;
case LE_EXPR: val = (cmp >= 0); break;
case GE_EXPR: val = (cmp <= 0); break;
default: done = false;
}
if (done)
{
if (val)
return boolean_true_node;
else
return fold_build2 (code2, boolean_type_node, op2a, op2b);
}
}
/* See if an equality test is redundant with the other comparison. */
else if (code1 == EQ_EXPR)
{
bool val;
switch (code2)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp < 0); break;
case GT_EXPR: val = (cmp > 0); break;
case LE_EXPR: val = (cmp <= 0); break;
case GE_EXPR: val = (cmp >= 0); break;
default:
val = false;
}
if (val)
return fold_build2 (code2, boolean_type_node, op2a, op2b);
}
else if (code2 == EQ_EXPR)
{
bool val;
switch (code1)
{
case EQ_EXPR: val = (cmp == 0); break;
case NE_EXPR: val = (cmp != 0); break;
case LT_EXPR: val = (cmp > 0); break;
case GT_EXPR: val = (cmp < 0); break;
case LE_EXPR: val = (cmp >= 0); break;
case GE_EXPR: val = (cmp <= 0); break;
default:
val = false;
}
if (val)
return fold_build2 (code1, boolean_type_node, op1a, op1b);
}
/* Chose the less restrictive of two < or <= comparisons. */
else if ((code1 == LT_EXPR || code1 == LE_EXPR)
&& (code2 == LT_EXPR || code2 == LE_EXPR))
{
if ((cmp < 0) || (cmp == 0 && code1 == LT_EXPR))
return fold_build2 (code2, boolean_type_node, op2a, op2b);
else
return fold_build2 (code1, boolean_type_node, op1a, op1b);
}
/* Likewise chose the less restrictive of two > or >= comparisons. */
else if ((code1 == GT_EXPR || code1 == GE_EXPR)
&& (code2 == GT_EXPR || code2 == GE_EXPR))
{
if ((cmp > 0) || (cmp == 0 && code1 == GT_EXPR))
return fold_build2 (code2, boolean_type_node, op2a, op2b);
else
return fold_build2 (code1, boolean_type_node, op1a, op1b);
}
/* Check for singleton ranges. */
else if (cmp == 0
&& ((code1 == LT_EXPR && code2 == GT_EXPR)
|| (code1 == GT_EXPR && code2 == LT_EXPR)))
return fold_build2 (NE_EXPR, boolean_type_node, op1a, op2b);
/* Check for less/greater pairs that don't restrict the range at all. */
else if (cmp >= 0
&& (code1 == LT_EXPR || code1 == LE_EXPR)
&& (code2 == GT_EXPR || code2 == GE_EXPR))
return boolean_true_node;
else if (cmp <= 0
&& (code1 == GT_EXPR || code1 == GE_EXPR)
&& (code2 == LT_EXPR || code2 == LE_EXPR))
return boolean_true_node;
}
/* Perhaps the first comparison is (NAME != 0) or (NAME == 1) where
NAME's definition is a truth value. See if there are any simplifications
that can be done against the NAME's definition. */
if (TREE_CODE (op1a) == SSA_NAME
&& (code1 == NE_EXPR || code1 == EQ_EXPR)
&& (integer_zerop (op1b) || integer_onep (op1b)))
{
bool invert = ((code1 == EQ_EXPR && integer_zerop (op1b))
|| (code1 == NE_EXPR && integer_onep (op1b)));
gimple stmt = SSA_NAME_DEF_STMT (op1a);
switch (gimple_code (stmt))
{
case GIMPLE_ASSIGN:
/* Try to simplify by copy-propagating the definition. */
return or_var_with_comparison (op1a, invert, code2, op2a, op2b);
case GIMPLE_PHI:
/* If every argument to the PHI produces the same result when
ORed with the second comparison, we win.
Do not do this unless the type is bool since we need a bool
result here anyway. */
if (TREE_CODE (TREE_TYPE (op1a)) == BOOLEAN_TYPE)
{
tree result = NULL_TREE;
unsigned i;
for (i = 0; i < gimple_phi_num_args (stmt); i++)
{
tree arg = gimple_phi_arg_def (stmt, i);
/* If this PHI has itself as an argument, ignore it.
If all the other args produce the same result,
we're still OK. */
if (arg == gimple_phi_result (stmt))
continue;
else if (TREE_CODE (arg) == INTEGER_CST)
{
if (invert ? integer_zerop (arg) : integer_nonzerop (arg))
{
if (!result)
result = boolean_true_node;
else if (!integer_onep (result))
return NULL_TREE;
}
else if (!result)
result = fold_build2 (code2, boolean_type_node,
op2a, op2b);
else if (!same_bool_comparison_p (result,
code2, op2a, op2b))
return NULL_TREE;
}
else if (TREE_CODE (arg) == SSA_NAME
&& !SSA_NAME_IS_DEFAULT_DEF (arg))
{
tree temp;
gimple def_stmt = SSA_NAME_DEF_STMT (arg);
/* In simple cases we can look through PHI nodes,
but we have to be careful with loops.
See PR49073. */
if (! dom_info_available_p (CDI_DOMINATORS)
|| gimple_bb (def_stmt) == gimple_bb (stmt)
|| dominated_by_p (CDI_DOMINATORS,
gimple_bb (def_stmt),
gimple_bb (stmt)))
return NULL_TREE;
temp = or_var_with_comparison (arg, invert, code2,
op2a, op2b);
if (!temp)
return NULL_TREE;
else if (!result)
result = temp;
else if (!same_bool_result_p (result, temp))
return NULL_TREE;
}
else
return NULL_TREE;
}
return result;
}
default:
break;
}
}
return NULL_TREE;
}
/* Try to simplify the OR of two comparisons, specified by
(OP1A CODE1 OP1B) and (OP2B CODE2 OP2B), respectively.
If this can be simplified to a single expression (without requiring
introducing more SSA variables to hold intermediate values),
return the resulting tree. Otherwise return NULL_TREE.
If the result expression is non-null, it has boolean type. */
tree
maybe_fold_or_comparisons (enum tree_code code1, tree op1a, tree op1b,
enum tree_code code2, tree op2a, tree op2b)
{
tree t = or_comparisons_1 (code1, op1a, op1b, code2, op2a, op2b);
if (t)
return t;
else
return or_comparisons_1 (code2, op2a, op2b, code1, op1a, op1b);
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* Fold STMT to a constant using VALUEIZE to valueize SSA names.
Either NULL_TREE, a simplified but non-constant or a constant
is returned.
??? This should go into a gimple-fold-inline.h file to be eventually
privatized with the single valueize function used in the various TUs
to avoid the indirect function call overhead. */
tree
gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree))
{
location_t loc = gimple_location (stmt);
switch (gimple_code (stmt))
{
case GIMPLE_ASSIGN:
{
enum tree_code subcode = gimple_assign_rhs_code (stmt);
switch (get_gimple_rhs_class (subcode))
{
case GIMPLE_SINGLE_RHS:
{
tree rhs = gimple_assign_rhs1 (stmt);
enum tree_code_class kind = TREE_CODE_CLASS (subcode);
if (TREE_CODE (rhs) == SSA_NAME)
{
/* If the RHS is an SSA_NAME, return its known constant value,
if any. */
return (*valueize) (rhs);
}
/* Handle propagating invariant addresses into address
operations. */
else if (TREE_CODE (rhs) == ADDR_EXPR
&& !is_gimple_min_invariant (rhs))
{
HOST_WIDE_INT offset = 0;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
tree base;
base = get_addr_base_and_unit_offset_1 (TREE_OPERAND (rhs, 0),
&offset,
valueize);
if (base
&& (CONSTANT_CLASS_P (base)
|| decl_address_invariant_p (base)))
return build_invariant_address (TREE_TYPE (rhs),
base, offset);
}
else if (TREE_CODE (rhs) == CONSTRUCTOR
&& TREE_CODE (TREE_TYPE (rhs)) == VECTOR_TYPE
&& (CONSTRUCTOR_NELTS (rhs)
== TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs))))
{
unsigned i;
tree.h (TREE_VECTOR_CST_ELTS): Remove. 2012-03-16 Richard Guenther <rguenther@suse.de> * tree.h (TREE_VECTOR_CST_ELTS): Remove. (VECTOR_CST_NELTS, VECTOR_CST_ELTS, VECTOR_CST_ELT): New defines. (struct tree_vector): Remove elements member, add variable size elts array member. (build_vector_stat): Declare. (build_vector): Define in terms of build_vector_stat. * tree.c (build_vector): Rename to ... (build_vector_stat): ... this. Take array of trees as parameter. (build_vector_from_ctor): Adjust. (integer_zerop, integer_onep, integer_all_onesp, iterative_hash_expr, initializer_zerop): Adjust. * cfgexpand.c (expand_debug_expr): Likewise. * expr.c (categorize_ctor_elements_1, expand_expr_real_1, const_vector_from_tree): Likewise. * fold-const.c (const_binop, operand_equal_p, native_encode_vector, native_interpret_vector, fold_unary_loc, vec_cst_ctor_to_array, fold_vec_perm, fold_binary_loc, fold_ternary_loc): Likewise. * tree-streamer-in.c (streamer_alloc_tree): Handle TS_VECTOR. (lto_input_ts_vector_tree_pointers): Adjust. * tree-streamer-out.c (streamer_write_tree_header): Handle TS_VECTOR. (write_ts_vector_tree_pointers): Adjust. * varasm.c (const_hash_1, compare_constant, copy_constant, output_constant): Adjust. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Adjust. * print-tree.c (print_node): Adjust. * tree-pretty-print.c (dump_generic_node): Adjust. * tree-vect-generic.c (uniform_vector_p, vector_element, lower_vec_perm): Adjust. * tree-vect-loop.c (get_initial_def_for_reduction): Adjust. * tree-vect-slp.c (vect_get_constant_vectors, vect_transform_slp_perm_load): Adjust. * tree-vect-stmts.c (vect_gen_perm_mask): Adjust. * expmed.c (make_tree): Adjust. * config/i386/i386.c (ix86_expand_builtin): Adjust. * config/sparc/sparc.c (sparc_handle_vis_mul8x16): Adjust interface and implementation. (sparc_fold_builtin): Adjust. c-family/ * c-pretty-print.c (pp_c_initializer_list): Adjust. From-SVN: r185458
2012-03-16 10:47:09 +01:00
tree val, *vec;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
tree.h (TREE_VECTOR_CST_ELTS): Remove. 2012-03-16 Richard Guenther <rguenther@suse.de> * tree.h (TREE_VECTOR_CST_ELTS): Remove. (VECTOR_CST_NELTS, VECTOR_CST_ELTS, VECTOR_CST_ELT): New defines. (struct tree_vector): Remove elements member, add variable size elts array member. (build_vector_stat): Declare. (build_vector): Define in terms of build_vector_stat. * tree.c (build_vector): Rename to ... (build_vector_stat): ... this. Take array of trees as parameter. (build_vector_from_ctor): Adjust. (integer_zerop, integer_onep, integer_all_onesp, iterative_hash_expr, initializer_zerop): Adjust. * cfgexpand.c (expand_debug_expr): Likewise. * expr.c (categorize_ctor_elements_1, expand_expr_real_1, const_vector_from_tree): Likewise. * fold-const.c (const_binop, operand_equal_p, native_encode_vector, native_interpret_vector, fold_unary_loc, vec_cst_ctor_to_array, fold_vec_perm, fold_binary_loc, fold_ternary_loc): Likewise. * tree-streamer-in.c (streamer_alloc_tree): Handle TS_VECTOR. (lto_input_ts_vector_tree_pointers): Adjust. * tree-streamer-out.c (streamer_write_tree_header): Handle TS_VECTOR. (write_ts_vector_tree_pointers): Adjust. * varasm.c (const_hash_1, compare_constant, copy_constant, output_constant): Adjust. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Adjust. * print-tree.c (print_node): Adjust. * tree-pretty-print.c (dump_generic_node): Adjust. * tree-vect-generic.c (uniform_vector_p, vector_element, lower_vec_perm): Adjust. * tree-vect-loop.c (get_initial_def_for_reduction): Adjust. * tree-vect-slp.c (vect_get_constant_vectors, vect_transform_slp_perm_load): Adjust. * tree-vect-stmts.c (vect_gen_perm_mask): Adjust. * expmed.c (make_tree): Adjust. * config/i386/i386.c (ix86_expand_builtin): Adjust. * config/sparc/sparc.c (sparc_handle_vis_mul8x16): Adjust interface and implementation. (sparc_fold_builtin): Adjust. c-family/ * c-pretty-print.c (pp_c_initializer_list): Adjust. From-SVN: r185458
2012-03-16 10:47:09 +01:00
vec = XALLOCAVEC (tree,
TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs)));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)
{
val = (*valueize) (val);
if (TREE_CODE (val) == INTEGER_CST
|| TREE_CODE (val) == REAL_CST
|| TREE_CODE (val) == FIXED_CST)
tree.h (TREE_VECTOR_CST_ELTS): Remove. 2012-03-16 Richard Guenther <rguenther@suse.de> * tree.h (TREE_VECTOR_CST_ELTS): Remove. (VECTOR_CST_NELTS, VECTOR_CST_ELTS, VECTOR_CST_ELT): New defines. (struct tree_vector): Remove elements member, add variable size elts array member. (build_vector_stat): Declare. (build_vector): Define in terms of build_vector_stat. * tree.c (build_vector): Rename to ... (build_vector_stat): ... this. Take array of trees as parameter. (build_vector_from_ctor): Adjust. (integer_zerop, integer_onep, integer_all_onesp, iterative_hash_expr, initializer_zerop): Adjust. * cfgexpand.c (expand_debug_expr): Likewise. * expr.c (categorize_ctor_elements_1, expand_expr_real_1, const_vector_from_tree): Likewise. * fold-const.c (const_binop, operand_equal_p, native_encode_vector, native_interpret_vector, fold_unary_loc, vec_cst_ctor_to_array, fold_vec_perm, fold_binary_loc, fold_ternary_loc): Likewise. * tree-streamer-in.c (streamer_alloc_tree): Handle TS_VECTOR. (lto_input_ts_vector_tree_pointers): Adjust. * tree-streamer-out.c (streamer_write_tree_header): Handle TS_VECTOR. (write_ts_vector_tree_pointers): Adjust. * varasm.c (const_hash_1, compare_constant, copy_constant, output_constant): Adjust. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Adjust. * print-tree.c (print_node): Adjust. * tree-pretty-print.c (dump_generic_node): Adjust. * tree-vect-generic.c (uniform_vector_p, vector_element, lower_vec_perm): Adjust. * tree-vect-loop.c (get_initial_def_for_reduction): Adjust. * tree-vect-slp.c (vect_get_constant_vectors, vect_transform_slp_perm_load): Adjust. * tree-vect-stmts.c (vect_gen_perm_mask): Adjust. * expmed.c (make_tree): Adjust. * config/i386/i386.c (ix86_expand_builtin): Adjust. * config/sparc/sparc.c (sparc_handle_vis_mul8x16): Adjust interface and implementation. (sparc_fold_builtin): Adjust. c-family/ * c-pretty-print.c (pp_c_initializer_list): Adjust. From-SVN: r185458
2012-03-16 10:47:09 +01:00
vec[i] = val;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
else
return NULL_TREE;
}
tree.h (TREE_VECTOR_CST_ELTS): Remove. 2012-03-16 Richard Guenther <rguenther@suse.de> * tree.h (TREE_VECTOR_CST_ELTS): Remove. (VECTOR_CST_NELTS, VECTOR_CST_ELTS, VECTOR_CST_ELT): New defines. (struct tree_vector): Remove elements member, add variable size elts array member. (build_vector_stat): Declare. (build_vector): Define in terms of build_vector_stat. * tree.c (build_vector): Rename to ... (build_vector_stat): ... this. Take array of trees as parameter. (build_vector_from_ctor): Adjust. (integer_zerop, integer_onep, integer_all_onesp, iterative_hash_expr, initializer_zerop): Adjust. * cfgexpand.c (expand_debug_expr): Likewise. * expr.c (categorize_ctor_elements_1, expand_expr_real_1, const_vector_from_tree): Likewise. * fold-const.c (const_binop, operand_equal_p, native_encode_vector, native_interpret_vector, fold_unary_loc, vec_cst_ctor_to_array, fold_vec_perm, fold_binary_loc, fold_ternary_loc): Likewise. * tree-streamer-in.c (streamer_alloc_tree): Handle TS_VECTOR. (lto_input_ts_vector_tree_pointers): Adjust. * tree-streamer-out.c (streamer_write_tree_header): Handle TS_VECTOR. (write_ts_vector_tree_pointers): Adjust. * varasm.c (const_hash_1, compare_constant, copy_constant, output_constant): Adjust. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Adjust. * print-tree.c (print_node): Adjust. * tree-pretty-print.c (dump_generic_node): Adjust. * tree-vect-generic.c (uniform_vector_p, vector_element, lower_vec_perm): Adjust. * tree-vect-loop.c (get_initial_def_for_reduction): Adjust. * tree-vect-slp.c (vect_get_constant_vectors, vect_transform_slp_perm_load): Adjust. * tree-vect-stmts.c (vect_gen_perm_mask): Adjust. * expmed.c (make_tree): Adjust. * config/i386/i386.c (ix86_expand_builtin): Adjust. * config/sparc/sparc.c (sparc_handle_vis_mul8x16): Adjust interface and implementation. (sparc_fold_builtin): Adjust. c-family/ * c-pretty-print.c (pp_c_initializer_list): Adjust. From-SVN: r185458
2012-03-16 10:47:09 +01:00
return build_vector (TREE_TYPE (rhs), vec);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
if (subcode == OBJ_TYPE_REF)
{
tree val = (*valueize) (OBJ_TYPE_REF_EXPR (rhs));
/* If callee is constant, we can fold away the wrapper. */
if (is_gimple_min_invariant (val))
return val;
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
if (kind == tcc_reference)
{
if ((TREE_CODE (rhs) == VIEW_CONVERT_EXPR
|| TREE_CODE (rhs) == REALPART_EXPR
|| TREE_CODE (rhs) == IMAGPART_EXPR)
&& TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME)
{
tree val = (*valueize) (TREE_OPERAND (rhs, 0));
return fold_unary_loc (EXPR_LOCATION (rhs),
TREE_CODE (rhs),
TREE_TYPE (rhs), val);
}
else if (TREE_CODE (rhs) == BIT_FIELD_REF
&& TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME)
{
tree val = (*valueize) (TREE_OPERAND (rhs, 0));
return fold_ternary_loc (EXPR_LOCATION (rhs),
TREE_CODE (rhs),
TREE_TYPE (rhs), val,
TREE_OPERAND (rhs, 1),
TREE_OPERAND (rhs, 2));
}
else if (TREE_CODE (rhs) == MEM_REF
&& TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME)
{
tree val = (*valueize) (TREE_OPERAND (rhs, 0));
if (TREE_CODE (val) == ADDR_EXPR
&& is_gimple_min_invariant (val))
{
tree tem = fold_build2 (MEM_REF, TREE_TYPE (rhs),
unshare_expr (val),
TREE_OPERAND (rhs, 1));
if (tem)
rhs = tem;
}
}
return fold_const_aggregate_ref_1 (rhs, valueize);
}
else if (kind == tcc_declaration)
return get_symbol_constant_value (rhs);
return rhs;
}
case GIMPLE_UNARY_RHS:
{
/* Handle unary operators that can appear in GIMPLE form.
Note that we know the single operand must be a constant,
so this should almost always return a simplified RHS. */
tree op0 = (*valueize) (gimple_assign_rhs1 (stmt));
return
fold_unary_ignore_overflow_loc (loc, subcode,
gimple_expr_type (stmt), op0);
}
case GIMPLE_BINARY_RHS:
{
/* Handle binary operators that can appear in GIMPLE form. */
tree op0 = (*valueize) (gimple_assign_rhs1 (stmt));
tree op1 = (*valueize) (gimple_assign_rhs2 (stmt));
/* Translate &x + CST into an invariant form suitable for
further propagation. */
if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR
&& TREE_CODE (op0) == ADDR_EXPR
&& TREE_CODE (op1) == INTEGER_CST)
{
tree off = fold_convert (ptr_type_node, op1);
return build_fold_addr_expr_loc
(loc,
fold_build2 (MEM_REF,
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
TREE_TYPE (TREE_TYPE (op0)),
unshare_expr (op0), off));
}
return fold_binary_loc (loc, subcode,
gimple_expr_type (stmt), op0, op1);
}
case GIMPLE_TERNARY_RHS:
{
/* Handle ternary operators that can appear in GIMPLE form. */
tree op0 = (*valueize) (gimple_assign_rhs1 (stmt));
tree op1 = (*valueize) (gimple_assign_rhs2 (stmt));
tree op2 = (*valueize) (gimple_assign_rhs3 (stmt));
/* Fold embedded expressions in ternary codes. */
if ((subcode == COND_EXPR
|| subcode == VEC_COND_EXPR)
&& COMPARISON_CLASS_P (op0))
{
tree op00 = (*valueize) (TREE_OPERAND (op0, 0));
tree op01 = (*valueize) (TREE_OPERAND (op0, 1));
tree tem = fold_binary_loc (loc, TREE_CODE (op0),
TREE_TYPE (op0), op00, op01);
if (tem)
op0 = tem;
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return fold_ternary_loc (loc, subcode,
gimple_expr_type (stmt), op0, op1, op2);
}
default:
gcc_unreachable ();
}
}
case GIMPLE_CALL:
{
Makefile.in (INTERNAL_FN_DEF, [...]): Define. gcc/ * Makefile.in (INTERNAL_FN_DEF, INTERNAL_FN_H): Define. (GIMPLE_H): Include $(INTERNAL_FN_H). (OBJS-common): Add internal-fn.o. (internal-fn.o): New rule. * internal-fn.def: New file. * internal-fn.h: Likewise. * internal-fn.c: Likewise. * gimple.h: Include internal-fn.h. (GF_CALL_INTERNAL): New gf_mask. (gimple_statement_call): Put fntype into a union with a new internal_fn field. (gimple_build_call_internal): Declare. (gimple_build_call_internal_vec): Likewise. (gimple_call_same_target_p): Likewise. (gimple_call_internal_p): New function. (gimple_call_internal_fn): Likewise. (gimple_call_fntype): Return null for internal calls. (gimple_call_set_fntype): Assert that the function is not internal. (gimple_call_set_fn): Likewise. (gimple_call_set_fndecl): Likewise. (gimple_call_set_internal_fn): New function. (gimple_call_addr_fndecl): Handle null functions. (gimple_call_return_type): Likewise null types. * gimple.c (gimple_build_call_internal_1): New function. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_call_same_target_p): Likewise. (gimple_call_flags): Handle calls to internal functions. (gimple_call_fnspec): New function. (gimple_call_arg_flags, gimple_call_return_flags): Use it. (gimple_has_side_effects): Handle null functions. (gimple_rhs_has_side_effects): Likewise. (gimple_call_copy_skip_args): Handle calls to internal functions. * cfgexpand.c (expand_call_stmt): Likewise. * expr.c (expand_expr_real_1): Assert that the call isn't internal. * gimple-fold.c (gimple_fold_call): Handle null functions. (gimple_fold_stmt_to_constant_1): Don't fold calls to internal functions. * gimple-low.c (gimple_check_call_args): Handle calls to internal functions. * gimple-pretty-print.c (dump_gimple_call): Likewise. * ipa-prop.c (ipa_analyze_call_uses): Handle null functions. * tree-cfg.c (verify_gimple_call): Handle calls to internal functions. (do_warn_unused_result): Likewise. * tree-eh.c (same_handler_p): Use gimple_call_same_target_p. * tree-ssa-ccp.c (ccp_fold_stmt): Handle calls to internal functions. * tree-ssa-dom.c (hashable_expr): Use the gimple statement to record the target of a call. (initialize_hash_element): Update accordingly. (hashable_expr_equal_p): Use gimple_call_same_target_p. (iterative_hash_hashable_expr): Handle calls to internal functions. (print_expr_hash_elt): Likewise. * tree-ssa-pre.c (can_value_number_call): Likewise. (eliminate): Handle null functions. * tree-ssa-sccvn.c (visit_use): Handle calls to internal functions. * tree-ssa-structalias.c (get_fi_for_callee): Likewise. (find_func_aliases): Likewise. * value-prof.c (gimple_ic_transform): Likewise. (gimple_indirect_call_to_profile): Likewise. * lto-streamer-in.c (input_gimple_stmt): Likewise. * lto-streamer-out.c (output_gimple_stmt): Likewise. From-SVN: r172758
2011-04-20 10:21:25 +02:00
tree fn;
if (gimple_call_internal_p (stmt))
{
enum tree_code subcode = ERROR_MARK;
switch (gimple_call_internal_fn (stmt))
{
case IFN_UBSAN_CHECK_ADD:
subcode = PLUS_EXPR;
break;
case IFN_UBSAN_CHECK_SUB:
subcode = MINUS_EXPR;
break;
case IFN_UBSAN_CHECK_MUL:
subcode = MULT_EXPR;
break;
default:
return NULL_TREE;
}
tree arg0 = gimple_call_arg (stmt, 0);
tree arg1 = gimple_call_arg (stmt, 1);
tree op0 = (*valueize) (arg0);
tree op1 = (*valueize) (arg1);
if (TREE_CODE (op0) != INTEGER_CST
|| TREE_CODE (op1) != INTEGER_CST)
{
switch (subcode)
{
case MULT_EXPR:
/* x * 0 = 0 * x = 0 without overflow. */
if (integer_zerop (op0) || integer_zerop (op1))
return build_zero_cst (TREE_TYPE (arg0));
break;
case MINUS_EXPR:
/* y - y = 0 without overflow. */
if (operand_equal_p (op0, op1, 0))
return build_zero_cst (TREE_TYPE (arg0));
break;
default:
break;
}
}
tree res
= fold_binary_loc (loc, subcode, TREE_TYPE (arg0), op0, op1);
if (res
&& TREE_CODE (res) == INTEGER_CST
&& !TREE_OVERFLOW (res))
return res;
return NULL_TREE;
}
Makefile.in (INTERNAL_FN_DEF, [...]): Define. gcc/ * Makefile.in (INTERNAL_FN_DEF, INTERNAL_FN_H): Define. (GIMPLE_H): Include $(INTERNAL_FN_H). (OBJS-common): Add internal-fn.o. (internal-fn.o): New rule. * internal-fn.def: New file. * internal-fn.h: Likewise. * internal-fn.c: Likewise. * gimple.h: Include internal-fn.h. (GF_CALL_INTERNAL): New gf_mask. (gimple_statement_call): Put fntype into a union with a new internal_fn field. (gimple_build_call_internal): Declare. (gimple_build_call_internal_vec): Likewise. (gimple_call_same_target_p): Likewise. (gimple_call_internal_p): New function. (gimple_call_internal_fn): Likewise. (gimple_call_fntype): Return null for internal calls. (gimple_call_set_fntype): Assert that the function is not internal. (gimple_call_set_fn): Likewise. (gimple_call_set_fndecl): Likewise. (gimple_call_set_internal_fn): New function. (gimple_call_addr_fndecl): Handle null functions. (gimple_call_return_type): Likewise null types. * gimple.c (gimple_build_call_internal_1): New function. (gimple_build_call_internal): Likewise. (gimple_build_call_internal_vec): Likewise. (gimple_call_same_target_p): Likewise. (gimple_call_flags): Handle calls to internal functions. (gimple_call_fnspec): New function. (gimple_call_arg_flags, gimple_call_return_flags): Use it. (gimple_has_side_effects): Handle null functions. (gimple_rhs_has_side_effects): Likewise. (gimple_call_copy_skip_args): Handle calls to internal functions. * cfgexpand.c (expand_call_stmt): Likewise. * expr.c (expand_expr_real_1): Assert that the call isn't internal. * gimple-fold.c (gimple_fold_call): Handle null functions. (gimple_fold_stmt_to_constant_1): Don't fold calls to internal functions. * gimple-low.c (gimple_check_call_args): Handle calls to internal functions. * gimple-pretty-print.c (dump_gimple_call): Likewise. * ipa-prop.c (ipa_analyze_call_uses): Handle null functions. * tree-cfg.c (verify_gimple_call): Handle calls to internal functions. (do_warn_unused_result): Likewise. * tree-eh.c (same_handler_p): Use gimple_call_same_target_p. * tree-ssa-ccp.c (ccp_fold_stmt): Handle calls to internal functions. * tree-ssa-dom.c (hashable_expr): Use the gimple statement to record the target of a call. (initialize_hash_element): Update accordingly. (hashable_expr_equal_p): Use gimple_call_same_target_p. (iterative_hash_hashable_expr): Handle calls to internal functions. (print_expr_hash_elt): Likewise. * tree-ssa-pre.c (can_value_number_call): Likewise. (eliminate): Handle null functions. * tree-ssa-sccvn.c (visit_use): Handle calls to internal functions. * tree-ssa-structalias.c (get_fi_for_callee): Likewise. (find_func_aliases): Likewise. * value-prof.c (gimple_ic_transform): Likewise. (gimple_indirect_call_to_profile): Likewise. * lto-streamer-in.c (input_gimple_stmt): Likewise. * lto-streamer-out.c (output_gimple_stmt): Likewise. From-SVN: r172758
2011-04-20 10:21:25 +02:00
fn = (*valueize) (gimple_call_fn (stmt));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
if (TREE_CODE (fn) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
&& DECL_BUILT_IN (TREE_OPERAND (fn, 0))
&& gimple_builtin_call_types_compatible_p (stmt,
TREE_OPERAND (fn, 0)))
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
tree *args = XALLOCAVEC (tree, gimple_call_num_args (stmt));
tree call, retval;
unsigned i;
for (i = 0; i < gimple_call_num_args (stmt); ++i)
args[i] = (*valueize) (gimple_call_arg (stmt, i));
call = build_call_array_loc (loc,
gimple_call_return_type (stmt),
fn, gimple_call_num_args (stmt), args);
retval = fold_call_expr (EXPR_LOCATION (call), call, false);
if (retval)
{
/* fold_call_expr wraps the result inside a NOP_EXPR. */
STRIP_NOPS (retval);
retval = fold_convert (gimple_call_return_type (stmt), retval);
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return retval;
}
return NULL_TREE;
}
default:
return NULL_TREE;
}
}
/* Fold STMT to a constant using VALUEIZE to valueize SSA names.
Returns NULL_TREE if folding to a constant is not possible, otherwise
returns a constant according to is_gimple_min_invariant. */
tree
gimple_fold_stmt_to_constant (gimple stmt, tree (*valueize) (tree))
{
tree res = gimple_fold_stmt_to_constant_1 (stmt, valueize);
if (res && is_gimple_min_invariant (res))
return res;
return NULL_TREE;
}
/* The following set of functions are supposed to fold references using
their constant initializers. */
static tree fold_ctor_reference (tree type, tree ctor,
unsigned HOST_WIDE_INT offset,
unsigned HOST_WIDE_INT size, tree);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* See if we can find constructor defining value of BASE.
When we know the consructor with constant offset (such as
base is array[40] and we do know constructor of array), then
BIT_OFFSET is adjusted accordingly.
As a special case, return error_mark_node when constructor
is not explicitly available, but it is known to be zero
such as 'static const int a;'. */
static tree
get_base_constructor (tree base, HOST_WIDE_INT *bit_offset,
tree (*valueize)(tree))
{
HOST_WIDE_INT bit_offset2, size, max_size;
if (TREE_CODE (base) == MEM_REF)
{
if (!integer_zerop (TREE_OPERAND (base, 1)))
{
cuintp.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/ada/ * gcc-interface/cuintp.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/c-family/ * c-ada-spec.c, c-common.c, c-format.c, c-pretty-print.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/c/ * c-parser.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/cp/ * error.c, init.c, parser.c, semantics.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/go/ * gofrontend/expressions.cc: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/java/ * class.c, expr.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. gcc/ * builtins.c, config/alpha/alpha.c, config/c6x/predicates.md, config/ia64/predicates.md, config/iq2000/iq2000.c, config/mips/mips.c, config/s390/s390.c, dbxout.c, dwarf2out.c, except.c, explow.c, expr.c, expr.h, fold-const.c, gimple-fold.c, gimple-ssa-strength-reduction.c, gimple.c, godump.c, graphite-scop-detection.c, graphite-sese-to-poly.c, omp-low.c, predict.c, rtlanal.c, sdbout.c, simplify-rtx.c, stor-layout.c, tree-data-ref.c, tree-dfa.c, tree-pretty-print.c, tree-sra.c, tree-ssa-alias.c, tree-ssa-forwprop.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-prefetch.c, tree-ssa-math-opts.c, tree-ssa-phiopt.c, tree-ssa-reassoc.c, tree-ssa-sccvn.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-vect-data-refs.c, tree-vect-patterns.c, tree-vectorizer.h, tree.c, var-tracking.c, varasm.c: Replace host_integerp (..., 0) with tree_fits_shwi_p throughout. From-SVN: r204955
2013-11-18 15:51:10 +01:00
if (!tree_fits_shwi_p (TREE_OPERAND (base, 1)))
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return NULL_TREE;
2014-05-06 18:25:05 +02:00
*bit_offset += (mem_ref_offset (base).to_short_addr ()
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
* BITS_PER_UNIT);
}
if (valueize
&& TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
base = valueize (TREE_OPERAND (base, 0));
if (!base || TREE_CODE (base) != ADDR_EXPR)
return NULL_TREE;
base = TREE_OPERAND (base, 0);
}
/* Get a CONSTRUCTOR. If BASE is a VAR_DECL, get its
DECL_INITIAL. If BASE is a nested reference into another
ARRAY_REF or COMPONENT_REF, make a recursive call to resolve
the inner reference. */
switch (TREE_CODE (base))
{
case VAR_DECL:
case CONST_DECL:
{
tree init = ctor_for_folding (base);
/* Our semantic is exact opposite of ctor_for_folding;
NULL means unknown, while error_mark_node is 0. */
if (init == error_mark_node)
return NULL_TREE;
if (!init)
return error_mark_node;
return init;
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
case ARRAY_REF:
case COMPONENT_REF:
base = get_ref_base_and_extent (base, &bit_offset2, &size, &max_size);
if (max_size == -1 || size != max_size)
return NULL_TREE;
*bit_offset += bit_offset2;
return get_base_constructor (base, bit_offset, valueize);
case STRING_CST:
case CONSTRUCTOR:
return base;
default:
return NULL_TREE;
}
}
/* CTOR is CONSTRUCTOR of an array type. Fold reference of type TYPE and size
SIZE to the memory at bit OFFSET. */
static tree
fold_array_ctor_reference (tree type, tree ctor,
unsigned HOST_WIDE_INT offset,
unsigned HOST_WIDE_INT size,
tree from_decl)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
unsigned HOST_WIDE_INT cnt;
tree cfield, cval;
2014-05-06 18:25:05 +02:00
offset_int low_bound;
offset_int elt_size;
offset_int index, max_index;
offset_int access_index;
tree domain_type = NULL_TREE, index_type = NULL_TREE;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
HOST_WIDE_INT inner_offset;
/* Compute low bound and elt size. */
if (TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE)
domain_type = TYPE_DOMAIN (TREE_TYPE (ctor));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
if (domain_type && TYPE_MIN_VALUE (domain_type))
{
/* Static constructors for variably sized objects makes no sense. */
gcc_assert (TREE_CODE (TYPE_MIN_VALUE (domain_type)) == INTEGER_CST);
index_type = TREE_TYPE (TYPE_MIN_VALUE (domain_type));
2014-05-06 18:25:05 +02:00
low_bound = wi::to_offset (TYPE_MIN_VALUE (domain_type));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
else
2014-05-06 18:25:05 +02:00
low_bound = 0;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* Static constructors for variably sized objects makes no sense. */
alloc-pool.c, [...]: Add missing whitespace before "(". gcc/ * alloc-pool.c, asan.c, auto-inc-dec.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, bt-load.c, builtins.c, calls.c, cfgcleanup.c, cfgexpand.c, cfghooks.c, cfgloop.c, cfgloopmanip.c, cfgrtl.c, cgraph.c, cgraph.h, cgraphbuild.c, cgraphclones.c, cgraphunit.c, collect2.c, combine-stack-adj.c, combine.c, compare-elim.c, context.c, context.h, cprop.c, cse.c, cselib.c, dbxout.c, dce.c, defaults.h, df-core.c, df-problems.c, df-scan.c, df.h, diagnostic.c, double-int.c, dse.c, dumpfile.c, dwarf2asm.c, dwarf2cfi.c, dwarf2out.c, emit-rtl.c, errors.c, except.c, expmed.c, expr.c, file-find.c, final.c, fixed-value.c, fold-const.c, function.c, fwprop.c, gcc-ar.c, gcc.c, gcov-io.c, gcov-io.h, gcov.c, gcse.c, genattr-common.c, genattr.c, genattrtab.c, genautomata.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, gengtype-state.c, gengtype.c, genmodes.c, genopinit.c, genoutput.c, genpeep.c, genpreds.c, genrecog.c, gensupport.c, ggc-common.c, ggc-page.c, gimple-fold.c, gimple-low.c, gimple-pretty-print.c, gimple-ssa-strength-reduction.c, gimple.c, gimple.h, godump.c, graphite-clast-to-gimple.c, graphite-optimize-isl.c, graphite-poly.h, graphite-sese-to-poly.c, graphite.c, haifa-sched.c, hash-table.c, hash-table.h, hwint.c, hwint.h, ifcvt.c, incpath.c, init-regs.c, input.h, intl.c, intl.h, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa-utils.c, ipa.c, ira-build.c, ira.c, jump.c, loop-doloop.c, loop-init.c, loop-invariant.c, loop-iv.c, lower-subreg.c, lto-cgraph.c, lto-streamer-in.c, lto-streamer-out.c, lto-wrapper.c, mcf.c, mode-switching.c, modulo-sched.c, omp-low.c, optabs.c, opts.c, pass_manager.h, passes.c, plugin.c, postreload-gcse.c, postreload.c, predict.c, prefix.c, pretty-print.c, print-rtl.c, print-tree.c, profile.c, read-md.c, real.c, real.h, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regmove.c, regrename.c, regs.h, regstat.c, reload1.c, reorg.c, rtl.c, rtl.h, rtlanal.c, sbitmap.c, sched-rgn.c, sdbout.c, sel-sched-ir.c, sel-sched.c, sparseset.c, stack-ptr-mod.c, statistics.c, stmt.c, stor-layout.c, store-motion.c, streamer-hooks.h, system.h, target-hooks-macros.h, targhooks.c, targhooks.h, toplev.c, tracer.c, trans-mem.c, tree-browser.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-data-ref.c, tree-data-ref.h, tree-eh.c, tree-emutls.c, tree-flow.h, tree-if-conv.c, tree-into-ssa.c, tree-iterator.c, tree-loop-distribution.c, tree-mudflap.c, tree-nested.c, tree-nomudflap.c, tree-nrv.c, tree-object-size.c, tree-optimize.c, tree-pass.h, tree-pretty-print.c, tree-profile.c, tree-scalar-evolution.c, tree-sra.c, tree-ssa-ccp.c, tree-ssa-coalesce.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-live.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-prefetch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-operands.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-threadedge.c, tree-ssa-threadupdate.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop-manip.c, tree-vect-stmts.c, tree-vectorizer.c, tree-vectorizer.h, tree-vrp.c, tree.c, tree.h, tsan.c, tsystem.h, value-prof.c, var-tracking.c, varasm.c, vec.h, vmsdbgout.c, vtable-verify.c, web.c: Add missing whitespace before "(". From-SVN: r203004
2013-09-28 10:42:34 +02:00
gcc_assert (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ctor))))
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
== INTEGER_CST);
2014-05-06 18:25:05 +02:00
elt_size = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ctor))));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* We can handle only constantly sized accesses that are known to not
be larger than size of array element. */
if (!TYPE_SIZE_UNIT (type)
|| TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
2014-05-06 18:25:05 +02:00
|| wi::lts_p (elt_size, wi::to_offset (TYPE_SIZE_UNIT (type)))
|| elt_size == 0)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return NULL_TREE;
/* Compute the array index we look for. */
2014-05-06 18:25:05 +02:00
access_index = wi::udiv_trunc (offset_int (offset / BITS_PER_UNIT),
elt_size);
Modify gcc/*.[hc] double_int call sites to use the new interface. This change entailed adding a few new methods to double_int. The change results in a 0.163% time improvement with a 70% confidence. Tested on x86_64. Index: gcc/ChangeLog 2012-09-06 Lawrence Crowl <crowl@google.com> * double-int.h (double_int::operator &=): New. (double_int::operator ^=): New. (double_int::operator |=): New. (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. (binary double_int::operator *): Remove parameter name. (binary double_int::operator +): Likewise. (binary double_int::operator -): Likewise. (binary double_int::operator &): Likewise. (double_int::operator |): Likewise. (double_int::operator ^): Likewise. (double_int::and_not): Likewise. (double_int::from_shwi): Tidy formatting. (double_int::from_uhwi): Likewise. (double_int::from_uhwi): Likewise. * double-int.c (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. * builtins.c: Modify to use the new double_int interface. * cgraph.c: Likewise. * combine.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimplify-rtx.c: Likewise. * ipa-prop.c: Likewise. * loop-iv.c: Likewise. * optabs.c: Likewise. * stor-layout.c: Likewise. * tree-affine.c: Likewise. * tree-cfg.c: Likewise. * tree-dfa.c: Likewise. * tree-flow-inline.h: Likewise. * tree-object-size.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-sccvn: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vrp.c: Likewise. * tree.h: Likewise. * tree.c: Likewise. * varasm.c: Likewise. From-SVN: r191047
2012-09-07 02:06:35 +02:00
access_index += low_bound;
if (index_type)
2014-05-06 18:25:05 +02:00
access_index = wi::ext (access_index, TYPE_PRECISION (index_type),
TYPE_SIGN (index_type));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* And offset within the access. */
Modify gcc/*.[hc] double_int call sites to use the new interface. This change entailed adding a few new methods to double_int. The change results in a 0.163% time improvement with a 70% confidence. Tested on x86_64. Index: gcc/ChangeLog 2012-09-06 Lawrence Crowl <crowl@google.com> * double-int.h (double_int::operator &=): New. (double_int::operator ^=): New. (double_int::operator |=): New. (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. (binary double_int::operator *): Remove parameter name. (binary double_int::operator +): Likewise. (binary double_int::operator -): Likewise. (binary double_int::operator &): Likewise. (double_int::operator |): Likewise. (double_int::operator ^): Likewise. (double_int::and_not): Likewise. (double_int::from_shwi): Tidy formatting. (double_int::from_uhwi): Likewise. (double_int::from_uhwi): Likewise. * double-int.c (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. * builtins.c: Modify to use the new double_int interface. * cgraph.c: Likewise. * combine.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimplify-rtx.c: Likewise. * ipa-prop.c: Likewise. * loop-iv.c: Likewise. * optabs.c: Likewise. * stor-layout.c: Likewise. * tree-affine.c: Likewise. * tree-cfg.c: Likewise. * tree-dfa.c: Likewise. * tree-flow-inline.h: Likewise. * tree-object-size.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-sccvn: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vrp.c: Likewise. * tree.h: Likewise. * tree.c: Likewise. * varasm.c: Likewise. From-SVN: r191047
2012-09-07 02:06:35 +02:00
inner_offset = offset % (elt_size.to_uhwi () * BITS_PER_UNIT);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* See if the array field is large enough to span whole access. We do not
care to fold accesses spanning multiple array indexes. */
Modify gcc/*.[hc] double_int call sites to use the new interface. This change entailed adding a few new methods to double_int. The change results in a 0.163% time improvement with a 70% confidence. Tested on x86_64. Index: gcc/ChangeLog 2012-09-06 Lawrence Crowl <crowl@google.com> * double-int.h (double_int::operator &=): New. (double_int::operator ^=): New. (double_int::operator |=): New. (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. (binary double_int::operator *): Remove parameter name. (binary double_int::operator +): Likewise. (binary double_int::operator -): Likewise. (binary double_int::operator &): Likewise. (double_int::operator |): Likewise. (double_int::operator ^): Likewise. (double_int::and_not): Likewise. (double_int::from_shwi): Tidy formatting. (double_int::from_uhwi): Likewise. (double_int::from_uhwi): Likewise. * double-int.c (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. * builtins.c: Modify to use the new double_int interface. * cgraph.c: Likewise. * combine.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimplify-rtx.c: Likewise. * ipa-prop.c: Likewise. * loop-iv.c: Likewise. * optabs.c: Likewise. * stor-layout.c: Likewise. * tree-affine.c: Likewise. * tree-cfg.c: Likewise. * tree-dfa.c: Likewise. * tree-flow-inline.h: Likewise. * tree-object-size.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-sccvn: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vrp.c: Likewise. * tree.h: Likewise. * tree.c: Likewise. * varasm.c: Likewise. From-SVN: r191047
2012-09-07 02:06:35 +02:00
if (inner_offset + size > elt_size.to_uhwi () * BITS_PER_UNIT)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return NULL_TREE;
2014-05-06 18:25:05 +02:00
index = low_bound - 1;
if (index_type)
2014-05-06 18:25:05 +02:00
index = wi::ext (index, TYPE_PRECISION (index_type),
TYPE_SIGN (index_type));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), cnt, cfield, cval)
{
/* Array constructor might explicitely set index, or specify range
or leave index NULL meaning that it is next index after previous
one. */
if (cfield)
{
if (TREE_CODE (cfield) == INTEGER_CST)
2014-05-06 18:25:05 +02:00
max_index = index = wi::to_offset (cfield);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
else
{
gcc_assert (TREE_CODE (cfield) == RANGE_EXPR);
2014-05-06 18:25:05 +02:00
index = wi::to_offset (TREE_OPERAND (cfield, 0));
max_index = wi::to_offset (TREE_OPERAND (cfield, 1));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
}
else
{
2014-05-06 18:25:05 +02:00
index += 1;
if (index_type)
2014-05-06 18:25:05 +02:00
index = wi::ext (index, TYPE_PRECISION (index_type),
TYPE_SIGN (index_type));
max_index = index;
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* Do we have match? */
2014-05-06 18:25:05 +02:00
if (wi::cmpu (access_index, index) >= 0
&& wi::cmpu (access_index, max_index) <= 0)
return fold_ctor_reference (type, cval, inner_offset, size,
from_decl);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
/* When memory is not explicitely mentioned in constructor,
it is 0 (or out of range). */
return build_zero_cst (type);
}
/* CTOR is CONSTRUCTOR of an aggregate or vector.
Fold reference of type TYPE and size SIZE to the memory at bit OFFSET. */
static tree
fold_nonarray_ctor_reference (tree type, tree ctor,
unsigned HOST_WIDE_INT offset,
unsigned HOST_WIDE_INT size,
tree from_decl)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
unsigned HOST_WIDE_INT cnt;
tree cfield, cval;
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), cnt, cfield,
cval)
{
tree byte_offset = DECL_FIELD_OFFSET (cfield);
tree field_offset = DECL_FIELD_BIT_OFFSET (cfield);
tree field_size = DECL_SIZE (cfield);
2014-05-06 18:25:05 +02:00
offset_int bitoffset;
offset_int bitoffset_end, access_end;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* Variable sized objects in static constructors makes no sense,
but field_size can be NULL for flexible array members. */
gcc_assert (TREE_CODE (field_offset) == INTEGER_CST
&& TREE_CODE (byte_offset) == INTEGER_CST
&& (field_size != NULL_TREE
? TREE_CODE (field_size) == INTEGER_CST
: TREE_CODE (TREE_TYPE (cfield)) == ARRAY_TYPE));
/* Compute bit offset of the field. */
2014-05-06 18:25:05 +02:00
bitoffset = (wi::to_offset (field_offset)
+ wi::lshift (wi::to_offset (byte_offset),
LOG2_BITS_PER_UNIT));
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* Compute bit offset where the field ends. */
if (field_size != NULL_TREE)
2014-05-06 18:25:05 +02:00
bitoffset_end = bitoffset + wi::to_offset (field_size);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
else
2014-05-06 18:25:05 +02:00
bitoffset_end = 0;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
2014-05-06 18:25:05 +02:00
access_end = offset_int (offset) + size;
/* Is there any overlap between [OFFSET, OFFSET+SIZE) and
[BITOFFSET, BITOFFSET_END)? */
2014-05-06 18:25:05 +02:00
if (wi::cmps (access_end, bitoffset) > 0
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
&& (field_size == NULL_TREE
2014-05-06 18:25:05 +02:00
|| wi::lts_p (offset, bitoffset_end)))
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
2014-05-06 18:25:05 +02:00
offset_int inner_offset = offset_int (offset) - bitoffset;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* We do have overlap. Now see if field is large enough to
cover the access. Give up for accesses spanning multiple
fields. */
2014-05-06 18:25:05 +02:00
if (wi::cmps (access_end, bitoffset_end) > 0)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return NULL_TREE;
2014-05-06 18:25:05 +02:00
if (wi::lts_p (offset, bitoffset))
return NULL_TREE;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
return fold_ctor_reference (type, cval,
Modify gcc/*.[hc] double_int call sites to use the new interface. This change entailed adding a few new methods to double_int. The change results in a 0.163% time improvement with a 70% confidence. Tested on x86_64. Index: gcc/ChangeLog 2012-09-06 Lawrence Crowl <crowl@google.com> * double-int.h (double_int::operator &=): New. (double_int::operator ^=): New. (double_int::operator |=): New. (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. (binary double_int::operator *): Remove parameter name. (binary double_int::operator +): Likewise. (binary double_int::operator -): Likewise. (binary double_int::operator &): Likewise. (double_int::operator |): Likewise. (double_int::operator ^): Likewise. (double_int::and_not): Likewise. (double_int::from_shwi): Tidy formatting. (double_int::from_uhwi): Likewise. (double_int::from_uhwi): Likewise. * double-int.c (double_int::mul_with_sign): Modify overflow parameter to bool*. (double_int::add_with_sign): New. (double_int::ule): New. (double_int::sle): New. * builtins.c: Modify to use the new double_int interface. * cgraph.c: Likewise. * combine.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * expmed.c: Likewise. * expr.c: Likewise. * fixed-value.c: Likewise. * fold-const.c: Likewise. * gimple-fold.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimplify-rtx.c: Likewise. * ipa-prop.c: Likewise. * loop-iv.c: Likewise. * optabs.c: Likewise. * stor-layout.c: Likewise. * tree-affine.c: Likewise. * tree-cfg.c: Likewise. * tree-dfa.c: Likewise. * tree-flow-inline.h: Likewise. * tree-object-size.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-sccvn: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vrp.c: Likewise. * tree.h: Likewise. * tree.c: Likewise. * varasm.c: Likewise. From-SVN: r191047
2012-09-07 02:06:35 +02:00
inner_offset.to_uhwi (), size,
from_decl);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
}
/* When memory is not explicitely mentioned in constructor, it is 0. */
return build_zero_cst (type);
}
/* CTOR is value initializing memory, fold reference of type TYPE and size SIZE
to the memory at bit OFFSET. */
static tree
fold_ctor_reference (tree type, tree ctor, unsigned HOST_WIDE_INT offset,
unsigned HOST_WIDE_INT size, tree from_decl)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
tree ret;
/* We found the field with exact match. */
if (useless_type_conversion_p (type, TREE_TYPE (ctor))
&& !offset)
return canonicalize_constructor_val (unshare_expr (ctor), from_decl);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
/* We are at the end of walk, see if we can view convert the
result. */
if (!AGGREGATE_TYPE_P (TREE_TYPE (ctor)) && !offset
/* VIEW_CONVERT_EXPR is defined only for matching sizes. */
&& !compare_tree_int (TYPE_SIZE (type), size)
&& !compare_tree_int (TYPE_SIZE (TREE_TYPE (ctor)), size))
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
ret = canonicalize_constructor_val (unshare_expr (ctor), from_decl);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
ret = fold_unary (VIEW_CONVERT_EXPR, type, ret);
if (ret)
STRIP_NOPS (ret);
return ret;
}
/* For constants and byte-aligned/sized reads try to go through
native_encode/interpret. */
if (CONSTANT_CLASS_P (ctor)
&& BITS_PER_UNIT == 8
&& offset % BITS_PER_UNIT == 0
&& size % BITS_PER_UNIT == 0
&& size <= MAX_BITSIZE_MODE_ANY_MODE)
{
unsigned char buf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
if (native_encode_expr (ctor, buf, size / BITS_PER_UNIT,
offset / BITS_PER_UNIT) > 0)
return native_interpret_expr (type, buf, size / BITS_PER_UNIT);
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
if (TREE_CODE (ctor) == CONSTRUCTOR)
{
if (TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE
|| TREE_CODE (TREE_TYPE (ctor)) == VECTOR_TYPE)
return fold_array_ctor_reference (type, ctor, offset, size,
from_decl);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
else
return fold_nonarray_ctor_reference (type, ctor, offset, size,
from_decl);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
return NULL_TREE;
}
/* Return the tree representing the element referenced by T if T is an
ARRAY_REF or COMPONENT_REF into constant aggregates valuezing SSA
names using VALUEIZE. Return NULL_TREE otherwise. */
tree
fold_const_aggregate_ref_1 (tree t, tree (*valueize) (tree))
{
tree ctor, idx, base;
HOST_WIDE_INT offset, size, max_size;
tree tem;
if (TREE_THIS_VOLATILE (t))
return NULL_TREE;
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
if (TREE_CODE_CLASS (TREE_CODE (t)) == tcc_declaration)
return get_symbol_constant_value (t);
tem = fold_read_from_constant_string (t);
if (tem)
return tem;
switch (TREE_CODE (t))
{
case ARRAY_REF:
case ARRAY_RANGE_REF:
/* Constant indexes are handled well by get_base_constructor.
Only special case variable offsets.
FIXME: This code can't handle nested references with variable indexes
(they will be handled only by iteration of ccp). Perhaps we can bring
get_ref_base_and_extent here and make it use a valueize callback. */
if (TREE_CODE (TREE_OPERAND (t, 1)) == SSA_NAME
&& valueize
&& (idx = (*valueize) (TREE_OPERAND (t, 1)))
&& TREE_CODE (idx) == INTEGER_CST)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
tree low_bound, unit_size;
/* If the resulting bit-offset is constant, track it. */
if ((low_bound = array_ref_low_bound (t),
TREE_CODE (low_bound) == INTEGER_CST)
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
&& (unit_size = array_ref_element_size (t),
2014-05-06 18:25:05 +02:00
tree_fits_uhwi_p (unit_size)))
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
{
2014-05-06 18:25:05 +02:00
offset_int woffset
= wi::sext (wi::to_offset (idx) - wi::to_offset (low_bound),
TYPE_PRECISION (TREE_TYPE (idx)));
if (wi::fits_shwi_p (woffset))
{
offset = woffset.to_shwi ();
/* TODO: This code seems wrong, multiply then check
to see if it fits. */
offset *= tree_to_uhwi (unit_size);
offset *= BITS_PER_UNIT;
base = TREE_OPERAND (t, 0);
ctor = get_base_constructor (base, &offset, valueize);
/* Empty constructor. Always fold to 0. */
if (ctor == error_mark_node)
return build_zero_cst (TREE_TYPE (t));
/* Out of bound array access. Value is undefined,
but don't fold. */
if (offset < 0)
return NULL_TREE;
/* We can not determine ctor. */
if (!ctor)
return NULL_TREE;
return fold_ctor_reference (TREE_TYPE (t), ctor, offset,
tree_to_uhwi (unit_size)
* BITS_PER_UNIT,
base);
}
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
}
}
/* Fallthru. */
case COMPONENT_REF:
case BIT_FIELD_REF:
case TARGET_MEM_REF:
case MEM_REF:
base = get_ref_base_and_extent (t, &offset, &size, &max_size);
ctor = get_base_constructor (base, &offset, valueize);
/* Empty constructor. Always fold to 0. */
if (ctor == error_mark_node)
return build_zero_cst (TREE_TYPE (t));
/* We do not know precise address. */
if (max_size == -1 || max_size != size)
return NULL_TREE;
/* We can not determine ctor. */
if (!ctor)
return NULL_TREE;
/* Out of bound array access. Value is undefined, but don't fold. */
if (offset < 0)
return NULL_TREE;
return fold_ctor_reference (TREE_TYPE (t), ctor, offset, size,
base);
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i]) 2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
2011-03-24 12:23:29 +01:00
case REALPART_EXPR:
case IMAGPART_EXPR:
{
tree c = fold_const_aggregate_ref_1 (TREE_OPERAND (t, 0), valueize);
if (c && TREE_CODE (c) == COMPLEX_CST)
return fold_build1_loc (EXPR_LOCATION (t),
TREE_CODE (t), TREE_TYPE (t), c);
break;
}
default:
break;
}
return NULL_TREE;
}
tree
fold_const_aggregate_ref (tree t)
{
return fold_const_aggregate_ref_1 (t, NULL);
}
/* Lookup virtual method with index TOKEN in a virtual table V
at OFFSET.
Set CAN_REFER if non-NULL to false if method
is not referable or if the virtual table is ill-formed (such as rewriten
by non-C++ produced symbol). Otherwise just return NULL in that calse. */
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
tree
gimple_get_virt_method_for_vtable (HOST_WIDE_INT token,
tree v,
unsigned HOST_WIDE_INT offset,
bool *can_refer)
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
{
tree vtable = v, init, fn;
unsigned HOST_WIDE_INT size;
unsigned HOST_WIDE_INT elt_size, access_index;
tree domain_type;
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
if (can_refer)
*can_refer = true;
/* First of all double check we have virtual table. */
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
if (TREE_CODE (v) != VAR_DECL
|| !DECL_VIRTUAL_P (v))
{
gcc_assert (in_lto_p);
/* Pass down that we lost track of the target. */
if (can_refer)
*can_refer = false;
return NULL_TREE;
}
init = ctor_for_folding (v);
/* The virtual tables should always be born with constructors
and we always should assume that they are avaialble for
folding. At the moment we do not stream them in all cases,
but it should never happen that ctor seem unreachable. */
gcc_assert (init);
if (init == error_mark_node)
{
gcc_assert (in_lto_p);
/* Pass down that we lost track of the target. */
if (can_refer)
*can_refer = false;
return NULL_TREE;
}
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
gcc_checking_assert (TREE_CODE (TREE_TYPE (v)) == ARRAY_TYPE);
decl.c, [...]: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/ada/ * gcc-interface/decl.c, gcc-interface/utils.c, gcc-interface/utils2.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/c-family/ * c-common.c, c-cppbuiltin.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/c/ * c-decl.c, c-typeck.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/cp/ * call.c, class.c, decl.c, error.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/objc/ * objc-encoding.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/ * alias.c, asan.c, builtins.c, cfgexpand.c, cgraph.c, config/aarch64/aarch64.c, config/alpha/predicates.md, config/arm/arm.c, config/darwin.c, config/epiphany/epiphany.c, config/i386/i386.c, config/iq2000/iq2000.c, config/m32c/m32c-pragma.c, config/mep/mep-pragma.c, config/mips/mips.c, config/picochip/picochip.c, config/rs6000/rs6000.c, cppbuiltin.c, dbxout.c, dwarf2out.c, emit-rtl.c, except.c, expr.c, fold-const.c, function.c, gimple-fold.c, godump.c, ipa-cp.c, ipa-prop.c, omp-low.c, predict.c, sdbout.c, stor-layout.c, trans-mem.c, tree-object-size.c, tree-sra.c, tree-ssa-ccp.c, tree-ssa-forwprop.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-niter.c, tree-ssa-loop-prefetch.c, tree-ssa-strlen.c, tree-stdarg.c, tree-switch-conversion.c, tree-vect-generic.c, tree-vect-loop.c, tree-vect-patterns.c, tree-vrp.c, tree.c, tsan.c, ubsan.c, varasm.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. From-SVN: r204961
2013-11-18 15:52:19 +01:00
size = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (v))));
offset *= BITS_PER_UNIT;
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
offset += token * size;
/* Lookup the value in the constructor that is assumed to be array.
This is equivalent to
fn = fold_ctor_reference (TREE_TYPE (TREE_TYPE (v)), init,
offset, size, NULL);
but in a constant time. We expect that frontend produced a simple
array without indexed initializers. */
gcc_checking_assert (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
domain_type = TYPE_DOMAIN (TREE_TYPE (init));
gcc_checking_assert (integer_zerop (TYPE_MIN_VALUE (domain_type)));
elt_size = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (init))));
access_index = offset / BITS_PER_UNIT / elt_size;
gcc_checking_assert (offset % (elt_size * BITS_PER_UNIT) == 0);
/* This code makes an assumption that there are no
indexed fileds produced by C++ FE, so we can directly index the array. */
if (access_index < CONSTRUCTOR_NELTS (init))
{
fn = CONSTRUCTOR_ELT (init, access_index)->value;
gcc_checking_assert (!CONSTRUCTOR_ELT (init, access_index)->index);
STRIP_NOPS (fn);
}
else
fn = NULL;
/* For type inconsistent program we may end up looking up virtual method
in virtual table that does not contain TOKEN entries. We may overrun
the virtual table and pick up a constant or RTTI info pointer.
In any case the call is undefined. */
if (!fn
|| (TREE_CODE (fn) != ADDR_EXPR && TREE_CODE (fn) != FDESC_EXPR)
|| TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL)
fn = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
else
{
fn = TREE_OPERAND (fn, 0);
/* When cgraph node is missing and function is not public, we cannot
devirtualize. This can happen in WHOPR when the actual method
ends up in other partition, because we found devirtualization
possibility too late. */
if (!can_refer_decl_in_current_unit_p (fn, vtable))
{
if (can_refer)
{
*can_refer = false;
return fn;
}
return NULL_TREE;
}
}
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
/* Make sure we create a cgraph node for functions we'll reference.
They can be non-existent if the reference comes from an entry
of an external vtable for example. */
IPA C++ refactoring 1/N * cgraph.h (symtab_node): (void register_symbol (void)): created from symtab_register_node (void remove (void)): created from symtab_remove_node (void dump (FILE *f)): created from dump_symtab_node (void DEBUG_FUNCTION debug (void)): created from debug_symtab_node (void DEBUG_FUNCTION verify (void)): created from verify_symtab_node (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type)): created from add_reference (struct ipa_ref *add_reference (symtab_node *referred_node, enum ipa_ref_use use_type, gimple stmt)): created from add_reference (struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type, gimple stmt)): created from maybe_add_reference (bool semantically_equivalent_p (symtab_node *target)): created from symtab_semantically_equivalent_p (void remove_from_same_comdat_group (void)): created from remove_from_same_comdat_group (void add_to_same_comdat_group (symtab_node *old_node)): created from symtab_add_to_same_comdat_group (void dissolve_same_comdat_group_list (void)): created from symtab_dissolve_same_comdat_group_list (bool used_from_object_file_p (void)): created from symtab_used_from_object_file_p (symtab_node *ultimate_alias_target (enum availability *avail = NULL)): created from symtab_alias_ultimate_target (inline symtab_node *next_defined_symbol (void)): created from symtab_next_defined_symbol (bool resolve_alias (symtab_node *target)): created from symtab_resolve_alias (bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), void *data, bool include_overwrite)): created from symtab_for_node_and_aliases (symtab_node *noninterposable_alias (void)): created from symtab_nonoverwritable_alias (inline symtab_node *get_alias_target (void)): created from symtab_alias_target (void set_section (const char *section)): created from set_section_1 (enum availability get_availability (void)): created from symtab_node_availability (void make_decl_local (void)): created from symtab_make_decl_local (bool real_symbol_p (void)): created from symtab_read_node (can_be_discarded_p (void)): created from symtab_can_be_discarded (inline bool comdat_local_p (void)): created from symtab_comdat_local_p (inline bool in_same_comdat_group_p (symtab_node *target)): created from symtab_in_same_comdat_p; (bool address_taken_from_non_vtable_p (void)): created from address_taken_from_non_vtable_p (static inline symtab_node *get (const_tree decl)): created from symtab_get_node (static void dump_table (FILE *)): created from dump_symtab (static inline DEBUG_FUNCTION void debug_symtab (void)): created from debug_symtab (static DEBUG_FUNCTION void verify_symtab_nodes (void)): created from verify_symtab (static bool used_from_object_file_p_worker (symtab_node *node)): created from symtab_used_from_object_file_p (void dump_base (FILE *)): created from dump_symtab_base (bool DEBUG_FUNCTION verify_base (void)): created from verify_symtab_base (void unregister (void)): created from symtab_unregister_node (struct symbol_priority_map *priority_info (void)): created from symtab_priority_info (static bool set_implicit_section (symtab_node *n, void *)): created from set_implicit_section (static bool noninterposable_alias (symtab_node *node, void *data)): created from symtab_nonoverwritable_alias_1 * cgraph.h (cgraph_node): (bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL)): created from cgraph_remove_node_and_inline_clones (void record_stmt_references (gimple stmt)): created from ipa_record_stmt_references (void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt, bool update_speculative = true)): created from cgraph_set_call_stmt_including_clones (cgraph_node *function_symbol (enum availability *avail = NULL)): created from cgraph_function_node (cgraph_node *create_clone (tree decl, gcov_type count, int freq, bool update_original, vec<cgraph_edge *> redirect_callers, bool call_duplication_hook, struct cgraph_node *new_inlined_to, bitmap args_to_skip)): created from cgraph_create_clone (cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, const char * suffix)): created from cgraph_create_virtual_clone (cgraph_node *find_replacement (void)): created from cgraph_find_replacement_node (cgraph_node *create_version_clone (tree new_decl, vec<cgraph_edge *> redirect_callers, bitmap bbs_to_copy)): created from cgraph_copy_node_for_versioning (cgraph_node *create_version_clone_with_body (vec<cgraph_edge *> redirect_callers, vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name)): created from cgraph_function_version_info (struct cgraph_function_version_info *insert_new_function_version (void)): created from insert_new_cgraph_node_version (struct cgraph_function_version_info *function_version (void)): created from get_cgraph_node_version (void analyze (void)): created from analyze_function (cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value, tree virtual_offset, tree real_alias) cgraph_add_thunk (inline cgraph_node *get_alias_target (void)): created from cgraph_alias_target (cgraph_node *ultimate_alias_target (availability *availability = NULL)): created from cgraph_function_or_thunk_node (bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)): created from expand_thunk (void reset (void)): created from cgraph_reset_node (void create_wrapper (cgraph_node *target)): created from cgraph_make_wrapper (void DEBUG_FUNCTION verify_node (void)): created from verify_cgraph_node (void remove (void)): created from cgraph_remove_node (void dump (FILE *f)): created from dump_cgraph_node (void DEBUG_FUNCTION debug (void)): created from debug_cgraph_node (bool get_body (void)): created from cgraph_get_body (void release_body (void)): created from cgraph_release_function_body (void unnest (void)): created from cgraph_unnest_node (void make_local (void)): created from cgraph_make_node_local (void mark_address_taken (void)): created from cgraph_mark_address_taken_node (struct cgraph_edge *create_edge (cgraph_node *callee, gimple call_stmt, gcov_type count, int freq)): created from cgraph_create_edge (struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, gcov_type count, int freq)): created from cgraph_create_indirect_edge (void create_edge_including_clones (struct cgraph_node *callee, gimple old_stmt, gimple stmt, gcov_type count, int freq, cgraph_inline_failed_t reason)): created from cgraph_create_edge_including_clones (cgraph_edge *get_edge (gimple call_stmt)): created from cgraph_edge (vec<cgraph_edge *> collect_callers (void)): created from collect_callers_of_node (void remove_callers (void)): created from cgraph_node_remove_callers (void remove_callees (void)): created from cgraph_node_remove_callees (enum availability get_availability (void)): created from cgraph_function_body_availability (void set_nothrow_flag (bool nothrow)): created from cgraph_set_nothrow_flag (void set_const_flag (bool readonly, bool looping)): created from cgraph_set_const_flag (void set_pure_flag (bool pure, bool looping)): created from cgraph_set_pure_flag (void call_duplication_hooks (cgraph_node *node2)): created from cgraph_call_node_duplication_hooks (bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, void *), void *data, bool include_overwritable)): created from cgraph_for_node_and_aliases (bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, void *data), void *data, bool include_overwritable)): created from cgraph_for_node_thunks_and_aliases (void call_function_insertion_hooks (void)): created from cgraph_call_function_insertion_hooks (inline void mark_force_output (void)): created from cgraph_mark_force_output_node (bool local_p (void)): created from cgraph_local_node (bool can_be_local_p (void)): created from cgraph_node_can_be_local_p (bool cannot_return_p (void)): created from cgraph_node_cannot_return (bool only_called_directly_p (void)): created from cgraph_only_called_directly_p (inline bool only_called_directly_or_aliased_p (void)): created from cgraph_only_called_directly_or_aliased_p (bool will_be_removed_from_program_if_no_direct_calls_p (void)): created from cgraph_will_be_removed_from_program_if_no_direct_calls (bool can_remove_if_no_direct_calls_and_refs_p (void)): created from cgraph_can_remove_if_no_direct_calls_and_refs_p (bool can_remove_if_no_direct_calls_p (void)): created from cgraph_can_remove_if_no_direct_calls_p (inline bool has_gimple_body_p (void)): created from cgraph_function_with_gimple_body_p (bool optimize_for_size_p (void)): created from cgraph_optimize_for_size_p (static void dump_cgraph (FILE *f)): created from dump_cgraph (static inline void debug_cgraph (void)): created from debug_cgraph (static void record_function_versions (tree decl1, tree decl2)): created from record_function_versions (static void delete_function_version (tree decl)): created from delete_function_version (static void add_new_function (tree fndecl, bool lowered)): created from cgraph_add_new_function (static inline cgraph_node *get (const_tree decl)): created from cgraph_get_node (static cgraph_node * create (tree decl)): created from cgraph_create_node (static cgraph_node * create_empty (void)): created from cgraph_create_empty_node (static cgraph_node * get_create (tree)): created from cgraph_get_create_node (static cgraph_node *get_for_asmname (tree asmname)): created from cgraph_node_for_asm (static cgraph_node * create_same_body_alias (tree alias, tree decl)): created from cgraph_same_body_alias (static bool used_from_object_file_p_worker (cgraph_node *node, void *): new function (static bool non_local_p (cgraph_node *node, void *)): created from cgraph_non_local_node_p_1 (static void DEBUG_FUNCTION verify_cgraph_nodes (void)): created from verify_cgraph (static bool make_local (cgraph_node *node, void *)): created from cgraph_make_node_local (static cgraph_node *create_alias (tree alias, tree target)): created from cgraph_create_function_alias (static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, gimple call_stmt, gcov_type count, int freq, bool indir_unknown_callee)): created from cgraph_create_edge_1 * cgraph.h (varpool_node): (void remove (void)): created from varpool_remove_node (void dump (FILE *f)): created from dump_varpool_node From-SVN: r212982
2014-07-24 14:07:13 +02:00
cgraph_node::get_create (fn);
cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. 2011-09-02 Martin Jambor <mjambor@suse.cz> * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta. * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use BINFO_VTABLE. Parameter delta removed, all callers updated. * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead BINFO_VTABLE. * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated all calls. * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed handling of thunk_delta. * ipa-cp.c (get_indirect_edge_target): Removed parameter delta. (devirtualization_time_bonus): Do not handle thunk deltas. (ipcp_discover_new_direct_edges): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. (try_make_edge_direct_simple_call): Likewise. (try_make_edge_direct_virtual_call): Likewise. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise. Mark parameter set as unused. (output_edge_opt_summary): Likewise. Mark both parameters as unused. (input_edge_opt_summary): Likewise. * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream BINFO_VIRTUALS at all. * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise. * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method. * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call discovery, xfailed test for inlining. * testsuite/g++.dg/ipa/ivinline-9.C: Likewise. From-SVN: r178472
2011-09-02 15:26:30 +02:00
return fn;
}
/* Return a declaration of a function which an OBJ_TYPE_REF references. TOKEN
is integer form of OBJ_TYPE_REF_TOKEN of the reference expression.
KNOWN_BINFO carries the binfo describing the true type of
OBJ_TYPE_REF_OBJECT(REF).
Set CAN_REFER if non-NULL to false if method
is not referable or if the virtual table is ill-formed (such as rewriten
by non-C++ produced symbol). Otherwise just return NULL in that calse. */
tree
gimple_get_virt_method_for_binfo (HOST_WIDE_INT token, tree known_binfo,
bool *can_refer)
{
unsigned HOST_WIDE_INT offset;
tree v;
v = BINFO_VTABLE (known_binfo);
/* If there is no virtual methods table, leave the OBJ_TYPE_REF alone. */
if (!v)
return NULL_TREE;
if (!vtable_pointer_value_to_vtable (v, &v, &offset))
{
if (can_refer)
*can_refer = false;
return NULL_TREE;
}
return gimple_get_virt_method_for_vtable (token, v, offset, can_refer);
}
/* Return true iff VAL is a gimple expression that is known to be
non-negative. Restricted to floating-point inputs. */
bool
gimple_val_nonnegative_real_p (tree val)
{
gimple def_stmt;
gcc_assert (val && SCALAR_FLOAT_TYPE_P (TREE_TYPE (val)));
/* Use existing logic for non-gimple trees. */
if (tree_expr_nonnegative_p (val))
return true;
if (TREE_CODE (val) != SSA_NAME)
return false;
/* Currently we look only at the immediately defining statement
to make this determination, since recursion on defining
statements of operands can lead to quadratic behavior in the
worst case. This is expected to catch almost all occurrences
in practice. It would be possible to implement limited-depth
recursion if important cases are lost. Alternatively, passes
that need this information (such as the pow/powi lowering code
in the cse_sincos pass) could be revised to provide it through
dataflow propagation. */
def_stmt = SSA_NAME_DEF_STMT (val);
if (is_gimple_assign (def_stmt))
{
tree op0, op1;
/* See fold-const.c:tree_expr_nonnegative_p for additional
cases that could be handled with recursion. */
switch (gimple_assign_rhs_code (def_stmt))
{
case ABS_EXPR:
/* Always true for floating-point operands. */
return true;
case MULT_EXPR:
/* True if the two operands are identical (since we are
restricted to floating-point inputs). */
op0 = gimple_assign_rhs1 (def_stmt);
op1 = gimple_assign_rhs2 (def_stmt);
if (op0 == op1
|| operand_equal_p (op0, op1, 0))
return true;
default:
return false;
}
}
else if (is_gimple_call (def_stmt))
{
tree fndecl = gimple_call_fndecl (def_stmt);
if (fndecl
&& DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
{
tree arg1;
switch (DECL_FUNCTION_CODE (fndecl))
{
CASE_FLT_FN (BUILT_IN_ACOS):
CASE_FLT_FN (BUILT_IN_ACOSH):
CASE_FLT_FN (BUILT_IN_CABS):
CASE_FLT_FN (BUILT_IN_COSH):
CASE_FLT_FN (BUILT_IN_ERFC):
CASE_FLT_FN (BUILT_IN_EXP):
CASE_FLT_FN (BUILT_IN_EXP10):
CASE_FLT_FN (BUILT_IN_EXP2):
CASE_FLT_FN (BUILT_IN_FABS):
CASE_FLT_FN (BUILT_IN_FDIM):
CASE_FLT_FN (BUILT_IN_HYPOT):
CASE_FLT_FN (BUILT_IN_POW10):
return true;
CASE_FLT_FN (BUILT_IN_SQRT):
/* sqrt(-0.0) is -0.0, and sqrt is not defined over other
nonnegative inputs. */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (val))))
return true;
break;
CASE_FLT_FN (BUILT_IN_POWI):
/* True if the second argument is an even integer. */
arg1 = gimple_call_arg (def_stmt, 1);
if (TREE_CODE (arg1) == INTEGER_CST
&& (TREE_INT_CST_LOW (arg1) & 1) == 0)
return true;
break;
CASE_FLT_FN (BUILT_IN_POW):
/* True if the second argument is an even integer-valued
real. */
arg1 = gimple_call_arg (def_stmt, 1);
if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE c;
HOST_WIDE_INT n;
c = TREE_REAL_CST (arg1);
n = real_to_integer (&c);
if ((n & 1) == 0)
{
REAL_VALUE_TYPE cint;
2014-05-06 18:25:05 +02:00
real_from_integer (&cint, VOIDmode, n, SIGNED);
if (real_identical (&c, &cint))
return true;
}
}
break;
default:
return false;
}
}
}
return false;
}
/* Given a pointer value OP0, return a simplified version of an
indirection through OP0, or NULL_TREE if no simplification is
possible. Note that the resulting type may be different from
the type pointed to in the sense that it is still compatible
from the langhooks point of view. */
tree
gimple_fold_indirect_ref (tree t)
{
tree ptype = TREE_TYPE (t), type = TREE_TYPE (ptype);
tree sub = t;
tree subtype;
STRIP_NOPS (sub);
subtype = TREE_TYPE (sub);
if (!POINTER_TYPE_P (subtype))
return NULL_TREE;
if (TREE_CODE (sub) == ADDR_EXPR)
{
tree op = TREE_OPERAND (sub, 0);
tree optype = TREE_TYPE (op);
/* *&p => p */
if (useless_type_conversion_p (type, optype))
return op;
/* *(foo *)&fooarray => fooarray[0] */
if (TREE_CODE (optype) == ARRAY_TYPE
&& TREE_CODE (TYPE_SIZE (TREE_TYPE (optype))) == INTEGER_CST
&& useless_type_conversion_p (type, TREE_TYPE (optype)))
{
tree type_domain = TYPE_DOMAIN (optype);
tree min_val = size_zero_node;
if (type_domain && TYPE_MIN_VALUE (type_domain))
min_val = TYPE_MIN_VALUE (type_domain);
if (TREE_CODE (min_val) == INTEGER_CST)
return build4 (ARRAY_REF, type, op, min_val, NULL_TREE, NULL_TREE);
}
/* *(foo *)&complexfoo => __real__ complexfoo */
else if (TREE_CODE (optype) == COMPLEX_TYPE
&& useless_type_conversion_p (type, TREE_TYPE (optype)))
return fold_build1 (REALPART_EXPR, type, op);
/* *(foo *)&vectorfoo => BIT_FIELD_REF<vectorfoo,...> */
else if (TREE_CODE (optype) == VECTOR_TYPE
&& useless_type_conversion_p (type, TREE_TYPE (optype)))
{
tree part_width = TYPE_SIZE (type);
tree index = bitsize_int (0);
return fold_build3 (BIT_FIELD_REF, type, op, part_width, index);
}
}
/* *(p + CST) -> ... */
if (TREE_CODE (sub) == POINTER_PLUS_EXPR
&& TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
{
tree addr = TREE_OPERAND (sub, 0);
tree off = TREE_OPERAND (sub, 1);
tree addrtype;
STRIP_NOPS (addr);
addrtype = TREE_TYPE (addr);
/* ((foo*)&vectorfoo)[1] -> BIT_FIELD_REF<vectorfoo,...> */
if (TREE_CODE (addr) == ADDR_EXPR
&& TREE_CODE (TREE_TYPE (addrtype)) == VECTOR_TYPE
&& useless_type_conversion_p (type, TREE_TYPE (TREE_TYPE (addrtype)))
&& tree_fits_uhwi_p (off))
{
decl.c, [...]: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/ada/ * gcc-interface/decl.c, gcc-interface/utils.c, gcc-interface/utils2.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/c-family/ * c-common.c, c-cppbuiltin.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/c/ * c-decl.c, c-typeck.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/cp/ * call.c, class.c, decl.c, error.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/objc/ * objc-encoding.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. gcc/ * alias.c, asan.c, builtins.c, cfgexpand.c, cgraph.c, config/aarch64/aarch64.c, config/alpha/predicates.md, config/arm/arm.c, config/darwin.c, config/epiphany/epiphany.c, config/i386/i386.c, config/iq2000/iq2000.c, config/m32c/m32c-pragma.c, config/mep/mep-pragma.c, config/mips/mips.c, config/picochip/picochip.c, config/rs6000/rs6000.c, cppbuiltin.c, dbxout.c, dwarf2out.c, emit-rtl.c, except.c, expr.c, fold-const.c, function.c, gimple-fold.c, godump.c, ipa-cp.c, ipa-prop.c, omp-low.c, predict.c, sdbout.c, stor-layout.c, trans-mem.c, tree-object-size.c, tree-sra.c, tree-ssa-ccp.c, tree-ssa-forwprop.c, tree-ssa-loop-ivcanon.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-niter.c, tree-ssa-loop-prefetch.c, tree-ssa-strlen.c, tree-stdarg.c, tree-switch-conversion.c, tree-vect-generic.c, tree-vect-loop.c, tree-vect-patterns.c, tree-vrp.c, tree.c, tsan.c, ubsan.c, varasm.c: Replace tree_low_cst (..., 1) with tree_to_uhwi throughout. From-SVN: r204961
2013-11-18 15:52:19 +01:00
unsigned HOST_WIDE_INT offset = tree_to_uhwi (off);
tree part_width = TYPE_SIZE (type);
unsigned HOST_WIDE_INT part_widthi
= tree_to_shwi (part_width) / BITS_PER_UNIT;
unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT;
tree index = bitsize_int (indexi);
if (offset / part_widthi
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (addrtype)))
return fold_build3 (BIT_FIELD_REF, type, TREE_OPERAND (addr, 0),
part_width, index);
}
/* ((foo*)&complexfoo)[1] -> __imag__ complexfoo */
if (TREE_CODE (addr) == ADDR_EXPR
&& TREE_CODE (TREE_TYPE (addrtype)) == COMPLEX_TYPE
&& useless_type_conversion_p (type, TREE_TYPE (TREE_TYPE (addrtype))))
{
tree size = TYPE_SIZE_UNIT (type);
if (tree_int_cst_equal (size, off))
return fold_build1 (IMAGPART_EXPR, type, TREE_OPERAND (addr, 0));
}
/* *(p + CST) -> MEM_REF <p, CST>. */
if (TREE_CODE (addr) != ADDR_EXPR
|| DECL_P (TREE_OPERAND (addr, 0)))
return fold_build2 (MEM_REF, type,
addr,
2014-05-06 18:25:05 +02:00
wide_int_to_tree (ptype, off));
}
/* *(foo *)fooarrptr => (*fooarrptr)[0] */
if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
&& TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (subtype)))) == INTEGER_CST
&& useless_type_conversion_p (type, TREE_TYPE (TREE_TYPE (subtype))))
{
tree type_domain;
tree min_val = size_zero_node;
tree osub = sub;
sub = gimple_fold_indirect_ref (sub);
if (! sub)
sub = build1 (INDIRECT_REF, TREE_TYPE (subtype), osub);
type_domain = TYPE_DOMAIN (TREE_TYPE (sub));
if (type_domain && TYPE_MIN_VALUE (type_domain))
min_val = TYPE_MIN_VALUE (type_domain);
if (TREE_CODE (min_val) == INTEGER_CST)
return build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE);
}
return NULL_TREE;
}
/* Return true if CODE is an operation that when operating on signed
integer types involves undefined behavior on overflow and the
operation can be expressed with unsigned arithmetic. */
bool
arith_code_with_undefined_signed_overflow (tree_code code)
{
switch (code)
{
case PLUS_EXPR:
case MINUS_EXPR:
case MULT_EXPR:
case NEGATE_EXPR:
case POINTER_PLUS_EXPR:
return true;
default:
return false;
}
}
/* Rewrite STMT, an assignment with a signed integer or pointer arithmetic
operation that can be transformed to unsigned arithmetic by converting
its operand, carrying out the operation in the corresponding unsigned
type and converting the result back to the original type.
Returns a sequence of statements that replace STMT and also contain
a modified form of STMT itself. */
gimple_seq
rewrite_to_defined_overflow (gimple stmt)
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "rewriting stmt with undefined signed "
"overflow ");
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
}
tree lhs = gimple_assign_lhs (stmt);
tree type = unsigned_type_for (TREE_TYPE (lhs));
gimple_seq stmts = NULL;
for (unsigned i = 1; i < gimple_num_ops (stmt); ++i)
{
gimple_seq stmts2 = NULL;
gimple_set_op (stmt, i,
force_gimple_operand (fold_convert (type,
gimple_op (stmt, i)),
&stmts2, true, NULL_TREE));
gimple_seq_add_seq (&stmts, stmts2);
}
gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt));
if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR)
gimple_assign_set_rhs_code (stmt, PLUS_EXPR);
gimple_seq_add_stmt (&stmts, stmt);
gimple cvt = gimple_build_assign_with_ops
(NOP_EXPR, lhs, gimple_assign_lhs (stmt), NULL_TREE);
gimple_seq_add_stmt (&stmts, cvt);
return stmts;
}
/* Return OP converted to TYPE by emitting a conversion statement on SEQ
if required using location LOC. Note that OP will be returned
unmodified if GIMPLE does not require an explicit conversion between
its type and TYPE. */
tree
gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op)
{
if (useless_type_conversion_p (type, TREE_TYPE (op)))
return op;
op = fold_convert_loc (loc, type, op);
gimple_seq stmts = NULL;
op = force_gimple_operand (op, &stmts, true, NULL_TREE);
gimple_seq_add_seq_without_update (seq, stmts);
return op;
}