163d1a8abSmrg /* Common hooks for IBM RS/6000.
2*ec02198aSmrg Copyright (C) 1991-2020 Free Software Foundation, Inc.
363d1a8abSmrg
463d1a8abSmrg This file is part of GCC.
563d1a8abSmrg
663d1a8abSmrg GCC is free software; you can redistribute it and/or modify it
763d1a8abSmrg under the terms of the GNU General Public License as published
863d1a8abSmrg by the Free Software Foundation; either version 3, or (at your
963d1a8abSmrg option) any later version.
1063d1a8abSmrg
1163d1a8abSmrg GCC is distributed in the hope that it will be useful, but WITHOUT
1263d1a8abSmrg ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1363d1a8abSmrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
1463d1a8abSmrg License for more details.
1563d1a8abSmrg
1663d1a8abSmrg You should have received a copy of the GNU General Public License
1763d1a8abSmrg along with GCC; see the file COPYING3. If not see
1863d1a8abSmrg <http://www.gnu.org/licenses/>. */
1963d1a8abSmrg
2063d1a8abSmrg #include "config.h"
2163d1a8abSmrg #include "system.h"
2263d1a8abSmrg #include "coretypes.h"
2363d1a8abSmrg #include "diagnostic-core.h"
2463d1a8abSmrg #include "tm.h"
2563d1a8abSmrg #include "common/common-target.h"
2663d1a8abSmrg #include "common/common-target-def.h"
2763d1a8abSmrg #include "opts.h"
2863d1a8abSmrg #include "flags.h"
2963d1a8abSmrg
3063d1a8abSmrg /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
3163d1a8abSmrg static const struct default_options rs6000_option_optimization_table[] =
3263d1a8abSmrg {
33*ec02198aSmrg /* Split multi-word types early. */
34*ec02198aSmrg { OPT_LEVELS_ALL, OPT_fsplit_wide_types_early, NULL, 1 },
3563d1a8abSmrg /* Enable -fsched-pressure for first pass instruction scheduling. */
3663d1a8abSmrg { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
37*ec02198aSmrg /* Enable -munroll-only-small-loops with -funroll-loops to unroll small
38*ec02198aSmrg loops at -O2 and above by default. */
39*ec02198aSmrg { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_funroll_loops, NULL, 1 },
40*ec02198aSmrg { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_munroll_only_small_loops, NULL, 1 },
41*ec02198aSmrg
42*ec02198aSmrg /* -frename-registers leads to non-optimal codegen and performance
43*ec02198aSmrg on rs6000, turn it off by default. */
44*ec02198aSmrg { OPT_LEVELS_ALL, OPT_frename_registers, NULL, 0 },
45*ec02198aSmrg
46*ec02198aSmrg /* Double growth factor to counter reduced min jump length. */
47*ec02198aSmrg { OPT_LEVELS_ALL, OPT__param_max_grow_copy_bb_insns_, NULL, 16 },
4863d1a8abSmrg { OPT_LEVELS_NONE, 0, NULL, 0 }
4963d1a8abSmrg };
5063d1a8abSmrg
5163d1a8abSmrg /* Implement TARGET_OPTION_INIT_STRUCT. */
5263d1a8abSmrg
5363d1a8abSmrg static void
rs6000_option_init_struct(struct gcc_options * opts)5463d1a8abSmrg rs6000_option_init_struct (struct gcc_options *opts)
5563d1a8abSmrg {
5663d1a8abSmrg if (DEFAULT_ABI == ABI_DARWIN)
5763d1a8abSmrg /* The Darwin libraries never set errno, so we might as well
5863d1a8abSmrg avoid calling them when that's the only reason we would. */
5963d1a8abSmrg opts->x_flag_errno_math = 0;
6063d1a8abSmrg
6163d1a8abSmrg /* Enable section anchors by default. */
6263d1a8abSmrg if (!TARGET_MACHO)
6363d1a8abSmrg opts->x_flag_section_anchors = 1;
64c7a68eb7Smrg
65c7a68eb7Smrg /* By default, always emit DWARF-2 unwind info. This allows debugging
66c7a68eb7Smrg without maintaining a stack frame back-chain. It also allows the
67c7a68eb7Smrg debugger to find out where on-entry register values are stored at any
68c7a68eb7Smrg point in a function, without having to analyze the executable code (which
69c7a68eb7Smrg isn't even possible to do in the general case). */
70c7a68eb7Smrg #ifdef OBJECT_FORMAT_ELF
71c7a68eb7Smrg opts->x_flag_asynchronous_unwind_tables = 1;
72c7a68eb7Smrg #endif
7363d1a8abSmrg }
7463d1a8abSmrg
7563d1a8abSmrg /* If not otherwise specified by a target, make 'long double' equivalent to
7663d1a8abSmrg 'double'. */
7763d1a8abSmrg
7863d1a8abSmrg #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
7963d1a8abSmrg #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
8063d1a8abSmrg #endif
8163d1a8abSmrg
8263d1a8abSmrg /* Implement TARGET_HANDLE_OPTION. */
8363d1a8abSmrg
8463d1a8abSmrg static bool
rs6000_handle_option(struct gcc_options * opts,struct gcc_options * opts_set,const struct cl_decoded_option * decoded,location_t loc)8563d1a8abSmrg rs6000_handle_option (struct gcc_options *opts, struct gcc_options *opts_set,
8663d1a8abSmrg const struct cl_decoded_option *decoded,
8763d1a8abSmrg location_t loc)
8863d1a8abSmrg {
8963d1a8abSmrg char *p, *q;
9063d1a8abSmrg size_t code = decoded->opt_index;
9163d1a8abSmrg const char *arg = decoded->arg;
9263d1a8abSmrg int value = decoded->value;
9363d1a8abSmrg
9463d1a8abSmrg switch (code)
9563d1a8abSmrg {
9663d1a8abSmrg case OPT_mfull_toc:
9763d1a8abSmrg opts->x_rs6000_isa_flags &= ~OPTION_MASK_MINIMAL_TOC;
9863d1a8abSmrg opts->x_TARGET_NO_FP_IN_TOC = 0;
9963d1a8abSmrg opts->x_TARGET_NO_SUM_IN_TOC = 0;
10063d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
10163d1a8abSmrg #ifdef TARGET_USES_SYSV4_OPT
10263d1a8abSmrg /* Note, V.4 no longer uses a normal TOC, so make -mfull-toc, be
10363d1a8abSmrg just the same as -mminimal-toc. */
10463d1a8abSmrg opts->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
10563d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
10663d1a8abSmrg #endif
10763d1a8abSmrg break;
10863d1a8abSmrg
10963d1a8abSmrg #ifdef TARGET_USES_SYSV4_OPT
11063d1a8abSmrg case OPT_mtoc:
11163d1a8abSmrg /* Make -mtoc behave like -mminimal-toc. */
11263d1a8abSmrg opts->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
11363d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
11463d1a8abSmrg break;
11563d1a8abSmrg #endif
11663d1a8abSmrg
11763d1a8abSmrg #ifdef TARGET_USES_AIX64_OPT
11863d1a8abSmrg case OPT_maix64:
11963d1a8abSmrg #else
12063d1a8abSmrg case OPT_m64:
12163d1a8abSmrg #endif
12263d1a8abSmrg opts->x_rs6000_isa_flags |= OPTION_MASK_POWERPC64;
12363d1a8abSmrg opts->x_rs6000_isa_flags |= (~opts_set->x_rs6000_isa_flags
12463d1a8abSmrg & OPTION_MASK_PPC_GFXOPT);
12563d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_POWERPC64;
12663d1a8abSmrg break;
12763d1a8abSmrg
12863d1a8abSmrg #ifdef TARGET_USES_AIX64_OPT
12963d1a8abSmrg case OPT_maix32:
13063d1a8abSmrg #else
13163d1a8abSmrg case OPT_m32:
13263d1a8abSmrg #endif
13363d1a8abSmrg opts->x_rs6000_isa_flags &= ~OPTION_MASK_POWERPC64;
13463d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_POWERPC64;
13563d1a8abSmrg break;
13663d1a8abSmrg
13763d1a8abSmrg case OPT_mminimal_toc:
13863d1a8abSmrg if (value == 1)
13963d1a8abSmrg {
14063d1a8abSmrg opts->x_TARGET_NO_FP_IN_TOC = 0;
14163d1a8abSmrg opts->x_TARGET_NO_SUM_IN_TOC = 0;
14263d1a8abSmrg }
14363d1a8abSmrg break;
14463d1a8abSmrg
14563d1a8abSmrg case OPT_mpowerpc_gpopt:
14663d1a8abSmrg case OPT_mpowerpc_gfxopt:
14763d1a8abSmrg break;
14863d1a8abSmrg
14963d1a8abSmrg case OPT_mdebug_:
15063d1a8abSmrg p = ASTRDUP (arg);
15163d1a8abSmrg opts->x_rs6000_debug = 0;
15263d1a8abSmrg
15363d1a8abSmrg while ((q = strtok (p, ",")) != NULL)
15463d1a8abSmrg {
15563d1a8abSmrg unsigned mask = 0;
15663d1a8abSmrg bool invert;
15763d1a8abSmrg
15863d1a8abSmrg p = NULL;
15963d1a8abSmrg if (*q == '!')
16063d1a8abSmrg {
16163d1a8abSmrg invert = true;
16263d1a8abSmrg q++;
16363d1a8abSmrg }
16463d1a8abSmrg else
16563d1a8abSmrg invert = false;
16663d1a8abSmrg
16763d1a8abSmrg if (! strcmp (q, "all"))
16863d1a8abSmrg mask = MASK_DEBUG_ALL;
16963d1a8abSmrg else if (! strcmp (q, "stack"))
17063d1a8abSmrg mask = MASK_DEBUG_STACK;
17163d1a8abSmrg else if (! strcmp (q, "arg"))
17263d1a8abSmrg mask = MASK_DEBUG_ARG;
17363d1a8abSmrg else if (! strcmp (q, "reg"))
17463d1a8abSmrg mask = MASK_DEBUG_REG;
17563d1a8abSmrg else if (! strcmp (q, "addr"))
17663d1a8abSmrg mask = MASK_DEBUG_ADDR;
17763d1a8abSmrg else if (! strcmp (q, "cost"))
17863d1a8abSmrg mask = MASK_DEBUG_COST;
17963d1a8abSmrg else if (! strcmp (q, "target"))
18063d1a8abSmrg mask = MASK_DEBUG_TARGET;
18163d1a8abSmrg else if (! strcmp (q, "builtin"))
18263d1a8abSmrg mask = MASK_DEBUG_BUILTIN;
18363d1a8abSmrg else
1840fc04c29Smrg error_at (loc, "unknown %<-mdebug-%s%> switch", q);
18563d1a8abSmrg
18663d1a8abSmrg if (invert)
18763d1a8abSmrg opts->x_rs6000_debug &= ~mask;
18863d1a8abSmrg else
18963d1a8abSmrg opts->x_rs6000_debug |= mask;
19063d1a8abSmrg }
19163d1a8abSmrg break;
19263d1a8abSmrg
19363d1a8abSmrg #ifdef TARGET_USES_SYSV4_OPT
19463d1a8abSmrg case OPT_mrelocatable:
19563d1a8abSmrg if (value == 1)
19663d1a8abSmrg {
19763d1a8abSmrg opts->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
19863d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_MINIMAL_TOC;
19963d1a8abSmrg opts->x_TARGET_NO_FP_IN_TOC = 1;
20063d1a8abSmrg }
20163d1a8abSmrg break;
20263d1a8abSmrg
20363d1a8abSmrg case OPT_mrelocatable_lib:
20463d1a8abSmrg if (value == 1)
20563d1a8abSmrg {
20663d1a8abSmrg opts->x_rs6000_isa_flags |= (OPTION_MASK_RELOCATABLE
20763d1a8abSmrg | OPTION_MASK_MINIMAL_TOC);
20863d1a8abSmrg opts_set->x_rs6000_isa_flags |= (OPTION_MASK_RELOCATABLE
20963d1a8abSmrg | OPTION_MASK_MINIMAL_TOC);
21063d1a8abSmrg opts->x_TARGET_NO_FP_IN_TOC = 1;
21163d1a8abSmrg }
21263d1a8abSmrg else
21363d1a8abSmrg {
21463d1a8abSmrg opts->x_rs6000_isa_flags &= ~OPTION_MASK_RELOCATABLE;
21563d1a8abSmrg opts_set->x_rs6000_isa_flags |= OPTION_MASK_RELOCATABLE;
21663d1a8abSmrg }
21763d1a8abSmrg break;
21863d1a8abSmrg #endif
21963d1a8abSmrg
22063d1a8abSmrg case OPT_mlong_double_:
22163d1a8abSmrg if (value != 64 && value != 128)
22263d1a8abSmrg {
2230fc04c29Smrg error_at (loc, "unknown switch %<-mlong-double-%s%>", arg);
22463d1a8abSmrg opts->x_rs6000_long_double_type_size
22563d1a8abSmrg = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
22663d1a8abSmrg return false;
22763d1a8abSmrg }
22863d1a8abSmrg break;
22963d1a8abSmrg
230*ec02198aSmrg case OPT_mabi_ibmlongdouble:
231*ec02198aSmrg case OPT_mabi_ieeelongdouble:
232*ec02198aSmrg if (opts->x_rs6000_long_double_type_size == 64)
233*ec02198aSmrg {
234*ec02198aSmrg error_at (loc, "option %<%s%> requires %<-mlong-double-128%>",
235*ec02198aSmrg decoded->orig_option_with_args_text);
236*ec02198aSmrg return true;
237*ec02198aSmrg }
238*ec02198aSmrg break;
239*ec02198aSmrg
24063d1a8abSmrg case OPT_mrecip:
24163d1a8abSmrg opts->x_rs6000_recip_name = (value) ? "default" : "none";
24263d1a8abSmrg break;
24363d1a8abSmrg }
24463d1a8abSmrg return true;
24563d1a8abSmrg }
24663d1a8abSmrg
24763d1a8abSmrg /* -fsplit-stack uses a field in the TCB, available with glibc-2.19.
24863d1a8abSmrg We also allow 2.18 because alignment padding guarantees that the
24963d1a8abSmrg space is available there too. */
25063d1a8abSmrg
25163d1a8abSmrg static bool
rs6000_supports_split_stack(bool report,struct gcc_options * opts ATTRIBUTE_UNUSED)25263d1a8abSmrg rs6000_supports_split_stack (bool report,
25363d1a8abSmrg struct gcc_options *opts ATTRIBUTE_UNUSED)
25463d1a8abSmrg {
25563d1a8abSmrg #ifndef TARGET_GLIBC_MAJOR
25663d1a8abSmrg #define TARGET_GLIBC_MAJOR 0
25763d1a8abSmrg #endif
25863d1a8abSmrg #ifndef TARGET_GLIBC_MINOR
25963d1a8abSmrg #define TARGET_GLIBC_MINOR 0
26063d1a8abSmrg #endif
26163d1a8abSmrg /* Note: Can't test DEFAULT_ABI here, it isn't set until later. */
26263d1a8abSmrg if (TARGET_GLIBC_MAJOR * 1000 + TARGET_GLIBC_MINOR >= 2018
26363d1a8abSmrg && TARGET_64BIT
26463d1a8abSmrg && TARGET_ELF)
26563d1a8abSmrg return true;
26663d1a8abSmrg
26763d1a8abSmrg if (report)
26863d1a8abSmrg error ("%<-fsplit-stack%> currently only supported on PowerPC64 GNU/Linux with glibc-2.18 or later");
26963d1a8abSmrg return false;
27063d1a8abSmrg }
27163d1a8abSmrg
27263d1a8abSmrg #undef TARGET_HANDLE_OPTION
27363d1a8abSmrg #define TARGET_HANDLE_OPTION rs6000_handle_option
27463d1a8abSmrg
27563d1a8abSmrg #undef TARGET_OPTION_INIT_STRUCT
27663d1a8abSmrg #define TARGET_OPTION_INIT_STRUCT rs6000_option_init_struct
27763d1a8abSmrg
27863d1a8abSmrg #undef TARGET_OPTION_OPTIMIZATION_TABLE
27963d1a8abSmrg #define TARGET_OPTION_OPTIMIZATION_TABLE rs6000_option_optimization_table
28063d1a8abSmrg
28163d1a8abSmrg #undef TARGET_SUPPORTS_SPLIT_STACK
28263d1a8abSmrg #define TARGET_SUPPORTS_SPLIT_STACK rs6000_supports_split_stack
28363d1a8abSmrg
28463d1a8abSmrg struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
285