Debian Codegraph @

gcc/config/loongarch/loongarch-def.h

raw
1 /* LoongArch definitions.
2 Copyright (C) 2021-2025 Free Software Foundation, Inc.
3 Contributed by Loongson Ltd.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 /* Definition of standard codes for:
22 - base architecture types (isa_base),
23 - ISA extensions (isa_ext),
24 - base ABI types (abi_base),
25 - ABI extension types (abi_ext).
26 - code models (cmodel)
27
28 These values are primarily used for implementing option handling
29 logic in "loongarch.opt", "loongarch-driver.cc" and "loongarch-opt.cc".
30
31 As for the result of this option handling process, the following
32 scheme is adopted to represent the final configuration:
33
34 - The target ABI is encoded with a tuple (abi_base, abi_ext)
35 using the code defined below.
36
37 - The target ISA is encoded with a "struct loongarch_isa" defined
38 in loongarch-cpu.h.
39
40 - The target microarchitecture is represented with a cpu model
41 index defined in loongarch-cpu.h.
42 */
43
44 #ifndef LOONGARCH_DEF_H
45 #define LOONGARCH_DEF_H
46
47 #if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)
48 #include <stdint.h>
49 #endif
50
51 #include "loongarch-def-array.h"
52 #include "loongarch-tune.h"
53
54
55 /* ISA base */
56 enum {
57 ISA_BASE_LA64 = 0, /* LoongArch64 */
58 N_ISA_BASE_TYPES = 1
59 };
60
61 extern loongarch_def_array<const char *, N_ISA_BASE_TYPES>
62 loongarch_isa_base_strings;
63
64
65 /* ISA extensions */
66 enum {
67 ISA_EXT_NONE = 0,
68 ISA_EXT_FPU32 = 1,
69 ISA_EXT_FPU64 = 2,
70 N_ISA_EXT_FPU_TYPES = 3,
71 ISA_EXT_SIMD_LSX = 3,
72 ISA_EXT_SIMD_LASX = 4,
73 N_ISA_EXT_TYPES = 5
74 };
75
76 extern loongarch_def_array<const char *, N_ISA_EXT_TYPES>
77 loongarch_isa_ext_strings;
78
79
80 /* Base ABI */
81 #define ABI_BASE_LP64D 0
82 #define ABI_BASE_LP64F 1
83 #define ABI_BASE_LP64S 2
84 #define N_ABI_BASE_TYPES 3
85
86 extern loongarch_def_array<const char *, N_ABI_BASE_TYPES>
87 loongarch_abi_base_strings;
88
89 #define TO_LP64_ABI_BASE(C) (C)
90
91 #define ABI_LP64_P(abi_base) \
92 (abi_base == ABI_BASE_LP64D \
93 || abi_base == ABI_BASE_LP64F \
94 || abi_base == ABI_BASE_LP64S)
95
96 #define ABI_FPU64_P(abi_base) \
97 (abi_base == ABI_BASE_LP64D)
98 #define ABI_FPU32_P(abi_base) \
99 (abi_base == ABI_BASE_LP64F)
100 #define ABI_NOFPU_P(abi_base) \
101 (abi_base == ABI_BASE_LP64S)
102
103
104 /* ABI Extension */
105 enum {
106 ABI_EXT_BASE = 0,
107 N_ABI_EXT_TYPES = 1
108 };
109
110 extern loongarch_def_array<const char *, N_ABI_EXT_TYPES>
111 loongarch_abi_ext_strings;
112
113
114 /* Code Model */
115 enum {
116 CMODEL_NORMAL = 0,
117 CMODEL_TINY = 1,
118 CMODEL_TINY_STATIC = 2,
119 CMODEL_MEDIUM = 3,
120 CMODEL_LARGE = 4,
121 CMODEL_EXTREME = 5,
122 N_CMODEL_TYPES = 6
123 };
124
125 extern loongarch_def_array<const char *, N_CMODEL_TYPES>
126 loongarch_cmodel_strings;
127
128
129 /* Explicit Reloc Type */
130 enum {
131 EXPLICIT_RELOCS_AUTO = 0,
132 EXPLICIT_RELOCS_NONE = 1,
133 EXPLICIT_RELOCS_ALWAYS = 2,
134 N_EXPLICIT_RELOCS_TYPES = 3
135 };
136
137 /* The common default value for variables whose assignments
138 are triggered by command-line options. */
139
140 #define M_OPT_UNSET -1
141 #define M_OPT_ABSENT(opt_enum) ((opt_enum) == M_OPT_UNSET)
142
143
144 /* Internal representation of the target. */
145 struct loongarch_isa
146 {
147 int base; /* ISA_BASE_ */
148 int fpu; /* ISA_EXT_FPU_ */
149 int simd; /* ISA_EXT_SIMD_ */
150
151 /* ISA evolution features implied by -march=, for -march=native probed
152 via CPUCFG. The features implied by base may be not included here.
153
154 Using int64_t instead of HOST_WIDE_INT for C compatibility. */
155 int64_t evolution;
156 int64_t evolution_set;
157
158 loongarch_isa () :
159 base (0), fpu (0), simd (0), evolution (0), evolution_set (0)
160 {}
161 loongarch_isa base_ (int _base) { base = _base; return *this; }
162 loongarch_isa fpu_ (int _fpu) { fpu = _fpu; return *this; }
163 loongarch_isa simd_ (int _simd) { simd = _simd; return *this; }
164 loongarch_isa evolution_ (int64_t _evolution)
165 { evolution = _evolution; return *this; }
166 };
167
168 struct loongarch_abi
169 {
170 int base; /* ABI_BASE_ */
171 int ext; /* ABI_EXT_ */
172 };
173
174 struct loongarch_target
175 {
176 struct loongarch_isa isa;
177 struct loongarch_abi abi;
178 int cpu_arch; /* ARCH_ */
179 int cpu_tune; /* TUNE_ */
180 int cmodel; /* CMODEL_ */
181 int tls_dialect; /* TLS_ */
182 };
183
184 /* ISA target presets (-march=*) */
185 enum {
186 ARCH_NATIVE = 0,
187 ARCH_ABI_DEFAULT = 1,
188 ARCH_LOONGARCH64 = 2,
189 ARCH_LA464 = 3,
190 ARCH_LA664 = 4,
191 ARCH_LA64V1_0 = 5,
192 ARCH_LA64V1_1 = 6,
193 N_ARCH_TYPES = 7,
194 };
195
196 /* Tune target presets (-mtune=*) */
197 enum {
198 TUNE_NATIVE = 0,
199 TUNE_GENERIC = 1,
200 TUNE_LOONGARCH64 = 2,
201 TUNE_LA464 = 3,
202 TUNE_LA664 = 4,
203 N_TUNE_TYPES = 5,
204 };
205
206 /* TLS types. */
207 enum {
208 TLS_TRADITIONAL = 0,
209 TLS_DESCRIPTORS = 1
210 };
211
212 /* Target preset properties */
213 extern loongarch_def_array<const char *, N_ARCH_TYPES>
214 loongarch_arch_strings;
215 extern loongarch_def_array<const char *, N_TUNE_TYPES>
216 loongarch_tune_strings;
217 extern loongarch_def_array<loongarch_isa, N_ARCH_TYPES>
218 loongarch_cpu_default_isa;
219 extern loongarch_def_array<int, N_TUNE_TYPES>
220 loongarch_cpu_issue_rate;
221 extern loongarch_def_array<int, N_TUNE_TYPES>
222 loongarch_cpu_multipass_dfa_lookahead;
223 extern loongarch_def_array<loongarch_cache, N_TUNE_TYPES>
224 loongarch_cpu_cache;
225 extern loongarch_def_array<loongarch_align, N_TUNE_TYPES>
226 loongarch_cpu_align;
227 extern loongarch_def_array<loongarch_rtx_cost_data, N_TUNE_TYPES>
228 loongarch_cpu_rtx_cost_data;
229 extern loongarch_def_array<
230 loongarch_def_array<loongarch_isa, N_ABI_EXT_TYPES>,
231 N_ABI_BASE_TYPES> abi_minimal_isa;
232
233 #endif /* LOONGARCH_DEF_H */