aboutsummaryrefslogtreecommitdiff
path: root/gcc/genmatch.c
AgeCommit message (Collapse)AuthorFilesLines
2016-10-13re PR target/77826 (ICE in decompose, at wide-int.h:928 w/ -m64 -O2 and above)Richard Biener1-25/+125
2016-10-13 Richard Biener <rguenther@suse.de> PR middle-end/77826 * genmatch.c (struct capture): Add value_match member. (commutate): Preserve value_match. (lower_opt_convert): Likewise. (lower_cond): Likewise. (replace_id): Likewise. (struct dt_operand): Add value_match member. (decision_tree::cmp_node): Compare it. (decision_tree::insert_operand): Honor it when finding and when appending a DT_MATCH. (dt_operand::gen_match_op): Generate a type check after operand_equal_p if ! value_match for both GENERIC and GIMPLE. (parser::get_internal_capture_id): New helper. (parser::finish_match_operand): New function lowering @@<id>. (parser::parse_capture): Parse @@<id> as value-match. (parser::parse_expr): Use get_internal_capture_id. (parser::parse_simplify): Call finish_match_operand. (walk_captures): New helper. * match.pd (X - (X / Y) * Y -> X % Y): Use value-matching instead of operand_equal_p. ((X /[ex] A) * A -> X): Likewise. ((X | Y) ^ X -> Y & ~ X): Handle constants properly by using convert[12] and value-matching. ((A | B) & (A | C) -> A | (B & C)): Likewise. ((X | Y) | Y -> X | Y): Likewise. ((X ^ Y) ^ Y -> X): Likewise. (A - (A & B) -> ~B & A): Likewise. ((T)(P + A) - (T)P -> (T) A): Likewise. ((T)P - (T)(P + A) -> -(T) A): Likewise. ((T)(P + A) - (T)(P + B) -> (T)A - (T)B): Likewise. * doc/match-and-simplify.texi: Amend capture section. From-SVN: r241108
2016-10-05re PR middle-end/77863 (genmatch segfault on a wrong usage of an for operator)Richard Biener1-2/+4
2016-10-05 Richard Biener <rguenther@suse.de> PR middle-end/77863 * genmatch.c (capture_info::walk_c_expr): Diagnose unknown capture ids in c-exprs. From-SVN: r240777
2016-10-05re PR target/77826 (ICE in decompose, at wide-int.h:928 w/ -m64 -O2 and above)Richard Biener1-5/+11
2016-10-05 Richard Biener <rguenther@suse.de> PR middle-end/77826 * genmatch.c (dt_operand::gen_match_op): Amend operand_equal_p with types_match for GIMPLE code gen to handle type mismatched constants properly. (dt_operand::gen): Adjust. * match.pd ((X /[ex] A) * A -> X): Properly handle converted and constant A. * gcc.dg/torture/pr77826.c: New testcase. From-SVN: r240776
2016-10-05re PR middle-end/77842 (genmatch segfault on a missing brace)Richard Biener1-0/+2
2016-10-05 Richard Biener <rguenther@suse.de> PR middle-end/77842 * genmatch.c (parser::parse_c_expr): Handle premature EOF. From-SVN: r240774
2016-10-01re PR middle-end/77798 (465.tonto ICE with trunk with -O2)Richard Biener1-5/+9
2016-10-01 Richard Biener <rguenther@suse.de> PR middle-end/77798 * genmatch.c (get_operand_type): Add operand position arg and handle COND_EXPR comparison operand with fixed boolean_type_node. (expr::gen_transform): Adjust. (dt_simplify::gen_1): Likewise. * gfortran.fortran-torture/compile/pr77798.f90: New testcase. From-SVN: r240696
2016-09-01c-ada-spec.c (dump_ada_function_declaration): Increase buffer size to ↵Martin Sebor1-1/+2
guarantee it fits the output of the formatted function... gcc/c-family/ChangeLog: * c-ada-spec.c (dump_ada_function_declaration): Increase buffer size to guarantee it fits the output of the formatted function regardless of its arguments. gcc/cp/ChangeLog: * mangle.c: Increase buffer size to guarantee it fits the output of the formatted function regardless of its arguments. gcc/go/ChangeLog: * gofrontend/expressions.cc: Increase buffer size to guarantee it fits the output of the formatted function regardless of its arguments. gcc/java/ChangeLog: * decl.c (give_name_to_locals): Increase buffer size to guarantee it fits the output of the formatted function regardless of its arguments. * mangle_name.c (append_unicode_mangled_name): Same. gcc/ChangeLog: * genmatch.c (parser::parse_expr): Increase buffer size to guarantee it fits the output of the formatted function regardless of its arguments. * gcc/genmodes.c (parser::parse_expr): Same. * gimplify.c (gimplify_asm_expr): Same. * passes.c (pass_manager::register_one_dump_file): Same. * print-tree.c (print_node): Same. From-SVN: r239949
2016-07-13use auto_vec for more local variablesTrevor Saunders1-8/+4
gcc/c/ChangeLog: 2016-07-12 Trevor Saunders <tbsaunde+gcc@tbsaunde.org> * c-parser.c (c_parser_generic_selection): Make type of variable auto_vec. (c_parser_omp_declare_simd): Likewise. gcc/ChangeLog: 2016-07-12 Trevor Saunders <tbsaunde+gcc@tbsaunde.org> * cfgexpand.c (expand_used_vars): Make the type of a local variable auto_vec. * genmatch.c (lower_for): Likewise. * haifa-sched.c (haifa_sched_init): Likewise. (add_to_speculative_block): Likewise. (create_check_block_twin): Likewise. * predict.c (handle_missing_profiles): Likewise. * tree-data-ref.c (loop_nest_has_data_refs): Likewise. * tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Likewise. * tree-ssa-loop-niter.c (discover_iteration_bound_by_body_walk): Likewise. (maybe_lower_iteration_bound): Likewise. * tree-ssa-sccvn.c (DFS): Likewise. * tree-stdarg.c (reachable_at_most_once): Likewise. * tree-vect-stmts.c (vectorizable_conversion): Likewise. (vectorizable_store): Likewise. From-SVN: r238285
2016-06-14re PR middle-end/71526 (ICE: verify_gimple failed)Richard Biener1-2/+8
2016-06-14 Richard Biener <rguenther@suse.de> PR middle-end/71526 * genmatch.c (expr::gen_transform): Use in_type for comparisons if available. * gfortran.dg/pr71526.f90: New testcase. From-SVN: r237441
2016-06-01genmatch.c (comparison_code_p): New predicate.Richard Biener1-6/+147
2016-06-01 Richard Biener <rguenther@suse.de> * genmatch.c (comparison_code_p): New predicate. (swap_tree_comparison): New function. (commutate): Add for_vec parameter to append new for entries. Support commutating relational operators by swapping it alongside operands. (lower_commutative): Adjust. (dt_simplify::gen): Do not pass artificial operators to gen functions. (decision_tree::gen): Do not add artificial operators as parameters. (parser::parse_expr): Verify operator commutativity when :c is applied. Allow :C to override this. * match.pd: Adjust patterns to use :C instead of :c where required. From-SVN: r236977
2016-04-26match.pd: X + X --> X * 2 for integersMarc Glisse1-1/+1
2016-04-26 Marc Glisse <marc.glisse@inria.fr> gcc/ * genmatch.c (write_predicate): Add ATTRIBUTE_UNUSED. * fold-const.c (fold_binary_loc): Remove 2 transformations superseded by match.pd. * match.pd (x+x -> x*2): Generalize to integers. gcc/testsuite/ * gcc.dg/fold-plusmult.c: Adjust. * gcc.dg/no-strict-overflow-6.c: Adjust. * gcc.dg/gomp/loop-1.c: Xfail some tests. From-SVN: r235444
2016-04-22[PATCH 1/2] (header usage fix) remove unused system header includesSzabolcs Nagy1-1/+0
2016-04-22 Szabolcs Nagy <szabolcs.nagy@arm.com> * auto-profile.c: Remove <string.h> include. * ipa-icf-gimple.c: Remove <list> include. * diagnostic.c: Remove <new> include. * genmatch.c: Likewise. * pretty-print.c: Likewise. * toplev.c: Likewise * c/c-objc-common.c: Likewise. * cp/error.c: Likewise. * fortran/error.c: Likewise. From-SVN: r235361
2016-03-22re PR tree-optimization/70251 (Wrong code with -O3 -march=skylake-avx512.)Richard Biener1-34/+38
2016-03-22 Richard Biener <rguenther@suse.de> PR middle-end/70251 * genmatch.c (gen_transform): Adjust last parameter to a three-state int... (capture::gen_transform): ... to change behavior when substituting a condition into cond or not-cond expr context. (dt_simplify::gen_1): Adjust. * gimple-match-head.c: Include gimplify.h for unshare_expr. * match.pd (A + (B vcmp C ? 1 : 0) -> A - (B vcmp C)): Revert last change and instead change to A + (B vcmp C ? 1 : 0) -> A - (B vcmp C ? -1 : 0). (A - (B vcmp C ? 1 : 0) -> A + (B vcmp C)): Likewise. * g++.dg/torture/pr70251.C: New testcase. From-SVN: r234405
2016-03-02genmatch.c (dt_node::gen_kids): Fix match code-gen for embedded GENERIC ↵Richard Biener1-1/+1
expressions in GIMPLE. 2016-03-02 Richard Biener <rguenther@suse.de> * genmatch.c (dt_node::gen_kids): Fix match code-gen for embedded GENERIC expressions in GIMPLE. From-SVN: r233902
2016-01-04Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r232055
2015-12-02tree.h (tree_invariant_p): Declare.Richard Biener1-2/+2
2015-12-02 Richard Biener <rguenther@suse.de> * tree.h (tree_invariant_p): Declare. * tree.c (tree_invariant_p): Export. * genmatch.c (dt_simplify::gen_1): For GENERIC code-gen never create SAVE_EXPRs but reject patterns if we would need to. From-SVN: r231178
2015-12-01re PR ada/68590 (FAIL: gnat.dg/loop_optimization19.adb scan-tree-dump-not ↵Richard Biener1-4/+9
optimized "Index_Check") 2015-12-01 Richard Biener <rguenther@suse.de> PR middle-end/68590 * genmatch.c (struct capture_info): Add match_use_count. (capture_info::walk_match): Increment match_use_count. (dt_simplify::gen_1): For GENERIC, only wrap multi-use replacements in a save_expr if they occur more often than in the original expression. From-SVN: r231110
2015-11-26genmatch.c (dt_simplify::gen_1): For generic wrap all multi-result-use ↵Richard Biener1-10/+4
captures in a SAVE_EXPR. 2015-11-26 Richard Biener <rguenther@suse.de> * genmatch.c (dt_simplify::gen_1): For generic wrap all multi-result-use captures in a SAVE_EXPR. From-SVN: r230955
2015-11-24destroy values as well as keys when removing them from hash mapsTrevor Saunders1-1/+2
gcc/ChangeLog: 2015-11-24 Trevor Saunders <tbsaunde+gcc@tbsaunde.org> * hash-map-traits.h (simple_hashmap_traits ::remove): call destructors on values that are being removed. * mem-stats.h (hash_map): Pass type of values to simple_hashmap_traits. * tree-sra.c (sra_deinitialize): Remove work around for hash maps not destructing values. * genmatch.c (sinfo_hashmap_traits): Adjust. * tree-ssa-uncprop.c (val_ssa_equiv_hash_traits): Likewise. From-SVN: r230801
2015-11-17Replace match.pd DEFINE_MATH_FNs with auto-generated listsRichard Sandiford1-0/+7
This patch autogenerates the operator lists for maths functions like SQRT, adding an additional entry for internal functions. E.g.: (define_operator_list SQRT BUILT_IN_SQRTF BUILT_IN_SQRT BUILT_IN_SQRTL IFN_SQRT) and: (define_operator_list CABS BUILT_IN_CABSF BUILT_IN_CABS BUILT_IN_CABSL null) (since there's no internal function for CABS). Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * Makefile.in (MOSTLYCLEANFILES): Add cfn-operators.pd. (generated_files): Likewise. (s-cfn-operators, cfn-operators.pd): New rules. (s-match): Depend on cfn-operators.pd. * gencfn-macros.c: Expand comment to describe -o behavior. (print_define_operator_list): New function. (main): Accept -o. Call print_define_operator_list. * genmatch.c (main): Add the current directory to the include path. * match.pd (DEFINE_MATH_FN): Delete. Include cfn-operators.pd instead. From-SVN: r230486
2015-11-17Add null identifiers to genmatchRichard Sandiford1-7/+62
This patch adds a null identifier that can never match anything and can never be generated. It is only valid in operator lists and fors. Later patches will add uses of it. The idea is to allow operator lists for maths functions that have four entries: - float built-in - double built-in - long double built-in - internal function Not all maths functions have an associated internal function, and for those the final operator will be "null". Any simplification that tries to use a null substitution will be skipped. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * doc/match-and-simplify.texi: Document the "null" identifier. * genmatch.c (id_base::NULL_ID): New kind. (null_id): New variable. (get_operator): Add a parameter that says whether null identifiers are allowed. (contains_id): New function. (lower_for): Skip substitutions that would have a null_id in either the match or the result. (parser::parse_for): Allow the null identifier to be used. (parser::parse_operator_list): Likewise. (main): Initialize null_id. From-SVN: r230485
2015-11-17Add genmatch support for internal functionsRichard Sandiford1-80/+77
This patch makes genmatch match calls based on combined_fn rather than built_in_function and extends the matching to internal functions. It also uses fold_const_call to fold the calls to a constant, rather than going through fold_builtin_n. In order to slightly simplify the code and remove potential ambiguity, the patch enforces lower case for tree codes (foo->FOO_EXPR), caps for functions (no built_in_hypot->BUILT_IN_HYPOT) and requires an exact match for user-defined identifiers. The first two were already met in practice but there were a couple of cases where operator lists were defined in one case and used in another. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * match.pd: Use HYPOT and COS rather than hypot and cos. Use CASE_CFN_* macros. Guard log/exp folds with SCALAR_FLOAT_TYPE_P. * genmatch.c (internal_fn): New enum. (fn_id::fn): Change to an unsigned int. (fn_id::fn_id): Accept internal_fn too. (add_builtin): Rename to... (add_function): ...this and turn into a template. (get_operator): Only try one variation if the original name fails. Only add _EXPR if the original name was all lower case. Try converting internal and built-in function names to their CFN equivalents. (expr::gen_transform): Use maybe_build_call_expr_loc for generic. (dt_simplify::gen_1): Likewise. (dt_node::gen_kids_1): Use gimple_call_combined_fn for gimple and get_call_combined_fn for generic. (dt_simplify::gen): Use combined_fn as the type of fn_ids. (decision_tree::gen): Likewise. (main): Use lower case in the strings for {VIEW_,}CONVERT[012]. Use add_function rather than add_builtin. Register internal functions too. * generic-match-head.c: Include case-cfn-macros.h. * gimple-fold.c (replace_stmt_with_simplification): Use gimple_call_combined_fn to test whether we can keep an existing call. * gimple-match.h (code_helper): Replace built_in_function with combined_fn. * gimple-match-head.c: Include fold-const-call.h, internal-fn.h and case-fn-macros.h. (gimple_resimplify1): Use fold_const_call. (gimple_resimplify2, gimple_resimplify3): Likewise. (build_call_internal, build_call): New functions. (maybe_push_res_to_seq): Use them. (gimple_simplify): Use fold_const_call. Set *rcode to a combined_fn rather than a built-in function. * tree.h (build_call_expr_internal_loc): Declare. (maybe_build_call_expr_loc): Likewise. * tree.c (build_call_expr_internal_loc_array): New function. (maybe_build_call_expr_loc): Likewise. From-SVN: r230484
2015-11-13Source range tracking in libcpp and C FE, with bit-packing optimizationDavid Malcolm1-4/+4
This patch combines: [PATCH 05/10] Add ranges to libcpp tokens (via ad-hoc data, unoptimized) [PATCH 06/10] Track expression ranges in C frontend [PATCH 07/10] Add plugin to recursively dump the source-ranges in a tree (v2) [PATCH 08/10] Wire things up so that libcpp users get token underlines [PATCH 09/10] Delay some resolution of ad-hoc locations, preserving ranges [PATCH 10/10] Compress short ranges into source_location [PATCH] libcpp: add examples to source_location description along with fixes for the nits identified during review. gcc/ChangeLog: * Makefile.in (OBJS): Add gcc-rich-location.o. * diagnostic.c (diagnostic_append_note): Pass line_table to rich_location ctor. (emit_diagnostic): Likewise. (inform): Likewise. (inform_n): Likewise. (warning): Likewise. (warning_at): Likewise. (warning_n): Likewise. (pedwarn): Likewise. (permerror): Likewise. (error): Likewise. (error_n): Likewise. (error_at): Likewise. (sorry): Likewise. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. (source_range::debug): Likewise. * gcc-rich-location.c: New file. * gcc-rich-location.h: New file. * genmatch.c (fatal_at): Pass line_table to rich_location ctor. (warning_at): Likewise. * gimple.h (gimple_set_block): Use set_block function. * input.c (dump_line_table_statistics): Dump stats on how many ranges were optimized vs how many needed ad-hoc table. (write_digit_row): Add "map" param; use its range_bits to calculate the per-character offset. (dump_location_info): Print the range and column bits for each ordinary map. Use the range bits to calculate the per-character offset. Pass the map as a new param to the various calls to write_digit_row. Eliminate uses of ORDINARY_MAP_NUMBER_OF_COLUMN_BITS. * print-tree.c (print_node): Print any source range information. * rtl-error.c (diagnostic_for_asm): Likewise. * toplev.c (general_init): Initialize line_table's default_range_bits. * tree-cfg.c (move_block_to_fn): Likewise. (move_block_to_fn): Likewise. * tree-inline.c (copy_phis_for_bb): Likewise. * tree.c (tree_set_block): Likewise. (get_pure_location): New function. (set_source_range): New functions. (set_block): New function. (set_source_range): New functions. * tree.h (CAN_HAVE_RANGE_P): New. (EXPR_LOCATION_RANGE): New. (EXPR_HAS_RANGE): New. (get_expr_source_range): New inline function. (DECL_LOCATION_RANGE): New. (set_source_range): New decls. (get_decl_source_range): New inline function. gcc/ada/ChangeLog: * gcc-interface/trans.c (Sloc_to_locus): Add line_table param when calling linemap_position_for_line_and_column. gcc/c-family/ChangeLog: * c-common.c (c_fully_fold_internal): Capture existing souce_range, and store it on the result. * c-opts.c (c_common_init_options): Set global_dc->colorize_source_p. gcc/c/ChangeLog: * c-decl.c (warn_defaults_to): Pass line_table to rich_location ctor. * c-errors.c (pedwarn_c99): Likewise. (pedwarn_c90): Likewise. * c-parser.c (set_c_expr_source_range): New functions. (c_token::get_range): New method. (c_token::get_finish): New method. (c_parser_expr_no_commas): Call set_c_expr_source_range on the ret based on the range from the start of the LHS to the end of the RHS. (c_parser_conditional_expression): Likewise, based on the range from the start of the cond.value to the end of exp2.value. (c_parser_binary_expression): Call set_c_expr_source_range on the stack values for TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR. (c_parser_cast_expression): Call set_c_expr_source_range on ret based on the cast_loc through to the end of the expr. (c_parser_unary_expression): Likewise, based on the op_loc through to the end of op. (c_parser_sizeof_expression) Likewise, based on the start of the sizeof token through to either the closing paren or the end of expr. (c_parser_postfix_expression): Likewise, using the token range, or from the open paren through to the close paren for parenthesized expressions. (c_parser_postfix_expression_after_primary): Likewise, for various kinds of expression. * c-tree.h (struct c_expr): Add field "src_range". (c_expr::get_start): New method. (c_expr::get_finish): New method. (set_c_expr_source_range): New decls. * c-typeck.c (parser_build_unary_op): Call set_c_expr_source_range on ret for prefix unary ops. (parser_build_binary_op): Likewise, running from the start of arg1.value through to the end of arg2.value. gcc/cp/ChangeLog: * error.c (pedwarn_cxx98): Pass line_table to rich_location ctor. gcc/fortran/ChangeLog: * error.c (gfc_warning): Pass line_table to rich_location ctor. (gfc_warning_now_at): Likewise. (gfc_warning_now): Likewise. (gfc_error_now): Likewise. (gfc_fatal_error): Likewise. (gfc_error): Likewise. (gfc_internal_error): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/diagnostic-token-ranges.c: New file. * gcc.dg/diagnostic-tree-expr-ranges-2.c: New file. * gcc.dg/plugin/diagnostic-test-expressions-1.c: New file. * gcc.dg/plugin/diagnostic-test-show-trees-1.c: New file. * gcc.dg/plugin/diagnostic_plugin_show_trees.c: New file. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (get_loc): Add line_table param when calling linemap_position_for_line_and_column. (test_show_locus): Pass line_table to rich_location ctors. (plugin_init): Remove setting of global_dc->colorize_source_p. * gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c: New file. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add diagnostic_plugin_test_tree_expression_range.c, diagnostic-test-expressions-1.c, diagnostic_plugin_show_trees.c, and diagnostic-test-show-trees-1.c. libcpp/ChangeLog: * errors.c (cpp_diagnostic): Pass pfile->line_table to rich_location ctor. (cpp_diagnostic_with_line): Likewise. * include/cpplib.h (struct cpp_token): Update comment for src_loc to indicate that the range of the token is "baked into" the source_location. * include/line-map.h (source_location): Update the descriptive comment to reflect the packing scheme for short ranges, adding worked examples of location encoding. (struct line_map_ordinary): Drop field "column_bits" in favor of field "m_column_and_range_bits"; add field "m_range_bits". (ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Delete. (location_adhoc_data): Add source_range field. (struct line_maps): Add fields "default_range_bits", "num_optimized_ranges" and "num_unoptimized_ranges". (get_combined_adhoc_loc): Add source_range param. (get_range_from_loc): New declaration. (pure_location_p): New prototype. (COMBINE_LOCATION_DATA): Add source_range param. (SOURCE_LINE): Update for renaming of column_bits. (SOURCE_COLUMN): Likewise. Shift the column right by the map's range_bits. (LAST_SOURCE_LINE_LOCATION): Update for renaming of column_bits. (linemap_position_for_line_and_column): Add line_maps * params. (rich_location::rich_location): Likewise. * lex.c (_cpp_lex_direct): Capture the range of the token, baking it into token->src_loc via a call to COMBINE_LOCATION_DATA. * line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): Reduce from 1U << 17 to 1U << 12. (location_adhoc_data_hash): Add the src_range into the hash value. (location_adhoc_data_eq): Require equality of the src_range values. (can_be_stored_compactly_p): New function. (get_combined_adhoc_loc): Add src_range param, and store it, via a bit-packing scheme for short ranges, otherwise within the lookaside table. Remove the requirement that data is non-NULL. (get_range_from_adhoc_loc): New function. (get_range_from_loc): New function. (pure_location_p): New function. (linemap_add): Ensure that start_location has zero for the range_bits, unless we're past LINE_MAP_MAX_LOCATION_WITH_COLS. Initialize range_bits to zero. Assert that the start_location is "pure". (linemap_line_start): Assert that the column_and_range_bits >= range_bits. Update determinination of whether we need to start a new map using the effective column bits, without the range bits. Use the set's default_range_bits in new maps, apart from those with column_bits == 0, which should also have 0 range_bits. Increase the column bits for new maps by the range bits. When adding lines to an existing map, use set->highest_line directly rather than offsetting highest by SOURCE_COLUMN. Add assertions to sanity-check the return value. (linemap_position_for_column): Offset to_column by range_bits. Update set->highest_location if necessary. (linemap_position_for_line_and_column): Add line_maps * param. Update the calculation to offset the column by range_bits, and conditionalize it on being <= LINE_MAP_MAX_LOCATION_WITH_COLS. Bound it by LINEMAPS_MACRO_LOWEST_LOCATION. Update set->highest_location if necessary. (linemap_position_for_loc_and_offset): Handle ad-hoc locations; pass "set" to linemap_position_for_line_and_column. (linemap_macro_map_loc_unwind_toward_spelling): Add line_maps param. Handle ad-hoc locations. (linemap_location_in_system_header_p): Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_macro_loc_to_spelling_point): Retain ad-hoc locations. Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_resolve_location): Retain ad-hoc locations. Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_unwind_toward_expansion): Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_expand_location): Extract the data pointer before extracting the location. (rich_location::rich_location): Add line_maps param; use it to extract the range from the source_location. * location-example.txt: Regenerate, showing new representation. From-SVN: r230331
2015-11-07Move #undef DEF_BUILTIN* to builtins.defRichard Sandiford1-2/+0
I was confused at first why tree-core.h was undefining DEF_BUILTIN_CHKP before defining it, then undefining it again after including builtins.def. This is because builtins.def provides a default definition of DEF_BUILTIN_CHKP, but leaves it up to the caller to undefine it where necessary. Similarly to the previous internal-fn.def patch, it seems more obvious for builtins.def to #undef things unconditionally. One argument might have been that keeping preprocessor stuff out of the .def files makes it easier for non-cpp parsers. In practice though we already have #ifs and multiline #defines, so single-line #undefs should be easy in comparison. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ada/ * gcc-interface/utils.c: Don't undef DEF_BUILTIN. gcc/c-family/ * c-common.c: Don't undef DEF_BUILTIN. gcc/jit/ * jit-builtins.c: Don't undef DEF_BUILTIN. gcc/lto/ * lto-lang.c: Don't undef DEF_BUILTIN. gcc/ * builtins.def: #undef DEF_BUILTIN and DEF_BUILTIN_CHKP * builtins.c, genmatch.c, tree-core.h: Don't undef them here. From-SVN: r229924
2015-11-06Reimplement diagnostic_show_locus, introducing rich_location classesDavid Malcolm1-7/+28
gcc/ChangeLog: * diagnostic-color.c (color_dict): Eliminate "caret"; add "range1" and "range2". (parse_gcc_colors): Update comment to describe default GCC_COLORS. * diagnostic-core.h (warning_at_rich_loc): New declaration. (error_at_rich_loc): New declaration. (permerror_at_rich_loc): New declaration. (inform_at_rich_loc): New declaration. * diagnostic-show-locus.c (adjust_line): Delete. (struct point_state): New struct. (class colorizer): New class. (class layout_point): New class. (class layout_range): New class. (struct line_bounds): New. (class layout): New class. (colorizer::colorizer): New ctor. (colorizer::~colorizer): New dtor. (layout::layout): New ctor. (layout::print_source_line): New method. (layout::print_annotation_line): New method. (layout::get_state_at_point): New method. (layout::get_x_bound_for_row): New method. (diagnostic_show_locus): Reimplement in terms of class layout. (diagnostic_print_caret_line): Delete. * diagnostic.c (diagnostic_initialize): Replace MAX_LOCATIONS_PER_MESSAGE with rich_location::MAX_RANGES. (diagnostic_set_info_translated): Convert param from location_t to rich_location *. Eliminate calls to set_location on the message in favor of storing the rich_location ptr there. (diagnostic_set_info): Convert param from location_t to rich_location *. (diagnostic_build_prefix): Break out array into... (diagnostic_kind_color): New variable. (diagnostic_get_color_for_kind): New function. (diagnostic_report_diagnostic): Colorize the option_text using the color for the severity. (diagnostic_append_note): Update for change in signature of diagnostic_set_info. (diagnostic_append_note_at_rich_loc): New function. (emit_diagnostic): Update for change in signature of diagnostic_set_info. (inform): Likewise. (inform_at_rich_loc): New function. (inform_n): Update for change in signature of diagnostic_set_info. (warning): Likewise. (warning_at): Likewise. (warning_at_rich_loc): New function. (warning_n): Update for change in signature of diagnostic_set_info. (pedwarn): Likewise. (permerror): Likewise. (permerror_at_rich_loc): New function. (error): Update for change in signature of diagnostic_set_info. (error_n): Likewise. (error_at): Likewise. (error_at_rich_loc): New function. (sorry): Update for change in signature of diagnostic_set_info. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. (source_range::debug): New function. * diagnostic.h (struct diagnostic_info): Eliminate field "override_column". Add field "richloc". (struct diagnostic_context): Add field "colorize_source_p". (diagnostic_override_column): Delete. (diagnostic_set_info): Convert param from location_t to rich_location *. (diagnostic_set_info_translated): Likewise. (diagnostic_append_note_at_rich_loc): New function. (diagnostic_num_locations): New function. (diagnostic_expand_location): Get the location from the rich_location. (diagnostic_print_caret_line): Delete. (diagnostic_get_color_for_kind): New declaration. * genmatch.c (linemap_client_expand_location_to_spelling_point): New. (error_cb): Update for change in signature of "error" callback. (fatal_at): Likewise. (warning_at): Likewise. * input.c (linemap_client_expand_location_to_spelling_point): New. * pretty-print.c (text_info::set_range): New method. (text_info::get_location): New method. * pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): Eliminate this macro. (struct text_info): Eliminate "locations" array in favor of "m_richloc", a rich_location *. (textinfo::set_location): Add a "caret_p" param, and reimplement in terms of a call to set_range. (textinfo::get_location): Eliminate inline implementation in favor of an out-of-line reimplementation. (textinfo::set_range): New method. * rtl-error.c (diagnostic_for_asm): Update for change in signature of diagnostic_set_info. * tree-diagnostic.c (default_tree_printer): Update for new "caret_p" param for textinfo::set_location. * tree-pretty-print.c (percent_K_format): Likewise. gcc/c-family/ChangeLog: * c-common.c (c_cpp_error): Convert parameter from location_t to rich_location *. Eliminate the "column_override" parameter and the call to diagnostic_override_column. Update the "done_lexing" clause to set range 0 on the rich_location, rather than overwriting a location_t. * c-common.h (c_cpp_error): Convert parameter from location_t to rich_location *. Eliminate the "column_override" parameter. gcc/c/ChangeLog: * c-decl.c (warn_defaults_to): Update for change in signature of diagnostic_set_info. * c-errors.c (pedwarn_c99): Likewise. (pedwarn_c90): Likewise. * c-objc-common.c (c_tree_printer): Update for new "caret_p" param for textinfo::set_location. gcc/cp/ChangeLog: * error.c (cp_printer): Update for new "caret_p" param for textinfo::set_location. (pedwarn_cxx98): Update for change in signature of diagnostic_set_info. gcc/fortran/ChangeLog: * cpp.c (cb_cpp_error): Convert parameter from location_t to rich_location *. Eliminate the "column_override" parameter. * error.c (gfc_warning): Update for change in signature of diagnostic_set_info. (gfc_format_decoder): Update handling of %C/%L for changes to struct text_info. (gfc_diagnostic_starter): Use richloc when determining whether to print one locus or two. When handling a location that will involve a call to diagnostic_show_locus, only attempt to print the locus for the primary location, and don't call into diagnostic_print_caret_line. (gfc_warning_now_at): Update for change in signature of diagnostic_set_info. (gfc_warning_now): Likewise. (gfc_error_now): Likewise. (gfc_fatal_error): Likewise. (gfc_error): Likewise. (gfc_internal_error): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-bw.c: New file. * gcc.dg/plugin/diagnostic-test-show-locus-color.c: New file. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: New file. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above. * lib/gcc-dg.exp: Load multiline.exp. libcpp/ChangeLog: * errors.c (cpp_diagnostic): Update for change in signature of "error" callback. (cpp_diagnostic_with_line): Likewise, calling override_column on the rich_location. * include/cpplib.h (struct cpp_callbacks): Within "error" callback, convert param from source_location to rich_location *, and drop column_override param. * include/line-map.h (struct source_range): New struct. (struct location_range): New struct. (class rich_location): New class. (linemap_client_expand_location_to_spelling_point): New declaration. * line-map.c (rich_location::rich_location): New ctors. (rich_location::lazily_expand_location): New method. (rich_location::override_column): New method. (rich_location::add_range): New methods. (rich_location::set_range): New method. From-SVN: r229884
2015-10-26Move cexp simplifications to match.pdRichard Sandiford1-2/+6
This required reinstating support for captures in the result of a simplification. That part (genmatch.c) is by Richard B. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ 2015-10-20 Richard Sandiford <richard.sandiford@arm.com> Richard Biener <rguenther@suse.de> * genmatch.c (dt_simplify::gen): Skip captures that are part of the result. (parser::parse_expr): Allow captures in results too. * builtins.c (fold_builtin_cexp): Delete. (fold_builtin_1): Handle constant cexp arguments here. * match.pd: Fold cexp(x+yi) to exp(x) * cexpi(y). Co-Authored-By: Richard Biener <rguenther@suse.de> From-SVN: r229308
2015-10-09genmatch.c (print_operand): Fix formatting.Richard Biener1-14/+22
2015-10-09 Richard Biener <rguenther@suse.de> * genmatch.c (print_operand): Fix formatting. (dt_node::append_simplify): Warn for multiple simplifiers that match the same pattern. * match.pd (log (exp @0)): Remove duplicates. From-SVN: r228648
2015-09-20switch from gimple to gimple*Trevor Saunders1-1/+1
This renames the gimple_statement_base struct to gimple removes the typedef of gimple_statement_base * to gimple, and then adjusts all of the places that use the type. gcc/ChangeLog: 2015-09-19 Trevor Saunders <tbsaunde@tbsaunde.org> * coretypes.h (gimple): Change typedef to be a forward declaration. * gimple.h (gimple_statement_base): rename to gimple. * (all functions and types using gimple): Adjust. * *.[ch]: Likewise. gcc/cp/ChangeLog: 2015-09-19 Trevor Saunders <tbsaunde@tbsaunde.org> * cp-gimplify.c (gimplify_must_not_throw_expr): Adjust. From-SVN: r227941
2015-09-17genmatch.c (parser::parse_expr): Improve error message for mis-placed flags.Richard Biener1-0/+3
2015-09-17 Richard Biener <rguenther@suse.de> * genmatch.c (parser::parse_expr): Improve error message for mis-placed flags. From-SVN: r227859
2015-08-31re PR tree-optimization/67381 (genmatch does not honor the order of patterns)Richard Biener1-3/+6
2015-08-31 Richard Biener <rguenther@suse.de> PR middle-end/67381 * genmatch.c (dt_node::gen_kids): Also treat matches as barrier. From-SVN: r227344
2015-08-25re PR tree-optimization/67306 (Patterns ICEs when moved using "simplify and ↵Richard Biener1-6/+25
match") 2015-08-25 Richard Biener <rguenther@suse.de> PR middle-end/67306 * genmatch.c (expr::gen_transform): Verify the result of builtin_decl_implicit. (dt_simplify::gen_1): Likewise. From-SVN: r227163
2015-08-04genmatch.c (dt_node::gen_kids_1): Use gassign and gcall in generated code.Richard Biener1-12/+11
2015-08-04 Richard Biener <rguenther@suse.de> * genmatch.c (dt_node::gen_kids_1): Use gassign and gcall in generated code. (dt_operand::gen_gimple_expr): Adjust. From-SVN: r226577
2015-08-03genmatch.c (simplify::for_subst_vec): New member.Richard Biener1-39/+174
2015-08-03 Richard Biener <rguenther@suse.de> * genmatch.c (simplify::for_subst_vec): New member. (binary_ok): New helper for for lowering. (lower_for): Delay substituting operators into result expressions if we can merge the results eventually again. (capture_info::walk_result): Adjust for user_id appearing as result expression operator. (expr::gen_transform): Likewise. (dt_simplify::gen_1): Likewise. (dt_simplify::gen): Pass not substituted operators to tail functions or initialize local variable with it. (decision_tree::gen): Adjust function signature. * match.pd: Fix tests against global code and add default cases to switch stmts. From-SVN: r226504
2015-08-03genmatch.c (dt_simplify::gen): Create captures array with an initializer.Richard Biener1-9/+8
2015-08-03 Richard Biener <rguenther@suse.de> * genmatch.c (dt_simplify::gen): Create captures array with an initializer. From-SVN: r226503
2015-08-03genmatch.c (struct sinfo, [...]): New hash-map to record equivalent transforms.Richard Biener1-6/+208
2015-08-03 Richard Biener <rguenther@suse.de> * genmatch.c (struct sinfo, struct sinfo_hashmap_traits, sinfo_map_t): New hash-map to record equivalent transforms. (dt_node::analyze): Populate the equivalent transforms hash-map. (dt_simplify::info): Add reference to hash-map entry. (dt_simplify::gen): If we have split out a function for the transform, generate a call to it. (sinfo_hashmap_traits::hash): New function. (compare_op): New helper function for ... (sinfo_hashmap_traits::equal_keys): ... this new function. (decision_tree::gen): Split out common equivalent transforms into functions. From-SVN: r226490
2015-07-30genmatch.c (decision_tree::gen_gimple): Merge with ...Richard Biener1-112/+63
2015-07-30 Richard Biener <rguenther@suse.de> * genmatch.c (decision_tree::gen_gimple): Merge with ... (decision_tree::gen_generic): ... this into ... (decision_tree::gen): ... this. (main): Adjust callers. From-SVN: r226396
2015-07-30genmatch.c (verbose): New global.Richard Biener1-19/+73
2015-07-30 Richard Biener <rguenther@suse.de> * genmatch.c (verbose): New global. (warning_at): Add overload with source_location. (capture_info::capture_info): Add bool whether generating gimple or generic. Add gimple member. (capture_info::cinfo): Add capture member. (capture_info::walk_match): Record capture. Warn on non-captured leafs. (capture_info::walk_c_expr): Add more fragments captures cannot escape through. Warn on escaped captures. (dt_simplify::gen_1): Warn on operands we force to have no side-effects. (main): Initialize verbose. * match.pd: Add integer_nonzerop and HONOR_NANS predicates. From-SVN: r226386
2015-07-29genmatch.c (c_expr::gen_transform): Error on unknown captures.Richard Biener1-7/+14
2015-07-29 Richard Biener <rguenther@suse.de> * genmatch.c (c_expr::gen_transform): Error on unknown captures. (parser::parse_capture): Add bool argument on whether to reject unknown captures. (parser::parse_expr): Adjust. (parser::parse_op): Likewise. (parser::parse_pattern): Likewise. From-SVN: r226344
2015-07-27genmatch.c (decision_tree::gen_gimple): Split out large subtrees into ↵Richard Biener1-8/+64
separate functions. 2015-07-27 Richard Biener <rguenther@suse.de> * genmatch.c (decision_tree::gen_gimple): Split out large subtrees into separate functions. (decision_tree::gen_generic): Likewise. From-SVN: r226241
2015-07-24genmatch.c (struct dt_node): Add statistic fields.Richard Biener1-0/+43
2015-07-24 Richard Biener <rguenther@suse.de> * genmatch.c (struct dt_node): Add statistic fields. (dt_node::analyze): New method. (decision_tree::gen_gimple): Call analyze on the root node and print statistics to stderr. (decision_tree::gen_generic): Likewise. From-SVN: r226154
2015-07-24genmatch.c (struct capture_info): Add same_as field.Richard Biener1-7/+24
2015-07-24 Richard Biener <rguenther@suse.de> * genmatch.c (struct capture_info): Add same_as field. (capture_info::capture_info): Initialize same_as. (capture_info::walk_match): Compute same_as. (capture_info::walk_result): Compute stuff for the leader. (capture_info::walk_c_expr): Likewise. (dt_simplify::gen_1): Only look at leaders when deciding to force no side-effects or emit side-effects of omitted operands. From-SVN: r226152
2015-07-24genmatch.c (add_operator): Allow SSA_NAME as predicate.Richard Biener1-1/+3
2015-07-24 Richard Biener <rguenther@suse.de> * genmatch.c (add_operator): Allow SSA_NAME as predicate. * fold-const.c (fold_comparison): Move parameter does not alias &local simplification ... * match.pd: ... as a pattern here. From-SVN: r226140
2015-07-22genmatch.c (expr::gen_transform): Clarify error message and display location.Richard Biener1-1/+1
2015-07-22 Richard Biener <rguenther@suse.de> * genmatch.c (expr::gen_transform): Clarify error message and display location. From-SVN: r226068
2015-07-22genmatch.c (struct operand): Add location member.Richard Biener1-72/+67
2015-07-22 Richard Biener <rguenther@suse.de> * genmatch.c (struct operand): Add location member. (predicate, expr, c_expr, capture, if_expr, with_expr): Adjust constructors. (struct simplify): Remove match_location and result_location members. (elsehwere): Adjust. From-SVN: r226067
2015-07-22genmatch.c (parser::parse_result): Properly handle match with result ↵Richard Biener1-0/+1
operands and conditions. 2015-07-22 Richard Biener <rguenther@suse.de> * genmatch.c (parser::parse_result): Properly handle match with result operands and conditions. From-SVN: r226060
2015-07-21re PR tree-optimization/66948 (Performance regression in bit manipulation code)Richard Biener1-7/+18
2015-07-21 Richard Biener <rguenther@suse.de> PR tree-optimization/66948 * genmatch.c (capture_info::walk_match): Also recurse to captures. Properly compute expr state from captures of captures. * match.pd: Add single-use guards to (X & C2) >> C1 into (X >> C1) & (C2 >> C1) transform. From-SVN: r226041
2015-07-15genmatch.c (parser::peek, [...]): Add argument to tell how many tokens to ↵Richard Biener1-12/+66
peek ahead (default 1). 2015-07-15 Richard Biener <rguenther@suse.de> * genmatch.c (parser::peek, parser::peek_ident): Add argument to tell how many tokens to peek ahead (default 1). (parser::eat_token, parser::eat_ident): Return token consumed. (parser::parse_result): Parse new switch statement. * match.pd: Use case statements where appropriate. From-SVN: r225809
2015-07-14genmatch.c (dt_node::gen_kids_1): Fix case label indenting.Richard Biener1-6/+6
2015-07-14 Richard Biener <rguenther@suse.de> * genmatch.c (dt_node::gen_kids_1): Fix case label indenting. (decision_tree::gen_gimple): Likewise. From-SVN: r225765
2015-07-14genmatch.c (struct operand): Add OP_IF and OP_WITH op_types.Richard Biener1-217/+293
2015-07-14 Richard Biener <rguenther@suse.de> * genmatch.c (struct operand): Add OP_IF and OP_WITH op_types. (struct if_expr): New. (struct with_expr): Likewise. (is_a_helper): Add helpers for if_expr and with_expr. (struct simplify): Add simplify_kind enum and member. Remove ifexpr_vec member. (simplify::simplify): Adjust. (lower_commutative): Adjust. (lower_opt_convert): Likewise. (lower_cond): Likewise. (replace_id): Handle with_expr and if_expr. (lower_for): Adjust. (dt_simplify::gen_1): New recursive worker, split out from ... (dt_simplify::gen): ... here. Deal with if and with expansion recursively. (capture_info::capture_info): Take context argument (capture_info::walk_result): Only analyze specific result. (parser::parse_result): New function. (parser::parse_simplify): Adjust to parse ifs with then end else case. (parser::parse_if): Simplify. (parser::parse_pattern): Pass down simplify kind. * match.pd: Convert if structure to new syntax. From-SVN: r225760
2015-07-13Fix double word typos.Aldy Hernandez1-3/+2
From-SVN: r225726
2015-07-10genmatch.c (dt_node::gen_kids_1): Fix indenting of case labels.Richard Biener1-25/+25
2015-07-10 Richard Biener <rguenther@suse.de> * genmatch.c (dt_node::gen_kids_1): Fix indenting of case labels. (decision_tree::gen_gimple): Likewise. (decision_tree::gen_generic): Likewise. From-SVN: r225663