LLDB mainline
ArchSpec.cpp
Go to the documentation of this file.
1//===-- ArchSpec.cpp ------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11
12#include "lldb/Utility/Log.h"
14#include "lldb/lldb-defines.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/BinaryFormat/COFF.h"
17#include "llvm/BinaryFormat/ELF.h"
18#include "llvm/BinaryFormat/MachO.h"
19#include "llvm/BinaryFormat/XCOFF.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/TargetParser/AMDGPUTargetParser.h"
22#include "llvm/TargetParser/ARMTargetParser.h"
23
24using namespace lldb;
25using namespace lldb_private;
26
27static bool cores_match(const ArchSpec::Core core1, const ArchSpec::Core core2,
28 bool enforce_exact_match);
29
30namespace lldb_private {
31
37 llvm::Triple::ArchType machine;
39 const char *const name;
40};
41
42} // namespace lldb_private
43
44// This core information can be looked using the ArchSpec::Core as the index
45static constexpr const CoreDefinition g_core_definitions[] = {
46 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_generic,
47 "arm"},
48 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv4,
49 "armv4"},
50 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv4t,
51 "armv4t"},
52 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv5,
53 "armv5"},
54 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv5e,
55 "armv5e"},
56 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv5t,
57 "armv5t"},
58 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv6,
59 "armv6"},
60 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv6m,
61 "armv6m"},
62 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7,
63 "armv7"},
64 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7a,
65 "armv7a"},
66 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7l,
67 "armv7l"},
68 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7f,
69 "armv7f"},
70 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7s,
71 "armv7s"},
72 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7k,
73 "armv7k"},
74 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7m,
75 "armv7m"},
76 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv7em,
77 "armv7em"},
78 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm,
79 ArchSpec::eCore_arm_armv8m_base, "armv8m.base"},
80 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm,
81 ArchSpec::eCore_arm_armv8m_main, "armv8m.main"},
82 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm,
83 ArchSpec::eCore_arm_armv8_1m_main, "armv8.1m.main"},
84 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_xscale,
85 "xscale"},
86 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumb,
87 "thumb"},
88 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv4t,
89 "thumbv4t"},
90 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv5,
91 "thumbv5"},
92 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv5e,
93 "thumbv5e"},
94 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv6,
95 "thumbv6"},
96 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv6m,
97 "thumbv6m"},
98 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7,
99 "thumbv7"},
100 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7s,
101 "thumbv7s"},
102 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7k,
103 "thumbv7k"},
104 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7f,
105 "thumbv7f"},
106 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7m,
107 "thumbv7m"},
108 {eByteOrderLittle, 4, 2, 4, llvm::Triple::thumb, ArchSpec::eCore_thumbv7em,
109 "thumbv7em"},
110 {eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64,
112 {eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64,
114 {eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64,
116 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arm, ArchSpec::eCore_arm_armv8l,
117 "armv8l"},
118 {eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64,
120 {eByteOrderLittle, 4, 4, 4, llvm::Triple::aarch64_32,
121 ArchSpec::eCore_arm_arm64_32, "arm64_32"},
122 {eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64,
123 ArchSpec::eCore_arm_aarch64, "aarch64"},
124 {eByteOrderLittle, 8, 4, 4, llvm::Triple::aarch64,
125 ArchSpec::eCore_arm_arm64ex1, "arm64e.x1"},
126
127 // mips32, mips32r2, mips32r3, mips32r5, mips32r6
128 {eByteOrderBig, 4, 2, 4, llvm::Triple::mips, ArchSpec::eCore_mips32,
129 "mips"},
130 {eByteOrderBig, 4, 2, 4, llvm::Triple::mips, ArchSpec::eCore_mips32r2,
131 "mipsr2"},
132 {eByteOrderBig, 4, 2, 4, llvm::Triple::mips, ArchSpec::eCore_mips32r3,
133 "mipsr3"},
134 {eByteOrderBig, 4, 2, 4, llvm::Triple::mips, ArchSpec::eCore_mips32r5,
135 "mipsr5"},
136 {eByteOrderBig, 4, 2, 4, llvm::Triple::mips, ArchSpec::eCore_mips32r6,
137 "mipsr6"},
138 {eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel, ArchSpec::eCore_mips32el,
139 "mipsel"},
140 {eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel,
141 ArchSpec::eCore_mips32r2el, "mipsr2el"},
142 {eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel,
143 ArchSpec::eCore_mips32r3el, "mipsr3el"},
144 {eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel,
145 ArchSpec::eCore_mips32r5el, "mipsr5el"},
146 {eByteOrderLittle, 4, 2, 4, llvm::Triple::mipsel,
147 ArchSpec::eCore_mips32r6el, "mipsr6el"},
148
149 // mips64, mips64r2, mips64r3, mips64r5, mips64r6
150 {eByteOrderBig, 8, 2, 4, llvm::Triple::mips64, ArchSpec::eCore_mips64,
151 "mips64"},
152 {eByteOrderBig, 8, 2, 4, llvm::Triple::mips64, ArchSpec::eCore_mips64r2,
153 "mips64r2"},
154 {eByteOrderBig, 8, 2, 4, llvm::Triple::mips64, ArchSpec::eCore_mips64r3,
155 "mips64r3"},
156 {eByteOrderBig, 8, 2, 4, llvm::Triple::mips64, ArchSpec::eCore_mips64r5,
157 "mips64r5"},
158 {eByteOrderBig, 8, 2, 4, llvm::Triple::mips64, ArchSpec::eCore_mips64r6,
159 "mips64r6"},
160 {eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el,
161 ArchSpec::eCore_mips64el, "mips64el"},
162 {eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el,
163 ArchSpec::eCore_mips64r2el, "mips64r2el"},
164 {eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el,
165 ArchSpec::eCore_mips64r3el, "mips64r3el"},
166 {eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el,
167 ArchSpec::eCore_mips64r5el, "mips64r5el"},
168 {eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el,
169 ArchSpec::eCore_mips64r6el, "mips64r6el"},
170
171 // MSP430
172 {eByteOrderLittle, 2, 2, 4, llvm::Triple::msp430, ArchSpec::eCore_msp430,
173 "msp430"},
174
175 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_generic,
176 "powerpc"},
177 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc601,
178 "ppc601"},
179 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc602,
180 "ppc602"},
181 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc603,
182 "ppc603"},
183 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc603e,
184 "ppc603e"},
185 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc603ev,
186 "ppc603ev"},
187 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc604,
188 "ppc604"},
189 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc604e,
190 "ppc604e"},
191 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc620,
192 "ppc620"},
193 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc750,
194 "ppc750"},
195 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc7400,
196 "ppc7400"},
197 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc7450,
198 "ppc7450"},
199 {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc970,
200 "ppc970"},
201
202 {eByteOrderLittle, 8, 4, 4, llvm::Triple::ppc64le,
203 ArchSpec::eCore_ppc64le_generic, "powerpc64le"},
204 {eByteOrderBig, 8, 4, 4, llvm::Triple::ppc64, ArchSpec::eCore_ppc64_generic,
205 "powerpc64"},
206 {eByteOrderBig, 8, 4, 4, llvm::Triple::ppc64,
208
209 {eByteOrderBig, 8, 2, 6, llvm::Triple::systemz,
211
212 {eByteOrderLittle, 4, 4, 4, llvm::Triple::sparc,
214 {eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9,
216
217 {eByteOrderLittle, 4, 1, 15, llvm::Triple::x86, ArchSpec::eCore_x86_32_i386,
218 "i386"},
219 {eByteOrderLittle, 4, 1, 15, llvm::Triple::x86, ArchSpec::eCore_x86_32_i486,
220 "i486"},
221 {eByteOrderLittle, 4, 1, 15, llvm::Triple::x86,
223 {eByteOrderLittle, 4, 1, 15, llvm::Triple::x86, ArchSpec::eCore_x86_32_i686,
224 "i686"},
225
226 {eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64,
228 {eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64,
230 {eByteOrderLittle, 8, 1, 15, llvm::Triple::x86_64,
232
233 {eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon,
235 {eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon,
237 {eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon,
239
240 {eByteOrderLittle, 4, 2, 8, llvm::Triple::riscv32, ArchSpec::eCore_riscv32,
241 "riscv32"},
242 {eByteOrderLittle, 8, 2, 8, llvm::Triple::riscv64, ArchSpec::eCore_riscv64,
243 "riscv64"},
244
245 {eByteOrderLittle, 4, 4, 4, llvm::Triple::loongarch32,
246 ArchSpec::eCore_loongarch32, "loongarch32"},
247 {eByteOrderLittle, 8, 4, 4, llvm::Triple::loongarch64,
248 ArchSpec::eCore_loongarch64, "loongarch64"},
249
250 {eByteOrderLittle, 4, 4, 4, llvm::Triple::UnknownArch,
251 ArchSpec::eCore_uknownMach32, "unknown-mach-32"},
252 {eByteOrderLittle, 8, 4, 4, llvm::Triple::UnknownArch,
253 ArchSpec::eCore_uknownMach64, "unknown-mach-64"},
254 {eByteOrderLittle, 4, 2, 4, llvm::Triple::arc, ArchSpec::eCore_arc, "arc"},
255
256 {eByteOrderLittle, 2, 2, 4, llvm::Triple::avr, ArchSpec::eCore_avr, "avr"},
257
258 {eByteOrderLittle, 4, 1, 4, llvm::Triple::wasm32, ArchSpec::eCore_wasm32,
259 "wasm32"},
260 {eByteOrderLittle, 8, 4, 16, llvm::Triple::amdgpu, ArchSpec::eCore_amd_gpu,
261 "amdgpu"},
262};
263
264// Ensure that we have an entry in the g_core_definitions for each core. If you
265// comment out an entry above, you will need to comment out the corresponding
266// ArchSpec::Core enumeration.
267static_assert(sizeof(g_core_definitions) / sizeof(CoreDefinition) ==
269 "make sure we have one core definition for each core");
270
271template <int I> struct ArchSpecValidator : ArchSpecValidator<I + 1> {
272 static_assert(g_core_definitions[I].core == I,
273 "g_core_definitions order doesn't match Core enumeration");
274};
275
276template <> struct ArchSpecValidator<ArchSpec::kNumCores> {};
277
279
287
294
296 for (const auto &def : g_core_definitions)
297 list.AppendString(def.name);
298}
299
301 for (const auto &def : g_core_definitions)
302 request.TryCompleteCurrentArg(def.name);
303}
304
305#define CPU_ANY (UINT32_MAX)
306
307//===----------------------------------------------------------------------===//
308// A table that gets searched linearly for matches. This table is used to
309// convert cpu type and subtypes to architecture names, and to convert
310// architecture names to cpu types and subtypes. The ordering is important and
311// allows the precedence to be set when the table is built.
312#define SUBTYPE_MASK 0x00FFFFFFu
313
314// clang-format off
316 {ArchSpec::eCore_arm_generic, llvm::MachO::CPU_TYPE_ARM, CPU_ANY, UINT32_MAX, UINT32_MAX},
317 {ArchSpec::eCore_arm_generic, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_ALL, UINT32_MAX, SUBTYPE_MASK},
318 {ArchSpec::eCore_arm_armv4, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V4T, UINT32_MAX, SUBTYPE_MASK},
319 {ArchSpec::eCore_arm_armv4t, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V4T, UINT32_MAX, SUBTYPE_MASK},
320 {ArchSpec::eCore_arm_armv6, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V6, UINT32_MAX, SUBTYPE_MASK},
321 {ArchSpec::eCore_arm_armv6m, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V6M, UINT32_MAX, SUBTYPE_MASK},
322 {ArchSpec::eCore_arm_armv5, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ, UINT32_MAX, SUBTYPE_MASK},
323 {ArchSpec::eCore_arm_armv5e, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ, UINT32_MAX, SUBTYPE_MASK},
324 {ArchSpec::eCore_arm_armv5t, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ, UINT32_MAX, SUBTYPE_MASK},
325 {ArchSpec::eCore_arm_xscale, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_XSCALE, UINT32_MAX, SUBTYPE_MASK},
326 {ArchSpec::eCore_arm_armv7, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7, UINT32_MAX, SUBTYPE_MASK},
327 {ArchSpec::eCore_arm_armv7f, llvm::MachO::CPU_TYPE_ARM, 10, UINT32_MAX, SUBTYPE_MASK},
328 {ArchSpec::eCore_arm_armv7s, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7S, UINT32_MAX, SUBTYPE_MASK},
329 {ArchSpec::eCore_arm_armv7k, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7K, UINT32_MAX, SUBTYPE_MASK},
330 {ArchSpec::eCore_arm_armv7m, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7M, UINT32_MAX, SUBTYPE_MASK},
331 {ArchSpec::eCore_arm_armv7em, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7EM, UINT32_MAX, SUBTYPE_MASK},
332 {ArchSpec::eCore_arm_armv8m_base, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V8M_BASE, UINT32_MAX, SUBTYPE_MASK},
333 {ArchSpec::eCore_arm_armv8m_main, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V8M_MAIN, UINT32_MAX, SUBTYPE_MASK},
334 {ArchSpec::eCore_arm_armv8_1m_main, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V8_1M_MAIN, UINT32_MAX, SUBTYPE_MASK},
335 {ArchSpec::eCore_arm_arm64e, llvm::MachO::CPU_TYPE_ARM64, llvm::MachO::CPU_SUBTYPE_ARM64E, UINT32_MAX, SUBTYPE_MASK},
336 {ArchSpec::eCore_arm_arm64ex1, llvm::MachO::CPU_TYPE_ARM64, llvm::MachO::CPU_SUBTYPE_ARM64E_X1, UINT32_MAX, SUBTYPE_MASK},
337 {ArchSpec::eCore_arm_arm64, llvm::MachO::CPU_TYPE_ARM64, llvm::MachO::CPU_SUBTYPE_ARM64_ALL, UINT32_MAX, SUBTYPE_MASK},
338 {ArchSpec::eCore_arm_arm64, llvm::MachO::CPU_TYPE_ARM64, llvm::MachO::CPU_SUBTYPE_ARM64_V8, UINT32_MAX, SUBTYPE_MASK},
339 {ArchSpec::eCore_arm_arm64, llvm::MachO::CPU_TYPE_ARM64, 13, UINT32_MAX, SUBTYPE_MASK},
340 {ArchSpec::eCore_arm_arm64_32, llvm::MachO::CPU_TYPE_ARM64_32, 0, UINT32_MAX, SUBTYPE_MASK},
341 {ArchSpec::eCore_arm_arm64_32, llvm::MachO::CPU_TYPE_ARM64_32, 1, UINT32_MAX, SUBTYPE_MASK},
342 {ArchSpec::eCore_arm_arm64, llvm::MachO::CPU_TYPE_ARM64, CPU_ANY, UINT32_MAX, SUBTYPE_MASK},
343 {ArchSpec::eCore_thumb, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_ALL, UINT32_MAX, SUBTYPE_MASK},
344 {ArchSpec::eCore_thumbv4t, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V4T, UINT32_MAX, SUBTYPE_MASK},
345 {ArchSpec::eCore_thumbv5, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V5, UINT32_MAX, SUBTYPE_MASK},
346 {ArchSpec::eCore_thumbv5e, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V5, UINT32_MAX, SUBTYPE_MASK},
347 {ArchSpec::eCore_thumbv6, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V6, UINT32_MAX, SUBTYPE_MASK},
348 {ArchSpec::eCore_thumbv6m, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V6M, UINT32_MAX, SUBTYPE_MASK},
349 {ArchSpec::eCore_thumbv7, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7, UINT32_MAX, SUBTYPE_MASK},
350 {ArchSpec::eCore_thumbv7f, llvm::MachO::CPU_TYPE_ARM, 10, UINT32_MAX, SUBTYPE_MASK},
351 {ArchSpec::eCore_thumbv7s, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7S, UINT32_MAX, SUBTYPE_MASK},
352 {ArchSpec::eCore_thumbv7k, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7K, UINT32_MAX, SUBTYPE_MASK},
353 {ArchSpec::eCore_thumbv7m, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7M, UINT32_MAX, SUBTYPE_MASK},
354 {ArchSpec::eCore_thumbv7em, llvm::MachO::CPU_TYPE_ARM, llvm::MachO::CPU_SUBTYPE_ARM_V7EM, UINT32_MAX, SUBTYPE_MASK},
355 {ArchSpec::eCore_ppc_generic, llvm::MachO::CPU_TYPE_POWERPC, CPU_ANY, UINT32_MAX, UINT32_MAX},
356 {ArchSpec::eCore_ppc_generic, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_ALL, UINT32_MAX, SUBTYPE_MASK},
357 {ArchSpec::eCore_ppc_ppc601, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_601, UINT32_MAX, SUBTYPE_MASK},
358 {ArchSpec::eCore_ppc_ppc602, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_602, UINT32_MAX, SUBTYPE_MASK},
359 {ArchSpec::eCore_ppc_ppc603, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_603, UINT32_MAX, SUBTYPE_MASK},
360 {ArchSpec::eCore_ppc_ppc603e, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_603e, UINT32_MAX, SUBTYPE_MASK},
361 {ArchSpec::eCore_ppc_ppc603ev, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_603ev, UINT32_MAX, SUBTYPE_MASK},
362 {ArchSpec::eCore_ppc_ppc604, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_604, UINT32_MAX, SUBTYPE_MASK},
363 {ArchSpec::eCore_ppc_ppc604e, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_604e, UINT32_MAX, SUBTYPE_MASK},
364 {ArchSpec::eCore_ppc_ppc620, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_620, UINT32_MAX, SUBTYPE_MASK},
365 {ArchSpec::eCore_ppc_ppc750, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_750, UINT32_MAX, SUBTYPE_MASK},
366 {ArchSpec::eCore_ppc_ppc7400, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_7400, UINT32_MAX, SUBTYPE_MASK},
367 {ArchSpec::eCore_ppc_ppc7450, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_7450, UINT32_MAX, SUBTYPE_MASK},
368 {ArchSpec::eCore_ppc_ppc970, llvm::MachO::CPU_TYPE_POWERPC, llvm::MachO::CPU_SUBTYPE_POWERPC_970, UINT32_MAX, SUBTYPE_MASK},
369 {ArchSpec::eCore_ppc64_generic, llvm::MachO::CPU_TYPE_POWERPC64, llvm::MachO::CPU_SUBTYPE_POWERPC_ALL, UINT32_MAX, SUBTYPE_MASK},
370 {ArchSpec::eCore_ppc64le_generic, llvm::MachO::CPU_TYPE_POWERPC64, CPU_ANY, UINT32_MAX, SUBTYPE_MASK},
371 {ArchSpec::eCore_ppc64_ppc970_64, llvm::MachO::CPU_TYPE_POWERPC64, 100, UINT32_MAX, SUBTYPE_MASK},
372 {ArchSpec::eCore_x86_32_i386, llvm::MachO::CPU_TYPE_I386, llvm::MachO::CPU_SUBTYPE_I386_ALL, UINT32_MAX, SUBTYPE_MASK},
373 {ArchSpec::eCore_x86_32_i486, llvm::MachO::CPU_TYPE_I386, llvm::MachO::CPU_SUBTYPE_486, UINT32_MAX, SUBTYPE_MASK},
374 {ArchSpec::eCore_x86_32_i486sx, llvm::MachO::CPU_TYPE_I386, llvm::MachO::CPU_SUBTYPE_486SX, UINT32_MAX, SUBTYPE_MASK},
375 {ArchSpec::eCore_x86_32_i386, llvm::MachO::CPU_TYPE_I386, CPU_ANY, UINT32_MAX, UINT32_MAX},
376 {ArchSpec::eCore_x86_64_x86_64, llvm::MachO::CPU_TYPE_X86_64, llvm::MachO::CPU_SUBTYPE_X86_64_ALL, UINT32_MAX, SUBTYPE_MASK},
377 {ArchSpec::eCore_x86_64_x86_64, llvm::MachO::CPU_TYPE_X86_64, llvm::MachO::CPU_SUBTYPE_X86_ARCH1, UINT32_MAX, SUBTYPE_MASK},
378 {ArchSpec::eCore_x86_64_x86_64h, llvm::MachO::CPU_TYPE_X86_64, llvm::MachO::CPU_SUBTYPE_X86_64_H, UINT32_MAX, SUBTYPE_MASK},
379 {ArchSpec::eCore_x86_64_x86_64, llvm::MachO::CPU_TYPE_X86_64, CPU_ANY, UINT32_MAX, UINT32_MAX},
380 {ArchSpec::eCore_riscv32, llvm::MachO::CPU_TYPE_RISCV, llvm::MachO::CPU_SUBTYPE_RISCV_ALL, UINT32_MAX, SUBTYPE_MASK},
381 {ArchSpec::eCore_riscv32, llvm::MachO::CPU_TYPE_RISCV, CPU_ANY, UINT32_MAX, SUBTYPE_MASK},
382 // Catch any unknown mach architectures so we can always use the object and symbol mach-o files
383 {ArchSpec::eCore_uknownMach32, 0, 0, 0xFF000000u, 0x00000000u},
384 {ArchSpec::eCore_uknownMach64, llvm::MachO::CPU_ARCH_ABI64, 0, 0xFF000000u, 0x00000000u}
385};
386// clang-format on
387
391
392//===----------------------------------------------------------------------===//
393// A table that gets searched linearly for matches. This table is used to
394// convert cpu type and subtypes to architecture names, and to convert
395// architecture names to cpu types and subtypes. The ordering is important and
396// allows the precedence to be set when the table is built.
397// clang-format off
399 {ArchSpec::eCore_sparc_generic, llvm::ELF::EM_SPARC }, // Sparc
400 {ArchSpec::eCore_x86_32_i386, llvm::ELF::EM_386 }, // Intel 80386
401 {ArchSpec::eCore_x86_32_i486, llvm::ELF::EM_IAMCU }, // Intel MCU // FIXME: is this correct?
402 {ArchSpec::eCore_ppc_generic, llvm::ELF::EM_PPC }, // PowerPC
403 {ArchSpec::eCore_ppc64le_generic, llvm::ELF::EM_PPC64, ArchSpec::eCore_ppc64le_generic}, // PowerPC64le
404 {ArchSpec::eCore_ppc64_generic, llvm::ELF::EM_PPC64, ArchSpec::eCore_ppc64_generic}, // PowerPC64
405 {ArchSpec::eCore_arm_generic, llvm::ELF::EM_ARM }, // ARM
406 {ArchSpec::eCore_arm_aarch64, llvm::ELF::EM_AARCH64 }, // ARM64
407 {ArchSpec::eCore_s390x_generic, llvm::ELF::EM_S390 }, // SystemZ
408 {ArchSpec::eCore_sparc9_generic, llvm::ELF::EM_SPARCV9 }, // SPARC V9
409 {ArchSpec::eCore_x86_64_x86_64, llvm::ELF::EM_X86_64 }, // AMD64
410 {ArchSpec::eCore_mips32, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips32}, // mips32
411 {ArchSpec::eCore_mips32r2, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips32r2}, // mips32r2
412 {ArchSpec::eCore_mips32r6, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips32r6}, // mips32r6
413 {ArchSpec::eCore_mips32el, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips32el}, // mips32el
414 {ArchSpec::eCore_mips32r2el, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips32r2el}, // mips32r2el
415 {ArchSpec::eCore_mips32r6el, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips32r6el}, // mips32r6el
417 {ArchSpec::eCore_mips64r2, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips64r2}, // mips64r2
418 {ArchSpec::eCore_mips64r6, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips64r6}, // mips64r6
419 {ArchSpec::eCore_mips64el, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips64el}, // mips64el
420 {ArchSpec::eCore_mips64r2el, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips64r2el}, // mips64r2el
421 {ArchSpec::eCore_mips64r6el, llvm::ELF::EM_MIPS, ArchSpec::eMIPSSubType_mips64r6el}, // mips64r6el
422 {ArchSpec::eCore_msp430, llvm::ELF::EM_MSP430 }, // MSP430
423 {ArchSpec::eCore_hexagon_generic, llvm::ELF::EM_HEXAGON }, // HEXAGON
424 {ArchSpec::eCore_arc, llvm::ELF::EM_ARC_COMPACT2}, // ARC
425 {ArchSpec::eCore_avr, llvm::ELF::EM_AVR }, // AVR
426 {ArchSpec::eCore_riscv32, llvm::ELF::EM_RISCV, ArchSpec::eRISCVSubType_riscv32}, // riscv32
427 {ArchSpec::eCore_riscv64, llvm::ELF::EM_RISCV, ArchSpec::eRISCVSubType_riscv64}, // riscv64
428 {ArchSpec::eCore_loongarch32, llvm::ELF::EM_LOONGARCH, ArchSpec::eLoongArchSubType_loongarch32}, // loongarch32
429 {ArchSpec::eCore_loongarch64, llvm::ELF::EM_LOONGARCH, ArchSpec::eLoongArchSubType_loongarch64}, // loongarch64
430 // Match every AMDGPU ELF subtype. SetArchitecture() converts recognized
431 // AMDGCN EF_AMDGPU_MACH values to triple subarchitectures.
432 {ArchSpec::eCore_amd_gpu, llvm::ELF::EM_AMDGPU, 0, UINT32_MAX, 0},
433};
434// clang-format on
435
438 std::size(g_elf_arch_entries),
440 "elf",
441};
442// clang-format off
444 {ArchSpec::eCore_x86_32_i386, llvm::COFF::IMAGE_FILE_MACHINE_I386}, // Intel 80x86
445 {ArchSpec::eCore_ppc_generic, llvm::COFF::IMAGE_FILE_MACHINE_POWERPC}, // PowerPC
446 {ArchSpec::eCore_ppc_generic, llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP}, // PowerPC (with FPU)
447 {ArchSpec::eCore_arm_generic, llvm::COFF::IMAGE_FILE_MACHINE_ARM}, // ARM
448 {ArchSpec::eCore_arm_armv7, llvm::COFF::IMAGE_FILE_MACHINE_ARMNT}, // ARMv7
449 {ArchSpec::eCore_thumb, llvm::COFF::IMAGE_FILE_MACHINE_THUMB}, // ARMv7
450 {ArchSpec::eCore_x86_64_x86_64, llvm::COFF::IMAGE_FILE_MACHINE_AMD64}, // AMD64
451 {ArchSpec::eCore_arm_arm64, llvm::COFF::IMAGE_FILE_MACHINE_ARM64} // ARM64
452};
453// clang-format on
454
457 std::size(g_coff_arch_entries),
459 "pe-coff",
460};
461
462// clang-format off
464 {ArchSpec::eCore_ppc_generic, llvm::XCOFF::TCPU_PPC},
465 {ArchSpec::eCore_ppc64_generic, llvm::XCOFF::TCPU_PPC64}
466};
467// clang-format on
468
471 std::size(g_xcoff_arch_entries),
473 "xcoff",
474};
475
476//===----------------------------------------------------------------------===//
477// Table of all ArchDefinitions
480
481//===----------------------------------------------------------------------===//
482// Static helper functions.
483
484// Get the architecture definition for a given object type.
486 for (const ArchDefinition *def : g_arch_definitions) {
487 if (def->type == arch_type)
488 return def;
489 }
490 return nullptr;
491}
492
493// Get an architecture definition by name.
494static const CoreDefinition *FindCoreDefinition(llvm::StringRef name) {
495 for (const auto &def : g_core_definitions) {
496 if (name.equals_insensitive(def.name))
497 return &def;
498 }
499 return nullptr;
500}
501
503 if (core < std::size(g_core_definitions))
504 return &g_core_definitions[core];
505 return nullptr;
506}
507
508// Get a definition entry by cpu type and subtype.
509static const ArchDefinitionEntry *
510FindArchDefinitionEntry(const ArchDefinition *def, uint32_t cpu, uint32_t sub) {
511 if (def == nullptr)
512 return nullptr;
513
514 const ArchDefinitionEntry *entries = def->entries;
515 for (size_t i = 0; i < def->num_entries; ++i) {
516 if (entries[i].cpu == (cpu & entries[i].cpu_mask))
517 if (entries[i].sub == (sub & entries[i].sub_mask))
518 return &entries[i];
519 }
520 return nullptr;
521}
522
523static const ArchDefinitionEntry *
525 if (def == nullptr)
526 return nullptr;
527
528 const ArchDefinitionEntry *entries = def->entries;
529 for (size_t i = 0; i < def->num_entries; ++i) {
530 if (entries[i].core == core)
531 return &entries[i];
532 }
533 return nullptr;
534}
535
536static llvm::StringRef GetAMDGPUVariantName(uint32_t sub);
537
538//===----------------------------------------------------------------------===//
539// Constructors and destructors.
540
541ArchSpec::ArchSpec() = default;
542
543ArchSpec::ArchSpec(const char *triple_cstr) {
544 if (triple_cstr)
545 SetTriple(triple_cstr);
546}
547
548ArchSpec::ArchSpec(llvm::StringRef triple_str) { SetTriple(triple_str); }
549
550ArchSpec::ArchSpec(const llvm::Triple &triple) { SetTriple(triple); }
551
552ArchSpec::ArchSpec(ArchitectureType arch_type, uint32_t cpu, uint32_t subtype) {
553 SetArchitecture(arch_type, cpu, subtype);
554}
555
556ArchSpec::~ArchSpec() = default;
557
559 m_triple = llvm::Triple();
562 m_flags = 0;
563}
564
565//===----------------------------------------------------------------------===//
566// Predicates.
567
568const char *ArchSpec::GetArchitectureName() const {
569 const CoreDefinition *core_def = FindCoreDefinition(m_core);
570 if (core_def)
571 return core_def->name;
572 return "unknown";
573}
574
575bool ArchSpec::IsMIPS() const { return GetTriple().isMIPS(); }
576
577bool ArchSpec::IsNVPTX() const { return GetTriple().isNVPTX(); }
578
579std::string ArchSpec::GetTargetABI() const {
580
581 std::string abi;
582
583 if (IsMIPS()) {
584 switch (GetFlags() & ArchSpec::eMIPSABI_mask) {
586 abi = "n64";
587 return abi;
589 abi = "n32";
590 return abi;
592 abi = "o32";
593 return abi;
594 default:
595 return abi;
596 }
597 }
598 return abi;
599}
600
601void ArchSpec::SetFlags(const std::string &elf_abi) {
602
603 uint32_t flag = GetFlags();
604 if (IsMIPS()) {
605 if (elf_abi == "n64")
607 else if (elf_abi == "n32")
609 else if (elf_abi == "o32")
611 }
612 SetFlags(flag);
613}
614
615std::string ArchSpec::GetClangTargetCPU() const {
616 std::string cpu;
617 if (IsMIPS()) {
618 switch (m_core) {
621 cpu = "mips32";
622 break;
625 cpu = "mips32r2";
626 break;
629 cpu = "mips32r3";
630 break;
633 cpu = "mips32r5";
634 break;
637 cpu = "mips32r6";
638 break;
641 cpu = "mips64";
642 break;
645 cpu = "mips64r2";
646 break;
649 cpu = "mips64r3";
650 break;
653 cpu = "mips64r5";
654 break;
657 cpu = "mips64r6";
658 break;
659 default:
660 break;
661 }
662 }
663
664 if (GetTriple().isARM())
665 cpu = llvm::ARM::getARMCPUForArch(GetTriple(), "").str();
666
667 if (GetTriple().getArch() == llvm::Triple::amdgpu)
668 cpu = llvm::AMDGPU::getArchNameFromSubArch(GetTriple().getSubArch());
669 return cpu;
670}
671
672static const ArchDefinitionEntry *
674 if (const CoreDefinition *core_def = FindCoreDefinition(core))
675 return FindArchDefinitionEntry(def, core_def->core);
676
677 return nullptr;
678}
679
680static uint32_t GetCPUType(const ArchDefinition *def, ArchSpec::Core core) {
681 if (const ArchDefinitionEntry *arch_def =
683 return arch_def->cpu;
685}
686
687static uint32_t GetCPUSubType(const ArchDefinition *def, ArchSpec::Core core) {
688 if (const ArchDefinitionEntry *arch_def =
690 return arch_def->sub;
692}
693
696}
697
701
702llvm::Triple::ArchType ArchSpec::GetMachine() const {
703 const CoreDefinition *core_def = FindCoreDefinition(m_core);
704 if (core_def)
705 return core_def->machine;
706
707 return llvm::Triple::UnknownArch;
708}
709
711 const CoreDefinition *core_def = FindCoreDefinition(m_core);
712 if (core_def) {
713 if (core_def->machine == llvm::Triple::mips64 ||
714 core_def->machine == llvm::Triple::mips64el) {
715 // For N32/O32 applications Address size is 4 bytes.
717 return 4;
718 }
719 return core_def->addr_byte_size;
720 }
721 return 0;
722}
723
725 const CoreDefinition *core_def = FindCoreDefinition(m_core);
726 if (core_def)
727 return core_def->default_byte_order;
728 return eByteOrderInvalid;
729}
730
732 switch (m_triple.getArch()) {
733 default:
734 return true;
735
736 case llvm::Triple::aarch64:
737 case llvm::Triple::aarch64_32:
738 case llvm::Triple::aarch64_be:
739 case llvm::Triple::arm:
740 case llvm::Triple::armeb:
741 case llvm::Triple::thumb:
742 case llvm::Triple::thumbeb:
743 return m_triple.isOSDarwin() || m_triple.isOSWindows();
744
745 case llvm::Triple::ppc:
746 case llvm::Triple::ppc64:
747 return m_triple.isOSDarwin();
748
749 case llvm::Triple::riscv64:
750 case llvm::Triple::riscv32:
751 case llvm::Triple::ppc64le:
752 case llvm::Triple::systemz:
753 case llvm::Triple::xcore:
754 case llvm::Triple::arc:
755 return false;
756 }
757}
758
764
765//===----------------------------------------------------------------------===//
766// Mutators.
767
768bool ArchSpec::SetTriple(const llvm::Triple &triple) {
769 m_triple = triple;
770 UpdateCore();
771 return IsValid();
772}
773
774bool lldb_private::ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str,
775 ArchSpec &arch) {
776 // Accept "12-10" or "12.10" as cpu type/subtype
777 if (triple_str.empty())
778 return false;
779
780 size_t pos = triple_str.find_first_of("-.");
781 if (pos == llvm::StringRef::npos)
782 return false;
783
784 llvm::StringRef cpu_str = triple_str.substr(0, pos);
785 llvm::StringRef remainder = triple_str.substr(pos + 1);
786 if (cpu_str.empty() || remainder.empty())
787 return false;
788
789 llvm::StringRef sub_str;
790 llvm::StringRef vendor;
791 llvm::StringRef os;
792 std::tie(sub_str, remainder) = remainder.split('-');
793 std::tie(vendor, os) = remainder.split('-');
794
795 uint32_t cpu = 0;
796 uint32_t sub = 0;
797 if (cpu_str.getAsInteger(10, cpu) || sub_str.getAsInteger(10, sub))
798 return false;
799
800 if (!arch.SetArchitecture(eArchTypeMachO, cpu, sub))
801 return false;
802 if (!vendor.empty() && !os.empty()) {
803 arch.GetTriple().setVendorName(vendor);
804 arch.GetTriple().setOSName(os);
805 }
806
807 return true;
808}
809
810bool ArchSpec::SetTriple(llvm::StringRef triple) {
811 if (triple.empty()) {
812 Clear();
813 return false;
814 }
815
816 if (ParseMachCPUDashSubtypeTriple(triple, *this))
817 return true;
818
819 llvm::Triple normalized(llvm::Triple::normalize(triple));
820 // Clang offload target IDs append the GPU and its features to a four-part
821 // triple. Rebuild the triple without that suffix and represent the GPU as its
822 // subarchitecture. For example, "amdgcn-amd-amdhsa--gfx942" becomes
823 // "amdgpu9.42-amd-amdhsa".
824 if (std::optional<llvm::AMDGPU::TargetID> target_id =
825 llvm::AMDGPU::TargetID::parseTargetIDString(triple)) {
826 llvm::Triple base(target_id->getTargetTripleString());
827 normalized = llvm::Triple(llvm::Triple::amdgpu,
828 llvm::AMDGPU::getSubArch(target_id->getGPUKind()),
829 base.getVendor(), base.getOS());
830 }
831 SetTriple(normalized);
832 return IsValid();
833}
834
835bool ArchSpec::ContainsOnlyArch(const llvm::Triple &normalized_triple) {
836 return !normalized_triple.getArchName().empty() &&
837 normalized_triple.getOSName().empty() &&
838 normalized_triple.getVendorName().empty() &&
839 normalized_triple.getEnvironmentName().empty();
840}
841
842void ArchSpec::MergeFrom(const ArchSpec &other) {
843 // ios-macabi always wins over macosx.
844 if ((GetTriple().getOS() == llvm::Triple::MacOSX ||
845 GetTriple().getOS() == llvm::Triple::UnknownOS) &&
846 other.GetTriple().getOS() == llvm::Triple::IOS &&
847 other.GetTriple().getEnvironment() == llvm::Triple::MacABI) {
848 (*this) = other;
849 return;
850 }
851
853 GetTriple().setVendor(other.GetTriple().getVendor());
855 GetTriple().setOS(other.GetTriple().getOS());
856 if (GetTriple().getArch() == llvm::Triple::UnknownArch) {
857 GetTriple().setArch(other.GetTriple().getArch());
858
859 // MachO unknown64 isn't really invalid as the debugger can still obtain
860 // information from the binary, e.g. line tables. As such, we don't update
861 // the core here.
862 if (other.GetCore() != eCore_uknownMach64)
863 UpdateCore();
864 }
865 // AMDGPU models share one LLDB core, so merge their triple subarchitectures
866 // explicitly. Keep this ArchSpec's platform fields in the comparison triple
867 // because they are handled separately in this function.
868 if (GetTriple().getArch() == llvm::Triple::amdgpu &&
869 other.GetTriple().getArch() == llvm::Triple::amdgpu) {
870 llvm::Triple other_arch = GetTriple();
871 other_arch.setArch(other.GetTriple().getArch(),
872 other.GetTriple().getSubArch());
873 // Use this triple as the right-hand operand so an incompatible merge
874 // leaves it unchanged.
875 llvm::Triple merged(other_arch.merge(GetTriple()));
876 GetTriple().setArch(merged.getArch(), merged.getSubArch());
877 }
880 GetTriple().setEnvironment(other.GetTriple().getEnvironment());
881 }
882 // If this and other are both arm ArchSpecs and this ArchSpec is a generic
883 // "some kind of arm" spec but the other ArchSpec is a specific arm core,
884 // adopt the specific arm core.
885 if (GetTriple().getArch() == llvm::Triple::arm &&
886 other.GetTriple().getArch() == llvm::Triple::arm &&
889 m_core = other.GetCore();
890 CoreUpdated(false);
891 }
892 if (GetFlags() == 0) {
893 SetFlags(other.GetFlags());
894 }
895}
896
897static llvm::StringRef GetAMDGPUVariantName(uint32_t sub) {
898 switch (sub) {
899#define X(NUM, ENUM, NAME) \
900 case llvm::ELF::ENUM: \
901 return NAME;
902 AMDGPU_MACH_LIST(X)
903#undef X
904 default:
905 return {};
906 }
907}
908
909bool ArchSpec::SetArchitecture(ArchitectureType arch_type, uint32_t cpu,
910 uint32_t sub, uint32_t os) {
912 bool update_triple = true;
913 const ArchDefinition *arch_def = FindArchDefinition(arch_type);
914 if (arch_def) {
915 const ArchDefinitionEntry *arch_def_entry =
916 FindArchDefinitionEntry(arch_def, cpu, sub);
917 if (arch_def_entry) {
918 const CoreDefinition *core_def = FindCoreDefinition(arch_def_entry->core);
919 if (core_def) {
920 m_core = core_def->core;
921 update_triple = false;
922 // Always use the architecture name because it might be more
923 // descriptive than the architecture enum ("armv7" ->
924 // llvm::Triple::arm).
925 m_triple.setArchName(llvm::StringRef(core_def->name));
926 if (arch_type == eArchTypeMachO) {
927 m_triple.setVendor(llvm::Triple::Apple);
928
929 // Don't set the OS. It could be simulator, macosx, ios, watchos,
930 // tvos, bridgeos. We could get close with the cpu type - but we
931 // can't get it right all of the time. Better to leave this unset
932 // so other sections of code will set it when they have more
933 // information. NB: don't call m_triple.setOS
934 // (llvm::Triple::UnknownOS). That sets the OSName to "unknown" and
935 // the ArchSpec::TripleVendorWasSpecified() method says that any
936 // OSName setting means it was specified.
937 } else if (arch_type == eArchTypeELF) {
938 switch (os) {
939 case llvm::ELF::ELFOSABI_AIX:
940 m_triple.setOS(llvm::Triple::OSType::AIX);
941 break;
942 case llvm::ELF::ELFOSABI_FREEBSD:
943 m_triple.setOS(llvm::Triple::OSType::FreeBSD);
944 break;
945 case llvm::ELF::ELFOSABI_GNU:
946 m_triple.setOS(llvm::Triple::OSType::Linux);
947 break;
948 case llvm::ELF::ELFOSABI_NETBSD:
949 m_triple.setOS(llvm::Triple::OSType::NetBSD);
950 break;
951 case llvm::ELF::ELFOSABI_OPENBSD:
952 m_triple.setOS(llvm::Triple::OSType::OpenBSD);
953 break;
954 case llvm::ELF::ELFOSABI_SOLARIS:
955 m_triple.setOS(llvm::Triple::OSType::Solaris);
956 break;
957 case llvm::ELF::ELFOSABI_STANDALONE:
958 m_triple.setOS(llvm::Triple::OSType::UnknownOS);
959 break;
960 case llvm::ELF::ELFOSABI_AMDGPU_HSA:
961 m_triple.setVendor(llvm::Triple::VendorType::AMD);
962 m_triple.setOS(llvm::Triple::OSType::AMDHSA);
963 break;
964 }
965 } else if (arch_type == eArchTypeCOFF && os == llvm::Triple::Win32) {
966 m_triple.setVendor(llvm::Triple::PC);
967 m_triple.setOS(llvm::Triple::Win32);
968 } else if (arch_type == eArchTypeXCOFF && os == llvm::Triple::AIX) {
969 m_triple.setVendor(llvm::Triple::IBM);
970 m_triple.setOS(llvm::Triple::AIX);
971 } else {
972 m_triple.setVendor(llvm::Triple::UnknownVendor);
973 m_triple.setOS(llvm::Triple::UnknownOS);
974 }
975 switch (m_triple.getArch()) {
976 case llvm::Triple::UnknownArch:
977 // Fall back onto setting the machine type if the arch by name
978 // failed...
979 m_triple.setArch(core_def->machine);
980 break;
981 case llvm::Triple::amdgpu: {
982 llvm::StringRef gpu = GetAMDGPUVariantName(sub);
983 if (!gpu.empty()) {
984 llvm::Triple::SubArchType sub_arch =
985 llvm::AMDGPU::getSubArchFromGPUName(gpu);
986 if (sub_arch == llvm::Triple::NoSubArch) {
987 Clear();
988 return false;
989 }
990 m_triple.setArch(llvm::Triple::amdgpu, sub_arch);
991 }
992 break;
993 }
994 default:
995 break;
996 }
997 }
998 } else {
1000 LLDB_LOGF(log,
1001 "Unable to find a core definition for cpu 0x%" PRIx32
1002 " sub %" PRId32,
1003 cpu, sub);
1004 }
1005 }
1006 CoreUpdated(update_triple);
1007 return IsValid();
1008}
1009
1011 const CoreDefinition *core_def = FindCoreDefinition(m_core);
1012 if (core_def)
1013 return core_def->min_opcode_byte_size;
1014 return 0;
1015}
1016
1018 const CoreDefinition *core_def = FindCoreDefinition(m_core);
1019 if (core_def)
1020 return core_def->max_opcode_byte_size;
1021 return 0;
1022}
1023
1024static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
1025 llvm::Triple::EnvironmentType rhs) {
1026 if (lhs == rhs)
1027 return true;
1028
1029 // Apple simulators are a different platform than what they simulate.
1030 // As the environments are different at this point, if one of them is a
1031 // simulator, then they are different.
1032 if (lhs == llvm::Triple::Simulator || rhs == llvm::Triple::Simulator)
1033 return false;
1034
1035 // If any of the environment is unknown then they are compatible
1036 if (lhs == llvm::Triple::UnknownEnvironment ||
1037 rhs == llvm::Triple::UnknownEnvironment)
1038 return true;
1039
1040 // If one of the environment is Android and the other one is EABI then they
1041 // are considered to be compatible. This is required as a workaround for
1042 // shared libraries compiled for Android without the NOTE section indicating
1043 // that they are using the Android ABI.
1044 if ((lhs == llvm::Triple::Android && rhs == llvm::Triple::EABI) ||
1045 (rhs == llvm::Triple::Android && lhs == llvm::Triple::EABI) ||
1046 (lhs == llvm::Triple::GNUEABI && rhs == llvm::Triple::EABI) ||
1047 (rhs == llvm::Triple::GNUEABI && lhs == llvm::Triple::EABI) ||
1048 (lhs == llvm::Triple::GNUEABIHF && rhs == llvm::Triple::EABIHF) ||
1049 (rhs == llvm::Triple::GNUEABIHF && lhs == llvm::Triple::EABIHF))
1050 return true;
1051
1052 return false;
1053}
1054
1055bool ArchSpec::IsMatch(const ArchSpec &rhs, MatchType match) const {
1056 if (GetByteOrder() != rhs.GetByteOrder() ||
1057 !cores_match(GetCore(), rhs.GetCore(), match == ExactMatch))
1058 return false;
1059
1060 const llvm::Triple &lhs_triple = GetTriple();
1061 const llvm::Triple &rhs_triple = rhs.GetTriple();
1062
1063 // AMDGPU models share one LLDB core, so compare their triple
1064 // subarchitectures explicitly. Keep the LHS platform fields in the
1065 // comparison triple because ArchSpec compares them separately below.
1066 if (lhs_triple.getArch() == llvm::Triple::amdgpu &&
1067 rhs_triple.getArch() == llvm::Triple::amdgpu) {
1068 llvm::Triple rhs_arch = lhs_triple;
1069 rhs_arch.setArch(rhs_triple.getArch(), rhs_triple.getSubArch());
1070 bool sub_arches_match =
1071 match == ExactMatch ? lhs_triple.getSubArch() == rhs_triple.getSubArch()
1072 : lhs_triple.isCompatibleWith(rhs_arch);
1073 if (!sub_arches_match)
1074 return false;
1075 }
1076
1077 const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
1078 const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
1079
1080 const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
1081 const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
1082
1083 bool both_windows = lhs_triple.isOSWindows() && rhs_triple.isOSWindows();
1084
1085 // On Windows, the vendor field doesn't have any practical effect, but
1086 // it is often set to either "pc" or "w64".
1087 if ((lhs_triple_vendor != rhs_triple_vendor) &&
1088 (match == ExactMatch || !both_windows)) {
1089 const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
1090 const bool lhs_vendor_specified = TripleVendorWasSpecified();
1091 // Both architectures had the vendor specified, so if they aren't equal
1092 // then we return false
1093 if (rhs_vendor_specified && lhs_vendor_specified)
1094 return false;
1095
1096 // Only fail if both vendor types are not unknown
1097 if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
1098 rhs_triple_vendor != llvm::Triple::UnknownVendor)
1099 return false;
1100 }
1101
1102 const llvm::Triple::EnvironmentType lhs_triple_env =
1103 lhs_triple.getEnvironment();
1104 const llvm::Triple::EnvironmentType rhs_triple_env =
1105 rhs_triple.getEnvironment();
1106
1107 if (match == CompatibleMatch) {
1108 // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match.
1109 if ((lhs_triple_os == llvm::Triple::IOS &&
1110 lhs_triple_env == llvm::Triple::MacABI &&
1111 rhs_triple_os == llvm::Triple::MacOSX) ||
1112 (lhs_triple_os == llvm::Triple::MacOSX &&
1113 rhs_triple_os == llvm::Triple::IOS &&
1114 rhs_triple_env == llvm::Triple::MacABI))
1115 return true;
1116 // x86_64-apple-driverkit, x86_64-apple-macosx are compatible, no match.
1117 if ((lhs_triple_os == llvm::Triple::DriverKit &&
1118 rhs_triple_os == llvm::Triple::MacOSX) ||
1119 (lhs_triple_os == llvm::Triple::MacOSX &&
1120 rhs_triple_os == llvm::Triple::DriverKit))
1121 return true;
1122 }
1123
1124 // x86_64-apple-ios-macabi and x86_64-apple-ios are not compatible.
1125 if (lhs_triple_os == llvm::Triple::IOS &&
1126 rhs_triple_os == llvm::Triple::IOS &&
1127 (lhs_triple_env == llvm::Triple::MacABI ||
1128 rhs_triple_env == llvm::Triple::MacABI) &&
1129 lhs_triple_env != rhs_triple_env)
1130 return false;
1131
1132 if (lhs_triple_os != rhs_triple_os) {
1133 const bool lhs_os_specified = TripleOSWasSpecified();
1134 const bool rhs_os_specified = rhs.TripleOSWasSpecified();
1135 // If both OS types are specified and different, fail.
1136 if (lhs_os_specified && rhs_os_specified)
1137 return false;
1138
1139 // If the pair of os+env is both unspecified, match any other os+env combo.
1140 if (match == CompatibleMatch &&
1141 ((!lhs_os_specified && !lhs_triple.hasEnvironment()) ||
1142 (!rhs_os_specified && !rhs_triple.hasEnvironment())))
1143 return true;
1144 }
1145
1146 if (match == CompatibleMatch && both_windows)
1147 return true; // The Windows environments (MSVC vs GNU) are compatible
1148
1149 return IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env);
1150}
1151
1153 const CoreDefinition *core_def;
1154 // AMDGPU subarchitectures have distinct architecture names (for example,
1155 // "amdgpu9.42"), but all share the generic LLDB AMDGPU core definition.
1156 if (m_triple.getArch() == llvm::Triple::amdgpu) {
1158 } else {
1159 core_def = FindCoreDefinition(m_triple.getArchName());
1160 }
1161
1162 if (core_def) {
1163 m_core = core_def->core;
1164 // Set the byte order to the default byte order for an architecture. This
1165 // can be modified if needed for cases when cores handle both big and
1166 // little endian
1167 m_byte_order = core_def->default_byte_order;
1168 } else {
1169 Clear();
1170 }
1171}
1172
1173//===----------------------------------------------------------------------===//
1174// Helper methods.
1175
1176void ArchSpec::CoreUpdated(bool update_triple) {
1177 const CoreDefinition *core_def = FindCoreDefinition(m_core);
1178 if (core_def) {
1179 if (update_triple)
1180 m_triple = llvm::Triple(core_def->name, "unknown", "unknown");
1181 m_byte_order = core_def->default_byte_order;
1182 } else {
1183 if (update_triple)
1184 m_triple = llvm::Triple();
1186 }
1187}
1188
1189//===----------------------------------------------------------------------===//
1190// Operators.
1191
1192// Checks core1's rules only, because they are not symmetric. Must not call
1193// cores_match() here, or an unmatched pair would loop between the two
1194// directions forever.
1196 const ArchSpec::Core core2,
1197 bool enforce_exact_match) {
1198 switch (core1) {
1200 return true;
1201
1203 if (enforce_exact_match)
1204 break;
1205 [[fallthrough]];
1207 if (core2 >= ArchSpec::kCore_arm_first && core2 <= ArchSpec::kCore_arm_last)
1208 return true;
1209 if (core2 >= ArchSpec::kCore_thumb_first &&
1211 return true;
1212 if (core2 == ArchSpec::kCore_arm_any)
1213 return true;
1214 break;
1215
1217 if ((core2 >= ArchSpec::kCore_x86_32_first &&
1218 core2 <= ArchSpec::kCore_x86_32_last) ||
1219 (core2 == ArchSpec::kCore_x86_32_any))
1220 return true;
1221 break;
1222
1224 if ((core2 >= ArchSpec::kCore_x86_64_first &&
1225 core2 <= ArchSpec::kCore_x86_64_last) ||
1226 (core2 == ArchSpec::kCore_x86_64_any))
1227 return true;
1228 break;
1229
1231 if ((core2 >= ArchSpec::kCore_ppc_first &&
1232 core2 <= ArchSpec::kCore_ppc_last) ||
1233 (core2 == ArchSpec::kCore_ppc_any))
1234 return true;
1235 break;
1236
1238 if ((core2 >= ArchSpec::kCore_ppc64_first &&
1239 core2 <= ArchSpec::kCore_ppc64_last) ||
1240 (core2 == ArchSpec::kCore_ppc64_any))
1241 return true;
1242 break;
1243
1245 if ((core2 >= ArchSpec::kCore_hexagon_first &&
1246 core2 <= ArchSpec::kCore_hexagon_last) ||
1247 (core2 == ArchSpec::kCore_hexagon_any))
1248 return true;
1249 break;
1250
1251 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1252 // Cortex-M0 - ARMv6-M - armv6m
1253 // Cortex-M3 - ARMv7-M - armv7m
1254 // Cortex-M4 - ARMv7E-M - armv7em
1256 if (!enforce_exact_match) {
1257 if (core2 == ArchSpec::eCore_arm_generic)
1258 return true;
1259 if (core2 == ArchSpec::eCore_arm_armv7m)
1260 return true;
1261 if (core2 == ArchSpec::eCore_arm_armv6m)
1262 return true;
1263 if (core2 == ArchSpec::eCore_arm_armv7)
1264 return true;
1265 }
1266 break;
1267
1268 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1269 // Cortex-M0 - ARMv6-M - armv6m
1270 // Cortex-M3 - ARMv7-M - armv7m
1271 // Cortex-M4 - ARMv7E-M - armv7em
1273 if (!enforce_exact_match) {
1274 if (core2 == ArchSpec::eCore_arm_generic)
1275 return true;
1276 if (core2 == ArchSpec::eCore_arm_armv6m)
1277 return true;
1278 if (core2 == ArchSpec::eCore_arm_armv7)
1279 return true;
1280 if (core2 == ArchSpec::eCore_arm_armv7em)
1281 return true;
1282 }
1283 break;
1284
1285 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M#Silicon_customization
1286 // Cortex-M0 - ARMv6-M - armv6m
1287 // Cortex-M3 - ARMv7-M - armv7m
1288 // Cortex-M4 - ARMv7E-M - armv7em
1290 if (!enforce_exact_match) {
1291 if (core2 == ArchSpec::eCore_arm_generic)
1292 return true;
1293 if (core2 == ArchSpec::eCore_arm_armv7em)
1294 return true;
1295 if (core2 == ArchSpec::eCore_arm_armv7)
1296 return true;
1297 if (core2 == ArchSpec::eCore_arm_armv6m)
1298 return true;
1299 }
1300 break;
1301
1307 if (!enforce_exact_match) {
1308 if (core2 == ArchSpec::eCore_arm_generic)
1309 return true;
1310 if (core2 == ArchSpec::eCore_arm_armv7)
1311 return true;
1312 }
1313 break;
1314
1317 if (!enforce_exact_match) {
1318 if (core2 == ArchSpec::eCore_x86_64_x86_64)
1319 return true;
1320 }
1321 break;
1322
1324 if (!enforce_exact_match) {
1325 if (core2 == ArchSpec::eCore_arm_arm64)
1326 return true;
1327 if (core2 == ArchSpec::eCore_arm_aarch64)
1328 return true;
1329 if (core2 == ArchSpec::eCore_arm_arm64e)
1330 return true;
1331 if (core2 == ArchSpec::eCore_arm_arm64ex1)
1332 return true;
1333 }
1334 break;
1335
1337 if (!enforce_exact_match) {
1338 if (core2 == ArchSpec::eCore_arm_arm64)
1339 return true;
1340 if (core2 == ArchSpec::eCore_arm_aarch64)
1341 return true;
1342 if (core2 == ArchSpec::eCore_arm_armv8)
1343 return true;
1344 if (core2 == ArchSpec::eCore_arm_arm64ex1)
1345 return true;
1346 }
1347 break;
1349 if (!enforce_exact_match) {
1350 if (core2 == ArchSpec::eCore_arm_arm64)
1351 return true;
1352 if (core2 == ArchSpec::eCore_arm_armv8)
1353 return true;
1354 if (core2 == ArchSpec::eCore_arm_arm64e)
1355 return true;
1356 if (core2 == ArchSpec::eCore_arm_arm64ex1)
1357 return true;
1358 }
1359 break;
1360
1362 if (!enforce_exact_match) {
1363 if (core2 == ArchSpec::eCore_arm_aarch64)
1364 return true;
1365 if (core2 == ArchSpec::eCore_arm_armv8)
1366 return true;
1367 if (core2 == ArchSpec::eCore_arm_arm64e)
1368 return true;
1369 if (core2 == ArchSpec::eCore_arm_arm64ex1)
1370 return true;
1371 }
1372 break;
1373
1375 if (!enforce_exact_match) {
1376 if (core2 == ArchSpec::eCore_arm_arm64e)
1377 return true;
1378 if (core2 == ArchSpec::eCore_arm_arm64)
1379 return true;
1380 if (core2 == ArchSpec::eCore_arm_aarch64)
1381 return true;
1382 if (core2 == ArchSpec::eCore_arm_armv8)
1383 return true;
1384 }
1385 break;
1386
1388 if (!enforce_exact_match) {
1389 if (core2 == ArchSpec::eCore_arm_generic)
1390 return true;
1391 }
1392 break;
1393
1395 if (!enforce_exact_match) {
1396 if (core2 >= ArchSpec::kCore_mips32_first &&
1398 return true;
1399 }
1400 break;
1401
1403 if (!enforce_exact_match) {
1404 if (core2 >= ArchSpec::kCore_mips32el_first &&
1406 return true;
1407 }
1408 break;
1409
1411 if (!enforce_exact_match) {
1412 if (core2 >= ArchSpec::kCore_mips32_first &&
1414 return true;
1415 if (core2 >= ArchSpec::kCore_mips64_first &&
1417 return true;
1418 }
1419 break;
1420
1422 if (!enforce_exact_match) {
1423 if (core2 >= ArchSpec::kCore_mips32el_first &&
1425 return true;
1426 if (core2 >= ArchSpec::kCore_mips64el_first &&
1428 return true;
1429 }
1430 break;
1431
1435 if (!enforce_exact_match) {
1436 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= (core1 - 10))
1437 return true;
1438 if (core2 >= ArchSpec::kCore_mips64_first && core2 <= (core1 - 1))
1439 return true;
1440 }
1441 break;
1442
1446 if (!enforce_exact_match) {
1447 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= (core1 - 10))
1448 return true;
1449 if (core2 >= ArchSpec::kCore_mips64el_first && core2 <= (core1 - 1))
1450 return true;
1451 }
1452 break;
1453
1457 if (!enforce_exact_match) {
1458 if (core2 >= ArchSpec::kCore_mips32_first && core2 <= core1)
1459 return true;
1460 }
1461 break;
1462
1466 if (!enforce_exact_match) {
1467 if (core2 >= ArchSpec::kCore_mips32el_first && core2 <= core1)
1468 return true;
1469 }
1470 break;
1471
1473 if (!enforce_exact_match) {
1474 if (core2 == ArchSpec::eCore_mips32 || core2 == ArchSpec::eCore_mips32r6)
1475 return true;
1476 }
1477 break;
1478
1480 if (!enforce_exact_match) {
1481 if (core2 == ArchSpec::eCore_mips32el ||
1483 return true;
1484 }
1485 break;
1486
1488 if (!enforce_exact_match) {
1489 if (core2 == ArchSpec::eCore_mips32 || core2 == ArchSpec::eCore_mips32r6)
1490 return true;
1491 if (core2 == ArchSpec::eCore_mips64 || core2 == ArchSpec::eCore_mips64r6)
1492 return true;
1493 }
1494 break;
1495
1497 if (!enforce_exact_match) {
1498 if (core2 == ArchSpec::eCore_mips32el ||
1500 return true;
1501 if (core2 == ArchSpec::eCore_mips64el ||
1503 return true;
1504 }
1505 break;
1506
1507 default:
1508 break;
1509 }
1510 return false;
1511}
1512
1513// The match rules only work in one direction, so this checks both ways.
1514static bool cores_match(const ArchSpec::Core core1, const ArchSpec::Core core2,
1515 bool enforce_exact_match) {
1516 if (core1 == core2)
1517 return true;
1518 return cores_match_one_direction(core1, core2, enforce_exact_match) ||
1519 cores_match_one_direction(core2, core1, enforce_exact_match);
1520}
1521
1522bool lldb_private::operator<(const ArchSpec &lhs, const ArchSpec &rhs) {
1523 const ArchSpec::Core lhs_core = lhs.GetCore();
1524 const ArchSpec::Core rhs_core = rhs.GetCore();
1525 if (lhs_core == rhs_core && lhs_core == ArchSpec::eCore_amd_gpu)
1526 return lhs.GetTriple().getSubArch() < rhs.GetTriple().getSubArch();
1527 return lhs_core < rhs_core;
1528}
1529
1530bool lldb_private::operator==(const ArchSpec &lhs, const ArchSpec &rhs) {
1531 if (lhs.GetCore() != rhs.GetCore())
1532 return false;
1533 return lhs.GetCore() != ArchSpec::eCore_amd_gpu ||
1534 lhs.GetTriple().getSubArch() == rhs.GetTriple().getSubArch();
1535}
1536
1537bool lldb_private::operator!=(const ArchSpec &lhs, const ArchSpec &rhs) {
1538 return !(lhs == rhs);
1539}
1540
1542 if (!TripleOSWasSpecified())
1543 return false;
1544
1546 return false;
1547
1548 const unsigned unspecified = 0;
1549 const llvm::Triple &triple = GetTriple();
1550 if (triple.isOSDarwin() && triple.getOSMajorVersion() == unspecified)
1551 return false;
1552
1553 return true;
1554}
1555
1557 if (GetTriple().getArch() == llvm::Triple::arm ||
1558 GetTriple().getArch() == llvm::Triple::thumb) {
1559 // v. https://en.wikipedia.org/wiki/ARM_Cortex-M
1560 //
1561 // Cortex-M0 through Cortex-M7 are ARM processor cores which can only
1562 // execute thumb instructions. We map the cores to arch names like this:
1563 //
1564 // Cortex-M0, Cortex-M0+, Cortex-M1: armv6m Cortex-M3: armv7m Cortex-M4,
1565 // Cortex-M7: armv7em
1566
1573 return true;
1574 }
1575 // Windows on ARM is always thumb.
1576 if (GetTriple().isOSWindows())
1577 return true;
1578 }
1579 return false;
1580}
1581
1582void ArchSpec::DumpTriple(llvm::raw_ostream &s) const {
1583 const llvm::Triple &triple = GetTriple();
1584 llvm::StringRef arch_str = triple.getArchName();
1585 llvm::StringRef vendor_str = triple.getVendorName();
1586 llvm::StringRef os_str = triple.getOSName();
1587 llvm::StringRef environ_str = triple.getEnvironmentName();
1588
1589 s << llvm::formatv("{0}-{1}-{2}", arch_str.empty() ? "*" : arch_str,
1590 vendor_str.empty() ? "*" : vendor_str,
1591 os_str.empty() ? "*" : os_str);
1592
1593 if (!environ_str.empty())
1594 s << "-" << environ_str;
1595}
static uint32_t GetCPUType(const ArchDefinition *def, ArchSpec::Core core)
Definition ArchSpec.cpp:680
#define SUBTYPE_MASK
Definition ArchSpec.cpp:312
static const ArchDefinition g_elf_arch_def
Definition ArchSpec.cpp:436
static const CoreDefinition * FindCoreDefinition(llvm::StringRef name)
Definition ArchSpec.cpp:494
static const ArchDefinitionEntry * FindArchDefEntryIfCoreIsValid(const ArchDefinition *def, ArchSpec::Core core)
Definition ArchSpec.cpp:673
static const ArchDefinitionEntry * FindArchDefinitionEntry(const ArchDefinition *def, uint32_t cpu, uint32_t sub)
Definition ArchSpec.cpp:510
static uint32_t GetCPUSubType(const ArchDefinition *def, ArchSpec::Core core)
Definition ArchSpec.cpp:687
static const ArchDefinitionEntry g_macho_arch_entries[]
Definition ArchSpec.cpp:315
static const ArchDefinitionEntry g_xcoff_arch_entries[]
Definition ArchSpec.cpp:463
static const ArchDefinitionEntry g_coff_arch_entries[]
Definition ArchSpec.cpp:443
static const ArchDefinitionEntry g_elf_arch_entries[]
Definition ArchSpec.cpp:398
static const ArchDefinition * FindArchDefinition(ArchitectureType arch_type)
Definition ArchSpec.cpp:485
static llvm::StringRef GetAMDGPUVariantName(uint32_t sub)
Definition ArchSpec.cpp:897
static bool cores_match_one_direction(const ArchSpec::Core core1, const ArchSpec::Core core2, bool enforce_exact_match)
#define CPU_ANY
Definition ArchSpec.cpp:305
static const ArchDefinition g_xcoff_arch_def
Definition ArchSpec.cpp:469
static constexpr const CoreDefinition g_core_definitions[]
Definition ArchSpec.cpp:45
#define X(NUM, ENUM, NAME)
static const ArchDefinition * g_arch_definitions[]
Definition ArchSpec.cpp:478
static bool cores_match(const ArchSpec::Core core1, const ArchSpec::Core core2, bool enforce_exact_match)
static const ArchDefinition g_coff_arch_def
Definition ArchSpec.cpp:455
static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs, llvm::Triple::EnvironmentType rhs)
static const ArchDefinition g_macho_arch_def
Definition ArchSpec.cpp:388
#define LLDB_LOGF(log,...)
Definition Log.h:389
An architecture specification class.
Definition ArchSpec.h:32
static void ListSupportedArchNames(StringList &list)
Definition ArchSpec.cpp:295
bool IsFullySpecifiedTriple() const
bool IsNVPTX() const
If NVPTX architecture return true.
Definition ArchSpec.cpp:577
static void AutoComplete(CompletionRequest &request)
Definition ArchSpec.cpp:300
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:710
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:375
void Clear()
Clears the object state.
Definition ArchSpec.cpp:558
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:465
void SetFlags(uint32_t flags)
Definition ArchSpec.h:538
bool IsAlwaysThumbInstructions() const
Detect whether this architecture uses thumb code exclusively.
bool TripleEnvironmentWasSpecified() const
Definition ArchSpec.h:386
bool IsMatch(const ArchSpec &rhs, MatchType match) const
Compare this ArchSpec to another ArchSpec.
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition ArchSpec.cpp:768
llvm::Triple m_triple
Definition ArchSpec.h:553
lldb::ByteOrder GetDefaultEndian() const
Returns the default endianness of the architecture.
Definition ArchSpec.cpp:724
lldb::ByteOrder m_byte_order
Definition ArchSpec.h:555
~ArchSpec()
Destructor.
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
Definition ArchSpec.cpp:909
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition ArchSpec.cpp:842
void DumpTriple(llvm::raw_ostream &s) const
uint32_t GetMachOCPUSubType() const
Definition ArchSpec.cpp:698
void CoreUpdated(bool update_triple)
bool IsMIPS() const
if MIPS architecture return true.
Definition ArchSpec.cpp:575
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
Definition ArchSpec.h:517
bool CharIsSignedByDefault() const
Returns true if 'char' is a signed type by default in the architecture false otherwise.
Definition ArchSpec.cpp:731
ArchSpec()
Default constructor.
uint32_t GetMachOCPUType() const
Definition ArchSpec.cpp:694
std::string GetTargetABI() const
Return a string representing target application ABI.
Definition ArchSpec.cpp:579
uint32_t GetMinimumOpcodeByteSize() const
uint32_t GetFlags() const
Definition ArchSpec.h:536
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition ArchSpec.cpp:759
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:702
std::string GetClangTargetCPU() const
Returns a string representing current architecture as a target CPU for tools like compiler,...
Definition ArchSpec.cpp:615
uint32_t GetMaximumOpcodeByteSize() const
bool TripleVendorWasSpecified() const
Definition ArchSpec.h:380
Core GetCore() const
Definition ArchSpec.h:456
bool TripleOSWasSpecified() const
Definition ArchSpec.h:384
static bool ContainsOnlyArch(const llvm::Triple &normalized_triple)
Returns true if the OS, vendor and environment fields of the triple are unset.
Definition ArchSpec.cpp:835
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:568
"lldb/Utility/ArgCompletionRequest.h"
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
void AppendString(const std::string &s)
#define LLDB_INVALID_CPUTYPE
#define UINT32_MAX
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch)
Definition ArchSpec.cpp:774
bool operator!=(const Address &lhs, const Address &rhs)
Definition Address.cpp:1011
TableValidator< 0 > validator
bool operator==(const Address &lhs, const Address &rhs)
Definition Address.cpp:1005
bool operator<(const Address &lhs, const Address &rhs)
Definition Address.cpp:974
ByteOrder
Byte ordering definitions.
ArchSpec::Core core
Definition ArchSpec.cpp:281
ArchitectureType type
Definition ArchSpec.cpp:289
const ArchDefinitionEntry * entries
Definition ArchSpec.cpp:291
size_t num_entries
Definition ArchSpec.cpp:290
const char * name
Definition ArchSpec.cpp:292
llvm::Triple::ArchType machine
Definition ArchSpec.cpp:37
const char *const name
Definition ArchSpec.cpp:39