diff options
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/c-family/c-common.cc | 4 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-family/c-gimplify.cc | 79 | ||||
-rw-r--r-- | gcc/c-family/c-opts.cc | 28 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 24 |
6 files changed, 151 insertions, 6 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index c326324..1247f51 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,21 @@ +2023-06-23 Marek Polacek <polacek@redhat.com> + + * c-common.h (cxx_dialect): Add cxx26 as a dialect. + * c-opts.cc (set_std_cxx26): New. + (c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is + enabled. + (c_common_post_options): Adjust comments. + * c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26, + and -std=gnu++2c. + (std=c++2b): Mark as Undocumented. + (std=c++23): No longer Undocumented. + +2023-06-21 Alexander Monakov <amonakov@ispras.ru> + + * c-gimplify.cc (fma_supported_p): New helper. + (c_gimplify_expr) [PLUS_EXPR, MINUS_EXPR]: Implement FMA + contraction. + 2023-06-16 Alex Coplan <alex.coplan@arm.com> * c.opt (Welaborated-enum-base): New. diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 9c8eed5..34566a3 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -1338,6 +1338,10 @@ shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise) int uns; tree type; + /* Do not shorten vector operations. */ + if (VECTOR_TYPE_P (result_type)) + return result_type; + /* Cast OP0 and OP1 to RESULT_TYPE. Doing so prevents excessive narrowing when we call get_narrower below. For example, suppose that OP0 is of unsigned int extended diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 336a09f..b5ef5ff 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -740,7 +740,9 @@ enum cxx_dialect { /* C++20 */ cxx20, /* C++23 */ - cxx23 + cxx23, + /* C++26 */ + cxx26 }; /* The C++ dialect being used. C++98 is the default. */ diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc index ef5c7d9..17b0610 100644 --- a/gcc/c-family/c-gimplify.cc +++ b/gcc/c-family/c-gimplify.cc @@ -41,6 +41,8 @@ along with GCC; see the file COPYING3. If not see #include "c-ubsan.h" #include "tree-nested.h" #include "context.h" +#include "tree-pass.h" +#include "internal-fn.h" /* The gimplification pass converts the language-dependent trees (ld-trees) emitted by the parser into language-independent trees @@ -686,6 +688,14 @@ c_build_bind_expr (location_t loc, tree block, tree body) return bind; } +/* Helper for c_gimplify_expr: test if target supports fma-like FN. */ + +static bool +fma_supported_p (enum internal_fn fn, tree type) +{ + return direct_internal_fn_supported_p (fn, type, OPTIMIZE_FOR_BOTH); +} + /* Gimplification of expression trees. */ /* Do C-specific gimplification on *EXPR_P. PRE_P and POST_P are as in @@ -739,6 +749,75 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED, break; } + case PLUS_EXPR: + case MINUS_EXPR: + { + tree type = TREE_TYPE (*expr_p); + /* For -ffp-contract=on we need to attempt FMA contraction only + during initial gimplification. Late contraction across statement + boundaries would violate language semantics. */ + if (SCALAR_FLOAT_TYPE_P (type) + && flag_fp_contract_mode == FP_CONTRACT_ON + && cfun && !(cfun->curr_properties & PROP_gimple_any) + && fma_supported_p (IFN_FMA, type)) + { + bool neg_mul = false, neg_add = code == MINUS_EXPR; + + tree *op0_p = &TREE_OPERAND (*expr_p, 0); + tree *op1_p = &TREE_OPERAND (*expr_p, 1); + + /* Look for ±(x * y) ± z, swapping operands if necessary. */ + if (TREE_CODE (*op0_p) == NEGATE_EXPR + && TREE_CODE (TREE_OPERAND (*op0_p, 0)) == MULT_EXPR) + /* '*EXPR_P' is '-(x * y) ± z'. This is fine. */; + else if (TREE_CODE (*op0_p) != MULT_EXPR) + { + std::swap (op0_p, op1_p); + std::swap (neg_mul, neg_add); + } + if (TREE_CODE (*op0_p) == NEGATE_EXPR) + { + op0_p = &TREE_OPERAND (*op0_p, 0); + neg_mul = !neg_mul; + } + if (TREE_CODE (*op0_p) != MULT_EXPR) + break; + auto_vec<tree, 3> ops (3); + ops.quick_push (TREE_OPERAND (*op0_p, 0)); + ops.quick_push (TREE_OPERAND (*op0_p, 1)); + ops.quick_push (*op1_p); + + enum internal_fn ifn = IFN_FMA; + if (neg_mul) + { + if (fma_supported_p (IFN_FNMA, type)) + ifn = IFN_FNMA; + else + ops[0] = build1 (NEGATE_EXPR, type, ops[0]); + } + if (neg_add) + { + enum internal_fn ifn2 = ifn == IFN_FMA ? IFN_FMS : IFN_FNMS; + if (fma_supported_p (ifn2, type)) + ifn = ifn2; + else + ops[2] = build1 (NEGATE_EXPR, type, ops[2]); + } + /* Avoid gimplify_arg: it emits all side effects into *PRE_P. */ + for (auto &&op : ops) + if (gimplify_expr (&op, pre_p, post_p, is_gimple_val, fb_rvalue) + == GS_ERROR) + return GS_ERROR; + + gcall *call = gimple_build_call_internal_vec (ifn, ops); + gimple_seq_add_stmt_without_update (pre_p, call); + *expr_p = create_tmp_var (type); + gimple_call_set_lhs (call, *expr_p); + return GS_ALL_DONE; + } + break; + } + default:; } diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index c68a2a2..af19140 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -111,6 +111,7 @@ static void set_std_cxx14 (int); static void set_std_cxx17 (int); static void set_std_cxx20 (int); static void set_std_cxx23 (int); +static void set_std_cxx26 (int); static void set_std_c89 (int, int); static void set_std_c99 (int); static void set_std_c11 (int); @@ -663,6 +664,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, set_std_cxx23 (code == OPT_std_c__23 /* ISO */); break; + case OPT_std_c__26: + case OPT_std_gnu__26: + if (!preprocessing_asm_p) + set_std_cxx26 (code == OPT_std_c__26 /* ISO */); + break; + case OPT_std_c90: case OPT_std_iso9899_199409: if (!preprocessing_asm_p) @@ -1032,7 +1039,8 @@ c_common_post_options (const char **pfilename) warn_narrowing = 1; /* Unless -f{,no-}ext-numeric-literals has been used explicitly, - for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals. */ + for -std=c++{11,14,17,20,23,26} default to + -fno-ext-numeric-literals. */ if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals)) cpp_opts->ext_numeric_literals = 0; } @@ -1820,6 +1828,24 @@ set_std_cxx23 (int iso) lang_hooks.name = "GNU C++23"; } +/* Set the C++ 2026 standard (without GNU extensions if ISO). */ +static void +set_std_cxx26 (int iso) +{ + cpp_set_lang (parse_in, iso ? CLK_CXX26: CLK_GNUCXX26); + flag_no_gnu_keywords = iso; + flag_no_nonansi_builtin = iso; + flag_iso = iso; + /* C++26 includes the C11 standard library. */ + flag_isoc94 = 1; + flag_isoc99 = 1; + flag_isoc11 = 1; + /* C++26 includes coroutines. */ + flag_coroutines = true; + cxx_dialect = cxx26; + lang_hooks.name = "GNU C++26"; +} + /* Args to -d specify what to dump. Silently ignore unrecognized options; they may be aimed at toplev.cc. */ static void diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 0930a3c04..c516091 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2403,13 +2403,21 @@ C++ ObjC++ Conform to the ISO 2020 C++ standard (experimental and incomplete support). std=c++2b -C++ ObjC++ Alias(std=c++23) +C++ ObjC++ Alias(std=c++23) Undocumented Conform to the ISO 2023 C++ draft standard (experimental and incomplete support). std=c++23 -C++ ObjC++ Undocumented +C++ ObjC++ Conform to the ISO 2023 C++ draft standard (experimental and incomplete support). +std=c++2c +C++ ObjC++ Alias(std=c++26) +Conform to the ISO 2026 C++ draft standard (experimental and incomplete support). + +std=c++26 +C++ ObjC++ Undocumented +Conform to the ISO 2026 C++ draft standard (experimental and incomplete support). + std=c11 C ObjC Conform to the ISO 2011 C standard. @@ -2489,13 +2497,21 @@ C++ ObjC++ Conform to the ISO 2020 C++ standard with GNU extensions (experimental and incomplete support). std=gnu++2b -C++ ObjC++ Alias(std=gnu++23) +C++ ObjC++ Alias(std=gnu++23) Undocumented Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support). std=gnu++23 -C++ ObjC++ Undocumented +C++ ObjC++ Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support). +std=gnu++2c +C++ ObjC++ Alias(std=gnu++26) +Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support). + +std=gnu++26 +C++ ObjC++ Undocumented +Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support). + std=gnu11 C ObjC Conform to the ISO 2011 C standard with GNU extensions. |