/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/TargetInfo.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- TargetInfo.cpp - Information about Target machine ----------------===// |
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 | | // |
9 | | // This file implements the TargetInfo and TargetInfoImpl interfaces. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/Basic/TargetInfo.h" |
14 | | #include "clang/Basic/AddressSpaces.h" |
15 | | #include "clang/Basic/CharInfo.h" |
16 | | #include "clang/Basic/Diagnostic.h" |
17 | | #include "clang/Basic/LangOptions.h" |
18 | | #include "llvm/ADT/APFloat.h" |
19 | | #include "llvm/ADT/STLExtras.h" |
20 | | #include "llvm/Support/ErrorHandling.h" |
21 | | #include "llvm/Support/TargetParser.h" |
22 | | #include <cstdlib> |
23 | | using namespace clang; |
24 | | |
25 | | static const LangASMap DefaultAddrSpaceMap = {0}; |
26 | | |
27 | | // TargetInfo Constructor. |
28 | 99.6k | TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { |
29 | | // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or |
30 | | // SPARC. These should be overridden by concrete targets as needed. |
31 | 99.6k | BigEndian = !T.isLittleEndian(); |
32 | 99.6k | TLSSupported = true; |
33 | 99.6k | VLASupported = true; |
34 | 99.6k | NoAsmVariants = false; |
35 | 99.6k | HasLegalHalfType = false; |
36 | 99.6k | HasFloat128 = false; |
37 | 99.6k | HasIbm128 = false; |
38 | 99.6k | HasFloat16 = false; |
39 | 99.6k | HasBFloat16 = false; |
40 | 99.6k | HasLongDouble = true; |
41 | 99.6k | HasFPReturn = true; |
42 | 99.6k | HasStrictFP = false; |
43 | 99.6k | PointerWidth = PointerAlign = 32; |
44 | 99.6k | BoolWidth = BoolAlign = 8; |
45 | 99.6k | IntWidth = IntAlign = 32; |
46 | 99.6k | LongWidth = LongAlign = 32; |
47 | 99.6k | LongLongWidth = LongLongAlign = 64; |
48 | | |
49 | | // Fixed point default bit widths |
50 | 99.6k | ShortAccumWidth = ShortAccumAlign = 16; |
51 | 99.6k | AccumWidth = AccumAlign = 32; |
52 | 99.6k | LongAccumWidth = LongAccumAlign = 64; |
53 | 99.6k | ShortFractWidth = ShortFractAlign = 8; |
54 | 99.6k | FractWidth = FractAlign = 16; |
55 | 99.6k | LongFractWidth = LongFractAlign = 32; |
56 | | |
57 | | // Fixed point default integral and fractional bit sizes |
58 | | // We give the _Accum 1 fewer fractional bits than their corresponding _Fract |
59 | | // types by default to have the same number of fractional bits between _Accum |
60 | | // and _Fract types. |
61 | 99.6k | PaddingOnUnsignedFixedPoint = false; |
62 | 99.6k | ShortAccumScale = 7; |
63 | 99.6k | AccumScale = 15; |
64 | 99.6k | LongAccumScale = 31; |
65 | | |
66 | 99.6k | SuitableAlign = 64; |
67 | 99.6k | DefaultAlignForAttributeAligned = 128; |
68 | 99.6k | MinGlobalAlign = 0; |
69 | | // From the glibc documentation, on GNU systems, malloc guarantees 16-byte |
70 | | // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See |
71 | | // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html. |
72 | | // This alignment guarantee also applies to Windows and Android. On Darwin |
73 | | // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems. |
74 | 99.6k | if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment()93.0k || T.isAndroid()84.2k ) |
75 | 15.3k | NewAlign = Triple.isArch64Bit() ? 12813.9k : Triple.isArch32Bit()1.46k ? 641.46k : 02 ; |
76 | 84.2k | else if (T.isOSDarwin() || T.isOSOpenBSD()22.7k ) |
77 | 61.4k | NewAlign = 128; |
78 | 22.7k | else |
79 | 22.7k | NewAlign = 0; // Infer from basic type alignment. |
80 | 99.6k | HalfWidth = 16; |
81 | 99.6k | HalfAlign = 16; |
82 | 99.6k | FloatWidth = 32; |
83 | 99.6k | FloatAlign = 32; |
84 | 99.6k | DoubleWidth = 64; |
85 | 99.6k | DoubleAlign = 64; |
86 | 99.6k | LongDoubleWidth = 64; |
87 | 99.6k | LongDoubleAlign = 64; |
88 | 99.6k | Float128Align = 128; |
89 | 99.6k | Ibm128Align = 128; |
90 | 99.6k | LargeArrayMinWidth = 0; |
91 | 99.6k | LargeArrayAlign = 0; |
92 | 99.6k | MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0; |
93 | 99.6k | MaxVectorAlign = 0; |
94 | 99.6k | MaxTLSAlign = 0; |
95 | 99.6k | SimdDefaultAlign = 0; |
96 | 99.6k | SizeType = UnsignedLong; |
97 | 99.6k | PtrDiffType = SignedLong; |
98 | 99.6k | IntMaxType = SignedLongLong; |
99 | 99.6k | IntPtrType = SignedLong; |
100 | 99.6k | WCharType = SignedInt; |
101 | 99.6k | WIntType = SignedInt; |
102 | 99.6k | Char16Type = UnsignedShort; |
103 | 99.6k | Char32Type = UnsignedInt; |
104 | 99.6k | Int64Type = SignedLongLong; |
105 | 99.6k | Int16Type = SignedShort; |
106 | 99.6k | SigAtomicType = SignedInt; |
107 | 99.6k | ProcessIDType = SignedInt; |
108 | 99.6k | UseSignedCharForObjCBool = true; |
109 | 99.6k | UseBitFieldTypeAlignment = true; |
110 | 99.6k | UseZeroLengthBitfieldAlignment = false; |
111 | 99.6k | UseLeadingZeroLengthBitfield = true; |
112 | 99.6k | UseExplicitBitFieldAlignment = true; |
113 | 99.6k | ZeroLengthBitfieldBoundary = 0; |
114 | 99.6k | MaxAlignedAttribute = 0; |
115 | 99.6k | HalfFormat = &llvm::APFloat::IEEEhalf(); |
116 | 99.6k | FloatFormat = &llvm::APFloat::IEEEsingle(); |
117 | 99.6k | DoubleFormat = &llvm::APFloat::IEEEdouble(); |
118 | 99.6k | LongDoubleFormat = &llvm::APFloat::IEEEdouble(); |
119 | 99.6k | Float128Format = &llvm::APFloat::IEEEquad(); |
120 | 99.6k | Ibm128Format = &llvm::APFloat::PPCDoubleDouble(); |
121 | 99.6k | MCountName = "mcount"; |
122 | 99.6k | UserLabelPrefix = "_"; |
123 | 99.6k | RegParmMax = 0; |
124 | 99.6k | SSERegParmMax = 0; |
125 | 99.6k | HasAlignMac68kSupport = false; |
126 | 99.6k | HasBuiltinMSVaList = false; |
127 | 99.6k | IsRenderScriptTarget = false; |
128 | 99.6k | HasAArch64SVETypes = false; |
129 | 99.6k | HasRISCVVTypes = false; |
130 | 99.6k | AllowAMDGPUUnsafeFPAtomics = false; |
131 | 99.6k | ARMCDECoprocMask = 0; |
132 | | |
133 | | // Default to no types using fpret. |
134 | 99.6k | RealTypeUsesObjCFPRetMask = 0; |
135 | | |
136 | | // Default to not using fp2ret for __Complex long double |
137 | 99.6k | ComplexLongDoubleUsesFP2Ret = false; |
138 | | |
139 | | // Set the C++ ABI based on the triple. |
140 | 99.6k | TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment() |
141 | 99.6k | ? TargetCXXABI::Microsoft8.79k |
142 | 99.6k | : TargetCXXABI::GenericItanium90.8k ); |
143 | | |
144 | | // Default to an empty address space map. |
145 | 99.6k | AddrSpaceMap = &DefaultAddrSpaceMap; |
146 | 99.6k | UseAddrSpaceMapMangling = false; |
147 | | |
148 | | // Default to an unknown platform name. |
149 | 99.6k | PlatformName = "unknown"; |
150 | 99.6k | PlatformMinVersion = VersionTuple(); |
151 | | |
152 | 99.6k | MaxOpenCLWorkGroupSize = 1024; |
153 | | |
154 | 99.6k | MaxBitIntWidth.reset(); |
155 | | |
156 | 99.6k | ProgramAddrSpace = 0; |
157 | 99.6k | } |
158 | | |
159 | | // Out of line virtual dtor for TargetInfo. |
160 | 93.2k | TargetInfo::~TargetInfo() {} |
161 | | |
162 | 161k | void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) { |
163 | 161k | DataLayoutString = DL.str(); |
164 | 161k | UserLabelPrefix = ULP; |
165 | 161k | } |
166 | | |
167 | | bool |
168 | 0 | TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const { |
169 | 0 | Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch"; |
170 | 0 | return false; |
171 | 0 | } |
172 | | |
173 | | bool |
174 | 0 | TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const { |
175 | 0 | Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return"; |
176 | 0 | return false; |
177 | 0 | } |
178 | | |
179 | | /// getTypeName - Return the user string for the specified integer type enum. |
180 | | /// For example, SignedShort -> "short". |
181 | 3.08M | const char *TargetInfo::getTypeName(IntType T) { |
182 | 3.08M | switch (T) { |
183 | 0 | default: llvm_unreachable("not an integer!"); |
184 | 271k | case SignedChar: return "signed char"; |
185 | 271k | case UnsignedChar: return "unsigned char"; |
186 | 271k | case SignedShort: return "short"; |
187 | 380k | case UnsignedShort: return "unsigned short"; |
188 | 456k | case SignedInt: return "int"; |
189 | 406k | case UnsignedInt: return "unsigned int"; |
190 | 234k | case SignedLong: return "long int"; |
191 | 235k | case UnsignedLong: return "long unsigned int"; |
192 | 276k | case SignedLongLong: return "long long int"; |
193 | 276k | case UnsignedLongLong: return "long long unsigned int"; |
194 | 3.08M | } |
195 | 3.08M | } |
196 | | |
197 | | /// getTypeConstantSuffix - Return the constant suffix for the specified |
198 | | /// integer type enum. For example, SignedLong -> "L". |
199 | 4.42M | const char *TargetInfo::getTypeConstantSuffix(IntType T) const { |
200 | 4.42M | switch (T) { |
201 | 0 | default: llvm_unreachable("not an integer!"); |
202 | 453k | case SignedChar: |
203 | 906k | case SignedShort: |
204 | 1.63M | case SignedInt: return ""; |
205 | 402k | case SignedLong: return "L"; |
206 | 472k | case SignedLongLong: return "LL"; |
207 | 362k | case UnsignedChar: |
208 | 362k | if (getCharWidth() < getIntWidth()) |
209 | 362k | return ""; |
210 | 362k | LLVM_FALLTHROUGH0 ;0 |
211 | 380k | case UnsignedShort: |
212 | 380k | if (getShortWidth() < getIntWidth()) |
213 | 380k | return ""; |
214 | 380k | LLVM_FALLTHROUGH76 ;76 |
215 | 419k | case UnsignedInt: return "U"; |
216 | 362k | case UnsignedLong: return "UL"; |
217 | 388k | case UnsignedLongLong: return "ULL"; |
218 | 4.42M | } |
219 | 4.42M | } |
220 | | |
221 | | /// getTypeFormatModifier - Return the printf format modifier for the |
222 | | /// specified integer type enum. For example, SignedLong -> "l". |
223 | | |
224 | 2.72M | const char *TargetInfo::getTypeFormatModifier(IntType T) { |
225 | 2.72M | switch (T) { |
226 | 0 | default: llvm_unreachable("not an integer!"); |
227 | 271k | case SignedChar: |
228 | 543k | case UnsignedChar: return "hh"; |
229 | 271k | case SignedShort: |
230 | 543k | case UnsignedShort: return "h"; |
231 | 305k | case SignedInt: |
232 | 609k | case UnsignedInt: return ""; |
233 | 234k | case SignedLong: |
234 | 470k | case UnsignedLong: return "l"; |
235 | 276k | case SignedLongLong: |
236 | 553k | case UnsignedLongLong: return "ll"; |
237 | 2.72M | } |
238 | 2.72M | } |
239 | | |
240 | | /// getTypeWidth - Return the width (in bits) of the specified integer type |
241 | | /// enum. For example, SignedInt -> getIntWidth(). |
242 | 16.7M | unsigned TargetInfo::getTypeWidth(IntType T) const { |
243 | 16.7M | switch (T) { |
244 | 0 | default: llvm_unreachable("not an integer!"); |
245 | 725k | case SignedChar: |
246 | 1.17M | case UnsignedChar: return getCharWidth(); |
247 | 725k | case SignedShort: |
248 | 1.37M | case UnsignedShort: return getShortWidth(); |
249 | 2.23M | case SignedInt: |
250 | 3.16M | case UnsignedInt: return getIntWidth(); |
251 | 7.13M | case SignedLong: |
252 | 9.32M | case UnsignedLong: return getLongWidth(); |
253 | 1.22M | case SignedLongLong: |
254 | 1.67M | case UnsignedLongLong: return getLongLongWidth(); |
255 | 16.7M | }; |
256 | 0 | } |
257 | | |
258 | | TargetInfo::IntType TargetInfo::getIntTypeByWidth( |
259 | 1.00M | unsigned BitWidth, bool IsSigned) const { |
260 | 1.00M | if (getCharWidth() == BitWidth) |
261 | 53.8k | return IsSigned ? SignedChar27.5k : UnsignedChar26.3k ; |
262 | 953k | if (getShortWidth() == BitWidth) |
263 | 62.7k | return IsSigned ? SignedShort33.5k : UnsignedShort29.1k ; |
264 | 890k | if (getIntWidth() == BitWidth) |
265 | 515k | return IsSigned ? SignedInt470k : UnsignedInt45.3k ; |
266 | 374k | if (getLongWidth() == BitWidth) |
267 | 365k | return IsSigned ? SignedLong218k : UnsignedLong146k ; |
268 | 9.35k | if (getLongLongWidth() == BitWidth) |
269 | 9.31k | return IsSigned ? SignedLongLong8.68k : UnsignedLongLong631 ; |
270 | 32 | return NoInt; |
271 | 9.35k | } |
272 | | |
273 | | TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth, |
274 | 1.23M | bool IsSigned) const { |
275 | 1.23M | if (getCharWidth() >= BitWidth) |
276 | 362k | return IsSigned ? SignedChar181k : UnsignedChar181k ; |
277 | 875k | if (getShortWidth() >= BitWidth) |
278 | 362k | return IsSigned ? SignedShort181k : UnsignedShort181k ; |
279 | 513k | if (getIntWidth() >= BitWidth) |
280 | 362k | return IsSigned ? SignedInt181k : UnsignedInt181k ; |
281 | 150k | if (getLongWidth() >= BitWidth) |
282 | 52.4k | return IsSigned ? SignedLong26.2k : UnsignedLong26.2k ; |
283 | 98.1k | if (getLongLongWidth() >= BitWidth) |
284 | 98.1k | return IsSigned ? SignedLongLong49.0k : UnsignedLongLong49.0k ; |
285 | 23 | return NoInt; |
286 | 98.1k | } |
287 | | |
288 | | FloatModeKind TargetInfo::getRealTypeByWidth(unsigned BitWidth, |
289 | 106 | FloatModeKind ExplicitType) const { |
290 | 106 | if (getHalfWidth() == BitWidth) |
291 | 21 | return FloatModeKind::Half; |
292 | 85 | if (getFloatWidth() == BitWidth) |
293 | 30 | return FloatModeKind::Float; |
294 | 55 | if (getDoubleWidth() == BitWidth) |
295 | 35 | return FloatModeKind::Double; |
296 | | |
297 | 20 | switch (BitWidth) { |
298 | 5 | case 96: |
299 | 5 | if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended()) |
300 | 5 | return FloatModeKind::LongDouble; |
301 | 0 | break; |
302 | 14 | case 128: |
303 | | // The caller explicitly asked for an IEEE compliant type but we still |
304 | | // have to check if the target supports it. |
305 | 14 | if (ExplicitType == FloatModeKind::Float128) |
306 | 3 | return hasFloat128Type() ? FloatModeKind::Float128 |
307 | 3 | : FloatModeKind::NoFloat0 ; |
308 | 11 | if (ExplicitType == FloatModeKind::Ibm128) |
309 | 6 | return hasIbm128Type() ? FloatModeKind::Ibm128 |
310 | 6 | : FloatModeKind::NoFloat0 ; |
311 | 5 | if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() || |
312 | 5 | &getLongDoubleFormat() == &llvm::APFloat::IEEEquad()3 ) |
313 | 2 | return FloatModeKind::LongDouble; |
314 | 3 | if (hasFloat128Type()) |
315 | 3 | return FloatModeKind::Float128; |
316 | 0 | break; |
317 | 20 | } |
318 | | |
319 | 1 | return FloatModeKind::NoFloat; |
320 | 20 | } |
321 | | |
322 | | /// getTypeAlign - Return the alignment (in bits) of the specified integer type |
323 | | /// enum. For example, SignedInt -> getIntAlign(). |
324 | 387k | unsigned TargetInfo::getTypeAlign(IntType T) const { |
325 | 387k | switch (T) { |
326 | 0 | default: llvm_unreachable("not an integer!"); |
327 | 0 | case SignedChar: |
328 | 28 | case UnsignedChar: return getCharAlign(); |
329 | 0 | case SignedShort: |
330 | 129k | case UnsignedShort: return getShortAlign(); |
331 | 131k | case SignedInt: |
332 | 256k | case UnsignedInt: return getIntAlign(); |
333 | 397 | case SignedLong: |
334 | 426 | case UnsignedLong: return getLongAlign(); |
335 | 55 | case SignedLongLong: |
336 | 55 | case UnsignedLongLong: return getLongLongAlign(); |
337 | 387k | }; |
338 | 0 | } |
339 | | |
340 | | /// isTypeSigned - Return whether an integer types is signed. Returns true if |
341 | | /// the type is signed; false otherwise. |
342 | 7.89M | bool TargetInfo::isTypeSigned(IntType T) { |
343 | 7.89M | switch (T) { |
344 | 0 | default: llvm_unreachable("not an integer!"); |
345 | 815k | case SignedChar: |
346 | 1.63M | case SignedShort: |
347 | 2.99M | case SignedInt: |
348 | 3.68M | case SignedLong: |
349 | 4.37M | case SignedLongLong: |
350 | 4.37M | return true; |
351 | 725k | case UnsignedChar: |
352 | 1.49M | case UnsignedShort: |
353 | 2.31M | case UnsignedInt: |
354 | 2.91M | case UnsignedLong: |
355 | 3.52M | case UnsignedLongLong: |
356 | 3.52M | return false; |
357 | 7.89M | }; |
358 | 0 | } |
359 | | |
360 | | /// adjust - Set forced language options. |
361 | | /// Apply changes to the target information with respect to certain |
362 | | /// language options which change the target configuration and adjust |
363 | | /// the language based on the target options where applicable. |
364 | 181k | void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { |
365 | 181k | if (Opts.NoBitFieldTypeAlign) |
366 | 2 | UseBitFieldTypeAlignment = false; |
367 | | |
368 | 181k | switch (Opts.WCharSize) { |
369 | 0 | default: llvm_unreachable("invalid wchar_t width"); |
370 | 181k | case 0: break; |
371 | 2 | case 1: WCharType = Opts.WCharIsSigned ? SignedChar0 : UnsignedChar; break; |
372 | 56 | case 2: WCharType = Opts.WCharIsSigned ? SignedShort0 : UnsignedShort; break; |
373 | 18 | case 4: WCharType = Opts.WCharIsSigned ? SignedInt14 : UnsignedInt4 ; break; |
374 | 181k | } |
375 | | |
376 | 181k | if (Opts.AlignDouble) { |
377 | 10 | DoubleAlign = LongLongAlign = 64; |
378 | 10 | LongDoubleAlign = 64; |
379 | 10 | } |
380 | | |
381 | 181k | if (Opts.OpenCL) { |
382 | | // OpenCL C requires specific widths for types, irrespective of |
383 | | // what these normally are for the target. |
384 | | // We also define long long and long double here, although the |
385 | | // OpenCL standard only mentions these as "reserved". |
386 | 1.83k | IntWidth = IntAlign = 32; |
387 | 1.83k | LongWidth = LongAlign = 64; |
388 | 1.83k | LongLongWidth = LongLongAlign = 128; |
389 | 1.83k | HalfWidth = HalfAlign = 16; |
390 | 1.83k | FloatWidth = FloatAlign = 32; |
391 | | |
392 | | // Embedded 32-bit targets (OpenCL EP) might have double C type |
393 | | // defined as float. Let's not override this as it might lead |
394 | | // to generating illegal code that uses 64bit doubles. |
395 | 1.83k | if (DoubleWidth != FloatWidth) { |
396 | 1.83k | DoubleWidth = DoubleAlign = 64; |
397 | 1.83k | DoubleFormat = &llvm::APFloat::IEEEdouble(); |
398 | 1.83k | } |
399 | 1.83k | LongDoubleWidth = LongDoubleAlign = 128; |
400 | | |
401 | 1.83k | unsigned MaxPointerWidth = getMaxPointerWidth(); |
402 | 1.83k | assert(MaxPointerWidth == 32 || MaxPointerWidth == 64); |
403 | 0 | bool Is32BitArch = MaxPointerWidth == 32; |
404 | 1.83k | SizeType = Is32BitArch ? UnsignedInt624 : UnsignedLong1.20k ; |
405 | 1.83k | PtrDiffType = Is32BitArch ? SignedInt624 : SignedLong1.20k ; |
406 | 1.83k | IntPtrType = Is32BitArch ? SignedInt624 : SignedLong1.20k ; |
407 | | |
408 | 1.83k | IntMaxType = SignedLongLong; |
409 | 1.83k | Int64Type = SignedLong; |
410 | | |
411 | 1.83k | HalfFormat = &llvm::APFloat::IEEEhalf(); |
412 | 1.83k | FloatFormat = &llvm::APFloat::IEEEsingle(); |
413 | 1.83k | LongDoubleFormat = &llvm::APFloat::IEEEquad(); |
414 | | |
415 | | // OpenCL C v3.0 s6.7.5 - The generic address space requires support for |
416 | | // OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space |
417 | | // feature |
418 | | // OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0 |
419 | | // or later and __opencl_c_pipes feature |
420 | | // FIXME: These language options are also defined in setLangDefaults() |
421 | | // for OpenCL C 2.0 but with no access to target capabilities. Target |
422 | | // should be immutable once created and thus these language options need |
423 | | // to be defined only once. |
424 | 1.83k | if (Opts.getOpenCLCompatibleVersion() == 300) { |
425 | 272 | const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts(); |
426 | 272 | Opts.OpenCLGenericAddressSpace = hasFeatureEnabled( |
427 | 272 | OpenCLFeaturesMap, "__opencl_c_generic_address_space"); |
428 | 272 | Opts.OpenCLPipes = |
429 | 272 | hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes"); |
430 | 272 | Opts.Blocks = |
431 | 272 | hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_device_enqueue"); |
432 | 272 | } |
433 | 1.83k | } |
434 | | |
435 | 181k | if (Opts.DoubleSize) { |
436 | 4 | if (Opts.DoubleSize == 32) { |
437 | 2 | DoubleWidth = 32; |
438 | 2 | LongDoubleWidth = 32; |
439 | 2 | DoubleFormat = &llvm::APFloat::IEEEsingle(); |
440 | 2 | LongDoubleFormat = &llvm::APFloat::IEEEsingle(); |
441 | 2 | } else if (Opts.DoubleSize == 64) { |
442 | 2 | DoubleWidth = 64; |
443 | 2 | LongDoubleWidth = 64; |
444 | 2 | DoubleFormat = &llvm::APFloat::IEEEdouble(); |
445 | 2 | LongDoubleFormat = &llvm::APFloat::IEEEdouble(); |
446 | 2 | } |
447 | 4 | } |
448 | | |
449 | 181k | if (Opts.LongDoubleSize) { |
450 | 46 | if (Opts.LongDoubleSize == DoubleWidth) { |
451 | 20 | LongDoubleWidth = DoubleWidth; |
452 | 20 | LongDoubleAlign = DoubleAlign; |
453 | 20 | LongDoubleFormat = DoubleFormat; |
454 | 26 | } else if (Opts.LongDoubleSize == 128) { |
455 | 16 | LongDoubleWidth = LongDoubleAlign = 128; |
456 | 16 | LongDoubleFormat = &llvm::APFloat::IEEEquad(); |
457 | 16 | } else if (10 Opts.LongDoubleSize == 8010 ) { |
458 | 10 | LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); |
459 | 10 | if (getTriple().isWindowsMSVCEnvironment()) { |
460 | 4 | LongDoubleWidth = 128; |
461 | 4 | LongDoubleAlign = 128; |
462 | 6 | } else { // Linux |
463 | 6 | if (getTriple().getArch() == llvm::Triple::x86) { |
464 | 4 | LongDoubleWidth = 96; |
465 | 4 | LongDoubleAlign = 32; |
466 | 4 | } else { |
467 | 2 | LongDoubleWidth = 128; |
468 | 2 | LongDoubleAlign = 128; |
469 | 2 | } |
470 | 6 | } |
471 | 10 | } |
472 | 46 | } |
473 | | |
474 | 181k | if (Opts.NewAlignOverride) |
475 | 6 | NewAlign = Opts.NewAlignOverride * getCharWidth(); |
476 | | |
477 | | // Each unsigned fixed point type has the same number of fractional bits as |
478 | | // its corresponding signed type. |
479 | 181k | PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint; |
480 | 181k | CheckFixedPointBits(); |
481 | | |
482 | 181k | if (Opts.ProtectParens && !checkArithmeticFenceSupported()11 ) { |
483 | 1 | Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens"; |
484 | 1 | Opts.ProtectParens = false; |
485 | 1 | } |
486 | | |
487 | 181k | if (Opts.MaxBitIntWidth) |
488 | 31.8k | MaxBitIntWidth = Opts.MaxBitIntWidth; |
489 | 181k | } |
490 | | |
491 | | bool TargetInfo::initFeatureMap( |
492 | | llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU, |
493 | 156k | const std::vector<std::string> &FeatureVec) const { |
494 | 164k | for (const auto &F : FeatureVec) { |
495 | 164k | StringRef Name = F; |
496 | | // Apply the feature via the target. |
497 | 164k | bool Enabled = Name[0] == '+'; |
498 | 164k | setFeatureEnabled(Features, Name.substr(1), Enabled); |
499 | 164k | } |
500 | 156k | return true; |
501 | 156k | } |
502 | | |
503 | | TargetInfo::CallingConvKind |
504 | 1.72M | TargetInfo::getCallingConvKind(bool ClangABICompat4) const { |
505 | 1.72M | if (getCXXABI() != TargetCXXABI::Microsoft && |
506 | 1.72M | (1.71M ClangABICompat41.71M || getTriple().isPS4()1.71M )) |
507 | 598 | return CCK_ClangABI4OrPS4; |
508 | 1.72M | return CCK_Default; |
509 | 1.72M | } |
510 | | |
511 | 211 | LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const { |
512 | 211 | switch (TK) { |
513 | 62 | case OCLTK_Image: |
514 | 108 | case OCLTK_Pipe: |
515 | 108 | return LangAS::opencl_global; |
516 | | |
517 | 16 | case OCLTK_Sampler: |
518 | 16 | return LangAS::opencl_constant; |
519 | | |
520 | 87 | default: |
521 | 87 | return LangAS::Default; |
522 | 211 | } |
523 | 211 | } |
524 | | |
525 | | //===----------------------------------------------------------------------===// |
526 | | |
527 | | |
528 | 8.69k | static StringRef removeGCCRegisterPrefix(StringRef Name) { |
529 | 8.69k | if (Name[0] == '%' || Name[0] == '#'8.07k ) |
530 | 640 | Name = Name.substr(1); |
531 | | |
532 | 8.69k | return Name; |
533 | 8.69k | } |
534 | | |
535 | | /// isValidClobber - Returns whether the passed in string is |
536 | | /// a valid clobber in an inline asm statement. This is used by |
537 | | /// Sema. |
538 | 3.40k | bool TargetInfo::isValidClobber(StringRef Name) const { |
539 | 3.40k | return (isValidGCCRegisterName(Name) || Name == "memory"2.16k || Name == "cc"1.21k || |
540 | 3.40k | Name == "unwind"5 ); |
541 | 3.40k | } |
542 | | |
543 | | /// isValidGCCRegisterName - Returns whether the passed in string |
544 | | /// is a valid register name according to GCC. This is used by Sema for |
545 | | /// inline asm statements. |
546 | 6.18k | bool TargetInfo::isValidGCCRegisterName(StringRef Name) const { |
547 | 6.18k | if (Name.empty()) |
548 | 0 | return false; |
549 | | |
550 | | // Get rid of any register prefix. |
551 | 6.18k | Name = removeGCCRegisterPrefix(Name); |
552 | 6.18k | if (Name.empty()) |
553 | 1 | return false; |
554 | | |
555 | 6.18k | ArrayRef<const char *> Names = getGCCRegNames(); |
556 | | |
557 | | // If we have a number it maps to an entry in the register name array. |
558 | 6.18k | if (isDigit(Name[0])) { |
559 | 26 | unsigned n; |
560 | 26 | if (!Name.getAsInteger(0, n)) |
561 | 26 | return n < Names.size(); |
562 | 26 | } |
563 | | |
564 | | // Check register names. |
565 | 6.15k | if (llvm::is_contained(Names, Name)) |
566 | 3.14k | return true; |
567 | | |
568 | | // Check any additional names that we have. |
569 | 3.01k | for (const AddlRegName &ARN : getGCCAddlRegNames()) |
570 | 140k | for (const char *AN : ARN.Names)35.1k { |
571 | 140k | if (!AN) |
572 | 34.7k | break; |
573 | | // Make sure the register that the additional name is for is within |
574 | | // the bounds of the register names from above. |
575 | 105k | if (AN == Name && ARN.RegNum < Names.size()382 ) |
576 | 382 | return true; |
577 | 105k | } |
578 | | |
579 | | // Now check aliases. |
580 | 2.62k | for (const GCCRegAlias &GRA : getGCCRegAliases()) |
581 | 25.2k | for (const char *A : GRA.Aliases)12.7k { |
582 | 25.2k | if (!A) |
583 | 12.3k | break; |
584 | 12.9k | if (A == Name) |
585 | 461 | return true; |
586 | 12.9k | } |
587 | | |
588 | 2.16k | return false; |
589 | 2.62k | } |
590 | | |
591 | | StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name, |
592 | 2.51k | bool ReturnCanonical) const { |
593 | 2.51k | assert(isValidGCCRegisterName(Name) && "Invalid register passed in"); |
594 | | |
595 | | // Get rid of any register prefix. |
596 | 0 | Name = removeGCCRegisterPrefix(Name); |
597 | | |
598 | 2.51k | ArrayRef<const char *> Names = getGCCRegNames(); |
599 | | |
600 | | // First, check if we have a number. |
601 | 2.51k | if (isDigit(Name[0])) { |
602 | 12 | unsigned n; |
603 | 12 | if (!Name.getAsInteger(0, n)) { |
604 | 12 | assert(n < Names.size() && "Out of bounds register number!"); |
605 | 0 | return Names[n]; |
606 | 12 | } |
607 | 12 | } |
608 | | |
609 | | // Check any additional names that we have. |
610 | 2.50k | for (const AddlRegName &ARN : getGCCAddlRegNames()) |
611 | 21.5k | for (const char *AN : ARN.Names)5.58k { |
612 | 21.5k | if (!AN) |
613 | 5.32k | break; |
614 | | // Make sure the register that the additional name is for is within |
615 | | // the bounds of the register names from above. |
616 | 16.1k | if (AN == Name && ARN.RegNum < Names.size()254 ) |
617 | 254 | return ReturnCanonical ? Names[ARN.RegNum]59 : Name195 ; |
618 | 16.1k | } |
619 | | |
620 | | // Now check aliases. |
621 | 2.24k | for (const GCCRegAlias &RA : getGCCRegAliases()) |
622 | 104k | for (const char *A : RA.Aliases)51.0k { |
623 | 104k | if (!A) |
624 | 50.8k | break; |
625 | 53.2k | if (A == Name) |
626 | 246 | return RA.Register; |
627 | 53.2k | } |
628 | | |
629 | 2.00k | return Name; |
630 | 2.24k | } |
631 | | |
632 | 8.77k | bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const { |
633 | 8.77k | const char *Name = Info.getConstraintStr().c_str(); |
634 | | // An output constraint must start with '=' or '+' |
635 | 8.77k | if (*Name != '=' && *Name != '+'846 ) |
636 | 66 | return false; |
637 | | |
638 | 8.71k | if (*Name == '+') |
639 | 780 | Info.setIsReadWrite(); |
640 | | |
641 | 8.71k | Name++; |
642 | 18.7k | while (*Name) { |
643 | 10.1k | switch (*Name) { |
644 | 6.11k | default: |
645 | 6.11k | if (!validateAsmConstraint(Name, Info)) { |
646 | | // FIXME: We temporarily return false |
647 | | // so we can add more constraints as we hit it. |
648 | | // Eventually, an unknown constraint should just be treated as 'g'. |
649 | 36 | return false; |
650 | 36 | } |
651 | 6.07k | break; |
652 | 6.07k | case '&': // early clobber. |
653 | 36 | Info.setEarlyClobber(); |
654 | 36 | break; |
655 | 7 | case '%': // commutative. |
656 | | // FIXME: Check that there is a another register after this one. |
657 | 7 | break; |
658 | 2.71k | case 'r': // general register. |
659 | 2.71k | Info.setAllowsRegister(); |
660 | 2.71k | break; |
661 | 526 | case 'm': // memory operand. |
662 | 526 | case 'o': // offsetable memory operand. |
663 | 526 | case 'V': // non-offsetable memory operand. |
664 | 526 | case '<': // autodecrement memory operand. |
665 | 526 | case '>': // autoincrement memory operand. |
666 | 526 | Info.setAllowsMemory(); |
667 | 526 | break; |
668 | 25 | case 'g': // general register, memory operand or immediate integer. |
669 | 25 | case 'X': // any operand. |
670 | 25 | Info.setAllowsRegister(); |
671 | 25 | Info.setAllowsMemory(); |
672 | 25 | break; |
673 | 648 | case ',': // multiple alternative constraint. Pass it. |
674 | | // Handle additional optional '=' or '+' modifiers. |
675 | 648 | if (Name[1] == '=' || Name[1] == '+'643 ) |
676 | 5 | Name++; |
677 | 648 | break; |
678 | 2 | case '#': // Ignore as constraint. |
679 | 3 | while (Name[1] && Name[1] != ','1 ) |
680 | 1 | Name++; |
681 | 2 | break; |
682 | 1 | case '?': // Disparage slightly code. |
683 | 2 | case '!': // Disparage severely. |
684 | 3 | case '*': // Ignore for choosing register preferences. |
685 | 12 | case 'i': // Ignore i,n,E,F as output constraints (match from the other |
686 | | // chars) |
687 | 21 | case 'n': |
688 | 30 | case 'E': |
689 | 39 | case 'F': |
690 | 39 | break; // Pass them. |
691 | 10.1k | } |
692 | | |
693 | 10.0k | Name++; |
694 | 10.0k | } |
695 | | |
696 | | // Early clobber with a read-write constraint which doesn't permit registers |
697 | | // is invalid. |
698 | 8.67k | if (Info.earlyClobber() && Info.isReadWrite()33 && !Info.allowsRegister()7 ) |
699 | 1 | return false; |
700 | | |
701 | | // If a constraint allows neither memory nor register operands it contains |
702 | | // only modifiers. Reject it. |
703 | 8.67k | return Info.allowsMemory() || Info.allowsRegister()8.15k ; |
704 | 8.67k | } |
705 | | |
706 | | bool TargetInfo::resolveSymbolicName(const char *&Name, |
707 | | ArrayRef<ConstraintInfo> OutputConstraints, |
708 | 52 | unsigned &Index) const { |
709 | 52 | assert(*Name == '[' && "Symbolic name did not start with '['"); |
710 | 0 | Name++; |
711 | 52 | const char *Start = Name; |
712 | 247 | while (*Name && *Name != ']'245 ) |
713 | 195 | Name++; |
714 | | |
715 | 52 | if (!*Name) { |
716 | | // Missing ']' |
717 | 2 | return false; |
718 | 2 | } |
719 | | |
720 | 50 | std::string SymbolicName(Start, Name - Start); |
721 | | |
722 | 183 | for (Index = 0; Index != OutputConstraints.size(); ++Index133 ) |
723 | 182 | if (SymbolicName == OutputConstraints[Index].getName()) |
724 | 49 | return true; |
725 | | |
726 | 1 | return false; |
727 | 50 | } |
728 | | |
729 | | bool TargetInfo::validateInputConstraint( |
730 | | MutableArrayRef<ConstraintInfo> OutputConstraints, |
731 | 10.7k | ConstraintInfo &Info) const { |
732 | 10.7k | const char *Name = Info.ConstraintStr.c_str(); |
733 | | |
734 | 10.7k | if (!*Name) |
735 | 2 | return false; |
736 | | |
737 | 23.0k | while (10.7k *Name) { |
738 | 12.3k | switch (*Name) { |
739 | 6.20k | default: |
740 | | // Check if we have a matching constraint |
741 | 6.20k | if (*Name >= '0' && *Name <= '9') { |
742 | 179 | const char *DigitStart = Name; |
743 | 180 | while (Name[1] >= '0' && Name[1] <= '9'3 ) |
744 | 1 | Name++; |
745 | 179 | const char *DigitEnd = Name; |
746 | 179 | unsigned i; |
747 | 179 | if (StringRef(DigitStart, DigitEnd - DigitStart + 1) |
748 | 179 | .getAsInteger(10, i)) |
749 | 0 | return false; |
750 | | |
751 | | // Check if matching constraint is out of bounds. |
752 | 179 | if (i >= OutputConstraints.size()) return false1 ; |
753 | | |
754 | | // A number must refer to an output only operand. |
755 | 178 | if (OutputConstraints[i].isReadWrite()) |
756 | 1 | return false; |
757 | | |
758 | | // If the constraint is already tied, it must be tied to the |
759 | | // same operand referenced to by the number. |
760 | 177 | if (Info.hasTiedOperand() && Info.getTiedOperand() != i1 ) |
761 | 1 | return false; |
762 | | |
763 | | // The constraint should have the same info as the respective |
764 | | // output constraint. |
765 | 176 | Info.setTiedOperand(i, OutputConstraints[i]); |
766 | 6.02k | } else if (!validateAsmConstraint(Name, Info)) { |
767 | | // FIXME: This error return is in place temporarily so we can |
768 | | // add more constraints as we hit it. Eventually, an unknown |
769 | | // constraint should just be treated as 'g'. |
770 | 15 | return false; |
771 | 15 | } |
772 | 6.18k | break; |
773 | 6.18k | case '[': { |
774 | 46 | unsigned Index = 0; |
775 | 46 | if (!resolveSymbolicName(Name, OutputConstraints, Index)) |
776 | 3 | return false; |
777 | | |
778 | | // If the constraint is already tied, it must be tied to the |
779 | | // same operand referenced to by the number. |
780 | 43 | if (Info.hasTiedOperand() && Info.getTiedOperand() != Index1 ) |
781 | 1 | return false; |
782 | | |
783 | | // A number must refer to an output only operand. |
784 | 42 | if (OutputConstraints[Index].isReadWrite()) |
785 | 1 | return false; |
786 | | |
787 | 41 | Info.setTiedOperand(Index, OutputConstraints[Index]); |
788 | 41 | break; |
789 | 42 | } |
790 | 0 | case '%': // commutative |
791 | | // FIXME: Fail if % is used with the last operand. |
792 | 0 | break; |
793 | 357 | case 'i': // immediate integer. |
794 | 357 | break; |
795 | 81 | case 'n': // immediate integer with a known value. |
796 | 81 | Info.setRequiresImmediate(); |
797 | 81 | break; |
798 | 67 | case 'I': // Various constant constraints with target-specific meanings. |
799 | 128 | case 'J': |
800 | 162 | case 'K': |
801 | 212 | case 'L': |
802 | 232 | case 'M': |
803 | 265 | case 'N': |
804 | 275 | case 'O': |
805 | 275 | case 'P': |
806 | 275 | if (!validateAsmConstraint(Name, Info)) |
807 | 16 | return false; |
808 | 259 | break; |
809 | 3.38k | case 'r': // general register. |
810 | 3.38k | Info.setAllowsRegister(); |
811 | 3.38k | break; |
812 | 435 | case 'm': // memory operand. |
813 | 435 | case 'o': // offsettable memory operand. |
814 | 435 | case 'V': // non-offsettable memory operand. |
815 | 523 | case '<': // autodecrement memory operand. |
816 | 611 | case '>': // autoincrement memory operand. |
817 | 611 | Info.setAllowsMemory(); |
818 | 611 | break; |
819 | 268 | case 'g': // general register, memory operand or immediate integer. |
820 | 533 | case 'X': // any operand. |
821 | 533 | Info.setAllowsRegister(); |
822 | 533 | Info.setAllowsMemory(); |
823 | 533 | break; |
824 | 44 | case 'E': // immediate floating point. |
825 | 88 | case 'F': // immediate floating point. |
826 | 139 | case 'p': // address operand. |
827 | 139 | break; |
828 | 683 | case ',': // multiple alternative constraint. Ignore comma. |
829 | 683 | break; |
830 | 3 | case '#': // Ignore as constraint. |
831 | 7 | while (Name[1] && Name[1] != ','6 ) |
832 | 4 | Name++; |
833 | 3 | break; |
834 | 0 | case '?': // Disparage slightly code. |
835 | 0 | case '!': // Disparage severely. |
836 | 2 | case '*': // Ignore for choosing register preferences. |
837 | 2 | break; // Pass them. |
838 | 12.3k | } |
839 | | |
840 | 12.2k | Name++; |
841 | 12.2k | } |
842 | | |
843 | 10.7k | return true; |
844 | 10.7k | } |
845 | | |
846 | 281k | void TargetInfo::CheckFixedPointBits() const { |
847 | | // Check that the number of fractional and integral bits (and maybe sign) can |
848 | | // fit into the bits given for a fixed point type. |
849 | 281k | assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth); |
850 | 0 | assert(AccumScale + getAccumIBits() + 1 <= AccumWidth); |
851 | 0 | assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth); |
852 | 0 | assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <= |
853 | 281k | ShortAccumWidth); |
854 | 0 | assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth); |
855 | 0 | assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <= |
856 | 281k | LongAccumWidth); |
857 | | |
858 | 0 | assert(getShortFractScale() + 1 <= ShortFractWidth); |
859 | 0 | assert(getFractScale() + 1 <= FractWidth); |
860 | 0 | assert(getLongFractScale() + 1 <= LongFractWidth); |
861 | 0 | assert(getUnsignedShortFractScale() <= ShortFractWidth); |
862 | 0 | assert(getUnsignedFractScale() <= FractWidth); |
863 | 0 | assert(getUnsignedLongFractScale() <= LongFractWidth); |
864 | | |
865 | | // Each unsigned fract type has either the same number of fractional bits |
866 | | // as, or one more fractional bit than, its corresponding signed fract type. |
867 | 0 | assert(getShortFractScale() == getUnsignedShortFractScale() || |
868 | 281k | getShortFractScale() == getUnsignedShortFractScale() - 1); |
869 | 0 | assert(getFractScale() == getUnsignedFractScale() || |
870 | 281k | getFractScale() == getUnsignedFractScale() - 1); |
871 | 0 | assert(getLongFractScale() == getUnsignedLongFractScale() || |
872 | 281k | getLongFractScale() == getUnsignedLongFractScale() - 1); |
873 | | |
874 | | // When arranged in order of increasing rank (see 6.3.1.3a), the number of |
875 | | // fractional bits is nondecreasing for each of the following sets of |
876 | | // fixed-point types: |
877 | | // - signed fract types |
878 | | // - unsigned fract types |
879 | | // - signed accum types |
880 | | // - unsigned accum types. |
881 | 0 | assert(getLongFractScale() >= getFractScale() && |
882 | 281k | getFractScale() >= getShortFractScale()); |
883 | 0 | assert(getUnsignedLongFractScale() >= getUnsignedFractScale() && |
884 | 281k | getUnsignedFractScale() >= getUnsignedShortFractScale()); |
885 | 0 | assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale); |
886 | 0 | assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() && |
887 | 281k | getUnsignedAccumScale() >= getUnsignedShortAccumScale()); |
888 | | |
889 | | // When arranged in order of increasing rank (see 6.3.1.3a), the number of |
890 | | // integral bits is nondecreasing for each of the following sets of |
891 | | // fixed-point types: |
892 | | // - signed accum types |
893 | | // - unsigned accum types |
894 | 0 | assert(getLongAccumIBits() >= getAccumIBits() && |
895 | 281k | getAccumIBits() >= getShortAccumIBits()); |
896 | 0 | assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() && |
897 | 281k | getUnsignedAccumIBits() >= getUnsignedShortAccumIBits()); |
898 | | |
899 | | // Each signed accum type has at least as many integral bits as its |
900 | | // corresponding unsigned accum type. |
901 | 0 | assert(getShortAccumIBits() >= getUnsignedShortAccumIBits()); |
902 | 0 | assert(getAccumIBits() >= getUnsignedAccumIBits()); |
903 | 0 | assert(getLongAccumIBits() >= getUnsignedLongAccumIBits()); |
904 | 281k | } |
905 | | |
906 | 35 | void TargetInfo::copyAuxTarget(const TargetInfo *Aux) { |
907 | 35 | auto *Target = static_cast<TransferrableTargetInfo*>(this); |
908 | 35 | auto *Src = static_cast<const TransferrableTargetInfo*>(Aux); |
909 | 35 | *Target = *Src; |
910 | 35 | } |