diff options
Diffstat (limited to 'gcc/config/s390/s390.c')
-rw-r--r-- | gcc/config/s390/s390.c | 891 |
1 files changed, 707 insertions, 184 deletions
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 7e7ed45230a..e0851e5cae8 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "backend.h" #include "target.h" +#include "target-globals.h" #include "rtl.h" #include "tree.h" #include "gimple.h" @@ -40,6 +41,7 @@ along with GCC; see the file COPYING3. If not see #include "recog.h" #include "cgraph.h" #include "diagnostic-core.h" +#include "diagnostic.h" #include "alias.h" #include "fold-const.h" #include "print-tree.h" @@ -79,6 +81,9 @@ along with GCC; see the file COPYING3. If not see /* This file should be included last. */ #include "target-def.h" +/* Remember the last target of s390_set_current_function. */ +static GTY(()) tree s390_previous_fndecl; + /* Define the specific costs for a given cpu. */ struct processor_costs @@ -116,7 +121,7 @@ struct processor_costs const int dsgr; }; -const struct processor_costs *s390_cost; +#define s390_cost ((const struct processor_costs *)(s390_cost_pointer)) static const struct processor_costs z900_cost = @@ -310,6 +315,27 @@ struct processor_costs zEC12_cost = COSTS_N_INSNS (160), /* DSGR cracked */ }; +static struct +{ + const char *const name; + const enum processor_type processor; + const struct processor_costs *cost; +} +const processor_table[] = +{ + { "g5", PROCESSOR_9672_G5, &z900_cost }, + { "g6", PROCESSOR_9672_G6, &z900_cost }, + { "z900", PROCESSOR_2064_Z900, &z900_cost }, + { "z990", PROCESSOR_2084_Z990, &z990_cost }, + { "z9-109", PROCESSOR_2094_Z9_109, &z9_109_cost }, + { "z9-ec", PROCESSOR_2094_Z9_EC, &z9_109_cost }, + { "z10", PROCESSOR_2097_Z10, &z10_cost }, + { "z196", PROCESSOR_2817_Z196, &z196_cost }, + { "zEC12", PROCESSOR_2827_ZEC12, &zEC12_cost }, + { "z13", PROCESSOR_2964_Z13, &zEC12_cost }, + { "native", PROCESSOR_NATIVE, NULL } +}; + extern int reload_completed; /* Kept up to date using the SCHED_VARIABLE_ISSUE hook. */ @@ -613,10 +639,6 @@ s390_init_builtins (void) NULL, NULL); tree noreturn_attr = tree_cons (get_identifier ("noreturn"), NULL, NULL); tree c_uint64_type_node; - unsigned int bflags_mask = (BFLAGS_MASK_INIT); - - bflags_mask |= (TARGET_VX) ? B_VX : 0; - bflags_mask |= (TARGET_HTM) ? B_HTM : 0; /* The uint64_type_node from tree.c is not compatible to the C99 uint64_t data type. What we want is c_uint64_type_node from @@ -629,46 +651,46 @@ s390_init_builtins (void) #undef DEF_TYPE #define DEF_TYPE(INDEX, BFLAGS, NODE, CONST_P) \ - if ((BFLAGS) == 0 || ((BFLAGS) & bflags_mask)) \ + if (s390_builtin_types[INDEX] == NULL) \ s390_builtin_types[INDEX] = (!CONST_P) ? \ (NODE) : build_type_variant ((NODE), 1, 0); #undef DEF_POINTER_TYPE #define DEF_POINTER_TYPE(INDEX, BFLAGS, INDEX_BASE) \ - if ((BFLAGS) == 0 || ((BFLAGS) & bflags_mask)) \ + if (s390_builtin_types[INDEX] == NULL) \ s390_builtin_types[INDEX] = \ build_pointer_type (s390_builtin_types[INDEX_BASE]); #undef DEF_DISTINCT_TYPE #define DEF_DISTINCT_TYPE(INDEX, BFLAGS, INDEX_BASE) \ - if ((BFLAGS) == 0 || ((BFLAGS) & bflags_mask)) \ + if (s390_builtin_types[INDEX] == NULL) \ s390_builtin_types[INDEX] = \ build_distinct_type_copy (s390_builtin_types[INDEX_BASE]); #undef DEF_VECTOR_TYPE #define DEF_VECTOR_TYPE(INDEX, BFLAGS, INDEX_BASE, ELEMENTS) \ - if ((BFLAGS) == 0 || ((BFLAGS) & bflags_mask)) \ + if (s390_builtin_types[INDEX] == NULL) \ s390_builtin_types[INDEX] = \ build_vector_type (s390_builtin_types[INDEX_BASE], ELEMENTS); #undef DEF_OPAQUE_VECTOR_TYPE #define DEF_OPAQUE_VECTOR_TYPE(INDEX, BFLAGS, INDEX_BASE, ELEMENTS) \ - if ((BFLAGS) == 0 || ((BFLAGS) & bflags_mask)) \ + if (s390_builtin_types[INDEX] == NULL) \ s390_builtin_types[INDEX] = \ build_opaque_vector_type (s390_builtin_types[INDEX_BASE], ELEMENTS); #undef DEF_FN_TYPE #define DEF_FN_TYPE(INDEX, BFLAGS, args...) \ - if ((BFLAGS) == 0 || ((BFLAGS) & bflags_mask)) \ + if (s390_builtin_fn_types[INDEX] == NULL) \ s390_builtin_fn_types[INDEX] = \ - build_function_type_list (args, NULL_TREE); + build_function_type_list (args, NULL_TREE); #undef DEF_OV_TYPE #define DEF_OV_TYPE(...) #include "s390-builtin-types.def" #undef B_DEF #define B_DEF(NAME, PATTERN, ATTRS, BFLAGS, OPFLAGS, FNTYPE) \ - if (((BFLAGS) & ~bflags_mask) == 0) \ + if (s390_builtin_decls[S390_BUILTIN_##NAME] == NULL) \ s390_builtin_decls[S390_BUILTIN_##NAME] = \ add_builtin_function ("__builtin_" #NAME, \ s390_builtin_fn_types[FNTYPE], \ @@ -678,7 +700,8 @@ s390_init_builtins (void) ATTRS); #undef OB_DEF #define OB_DEF(NAME, FIRST_VAR_NAME, LAST_VAR_NAME, BFLAGS, FNTYPE) \ - if (((BFLAGS) & ~bflags_mask) == 0) \ + if (s390_builtin_decls[S390_OVERLOADED_BUILTIN_##NAME + S390_BUILTIN_MAX] \ + == NULL) \ s390_builtin_decls[S390_OVERLOADED_BUILTIN_##NAME + S390_BUILTIN_MAX] = \ add_builtin_function ("__builtin_" #NAME, \ s390_builtin_fn_types[FNTYPE], \ @@ -762,10 +785,29 @@ s390_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, if (TARGET_DEBUG_ARG) { fprintf (stderr, - "s390_expand_builtin, code = %4d, %s\n", - (int)fcode, IDENTIFIER_POINTER (DECL_NAME (fndecl))); + "s390_expand_builtin, code = %4d, %s, bflags = 0x%x\n", + (int)fcode, IDENTIFIER_POINTER (DECL_NAME (fndecl)), + bflags_for_builtin (fcode)); } + if (S390_USE_TARGET_ATTRIBUTE) + { + unsigned int bflags; + + bflags = bflags_for_builtin (fcode); + if ((bflags & B_HTM) && !TARGET_HTM) + { + error ("Builtin %qF is not supported without -mhtm " + "(default with -march=zEC12 and higher).", fndecl); + return const0_rtx; + } + if ((bflags & B_VX) && !TARGET_VX) + { + error ("Builtin %qF is not supported without -mvx " + "(default with -march=z13 and higher).", fndecl); + return const0_rtx; + } + } if (fcode >= S390_OVERLOADED_BUILTIN_VAR_OFFSET && fcode < S390_ALL_BUILTIN_MAX) { @@ -907,14 +949,6 @@ s390_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, arity++; } - if (last_vec_mode != VOIDmode && !TARGET_VX) - { - error ("Vector type builtin %qF is not supported without -mvx " - "(default with -march=z13).", - fndecl); - return const0_rtx; - } - switch (arity) { case 0: @@ -6701,6 +6735,63 @@ s390_function_num_hotpatch_hw (tree decl, } } +/* Write the current .machine and .machinemode specification to the assembler + file. */ + +#if S390_USE_TARGET_ATTRIBUTE +static void +s390_asm_output_machine_for_arch (FILE *asm_out_file) +{ + fprintf (asm_out_file, "\t.machinemode %s\n", + (TARGET_ZARCH) ? "zarch" : "esa"); + fprintf (asm_out_file, "\t.machine \"%s", processor_table[s390_arch].name); + if (S390_USE_ARCHITECTURE_MODIFIERS) + { + int cpu_flags; + + cpu_flags = processor_flags_table[(int) s390_arch]; + if (TARGET_HTM && !(cpu_flags & PF_TX)) + fprintf (asm_out_file, "+htm"); + else if (!TARGET_HTM && (cpu_flags & PF_TX)) + fprintf (asm_out_file, "+nohtm"); + if (TARGET_VX && !(cpu_flags & PF_VX)) + fprintf (asm_out_file, "+vx"); + else if (!TARGET_VX && (cpu_flags & PF_VX)) + fprintf (asm_out_file, "+novx"); + } + fprintf (asm_out_file, "\"\n"); +} + +/* Write an extra function header before the very start of the function. */ + +void +s390_asm_output_function_prefix (FILE *asm_out_file, + const char *fnname ATTRIBUTE_UNUSED) +{ + if (DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl) == NULL) + return; + /* Since only the function specific options are saved but not the indications + which options are set, it's too much work here to figure out which options + have actually changed. Thus, generate .machine and .machinemode whenever a + function has the target attribute or pragma. */ + fprintf (asm_out_file, "\t.machinemode push\n"); + fprintf (asm_out_file, "\t.machine push\n"); + s390_asm_output_machine_for_arch (asm_out_file); +} + +/* Write an extra function footer after the very end of the function. */ + +void +s390_asm_declare_function_size (FILE *asm_out_file, + const char *fnname ATTRIBUTE_UNUSED, tree decl) +{ + if (DECL_FUNCTION_SPECIFIC_TARGET (decl) == NULL) + return; + fprintf (asm_out_file, "\t.machine pop\n"); + fprintf (asm_out_file, "\t.machinemode pop\n"); +} +#endif + /* Write the extra assembler code needed to declare a function properly. */ void @@ -6742,6 +6833,28 @@ s390_asm_output_function_label (FILE *asm_out_file, const char *fname, ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (function_alignment)); } + if (S390_USE_TARGET_ATTRIBUTE && TARGET_DEBUG_ARG) + { + asm_fprintf (asm_out_file, "\t# fn:%s ar%d\n", fname, s390_arch); + asm_fprintf (asm_out_file, "\t# fn:%s tu%d\n", fname, s390_tune); + asm_fprintf (asm_out_file, "\t# fn:%s sg%d\n", fname, s390_stack_guard); + asm_fprintf (asm_out_file, "\t# fn:%s ss%d\n", fname, s390_stack_size); + asm_fprintf (asm_out_file, "\t# fn:%s bc%d\n", fname, s390_branch_cost); + asm_fprintf (asm_out_file, "\t# fn:%s wf%d\n", fname, + s390_warn_framesize); + asm_fprintf (asm_out_file, "\t# fn:%s ba%d\n", fname, TARGET_BACKCHAIN); + asm_fprintf (asm_out_file, "\t# fn:%s hd%d\n", fname, TARGET_HARD_DFP); + asm_fprintf (asm_out_file, "\t# fn:%s hf%d\n", fname, !TARGET_SOFT_FLOAT); + asm_fprintf (asm_out_file, "\t# fn:%s ht%d\n", fname, TARGET_OPT_HTM); + asm_fprintf (asm_out_file, "\t# fn:%s vx%d\n", fname, TARGET_OPT_VX); + asm_fprintf (asm_out_file, "\t# fn:%s ps%d\n", fname, + TARGET_PACKED_STACK); + asm_fprintf (asm_out_file, "\t# fn:%s se%d\n", fname, TARGET_SMALL_EXEC); + asm_fprintf (asm_out_file, "\t# fn:%s mv%d\n", fname, TARGET_MVCLE); + asm_fprintf (asm_out_file, "\t# fn:%s zv%d\n", fname, TARGET_ZVECTOR); + asm_fprintf (asm_out_file, "\t# fn:%s wd%d\n", fname, + s390_warn_dynamicstack_p); + } ASM_OUTPUT_LABEL (asm_out_file, fname); if (hw_after > 0) asm_fprintf (asm_out_file, @@ -13434,230 +13547,254 @@ s390_loop_unroll_adjust (unsigned nunroll, struct loop *loop) } } +/* Restore the current options. This is a hook function and also called + internally. */ + static void -s390_option_override (void) +s390_function_specific_restore (struct gcc_options *opts, + struct cl_target_option *ptr ATTRIBUTE_UNUSED) { - unsigned int i; - cl_deferred_option *opt; - vec<cl_deferred_option> *v = - (vec<cl_deferred_option> *) s390_deferred_options; - - if (v) - FOR_EACH_VEC_ELT (*v, i, opt) - { - switch (opt->opt_index) - { - case OPT_mhotpatch_: - { - int val1; - int val2; - char s[256]; - char *t; - - strncpy (s, opt->arg, 256); - s[255] = 0; - t = strchr (s, ','); - if (t != NULL) - { - *t = 0; - t++; - val1 = integral_argument (s); - val2 = integral_argument (t); - } - else - { - val1 = -1; - val2 = -1; - } - if (val1 == -1 || val2 == -1) - { - /* argument is not a plain number */ - error ("arguments to %qs should be non-negative integers", - "-mhotpatch=n,m"); - break; - } - else if (val1 > s390_hotpatch_hw_max - || val2 > s390_hotpatch_hw_max) - { - error ("argument to %qs is too large (max. %d)", - "-mhotpatch=n,m", s390_hotpatch_hw_max); - break; - } - s390_hotpatch_hw_before_label = val1; - s390_hotpatch_hw_after_label = val2; - break; - } - default: - gcc_unreachable (); - } - } - - /* Set up function hooks. */ - init_machine_status = s390_init_machine_status; + opts->x_s390_cost_pointer = (long)processor_table[opts->x_s390_tune].cost; +} +static void +s390_option_override_internal (struct gcc_options *opts, + const struct gcc_options *opts_set) +{ /* Architecture mode defaults according to ABI. */ - if (!(target_flags_explicit & MASK_ZARCH)) + if (!(opts_set->x_target_flags & MASK_ZARCH)) { if (TARGET_64BIT) - target_flags |= MASK_ZARCH; + opts->x_target_flags |= MASK_ZARCH; else - target_flags &= ~MASK_ZARCH; + opts->x_target_flags &= ~MASK_ZARCH; } - /* Set the march default in case it hasn't been specified on - cmdline. */ - if (s390_arch == PROCESSOR_max) - { - s390_arch_string = TARGET_ZARCH? "z900" : "g5"; - s390_arch = TARGET_ZARCH ? PROCESSOR_2064_Z900 : PROCESSOR_9672_G5; - s390_arch_flags = processor_flags_table[(int)s390_arch]; - } + /* Set the march default in case it hasn't been specified on cmdline. */ + if (!opts_set->x_s390_arch) + opts->x_s390_arch = TARGET_ZARCH_P (opts->x_target_flags) + ? PROCESSOR_2064_Z900 : PROCESSOR_9672_G5; + opts->x_s390_arch_flags = processor_flags_table[(int) opts->x_s390_arch]; /* Determine processor to tune for. */ - if (s390_tune == PROCESSOR_max) - { - s390_tune = s390_arch; - s390_tune_flags = s390_arch_flags; - } + if (!opts_set->x_s390_tune) + opts->x_s390_tune = opts->x_s390_arch; + opts->x_s390_tune_flags = processor_flags_table[opts->x_s390_tune]; /* Sanity checks. */ - if (s390_arch == PROCESSOR_NATIVE || s390_tune == PROCESSOR_NATIVE) + if (opts->x_s390_arch == PROCESSOR_NATIVE + || opts->x_s390_tune == PROCESSOR_NATIVE) gcc_unreachable (); - if (TARGET_ZARCH && !TARGET_CPU_ZARCH) - error ("z/Architecture mode not supported on %s", s390_arch_string); - if (TARGET_64BIT && !TARGET_ZARCH) + if (TARGET_ZARCH_P (opts->x_target_flags) && !TARGET_CPU_ZARCH_P (opts)) + error ("z/Architecture mode not supported on %s", + processor_table[(int)opts->x_s390_arch].name); + if (TARGET_64BIT && !TARGET_ZARCH_P (opts->x_target_flags)) error ("64-bit ABI not supported in ESA/390 mode"); - /* Use hardware DFP if available and not explicitly disabled by - user. E.g. with -m31 -march=z10 -mzarch */ - if (!(target_flags_explicit & MASK_HARD_DFP) && TARGET_DFP) - target_flags |= MASK_HARD_DFP; - /* Enable hardware transactions if available and not explicitly disabled by user. E.g. with -m31 -march=zEC12 -mzarch */ - if (!(target_flags_explicit & MASK_OPT_HTM) && TARGET_CPU_HTM && TARGET_ZARCH) - target_flags |= MASK_OPT_HTM; + if (!TARGET_OPT_HTM_P (opts_set->x_target_flags)) + { + if (TARGET_CPU_HTM_P (opts) && TARGET_ZARCH_P (opts->x_target_flags)) + opts->x_target_flags |= MASK_OPT_HTM; + else + opts->x_target_flags &= ~MASK_OPT_HTM; + } - if (target_flags_explicit & MASK_OPT_VX) + if (TARGET_OPT_VX_P (opts_set->x_target_flags)) { - if (TARGET_OPT_VX) + if (TARGET_OPT_VX_P (opts->x_target_flags)) { - if (!TARGET_CPU_VX) + if (!TARGET_CPU_VX_P (opts)) error ("hardware vector support not available on %s", - s390_arch_string); - if (TARGET_SOFT_FLOAT) + processor_table[(int)opts->x_s390_arch].name); + if (TARGET_SOFT_FLOAT_P (opts->x_target_flags)) error ("hardware vector support not available with -msoft-float"); } } - else if (TARGET_CPU_VX) - /* Enable vector support if available and not explicitly disabled - by user. E.g. with -m31 -march=z13 -mzarch */ - target_flags |= MASK_OPT_VX; + else + { + if (TARGET_CPU_VX_P (opts)) + /* Enable vector support if available and not explicitly disabled + by user. E.g. with -m31 -march=z13 -mzarch */ + opts->x_target_flags |= MASK_OPT_VX; + else + opts->x_target_flags &= ~MASK_OPT_VX; + } - if (TARGET_HARD_DFP && !TARGET_DFP) + /* Use hardware DFP if available and not explicitly disabled by + user. E.g. with -m31 -march=z10 -mzarch */ + if (!TARGET_HARD_DFP_P (opts_set->x_target_flags)) + { + if (TARGET_DFP_P (opts)) + opts->x_target_flags |= MASK_HARD_DFP; + else + opts->x_target_flags &= ~MASK_HARD_DFP; + } + + if (TARGET_HARD_DFP_P (opts->x_target_flags) && !TARGET_DFP_P (opts)) { - if (target_flags_explicit & MASK_HARD_DFP) + if (TARGET_HARD_DFP_P (opts_set->x_target_flags)) { - if (!TARGET_CPU_DFP) + if (!TARGET_CPU_DFP_P (opts)) error ("hardware decimal floating point instructions" - " not available on %s", s390_arch_string); - if (!TARGET_ZARCH) + " not available on %s", + processor_table[(int)opts->x_s390_arch].name); + if (!TARGET_ZARCH_P (opts->x_target_flags)) error ("hardware decimal floating point instructions" " not available in ESA/390 mode"); } else - target_flags &= ~MASK_HARD_DFP; + opts->x_target_flags &= ~MASK_HARD_DFP; } - if ((target_flags_explicit & MASK_SOFT_FLOAT) && TARGET_SOFT_FLOAT) + if (TARGET_SOFT_FLOAT_P (opts_set->x_target_flags) + && TARGET_SOFT_FLOAT_P (opts->x_target_flags)) { - if ((target_flags_explicit & MASK_HARD_DFP) && TARGET_HARD_DFP) + if (TARGET_HARD_DFP_P (opts_set->x_target_flags) + && TARGET_HARD_DFP_P (opts->x_target_flags)) error ("-mhard-dfp can%'t be used in conjunction with -msoft-float"); - target_flags &= ~MASK_HARD_DFP; - } - - /* Set processor cost function. */ - switch (s390_tune) - { - case PROCESSOR_2084_Z990: - s390_cost = &z990_cost; - break; - case PROCESSOR_2094_Z9_109: - case PROCESSOR_2094_Z9_EC: - s390_cost = &z9_109_cost; - break; - case PROCESSOR_2097_Z10: - s390_cost = &z10_cost; - break; - case PROCESSOR_2817_Z196: - s390_cost = &z196_cost; - break; - case PROCESSOR_2827_ZEC12: - case PROCESSOR_2964_Z13: - s390_cost = &zEC12_cost; - break; - default: - s390_cost = &z900_cost; + opts->x_target_flags &= ~MASK_HARD_DFP; } - if (TARGET_BACKCHAIN && TARGET_PACKED_STACK && TARGET_HARD_FLOAT) + if (TARGET_BACKCHAIN_P (opts->x_target_flags) + && TARGET_PACKED_STACK_P (opts->x_target_flags) + && TARGET_HARD_FLOAT_P (opts->x_target_flags)) error ("-mbackchain -mpacked-stack -mhard-float are not supported " "in combination"); - if (s390_stack_size) + if (opts->x_s390_stack_size) { - if (s390_stack_guard >= s390_stack_size) + if (opts->x_s390_stack_guard >= opts->x_s390_stack_size) error ("stack size must be greater than the stack guard value"); - else if (s390_stack_size > 1 << 16) + else if (opts->x_s390_stack_size > 1 << 16) error ("stack size must not be greater than 64k"); } - else if (s390_stack_guard) + else if (opts->x_s390_stack_guard) error ("-mstack-guard implies use of -mstack-size"); #ifdef TARGET_DEFAULT_LONG_DOUBLE_128 - if (!(target_flags_explicit & MASK_LONG_DOUBLE_128)) - target_flags |= MASK_LONG_DOUBLE_128; + if (!TARGET_LONG_DOUBLE_128_P (opts_set->x_target_flags)) + opts->x_target_flags |= MASK_LONG_DOUBLE_128; #endif - if (s390_tune >= PROCESSOR_2097_Z10) + if (opts->x_s390_tune >= PROCESSOR_2097_Z10) { maybe_set_param_value (PARAM_MAX_UNROLLED_INSNS, 100, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); maybe_set_param_value (PARAM_MAX_UNROLL_TIMES, 32, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); maybe_set_param_value (PARAM_MAX_COMPLETELY_PEELED_INSNS, 2000, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); maybe_set_param_value (PARAM_MAX_COMPLETELY_PEEL_TIMES, 64, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); } maybe_set_param_value (PARAM_MAX_PENDING_LIST_LENGTH, 256, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); /* values for loop prefetching */ maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE, 256, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); maybe_set_param_value (PARAM_L1_CACHE_SIZE, 128, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); /* s390 has more than 2 levels and the size is much larger. Since we are always running virtualized assume that we only get a small part of the caches above l1. */ maybe_set_param_value (PARAM_L2_CACHE_SIZE, 1500, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); maybe_set_param_value (PARAM_PREFETCH_MIN_INSN_TO_MEM_RATIO, 2, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES, 6, - global_options.x_param_values, - global_options_set.x_param_values); + opts->x_param_values, + opts_set->x_param_values); + + /* Use the alternative scheduling-pressure algorithm by default. */ + maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM, 2, + opts->x_param_values, + opts_set->x_param_values); + + /* Call target specific restore function to do post-init work. At the moment, + this just sets opts->x_s390_cost_pointer. */ + s390_function_specific_restore (opts, NULL); +} + +static void +s390_option_override (void) +{ + unsigned int i; + cl_deferred_option *opt; + vec<cl_deferred_option> *v = + (vec<cl_deferred_option> *) s390_deferred_options; + + if (v) + FOR_EACH_VEC_ELT (*v, i, opt) + { + switch (opt->opt_index) + { + case OPT_mhotpatch_: + { + int val1; + int val2; + char s[256]; + char *t; + + strncpy (s, opt->arg, 256); + s[255] = 0; + t = strchr (s, ','); + if (t != NULL) + { + *t = 0; + t++; + val1 = integral_argument (s); + val2 = integral_argument (t); + } + else + { + val1 = -1; + val2 = -1; + } + if (val1 == -1 || val2 == -1) + { + /* argument is not a plain number */ + error ("arguments to %qs should be non-negative integers", + "-mhotpatch=n,m"); + break; + } + else if (val1 > s390_hotpatch_hw_max + || val2 > s390_hotpatch_hw_max) + { + error ("argument to %qs is too large (max. %d)", + "-mhotpatch=n,m", s390_hotpatch_hw_max); + break; + } + s390_hotpatch_hw_before_label = val1; + s390_hotpatch_hw_after_label = val2; + break; + } + default: + gcc_unreachable (); + } + } + + /* Set up function hooks. */ + init_machine_status = s390_init_machine_status; + + s390_option_override_internal (&global_options, &global_options_set); + + /* Save the initial options in case the user does function specific + options. */ + target_option_default_node = build_target_option_node (&global_options); + target_option_current_node = target_option_default_node; /* This cannot reside in s390_option_optimization_table since HAVE_prefetch requires the arch flags to be evaluated already. Since prefetching @@ -13665,11 +13802,6 @@ s390_option_override (void) if (flag_prefetch_loop_arrays < 0 && HAVE_prefetch && optimize >= 3) flag_prefetch_loop_arrays = 1; - /* Use the alternative scheduling-pressure algorithm by default. */ - maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM, 2, - global_options.x_param_values, - global_options_set.x_param_values); - if (TARGET_TPF) { /* Don't emit DWARF3/4 unless specifically selected. The TPF @@ -13696,6 +13828,386 @@ s390_option_override (void) register_pass (&insert_pass_s390_early_mach); } +#if S390_USE_TARGET_ATTRIBUTE +/* Inner function to process the attribute((target(...))), take an argument and + set the current options from the argument. If we have a list, recursively go + over the list. */ + +static bool +s390_valid_target_attribute_inner_p (tree args, + struct gcc_options *opts, + struct gcc_options *new_opts_set, + bool force_pragma) +{ + char *next_optstr; + bool ret = true; + +#define S390_ATTRIB(S,O,A) { S, sizeof (S)-1, O, A, 0 } +#define S390_PRAGMA(S,O,A) { S, sizeof (S)-1, O, A, 1 } + static const struct + { + const char *string; + size_t len; + int opt; + int has_arg; + int only_as_pragma; + } attrs[] = { + /* enum options */ + S390_ATTRIB ("arch=", OPT_march_, 1), + S390_ATTRIB ("tune=", OPT_mtune_, 1), + /* uinteger options */ + S390_ATTRIB ("stack-guard=", OPT_mstack_guard_, 1), + S390_ATTRIB ("stack-size=", OPT_mstack_size_, 1), + S390_ATTRIB ("branch-cost=", OPT_mbranch_cost_, 1), + S390_ATTRIB ("warn-framesize=", OPT_mwarn_framesize_, 1), + /* flag options */ + S390_ATTRIB ("backchain", OPT_mbackchain, 0), + S390_ATTRIB ("hard-dfp", OPT_mhard_dfp, 0), + S390_ATTRIB ("hard-float", OPT_mhard_float, 0), + S390_ATTRIB ("htm", OPT_mhtm, 0), + S390_ATTRIB ("vx", OPT_mvx, 0), + S390_ATTRIB ("packed-stack", OPT_mpacked_stack, 0), + S390_ATTRIB ("small-exec", OPT_msmall_exec, 0), + S390_ATTRIB ("soft-float", OPT_msoft_float, 0), + S390_ATTRIB ("mvcle", OPT_mmvcle, 0), + S390_PRAGMA ("zvector", OPT_mzvector, 0), + /* boolean options */ + S390_ATTRIB ("warn-dynamicstack", OPT_mwarn_dynamicstack, 0), + }; +#undef S390_ATTRIB +#undef S390_PRAGMA + + /* If this is a list, recurse to get the options. */ + if (TREE_CODE (args) == TREE_LIST) + { + bool ret = true; + int num_pragma_values; + int i; + + /* Note: attribs.c:decl_attributes prepends the values from + current_target_pragma to the list of target attributes. To determine + whether we're looking at a value of the attribute or the pragma we + assume that the first [list_length (current_target_pragma)] values in + the list are the values from the pragma. */ + num_pragma_values = (!force_pragma && current_target_pragma != NULL) + ? list_length (current_target_pragma) : 0; + for (i = 0; args; args = TREE_CHAIN (args), i++) + { + bool is_pragma; + + is_pragma = (force_pragma || i < num_pragma_values); + if (TREE_VALUE (args) + && !s390_valid_target_attribute_inner_p (TREE_VALUE (args), + opts, new_opts_set, + is_pragma)) + { + ret = false; + } + } + return ret; + } + + else if (TREE_CODE (args) != STRING_CST) + { + error ("attribute %<target%> argument not a string"); + return false; + } + + /* Handle multiple arguments separated by commas. */ + next_optstr = ASTRDUP (TREE_STRING_POINTER (args)); + + while (next_optstr && *next_optstr != '\0') + { + char *p = next_optstr; + char *orig_p = p; + char *comma = strchr (next_optstr, ','); + size_t len, opt_len; + int opt; + bool opt_set_p; + char ch; + unsigned i; + int mask = 0; + enum cl_var_type var_type; + bool found; + + if (comma) + { + *comma = '\0'; + len = comma - next_optstr; + next_optstr = comma + 1; + } + else + { + len = strlen (p); + next_optstr = NULL; + } + + /* Recognize no-xxx. */ + if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-') + { + opt_set_p = false; + p += 3; + len -= 3; + } + else + opt_set_p = true; + + /* Find the option. */ + ch = *p; + found = false; + for (i = 0; i < ARRAY_SIZE (attrs); i++) + { + opt_len = attrs[i].len; + if (ch == attrs[i].string[0] + && ((attrs[i].has_arg) ? len > opt_len : len == opt_len) + && memcmp (p, attrs[i].string, opt_len) == 0) + { + opt = attrs[i].opt; + if (!opt_set_p && cl_options[opt].cl_reject_negative) + continue; + mask = cl_options[opt].var_value; + var_type = cl_options[opt].var_type; + found = true; + break; + } + } + + /* Process the option. */ + if (!found) + { + error ("attribute(target(\"%s\")) is unknown", orig_p); + return false; + } + else if (attrs[i].only_as_pragma && !force_pragma) + { + /* Value is not allowed for the target attribute. */ + error ("Value %qs is not supported by attribute %<target%>", + attrs[i].string); + return false; + } + + else if (var_type == CLVC_BIT_SET || var_type == CLVC_BIT_CLEAR) + { + if (var_type == CLVC_BIT_CLEAR) + opt_set_p = !opt_set_p; + + if (opt_set_p) + opts->x_target_flags |= mask; + else + opts->x_target_flags &= ~mask; + new_opts_set->x_target_flags |= mask; + } + + else if (cl_options[opt].var_type == CLVC_BOOLEAN) + { + int value; + + if (cl_options[opt].cl_uinteger) + { + /* Unsigned integer argument. Code based on the function + decode_cmdline_option () in opts-common.c. */ + value = integral_argument (p + opt_len); + } + else + value = (opt_set_p) ? 1 : 0; + + if (value != -1) + { + struct cl_decoded_option decoded; + + /* Value range check; only implemented for numeric and boolean + options at the moment. */ + generate_option (opt, NULL, value, CL_TARGET, &decoded); + s390_handle_option (opts, new_opts_set, &decoded, input_location); + set_option (opts, new_opts_set, opt, value, + p + opt_len, DK_UNSPECIFIED, input_location, + global_dc); + } + else + { + error ("attribute(target(\"%s\")) is unknown", orig_p); + ret = false; + } + } + + else if (cl_options[opt].var_type == CLVC_ENUM) + { + bool arg_ok; + int value; + + arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET); + if (arg_ok) + set_option (opts, new_opts_set, opt, value, + p + opt_len, DK_UNSPECIFIED, input_location, + global_dc); + else + { + error ("attribute(target(\"%s\")) is unknown", orig_p); + ret = false; + } + } + + else + gcc_unreachable (); + } + return ret; +} + +/* Return a TARGET_OPTION_NODE tree of the target options listed or NULL. */ + +tree +s390_valid_target_attribute_tree (tree args, + struct gcc_options *opts, + const struct gcc_options *opts_set, + bool force_pragma) +{ + tree t = NULL_TREE; + struct gcc_options new_opts_set; + + memset (&new_opts_set, 0, sizeof (new_opts_set)); + + /* Process each of the options on the chain. */ + if (! s390_valid_target_attribute_inner_p (args, opts, &new_opts_set, + force_pragma)) + return error_mark_node; + + /* If some option was set (even if it has not changed), rerun + s390_option_override_internal, and then save the options away. */ + if (new_opts_set.x_target_flags + || new_opts_set.x_s390_arch + || new_opts_set.x_s390_tune + || new_opts_set.x_s390_stack_guard + || new_opts_set.x_s390_stack_size + || new_opts_set.x_s390_branch_cost + || new_opts_set.x_s390_warn_framesize + || new_opts_set.x_s390_warn_dynamicstack_p) + { + const unsigned char *src = (const unsigned char *)opts_set; + unsigned char *dest = (unsigned char *)&new_opts_set; + unsigned int i; + + /* Merge the original option flags into the new ones. */ + for (i = 0; i < sizeof(*opts_set); i++) + dest[i] |= src[i]; + + /* Do any overrides, such as arch=xxx, or tune=xxx support. */ + s390_option_override_internal (opts, &new_opts_set); + /* Save the current options unless we are validating options for + #pragma. */ + t = build_target_option_node (opts); + } + return t; +} + +/* Hook to validate attribute((target("string"))). */ + +static bool +s390_valid_target_attribute_p (tree fndecl, + tree ARG_UNUSED (name), + tree args, + int ARG_UNUSED (flags)) +{ + struct gcc_options func_options; + tree new_target, new_optimize; + bool ret = true; + + /* attribute((target("default"))) does nothing, beyond + affecting multi-versioning. */ + if (TREE_VALUE (args) + && TREE_CODE (TREE_VALUE (args)) == STRING_CST + && TREE_CHAIN (args) == NULL_TREE + && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0) + return true; + + tree old_optimize = build_optimization_node (&global_options); + + /* Get the optimization options of the current function. */ + tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl); + + if (!func_optimize) + func_optimize = old_optimize; + + /* Init func_options. */ + memset (&func_options, 0, sizeof (func_options)); + init_options_struct (&func_options, NULL); + lang_hooks.init_options_struct (&func_options); + + cl_optimization_restore (&func_options, TREE_OPTIMIZATION (func_optimize)); + + /* Initialize func_options to the default before its target options can + be set. */ + cl_target_option_restore (&func_options, + TREE_TARGET_OPTION (target_option_default_node)); + + new_target = s390_valid_target_attribute_tree (args, &func_options, + &global_options_set, + (args == + current_target_pragma)); + new_optimize = build_optimization_node (&func_options); + if (new_target == error_mark_node) + ret = false; + else if (fndecl && new_target) + { + DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target; + if (old_optimize != new_optimize) + DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize; + } + return ret; +} + +/* Restore targets globals from NEW_TREE and invalidate s390_previous_fndecl + cache. */ + +void +s390_activate_target_options (tree new_tree) +{ + cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree)); + if (TREE_TARGET_GLOBALS (new_tree)) + restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); + else if (new_tree == target_option_default_node) + restore_target_globals (&default_target_globals); + else + TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts (); + s390_previous_fndecl = NULL_TREE; +} + +/* Establish appropriate back-end context for processing the function + FNDECL. The argument might be NULL to indicate processing at top + level, outside of any function scope. */ +static void +s390_set_current_function (tree fndecl) +{ + /* Only change the context if the function changes. This hook is called + several times in the course of compiling a function, and we don't want to + slow things down too much or call target_reinit when it isn't safe. */ + if (fndecl == s390_previous_fndecl) + return; + + tree old_tree; + if (s390_previous_fndecl == NULL_TREE) + old_tree = target_option_current_node; + else if (DECL_FUNCTION_SPECIFIC_TARGET (s390_previous_fndecl)) + old_tree = DECL_FUNCTION_SPECIFIC_TARGET (s390_previous_fndecl); + else + old_tree = target_option_default_node; + + if (fndecl == NULL_TREE) + { + if (old_tree != target_option_current_node) + s390_activate_target_options (target_option_current_node); + return; + } + + tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + if (new_tree == NULL_TREE) + new_tree = target_option_default_node; + + if (old_tree != new_tree) + s390_activate_target_options (new_tree); + s390_previous_fndecl = fndecl; +} +#endif + /* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P. */ static bool @@ -14136,6 +14648,17 @@ s390_invalid_binary_op (int op ATTRIBUTE_UNUSED, const_tree type1, const_tree ty #undef TARGET_ASM_FILE_END #define TARGET_ASM_FILE_END s390_asm_file_end +#if S390_USE_TARGET_ATTRIBUTE +#undef TARGET_SET_CURRENT_FUNCTION +#define TARGET_SET_CURRENT_FUNCTION s390_set_current_function + +#undef TARGET_OPTION_VALID_ATTRIBUTE_P +#define TARGET_OPTION_VALID_ATTRIBUTE_P s390_valid_target_attribute_p +#endif + +#undef TARGET_OPTION_RESTORE +#define TARGET_OPTION_RESTORE s390_function_specific_restore + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-s390.h" |