https://gcc.gnu.org/g:a57244a813abcb0f4a831860346480cd0f806d06
commit a57244a813abcb0f4a831860346480cd0f806d06 Author: Michael Meissner <[email protected]> Date: Thu Nov 6 19:55:31 2025 -0500 Add -mcpu=future option. 2025-11-06 Michael Meissner <[email protected]> gcc/ * config/rs6000/rs6000-c.cc (rs6000_target_modify_macros): Define _ARCH_FUTURE if -mcpu=future was used. (rs6000_cpu_cpp_builtins): Likewise. * config/rs6000/rs6000-cpus.def (FUTURE_MASKS_SERVER): New macro. (future cpu): Add support for -mcpu=future. * config/rs6000/rs6000-opts.h (PROCESSOR_FUTURE): Define to be power11. * config/rs6000/rs6000-protos.h (rs6000_target_modify_macros): Add -mcpu=future support. (rs6000_target_modify_macros_ptr): Likewise. * config/rs6000/rs6000-tables.opt: Regenerate. * config/rs6000/rs6000.cc (rs6000_target_modify_macros_ptr): Add -mcpu=future support. (rs6000_debug_reg_global): Likewise. (rs6000_option_override_internal): Likewise. (rs6000_pragma_target_parse): Likewise. (rs6000_function_specific_save): Likewise. (rs6000_function_specific_restore): Likewise. (rs6000_function_specific_print): Likewise. (rs6000_print_options_internal): Likewise. (rs6000_print_isa_options): Likewise. * config/rs6000/rs6000.h (TARGET_FUTURE): New macro. * config/rs6000/rs6000.opt (TARGET_FUTURE): New target variable. (x_TARGET_FUTURE): Likewise. gcc/testsuite/ * gcc.target/powerpc/future-1.c: New test. * gcc.target/powerpc/future-2.c: Likewise. Diff: --- gcc/config/rs6000/rs6000-c.cc | 16 ++++-- gcc/config/rs6000/rs6000-cpus.def | 4 ++ gcc/config/rs6000/rs6000-opts.h | 2 + gcc/config/rs6000/rs6000-protos.h | 5 +- gcc/config/rs6000/rs6000-tables.opt | 3 ++ gcc/config/rs6000/rs6000.cc | 79 +++++++++++++++++++++-------- gcc/config/rs6000/rs6000.h | 10 ++++ gcc/config/rs6000/rs6000.opt | 7 +++ gcc/testsuite/gcc.target/powerpc/future-1.c | 13 +++++ gcc/testsuite/gcc.target/powerpc/future-2.c | 24 +++++++++ 10 files changed, 137 insertions(+), 26 deletions(-) diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc index d3b0a5668212..f9770ea0946b 100644 --- a/gcc/config/rs6000/rs6000-c.cc +++ b/gcc/config/rs6000/rs6000-c.cc @@ -338,13 +338,19 @@ rs6000_define_or_undefine_macro (bool define_p, const char *name) #pragma GCC target, we need to adjust the macros dynamically. */ void -rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags) +rs6000_target_modify_macros (bool define_p, + HOST_WIDE_INT flags, + bool change_future_p, + bool future_p) { if (TARGET_DEBUG_BUILTIN || TARGET_DEBUG_TARGET) fprintf (stderr, - "rs6000_target_modify_macros (%s, " HOST_WIDE_INT_PRINT_HEX ")\n", + "rs6000_target_modify_macros (%s, " HOST_WIDE_INT_PRINT_HEX + ", change future: %s, future: %s)\n", (define_p) ? "define" : "undef", - flags); + flags, + change_future_p ? "true" : "false", + future_p ? "true" : "false"); /* Each of the flags mentioned below controls whether certain preprocessor macros will be automatically defined when @@ -437,6 +443,8 @@ rs6000_target_modify_macros (bool define_p, HOST_WIDE_INT flags) rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR10"); if ((flags & OPTION_MASK_POWER11) != 0) rs6000_define_or_undefine_macro (define_p, "_ARCH_PWR11"); + if (change_future_p) + rs6000_define_or_undefine_macro (future_p, "_ARCH_FUTURE"); if ((flags & OPTION_MASK_SOFT_FLOAT) != 0) rs6000_define_or_undefine_macro (define_p, "_SOFT_FLOAT"); if ((flags & OPTION_MASK_RECIP_PRECISION) != 0) @@ -605,7 +613,7 @@ void rs6000_cpu_cpp_builtins (cpp_reader *pfile) { /* Define all of the common macros. */ - rs6000_target_modify_macros (true, rs6000_isa_flags); + rs6000_target_modify_macros (true, rs6000_isa_flags, true, TARGET_FUTURE); if (TARGET_FRE) builtin_define ("__RECIP__"); diff --git a/gcc/config/rs6000/rs6000-cpus.def b/gcc/config/rs6000/rs6000-cpus.def index 4a1037616d7f..4cbbe94a0107 100644 --- a/gcc/config/rs6000/rs6000-cpus.def +++ b/gcc/config/rs6000/rs6000-cpus.def @@ -92,6 +92,9 @@ | OPTION_MASK_FLOAT128_HW \ | OPTION_MASK_P9_MINMAX) +/* Options for -mcpu=future. */ +#define FUTURE_MASKS_SERVER POWER11_MASKS_SERVER + /* Flags that need to be turned off if -mno-altivec. */ #define OTHER_ALTIVEC_MASKS (OTHER_VSX_VECTOR_MASKS \ | OPTION_MASK_VSX) @@ -255,3 +258,4 @@ RS6000_CPU ("powerpc64", PROCESSOR_POWERPC64, OPTION_MASK_PPC_GFXOPT RS6000_CPU ("powerpc64le", PROCESSOR_POWER8, MASK_POWERPC64 | ISA_2_7_MASKS_SERVER | OPTION_MASK_HTM) RS6000_CPU ("rs64", PROCESSOR_RS64A, OPTION_MASK_PPC_GFXOPT | MASK_POWERPC64) +RS6000_CPU ("future", PROCESSOR_FUTURE, MASK_POWERPC64 | FUTURE_MASKS_SERVER) diff --git a/gcc/config/rs6000/rs6000-opts.h b/gcc/config/rs6000/rs6000-opts.h index c31d2975f046..be2cacbd5e6a 100644 --- a/gcc/config/rs6000/rs6000-opts.h +++ b/gcc/config/rs6000/rs6000-opts.h @@ -71,6 +71,8 @@ enum processor_type PROCESSOR_TITAN }; +/* Treat -mcpu=future as -mcpu=power11. */ +#define PROCESSOR_FUTURE PROCESSOR_POWER11 /* Types of costly dependences. */ enum rs6000_dependence_cost diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h index 234eb0ae2b3a..5392eaf6309e 100644 --- a/gcc/config/rs6000/rs6000-protos.h +++ b/gcc/config/rs6000/rs6000-protos.h @@ -324,8 +324,9 @@ extern void rs6000_cpu_cpp_builtins (struct cpp_reader *); extern bool rs6000_pragma_target_parse (tree, tree); #endif extern void rs6000_activate_target_options (tree new_tree); -extern void rs6000_target_modify_macros (bool, HOST_WIDE_INT); -extern void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT); +extern void rs6000_target_modify_macros (bool, HOST_WIDE_INT, bool, bool); +extern void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT, bool, + bool); #ifdef NO_DOLLAR_IN_LABEL const char * rs6000_xcoff_strip_dollar (const char *); diff --git a/gcc/config/rs6000/rs6000-tables.opt b/gcc/config/rs6000/rs6000-tables.opt index f5bbed5ea746..9e68c5a66e13 100644 --- a/gcc/config/rs6000/rs6000-tables.opt +++ b/gcc/config/rs6000/rs6000-tables.opt @@ -200,3 +200,6 @@ Enum(rs6000_cpu_opt_value) String(powerpc64le) Value(56) EnumValue Enum(rs6000_cpu_opt_value) String(rs64) Value(57) +EnumValue +Enum(rs6000_cpu_opt_value) String(future) Value(58) + diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 1d5cd25c0f08..782977c83a8a 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -277,7 +277,7 @@ bool cpu_builtin_p = false; /* Pointer to function (in rs6000-c.cc) that can define or undefine target macros that have changed. Languages that don't support the preprocessor don't link in rs6000-c.cc, so we can't call it directly. */ -void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT); +void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT, bool, bool); /* Simplfy register classes into simpler classifications. We assume GPR_REG_TYPE - FPR_REG_TYPE are ordered so that we can use a simple range @@ -1170,7 +1170,7 @@ enum reg_class (*rs6000_preferred_reload_class_ptr) (rtx, enum reg_class) const int INSN_NOT_AVAILABLE = -1; static void rs6000_print_isa_options (FILE *, int, const char *, - HOST_WIDE_INT); + HOST_WIDE_INT, bool); static HOST_WIDE_INT rs6000_disable_incompatible_switches (void); static enum rs6000_reg_type register_to_reg_type (rtx, bool *); @@ -2398,9 +2398,11 @@ rs6000_debug_reg_global (void) const char *name = processor_target_table[rs6000_cpu_index].name; HOST_WIDE_INT flags = processor_target_table[rs6000_cpu_index].target_enable; + bool future = strcmp (processor_target_table[rs6000_cpu_index].name, + "future") == 0; sprintf (flags_buffer, "-mcpu=%s flags", name); - rs6000_print_isa_options (stderr, 0, flags_buffer, flags); + rs6000_print_isa_options (stderr, 0, flags_buffer, flags, future); } else fprintf (stderr, DEBUG_FMT_S, "cpu", "<none>"); @@ -2410,21 +2412,24 @@ rs6000_debug_reg_global (void) const char *name = processor_target_table[rs6000_tune_index].name; HOST_WIDE_INT flags = processor_target_table[rs6000_tune_index].target_enable; + bool future = strcmp (processor_target_table[rs6000_tune_index].name, + "future") == 0; sprintf (flags_buffer, "-mtune=%s flags", name); - rs6000_print_isa_options (stderr, 0, flags_buffer, flags); + rs6000_print_isa_options (stderr, 0, flags_buffer, flags, future); } else fprintf (stderr, DEBUG_FMT_S, "tune", "<none>"); cl_target_option_save (&cl_opts, &global_options, &global_options_set); rs6000_print_isa_options (stderr, 0, "rs6000_isa_flags", - rs6000_isa_flags); + rs6000_isa_flags, TARGET_FUTURE); rs6000_print_isa_options (stderr, 0, "rs6000_isa_flags_explicit", - rs6000_isa_flags_explicit); + rs6000_isa_flags_explicit, false); - rs6000_print_isa_options (stderr, 0, "TARGET_DEFAULT", TARGET_DEFAULT); + rs6000_print_isa_options (stderr, 0, "TARGET_DEFAULT", TARGET_DEFAULT, + false); fprintf (stderr, DEBUG_FMT_S, "--with-cpu default", OPTION_TARGET_CPU_DEFAULT ? OPTION_TARGET_CPU_DEFAULT : "<none>"); @@ -3621,7 +3626,8 @@ rs6000_option_override_internal (bool global_init_p) /* Print defaults. */ if ((TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) && global_init_p) - rs6000_print_isa_options (stderr, 0, "TARGET_DEFAULT", TARGET_DEFAULT); + rs6000_print_isa_options (stderr, 0, "TARGET_DEFAULT", TARGET_DEFAULT, + false); /* Remember the explicit arguments. */ if (global_init_p) @@ -3725,6 +3731,8 @@ rs6000_option_override_internal (bool global_init_p) rs6000_isa_flags &= ~set_masks; rs6000_isa_flags |= (processor_target_table[cpu_index].target_enable & set_masks); + TARGET_FUTURE = strcmp (processor_target_table[cpu_index].name, + "future") == 0; } else { @@ -3750,6 +3758,7 @@ rs6000_option_override_internal (bool global_init_p) flags = processor_target_table[default_cpu_index].target_enable; } rs6000_isa_flags |= (flags & ~rs6000_isa_flags_explicit); + TARGET_FUTURE = false; } /* Don't expect powerpc64 enabled on those OSes with OS_MISSING_POWERPC64, @@ -3871,7 +3880,8 @@ rs6000_option_override_internal (bool global_init_p) & ~rs6000_isa_flags_explicit); if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) - rs6000_print_isa_options (stderr, 0, "before defaults", rs6000_isa_flags); + rs6000_print_isa_options (stderr, 0, "before defaults", rs6000_isa_flags, + TARGET_FUTURE); #ifdef XCOFF_DEBUGGING_INFO /* For AIX default to 64-bit DWARF. */ @@ -4232,7 +4242,8 @@ rs6000_option_override_internal (bool global_init_p) /* Print the options after updating the defaults. */ if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) - rs6000_print_isa_options (stderr, 0, "after defaults", rs6000_isa_flags); + rs6000_print_isa_options (stderr, 0, "after defaults", rs6000_isa_flags, + TARGET_FUTURE); /* E500mc does "better" if we inline more aggressively. Respect the user's opinion, though. */ @@ -4339,7 +4350,8 @@ rs6000_option_override_internal (bool global_init_p) TARGET_NO_FP_IN_TOC = 1; if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) - rs6000_print_isa_options (stderr, 0, "before subtarget", rs6000_isa_flags); + rs6000_print_isa_options (stderr, 0, "before subtarget", rs6000_isa_flags, + TARGET_FUTURE); #ifdef SUBTARGET_OVERRIDE_OPTIONS SUBTARGET_OVERRIDE_OPTIONS; @@ -4406,7 +4418,8 @@ rs6000_option_override_internal (bool global_init_p) rs6000_isa_flags &= ~OPTION_MASK_PCREL_OPT; if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) - rs6000_print_isa_options (stderr, 0, "after subtarget", rs6000_isa_flags); + rs6000_print_isa_options (stderr, 0, "after subtarget", rs6000_isa_flags, + TARGET_FUTURE); rs6000_always_hint = (rs6000_tune != PROCESSOR_POWER4 && rs6000_tune != PROCESSOR_POWER5 @@ -24879,6 +24892,7 @@ rs6000_pragma_target_parse (tree args, tree pop_target) tree cur_tree; struct cl_target_option *prev_opt, *cur_opt; HOST_WIDE_INT prev_flags, cur_flags, diff_flags; + bool prev_future, cur_future, diff_future; if (TARGET_DEBUG_TARGET) { @@ -24931,21 +24945,28 @@ rs6000_pragma_target_parse (tree args, tree pop_target) { prev_opt = TREE_TARGET_OPTION (prev_tree); prev_flags = prev_opt->x_rs6000_isa_flags; + prev_future = prev_opt->x_TARGET_FUTURE; cur_opt = TREE_TARGET_OPTION (cur_tree); cur_flags = cur_opt->x_rs6000_isa_flags; + cur_future = cur_opt->x_TARGET_FUTURE; diff_flags = (prev_flags ^ cur_flags); + diff_future = (prev_future ^ cur_future); - if (diff_flags != 0) + if (diff_flags != 0 || diff_future) { /* Delete old macros. */ rs6000_target_modify_macros_ptr (false, - prev_flags & diff_flags); + prev_flags & diff_flags, + diff_future, + prev_future); /* Define new macros. */ rs6000_target_modify_macros_ptr (true, - cur_flags & diff_flags); + cur_flags & diff_flags, + diff_future, + cur_future); } } @@ -25059,6 +25080,7 @@ rs6000_function_specific_save (struct cl_target_option *ptr, { ptr->x_rs6000_isa_flags = opts->x_rs6000_isa_flags; ptr->x_rs6000_isa_flags_explicit = opts->x_rs6000_isa_flags_explicit; + ptr->x_TARGET_FUTURE = opts->x_TARGET_FUTURE; } /* Restore the current options */ @@ -25071,6 +25093,7 @@ rs6000_function_specific_restore (struct gcc_options *opts, { opts->x_rs6000_isa_flags = ptr->x_rs6000_isa_flags; opts->x_rs6000_isa_flags_explicit = ptr->x_rs6000_isa_flags_explicit; + opts->x_TARGET_FUTURE = ptr->x_TARGET_FUTURE; (void) rs6000_option_override_internal (false); } @@ -25081,10 +25104,12 @@ rs6000_function_specific_print (FILE *file, int indent, struct cl_target_option *ptr) { rs6000_print_isa_options (file, indent, "Isa options set", - ptr->x_rs6000_isa_flags); + ptr->x_rs6000_isa_flags, + ptr->x_TARGET_FUTURE); rs6000_print_isa_options (file, indent, "Isa options explicit", - ptr->x_rs6000_isa_flags_explicit); + ptr->x_rs6000_isa_flags_explicit, + ptr->x_TARGET_FUTURE); } /* Helper function to print the current isa or misc options on a line. */ @@ -25096,7 +25121,8 @@ rs6000_print_options_internal (FILE *file, HOST_WIDE_INT flags, const char *prefix, const struct rs6000_opt_mask *opts, - size_t num_elements) + size_t num_elements, + bool future) { size_t i; size_t start_column = 0; @@ -25162,6 +25188,18 @@ rs6000_print_options_internal (FILE *file, comma_len = strlen (", "); } + if (future) + { + cur_column += sizeof ("-mcpu=future") - 1; + if (cur_column > max_column) + { + fprintf (stderr, ", \\\n%*s", (int)start_column, ""); + comma = ""; + } + + fprintf (file, "%s%s", comma, "-mcpu=future"); + } + fputs ("\n", file); } @@ -25169,11 +25207,12 @@ rs6000_print_options_internal (FILE *file, static void rs6000_print_isa_options (FILE *file, int indent, const char *string, - HOST_WIDE_INT flags) + HOST_WIDE_INT flags, bool future) { rs6000_print_options_internal (file, indent, string, flags, "-m", &rs6000_opt_masks[0], - ARRAY_SIZE (rs6000_opt_masks)); + ARRAY_SIZE (rs6000_opt_masks), + future); } /* If the user used -mno-vsx, we need turn off all of the implicit ISA 2.06, diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index db6112a09e11..c857a155bd2e 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -555,6 +555,16 @@ extern int rs6000_vector_align[]; #define TARGET_DIRECT_MOVE_64BIT (TARGET_DIRECT_MOVE \ && TARGET_POWERPC64) +/* Is this a future machine with potentially new feaatures? */ +#ifndef TARGET_FUTURE +#ifdef GENERATOR_FILE +#define TARGET_FUTURE false +#else +#define TARGET_FUTURE global_options.x_TARGET_FUTURE +#endif +#endif + + /* Inlining allows targets to define the meanings of bits in target_info field of ipa_fn_summary by itself, the used bits for rs6000 are listed below. */ diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt index 88cf16ca581a..489c85c9bb3b 100644 --- a/gcc/config/rs6000/rs6000.opt +++ b/gcc/config/rs6000/rs6000.opt @@ -44,6 +44,13 @@ enum processor_type rs6000_cpu = PROCESSOR_PPC603 TargetVariable enum processor_type rs6000_tune = PROCESSOR_PPC603 +;; Whether the current processor is a potential future processor +Variable +bool TARGET_FUTURE = false + +TargetSave +bool x_TARGET_FUTURE + ;; Always emit branch hint bits. TargetVariable unsigned char rs6000_always_hint diff --git a/gcc/testsuite/gcc.target/powerpc/future-1.c b/gcc/testsuite/gcc.target/powerpc/future-1.c new file mode 100644 index 000000000000..7bd8e5ddbd00 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/future-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-mdejagnu-cpu=future -O2" } */ + +/* Basic check to see if the compiler supports -mcpu=future and if it defines + _ARCH_FUTURE. */ + +#ifndef _ARCH_FUTURE +#error "-mcpu=future is not supported" +#endif + +void foo (void) +{ +} diff --git a/gcc/testsuite/gcc.target/powerpc/future-2.c b/gcc/testsuite/gcc.target/powerpc/future-2.c new file mode 100644 index 000000000000..5552cefa3c2e --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/future-2.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +/* Check if we can set the future target via a target attribute. */ + +__attribute__((__target__("cpu=power9"))) +void foo_p9 (void) +{ +} + +__attribute__((__target__("cpu=power10"))) +void foo_p10 (void) +{ +} + +__attribute__((__target__("cpu=power11"))) +void foo_p11 (void) +{ +} + +__attribute__((__target__("cpu=future"))) +void foo_future (void) +{ +}
