Debian Codegraph @

gcc/common/config/s390/s390-common.cc

raw
1 /* Common hooks for IBM S/390 and zSeries.
2 Copyright (C) 1999-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "diagnostic-core.h"
24 #include "tm.h"
25 #include "common/common-target.h"
26 #include "common/common-target-def.h"
27 #include "opts.h"
28 #include "flags.h"
29
30 EXPORTED_CONST int processor_flags_table[] =
31 {
32 /* z900 */ PF_IEEE_FLOAT | PF_ZARCH,
33 /* z990 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT,
34 /* z9-109 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
35 | PF_EXTIMM,
36 /* z9-ec */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
37 | PF_EXTIMM | PF_DFP,
38 /* z10 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
39 | PF_EXTIMM | PF_DFP | PF_Z10,
40 /* z196 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
41 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196,
42 /* zEC12 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
43 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196 | PF_ZEC12 | PF_TX,
44 /* z13 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
45 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196 | PF_ZEC12 | PF_TX
46 | PF_Z13 | PF_VX,
47 /* z14 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
48 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196 | PF_ZEC12 | PF_TX
49 | PF_Z13 | PF_VX | PF_VXE | PF_Z14,
50 /* z15 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
51 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196 | PF_ZEC12 | PF_TX
52 | PF_Z13 | PF_VX | PF_VXE | PF_Z14 | PF_VXE2 | PF_Z15,
53 /* z16 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
54 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196 | PF_ZEC12 | PF_TX
55 | PF_Z13 | PF_VX | PF_VXE | PF_Z14 | PF_VXE2 | PF_Z15
56 | PF_NNPA | PF_Z16,
57 /* z17 */ PF_IEEE_FLOAT | PF_ZARCH | PF_LONG_DISPLACEMENT
58 | PF_EXTIMM | PF_DFP | PF_Z10 | PF_Z196 | PF_ZEC12 | PF_TX
59 | PF_Z13 | PF_VX | PF_VXE | PF_Z14 | PF_VXE2 | PF_Z15
60 | PF_NNPA | PF_Z16 | PF_VXE3 | PF_Z17
61 };
62
63 /* Change optimizations to be performed, depending on the
64 optimization level. */
65
66 static const struct default_options s390_option_optimization_table[] =
67 {
68 /* Enable -fsched-pressure by default when optimizing. */
69 { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
70
71 /* Enable -munroll-only-small-loops with -funroll-loops to unroll small
72 loops at -O2 and above by default. */
73 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_funroll_loops, NULL, 1 },
74 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_munroll_only_small_loops, NULL, 1 },
75
76 /* ??? There are apparently still problems with -fcaller-saves. */
77 { OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 },
78
79 /* Use MVCLE instructions to decrease code size if requested. */
80 { OPT_LEVELS_SIZE, OPT_mmvcle, NULL, 1 },
81
82 { OPT_LEVELS_NONE, 0, NULL, 0 }
83 };
84
85 /* Implement TARGET_OPTION_INIT_STRUCT. */
86
87 static void
88 s390_option_init_struct (struct gcc_options *opts)
89 {
90 /* By default, always emit DWARF-2 unwind info. This allows debugging
91 without maintaining a stack frame back-chain. */
92 opts->x_flag_asynchronous_unwind_tables = 1;
93
94 /* Enable section anchors by default. */
95 opts->x_flag_section_anchors = 1;
96 }
97
98 /* Implement TARGET_HANDLE_OPTION. */
99
100 bool
101 s390_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED,
102 struct gcc_options *opts_set ATTRIBUTE_UNUSED,
103 const struct cl_decoded_option *decoded,
104 location_t loc)
105 {
106 size_t code = decoded->opt_index;
107 int value = decoded->value;
108
109 switch (code)
110 {
111 case OPT_mstack_guard_:
112 if (value != 0 && exact_log2 (value) == -1)
113 error_at (loc, "stack guard value must be an exact power of 2");
114 return true;
115
116 case OPT_mstack_size_:
117 if (value != 0 && exact_log2 (value) == -1)
118 error_at (loc, "stack size must be an exact power of 2");
119 return true;
120
121 default:
122 return true;
123 }
124 }
125
126 /* -fsplit-stack uses a field in the TCB, available with glibc-2.23.
127 We don't verify it, since earlier versions just have padding at
128 its place, which works just as well. For other libc implementations
129 we disable the feature entirely to avoid corrupting the TCB. */
130
131 static bool
132 s390_supports_split_stack (bool report,
133 struct gcc_options *opts ATTRIBUTE_UNUSED)
134 {
135 #ifdef OPTION_GLIBC_P
136 if (OPTION_GLIBC_P (opts))
137 return true;
138 #endif
139
140 if (report)
141 error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
142 return false;
143 }
144
145 #undef TARGET_DEFAULT_TARGET_FLAGS
146 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT)
147
148 #undef TARGET_HANDLE_OPTION
149 #define TARGET_HANDLE_OPTION s390_handle_option
150
151 #undef TARGET_OPTION_OPTIMIZATION_TABLE
152 #define TARGET_OPTION_OPTIMIZATION_TABLE s390_option_optimization_table
153
154 #undef TARGET_OPTION_INIT_STRUCT
155 #define TARGET_OPTION_INIT_STRUCT s390_option_init_struct
156
157 #undef TARGET_SUPPORTS_SPLIT_STACK
158 #define TARGET_SUPPORTS_SPLIT_STACK s390_supports_split_stack
159
160 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;