clang  11.0.0git
TargetInfo.cpp
Go to the documentation of this file.
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"
15 #include "clang/Basic/CharInfo.h"
16 #include "clang/Basic/Diagnostic.h"
18 #include "llvm/ADT/APFloat.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/TargetParser.h"
23 #include <cstdlib>
24 using namespace clang;
25 
26 static const LangASMap DefaultAddrSpaceMap = {0};
27 
28 // TargetInfo Constructor.
29 TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) {
30  // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
31  // SPARC. These should be overridden by concrete targets as needed.
32  BigEndian = !T.isLittleEndian();
33  TLSSupported = true;
34  VLASupported = true;
35  NoAsmVariants = false;
36  HasLegalHalfType = false;
37  HasFloat128 = false;
38  HasFloat16 = false;
39  HasBFloat16 = false;
40  HasStrictFP = false;
42  BoolWidth = BoolAlign = 8;
43  IntWidth = IntAlign = 32;
44  LongWidth = LongAlign = 32;
46 
47  // Fixed point default bit widths
49  AccumWidth = AccumAlign = 32;
52  FractWidth = FractAlign = 16;
54 
55  // Fixed point default integral and fractional bit sizes
56  // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
57  // types by default to have the same number of fractional bits between _Accum
58  // and _Fract types.
60  ShortAccumScale = 7;
61  AccumScale = 15;
62  LongAccumScale = 31;
63 
64  SuitableAlign = 64;
66  MinGlobalAlign = 0;
67  // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
68  // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
69  // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
70  // This alignment guarantee also applies to Windows and Android.
71  if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
72  NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
73  else
74  NewAlign = 0; // Infer from basic type alignment.
75  HalfWidth = 16;
76  HalfAlign = 16;
77  FloatWidth = 32;
78  FloatAlign = 32;
79  DoubleWidth = 64;
80  DoubleAlign = 64;
81  LongDoubleWidth = 64;
82  LongDoubleAlign = 64;
83  Float128Align = 128;
85  LargeArrayAlign = 0;
87  MaxVectorAlign = 0;
88  MaxTLSAlign = 0;
89  SimdDefaultAlign = 0;
106  HalfFormat = &llvm::APFloat::IEEEhalf();
107  FloatFormat = &llvm::APFloat::IEEEsingle();
108  DoubleFormat = &llvm::APFloat::IEEEdouble();
109  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
110  Float128Format = &llvm::APFloat::IEEEquad();
111  MCountName = "mcount";
112  RegParmMax = 0;
113  SSERegParmMax = 0;
114  HasAlignMac68kSupport = false;
115  HasBuiltinMSVaList = false;
116  IsRenderScriptTarget = false;
117  HasAArch64SVETypes = false;
118  ARMCDECoprocMask = 0;
119 
120  // Default to no types using fpret.
122 
123  // Default to not using fp2ret for __Complex long double
125 
126  // Set the C++ ABI based on the triple.
127  TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
130 
131  // Default to an empty address space map.
133  UseAddrSpaceMapMangling = false;
134 
135  // Default to an unknown platform name.
136  PlatformName = "unknown";
137  PlatformMinVersion = VersionTuple();
138 
139  MaxOpenCLWorkGroupSize = 1024;
140 }
141 
142 // Out of line virtual dtor for TargetInfo.
144 
145 void TargetInfo::resetDataLayout(StringRef DL) {
146  DataLayout.reset(new llvm::DataLayout(DL));
147 }
148 
149 bool
151  Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
152  return false;
153 }
154 
155 bool
157  Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
158  return false;
159 }
160 
161 /// getTypeName - Return the user string for the specified integer type enum.
162 /// For example, SignedShort -> "short".
164  switch (T) {
165  default: llvm_unreachable("not an integer!");
166  case SignedChar: return "signed char";
167  case UnsignedChar: return "unsigned char";
168  case SignedShort: return "short";
169  case UnsignedShort: return "unsigned short";
170  case SignedInt: return "int";
171  case UnsignedInt: return "unsigned int";
172  case SignedLong: return "long int";
173  case UnsignedLong: return "long unsigned int";
174  case SignedLongLong: return "long long int";
175  case UnsignedLongLong: return "long long unsigned int";
176  }
177 }
178 
179 /// getTypeConstantSuffix - Return the constant suffix for the specified
180 /// integer type enum. For example, SignedLong -> "L".
182  switch (T) {
183  default: llvm_unreachable("not an integer!");
184  case SignedChar:
185  case SignedShort:
186  case SignedInt: return "";
187  case SignedLong: return "L";
188  case SignedLongLong: return "LL";
189  case UnsignedChar:
190  if (getCharWidth() < getIntWidth())
191  return "";
192  LLVM_FALLTHROUGH;
193  case UnsignedShort:
194  if (getShortWidth() < getIntWidth())
195  return "";
196  LLVM_FALLTHROUGH;
197  case UnsignedInt: return "U";
198  case UnsignedLong: return "UL";
199  case UnsignedLongLong: return "ULL";
200  }
201 }
202 
203 /// getTypeFormatModifier - Return the printf format modifier for the
204 /// specified integer type enum. For example, SignedLong -> "l".
205 
207  switch (T) {
208  default: llvm_unreachable("not an integer!");
209  case SignedChar:
210  case UnsignedChar: return "hh";
211  case SignedShort:
212  case UnsignedShort: return "h";
213  case SignedInt:
214  case UnsignedInt: return "";
215  case SignedLong:
216  case UnsignedLong: return "l";
217  case SignedLongLong:
218  case UnsignedLongLong: return "ll";
219  }
220 }
221 
222 /// getTypeWidth - Return the width (in bits) of the specified integer type
223 /// enum. For example, SignedInt -> getIntWidth().
225  switch (T) {
226  default: llvm_unreachable("not an integer!");
227  case SignedChar:
228  case UnsignedChar: return getCharWidth();
229  case SignedShort:
230  case UnsignedShort: return getShortWidth();
231  case SignedInt:
232  case UnsignedInt: return getIntWidth();
233  case SignedLong:
234  case UnsignedLong: return getLongWidth();
235  case SignedLongLong:
236  case UnsignedLongLong: return getLongLongWidth();
237  };
238 }
239 
241  unsigned BitWidth, bool IsSigned) const {
242  if (getCharWidth() == BitWidth)
243  return IsSigned ? SignedChar : UnsignedChar;
244  if (getShortWidth() == BitWidth)
245  return IsSigned ? SignedShort : UnsignedShort;
246  if (getIntWidth() == BitWidth)
247  return IsSigned ? SignedInt : UnsignedInt;
248  if (getLongWidth() == BitWidth)
249  return IsSigned ? SignedLong : UnsignedLong;
250  if (getLongLongWidth() == BitWidth)
251  return IsSigned ? SignedLongLong : UnsignedLongLong;
252  return NoInt;
253 }
254 
256  bool IsSigned) const {
257  if (getCharWidth() >= BitWidth)
258  return IsSigned ? SignedChar : UnsignedChar;
259  if (getShortWidth() >= BitWidth)
260  return IsSigned ? SignedShort : UnsignedShort;
261  if (getIntWidth() >= BitWidth)
262  return IsSigned ? SignedInt : UnsignedInt;
263  if (getLongWidth() >= BitWidth)
264  return IsSigned ? SignedLong : UnsignedLong;
265  if (getLongLongWidth() >= BitWidth)
266  return IsSigned ? SignedLongLong : UnsignedLongLong;
267  return NoInt;
268 }
269 
271  bool ExplicitIEEE) const {
272  if (getFloatWidth() == BitWidth)
273  return Float;
274  if (getDoubleWidth() == BitWidth)
275  return Double;
276 
277  switch (BitWidth) {
278  case 96:
279  if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
280  return LongDouble;
281  break;
282  case 128:
283  // The caller explicitly asked for an IEEE compliant type but we still
284  // have to check if the target supports it.
285  if (ExplicitIEEE)
286  return hasFloat128Type() ? Float128 : NoFloat;
287  if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
288  &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
289  return LongDouble;
290  if (hasFloat128Type())
291  return Float128;
292  break;
293  }
294 
295  return NoFloat;
296 }
297 
298 /// getTypeAlign - Return the alignment (in bits) of the specified integer type
299 /// enum. For example, SignedInt -> getIntAlign().
301  switch (T) {
302  default: llvm_unreachable("not an integer!");
303  case SignedChar:
304  case UnsignedChar: return getCharAlign();
305  case SignedShort:
306  case UnsignedShort: return getShortAlign();
307  case SignedInt:
308  case UnsignedInt: return getIntAlign();
309  case SignedLong:
310  case UnsignedLong: return getLongAlign();
311  case SignedLongLong:
312  case UnsignedLongLong: return getLongLongAlign();
313  };
314 }
315 
316 /// isTypeSigned - Return whether an integer types is signed. Returns true if
317 /// the type is signed; false otherwise.
319  switch (T) {
320  default: llvm_unreachable("not an integer!");
321  case SignedChar:
322  case SignedShort:
323  case SignedInt:
324  case SignedLong:
325  case SignedLongLong:
326  return true;
327  case UnsignedChar:
328  case UnsignedShort:
329  case UnsignedInt:
330  case UnsignedLong:
331  case UnsignedLongLong:
332  return false;
333  };
334 }
335 
336 /// adjust - Set forced language options.
337 /// Apply changes to the target information with respect to certain
338 /// language options which change the target configuration and adjust
339 /// the language based on the target options where applicable.
341  if (Opts.NoBitFieldTypeAlign)
342  UseBitFieldTypeAlignment = false;
343 
344  switch (Opts.WCharSize) {
345  default: llvm_unreachable("invalid wchar_t width");
346  case 0: break;
347  case 1: WCharType = Opts.WCharIsSigned ? SignedChar : UnsignedChar; break;
348  case 2: WCharType = Opts.WCharIsSigned ? SignedShort : UnsignedShort; break;
349  case 4: WCharType = Opts.WCharIsSigned ? SignedInt : UnsignedInt; break;
350  }
351 
352  if (Opts.AlignDouble) {
353  DoubleAlign = LongLongAlign = 64;
354  LongDoubleAlign = 64;
355  }
356 
357  if (Opts.OpenCL) {
358  // OpenCL C requires specific widths for types, irrespective of
359  // what these normally are for the target.
360  // We also define long long and long double here, although the
361  // OpenCL standard only mentions these as "reserved".
362  IntWidth = IntAlign = 32;
363  LongWidth = LongAlign = 64;
365  HalfWidth = HalfAlign = 16;
366  FloatWidth = FloatAlign = 32;
367 
368  // Embedded 32-bit targets (OpenCL EP) might have double C type
369  // defined as float. Let's not override this as it might lead
370  // to generating illegal code that uses 64bit doubles.
371  if (DoubleWidth != FloatWidth) {
372  DoubleWidth = DoubleAlign = 64;
373  DoubleFormat = &llvm::APFloat::IEEEdouble();
374  }
376 
377  unsigned MaxPointerWidth = getMaxPointerWidth();
378  assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
379  bool Is32BitArch = MaxPointerWidth == 32;
380  SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
381  PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
382  IntPtrType = Is32BitArch ? SignedInt : SignedLong;
383 
386 
387  HalfFormat = &llvm::APFloat::IEEEhalf();
388  FloatFormat = &llvm::APFloat::IEEEsingle();
389  LongDoubleFormat = &llvm::APFloat::IEEEquad();
390  }
391 
392  if (Opts.DoubleSize) {
393  if (Opts.DoubleSize == 32) {
394  DoubleWidth = 32;
395  LongDoubleWidth = 32;
396  DoubleFormat = &llvm::APFloat::IEEEsingle();
397  LongDoubleFormat = &llvm::APFloat::IEEEsingle();
398  } else if (Opts.DoubleSize == 64) {
399  DoubleWidth = 64;
400  LongDoubleWidth = 64;
401  DoubleFormat = &llvm::APFloat::IEEEdouble();
402  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
403  }
404  }
405 
406  if (Opts.LongDoubleSize) {
407  if (Opts.LongDoubleSize == DoubleWidth) {
411  } else if (Opts.LongDoubleSize == 128) {
413  LongDoubleFormat = &llvm::APFloat::IEEEquad();
414  }
415  }
416 
417  if (Opts.NewAlignOverride)
418  NewAlign = Opts.NewAlignOverride * getCharWidth();
419 
420  // Each unsigned fixed point type has the same number of fractional bits as
421  // its corresponding signed type.
422  PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
423  CheckFixedPointBits();
424 }
425 
427  llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
428  const std::vector<std::string> &FeatureVec) const {
429  for (const auto &F : FeatureVec) {
430  StringRef Name = F;
431  // Apply the feature via the target.
432  bool Enabled = Name[0] == '+';
433  setFeatureEnabled(Features, Name.substr(1), Enabled);
434  }
435  return true;
436 }
437 
439 TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
441  (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4))
442  return CCK_ClangABI4OrPS4;
443  return CCK_Default;
444 }
445 
447  switch (TK) {
448  case OCLTK_Image:
449  case OCLTK_Pipe:
450  return LangAS::opencl_global;
451 
452  case OCLTK_Sampler:
454 
455  default:
456  return LangAS::Default;
457  }
458 }
459 
460 //===----------------------------------------------------------------------===//
461 
462 
463 static StringRef removeGCCRegisterPrefix(StringRef Name) {
464  if (Name[0] == '%' || Name[0] == '#')
465  Name = Name.substr(1);
466 
467  return Name;
468 }
469 
470 /// isValidClobber - Returns whether the passed in string is
471 /// a valid clobber in an inline asm statement. This is used by
472 /// Sema.
473 bool TargetInfo::isValidClobber(StringRef Name) const {
474  return (isValidGCCRegisterName(Name) ||
475  Name == "memory" || Name == "cc");
476 }
477 
478 /// isValidGCCRegisterName - Returns whether the passed in string
479 /// is a valid register name according to GCC. This is used by Sema for
480 /// inline asm statements.
481 bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
482  if (Name.empty())
483  return false;
484 
485  // Get rid of any register prefix.
486  Name = removeGCCRegisterPrefix(Name);
487  if (Name.empty())
488  return false;
489 
491 
492  // If we have a number it maps to an entry in the register name array.
493  if (isDigit(Name[0])) {
494  unsigned n;
495  if (!Name.getAsInteger(0, n))
496  return n < Names.size();
497  }
498 
499  // Check register names.
500  if (llvm::is_contained(Names, Name))
501  return true;
502 
503  // Check any additional names that we have.
504  for (const AddlRegName &ARN : getGCCAddlRegNames())
505  for (const char *AN : ARN.Names) {
506  if (!AN)
507  break;
508  // Make sure the register that the additional name is for is within
509  // the bounds of the register names from above.
510  if (AN == Name && ARN.RegNum < Names.size())
511  return true;
512  }
513 
514  // Now check aliases.
515  for (const GCCRegAlias &GRA : getGCCRegAliases())
516  for (const char *A : GRA.Aliases) {
517  if (!A)
518  break;
519  if (A == Name)
520  return true;
521  }
522 
523  return false;
524 }
525 
527  bool ReturnCanonical) const {
528  assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
529 
530  // Get rid of any register prefix.
531  Name = removeGCCRegisterPrefix(Name);
532 
534 
535  // First, check if we have a number.
536  if (isDigit(Name[0])) {
537  unsigned n;
538  if (!Name.getAsInteger(0, n)) {
539  assert(n < Names.size() && "Out of bounds register number!");
540  return Names[n];
541  }
542  }
543 
544  // Check any additional names that we have.
545  for (const AddlRegName &ARN : getGCCAddlRegNames())
546  for (const char *AN : ARN.Names) {
547  if (!AN)
548  break;
549  // Make sure the register that the additional name is for is within
550  // the bounds of the register names from above.
551  if (AN == Name && ARN.RegNum < Names.size())
552  return ReturnCanonical ? Names[ARN.RegNum] : Name;
553  }
554 
555  // Now check aliases.
556  for (const GCCRegAlias &RA : getGCCRegAliases())
557  for (const char *A : RA.Aliases) {
558  if (!A)
559  break;
560  if (A == Name)
561  return RA.Register;
562  }
563 
564  return Name;
565 }
566 
568  const char *Name = Info.getConstraintStr().c_str();
569  // An output constraint must start with '=' or '+'
570  if (*Name != '=' && *Name != '+')
571  return false;
572 
573  if (*Name == '+')
574  Info.setIsReadWrite();
575 
576  Name++;
577  while (*Name) {
578  switch (*Name) {
579  default:
580  if (!validateAsmConstraint(Name, Info)) {
581  // FIXME: We temporarily return false
582  // so we can add more constraints as we hit it.
583  // Eventually, an unknown constraint should just be treated as 'g'.
584  return false;
585  }
586  break;
587  case '&': // early clobber.
588  Info.setEarlyClobber();
589  break;
590  case '%': // commutative.
591  // FIXME: Check that there is a another register after this one.
592  break;
593  case 'r': // general register.
594  Info.setAllowsRegister();
595  break;
596  case 'm': // memory operand.
597  case 'o': // offsetable memory operand.
598  case 'V': // non-offsetable memory operand.
599  case '<': // autodecrement memory operand.
600  case '>': // autoincrement memory operand.
601  Info.setAllowsMemory();
602  break;
603  case 'g': // general register, memory operand or immediate integer.
604  case 'X': // any operand.
605  Info.setAllowsRegister();
606  Info.setAllowsMemory();
607  break;
608  case ',': // multiple alternative constraint. Pass it.
609  // Handle additional optional '=' or '+' modifiers.
610  if (Name[1] == '=' || Name[1] == '+')
611  Name++;
612  break;
613  case '#': // Ignore as constraint.
614  while (Name[1] && Name[1] != ',')
615  Name++;
616  break;
617  case '?': // Disparage slightly code.
618  case '!': // Disparage severely.
619  case '*': // Ignore for choosing register preferences.
620  case 'i': // Ignore i,n,E,F as output constraints (match from the other
621  // chars)
622  case 'n':
623  case 'E':
624  case 'F':
625  break; // Pass them.
626  }
627 
628  Name++;
629  }
630 
631  // Early clobber with a read-write constraint which doesn't permit registers
632  // is invalid.
633  if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister())
634  return false;
635 
636  // If a constraint allows neither memory nor register operands it contains
637  // only modifiers. Reject it.
638  return Info.allowsMemory() || Info.allowsRegister();
639 }
640 
641 bool TargetInfo::resolveSymbolicName(const char *&Name,
642  ArrayRef<ConstraintInfo> OutputConstraints,
643  unsigned &Index) const {
644  assert(*Name == '[' && "Symbolic name did not start with '['");
645  Name++;
646  const char *Start = Name;
647  while (*Name && *Name != ']')
648  Name++;
649 
650  if (!*Name) {
651  // Missing ']'
652  return false;
653  }
654 
655  std::string SymbolicName(Start, Name - Start);
656 
657  for (Index = 0; Index != OutputConstraints.size(); ++Index)
658  if (SymbolicName == OutputConstraints[Index].getName())
659  return true;
660 
661  return false;
662 }
663 
665  MutableArrayRef<ConstraintInfo> OutputConstraints,
666  ConstraintInfo &Info) const {
667  const char *Name = Info.ConstraintStr.c_str();
668 
669  if (!*Name)
670  return false;
671 
672  while (*Name) {
673  switch (*Name) {
674  default:
675  // Check if we have a matching constraint
676  if (*Name >= '0' && *Name <= '9') {
677  const char *DigitStart = Name;
678  while (Name[1] >= '0' && Name[1] <= '9')
679  Name++;
680  const char *DigitEnd = Name;
681  unsigned i;
682  if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
683  .getAsInteger(10, i))
684  return false;
685 
686  // Check if matching constraint is out of bounds.
687  if (i >= OutputConstraints.size()) return false;
688 
689  // A number must refer to an output only operand.
690  if (OutputConstraints[i].isReadWrite())
691  return false;
692 
693  // If the constraint is already tied, it must be tied to the
694  // same operand referenced to by the number.
695  if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
696  return false;
697 
698  // The constraint should have the same info as the respective
699  // output constraint.
700  Info.setTiedOperand(i, OutputConstraints[i]);
701  } else if (!validateAsmConstraint(Name, Info)) {
702  // FIXME: This error return is in place temporarily so we can
703  // add more constraints as we hit it. Eventually, an unknown
704  // constraint should just be treated as 'g'.
705  return false;
706  }
707  break;
708  case '[': {
709  unsigned Index = 0;
710  if (!resolveSymbolicName(Name, OutputConstraints, Index))
711  return false;
712 
713  // If the constraint is already tied, it must be tied to the
714  // same operand referenced to by the number.
715  if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
716  return false;
717 
718  // A number must refer to an output only operand.
719  if (OutputConstraints[Index].isReadWrite())
720  return false;
721 
722  Info.setTiedOperand(Index, OutputConstraints[Index]);
723  break;
724  }
725  case '%': // commutative
726  // FIXME: Fail if % is used with the last operand.
727  break;
728  case 'i': // immediate integer.
729  break;
730  case 'n': // immediate integer with a known value.
731  Info.setRequiresImmediate();
732  break;
733  case 'I': // Various constant constraints with target-specific meanings.
734  case 'J':
735  case 'K':
736  case 'L':
737  case 'M':
738  case 'N':
739  case 'O':
740  case 'P':
741  if (!validateAsmConstraint(Name, Info))
742  return false;
743  break;
744  case 'r': // general register.
745  Info.setAllowsRegister();
746  break;
747  case 'm': // memory operand.
748  case 'o': // offsettable memory operand.
749  case 'V': // non-offsettable memory operand.
750  case '<': // autodecrement memory operand.
751  case '>': // autoincrement memory operand.
752  Info.setAllowsMemory();
753  break;
754  case 'g': // general register, memory operand or immediate integer.
755  case 'X': // any operand.
756  Info.setAllowsRegister();
757  Info.setAllowsMemory();
758  break;
759  case 'E': // immediate floating point.
760  case 'F': // immediate floating point.
761  case 'p': // address operand.
762  break;
763  case ',': // multiple alternative constraint. Ignore comma.
764  break;
765  case '#': // Ignore as constraint.
766  while (Name[1] && Name[1] != ',')
767  Name++;
768  break;
769  case '?': // Disparage slightly code.
770  case '!': // Disparage severely.
771  case '*': // Ignore for choosing register preferences.
772  break; // Pass them.
773  }
774 
775  Name++;
776  }
777 
778  return true;
779 }
780 
781 void TargetInfo::CheckFixedPointBits() const {
782  // Check that the number of fractional and integral bits (and maybe sign) can
783  // fit into the bits given for a fixed point type.
785  assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
792 
793  assert(getShortFractScale() + 1 <= ShortFractWidth);
794  assert(getFractScale() + 1 <= FractWidth);
795  assert(getLongFractScale() + 1 <= LongFractWidth);
797  assert(getUnsignedFractScale() <= FractWidth);
799 
800  // Each unsigned fract type has either the same number of fractional bits
801  // as, or one more fractional bit than, its corresponding signed fract type.
804  assert(getFractScale() == getUnsignedFractScale() ||
808 
809  // When arranged in order of increasing rank (see 6.3.1.3a), the number of
810  // fractional bits is nondecreasing for each of the following sets of
811  // fixed-point types:
812  // - signed fract types
813  // - unsigned fract types
814  // - signed accum types
815  // - unsigned accum types.
816  assert(getLongFractScale() >= getFractScale() &&
823 
824  // When arranged in order of increasing rank (see 6.3.1.3a), the number of
825  // integral bits is nondecreasing for each of the following sets of
826  // fixed-point types:
827  // - signed accum types
828  // - unsigned accum types
829  assert(getLongAccumIBits() >= getAccumIBits() &&
833 
834  // Each signed accum type has at least as many integral bits as its
835  // corresponding unsigned accum type.
837  assert(getAccumIBits() >= getUnsignedAccumIBits());
839 }
840 
842  auto *Target = static_cast<TransferrableTargetInfo*>(this);
843  auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
844  *Target = *Src;
845 }
OpenCLTypeKind
OpenCL type kinds.
Definition: TargetInfo.h:166
virtual bool checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection branch.
Definition: TargetInfo.cpp:156
unsigned getTypeWidth(IntType T) const
Return the width (in bits) of the specified integer type enum.
Definition: TargetInfo.cpp:224
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of &#39;float&#39;.
Definition: TargetInfo.h:628
unsigned getLongAccumIBits() const
Definition: TargetInfo.h:490
unsigned char LargeArrayMinWidth
Definition: TargetInfo.h:68
virtual void adjust(LangOptions &Opts)
Set forced language options.
Definition: TargetInfo.cpp:340
unsigned getLongWidth() const
getLongWidth/Align - Return the size of &#39;signed long&#39; and &#39;unsigned long&#39; for this target...
Definition: TargetInfo.h:437
const llvm::fltSemantics * FloatFormat
Definition: TargetInfo.h:106
virtual bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const =0
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1060
unsigned getLongAlign() const
Definition: TargetInfo.h:438
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:255
virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const
Get address space for OpenCL type.
Definition: TargetInfo.cpp:446
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
Definition: TargetInfo.cpp:664
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1330
unsigned getAccumIBits() const
Definition: TargetInfo.h:485
TargetInfo(const llvm::Triple &T)
Definition: TargetInfo.cpp:29
unsigned getCharWidth() const
Definition: TargetInfo.h:419
unsigned short SimdDefaultAlign
Definition: TargetInfo.h:198
unsigned getShortAccumIBits() const
Definition: TargetInfo.h:478
void setRequiresImmediate(int Min, int Max)
Definition: TargetInfo.h:963
static const LangASMap DefaultAddrSpaceMap
Definition: TargetInfo.cpp:26
unsigned getCharAlign() const
Definition: TargetInfo.h:420
unsigned UseSignedCharForObjCBool
Whether Objective-C&#39;s built-in boolean type should be signed char.
Definition: TargetInfo.h:140
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
Definition: AddressSpaces.h:25
virtual void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const
Enable or disable a specific target feature; the feature name must be valid.
Definition: TargetInfo.h:1164
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1129
unsigned getIntAlign() const
Definition: TargetInfo.h:433
const char * getTypeConstantSuffix(IntType T) const
Return the constant suffix for the specified integer type enum.
Definition: TargetInfo.cpp:181
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
Definition: TargetInfo.cpp:526
const char * MCountName
Definition: TargetInfo.h:200
unsigned getUnsignedLongAccumIBits() const
Definition: TargetInfo.h:520
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:54
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
Definition: TargetInfo.cpp:318
unsigned char MaxAtomicPromoteWidth
Definition: TargetInfo.h:197
const llvm::fltSemantics * HalfFormat
Definition: TargetInfo.h:106
unsigned char SSERegParmMax
Definition: TargetInfo.h:201
const llvm::fltSemantics * Float128Format
Definition: TargetInfo.h:106
The Microsoft ABI is the ABI used by Microsoft Visual Studio (and compatible compilers).
Definition: TargetCXXABI.h:125
unsigned ARMCDECoprocMask
Definition: TargetInfo.h:221
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:153
unsigned getShortWidth() const
Return the size of &#39;signed short&#39; and &#39;unsigned short&#39; for this target, in bits.
Definition: TargetInfo.h:424
Defines the Diagnostic-related interfaces.
unsigned HasAArch64SVETypes
Definition: TargetInfo.h:219
VersionTuple PlatformMinVersion
Definition: TargetInfo.h:209
unsigned ComplexLongDoubleUsesFP2Ret
Definition: TargetInfo.h:213
unsigned getLongLongAlign() const
Definition: TargetInfo.h:443
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
Definition: TargetInfo.h:155
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Definition: TargetInfo.cpp:481
unsigned RealTypeUsesObjCFPRet
Definition: TargetInfo.h:212
Provides definitions for the various language-specific address spaces.
virtual bool checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection branch.
Definition: TargetInfo.cpp:150
StringRef PlatformName
Definition: TargetInfo.h:208
virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const
Definition: TargetInfo.cpp:439
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
Definition: TargetInfo.cpp:473
unsigned char DefaultAlignForAttributeAligned
Definition: TargetInfo.h:99
const llvm::fltSemantics & getLongDoubleFormat() const
Definition: TargetInfo.h:646
unsigned HasBuiltinMSVaList
Definition: TargetInfo.h:215
Exposes information about the current target.
Definition: TargetInfo.h:179
unsigned HasAlignMac68kSupport
Definition: TargetInfo.h:211
unsigned char RegParmMax
Definition: TargetInfo.h:201
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:426
Defines the clang::LangOptions interface.
unsigned MaxOpenCLWorkGroupSize
Definition: TargetInfo.h:223
unsigned getIntWidth() const
getIntWidth/Align - Return the size of &#39;signed int&#39; and &#39;unsigned int&#39; for this target, in bits.
Definition: TargetInfo.h:432
unsigned UseBitFieldTypeAlignment
Control whether the alignment of bit-field types is respected when laying out structures.
Definition: TargetInfo.h:147
static StringRef removeGCCRegisterPrefix(StringRef Name)
Definition: TargetInfo.cpp:463
unsigned getShortAlign() const
Return the alignment of &#39;signed short&#39; and &#39;unsigned short&#39; for this target.
Definition: TargetInfo.h:428
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of &#39;double&#39;.
Definition: TargetInfo.h:638
unsigned getTypeAlign(IntType T) const
Return the alignment (in bits) of the specified integer type enum.
Definition: TargetInfo.cpp:300
static const char * getTypeName(IntType T)
Return the user string for the specified integer type enum.
Definition: TargetInfo.cpp:163
const llvm::fltSemantics * LongDoubleFormat
Definition: TargetInfo.h:106
const LangASMap * AddrSpaceMap
Definition: TargetInfo.h:203
unsigned IsRenderScriptTarget
Definition: TargetInfo.h:217
unsigned UseExplicitBitFieldAlignment
Whether explicit bit field alignment attributes are honored.
Definition: TargetInfo.h:158
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of &#39;signed long long&#39; and &#39;unsigned long long&#39; for this targ...
Definition: TargetInfo.h:442
unsigned getUnsignedAccumScale() const
getUnsignedAccumScale/IBits - Return the number of fractional/integral bits in a &#39;unsigned _Accum&#39; ty...
Definition: TargetInfo.h:507
bool validateOutputConstraint(ConstraintInfo &Info) const
Definition: TargetInfo.cpp:567
virtual ArrayRef< AddlRegName > getGCCAddlRegNames() const
Definition: TargetInfo.h:1472
virtual ~TargetInfo()
Definition: TargetInfo.cpp:143
The generic Itanium ABI is the standard ABI of most open-source and Unix-like platforms.
Definition: TargetCXXABI.h:33
virtual ArrayRef< GCCRegAlias > getGCCRegAliases() const =0
unsigned getUnsignedAccumIBits() const
Definition: TargetInfo.h:510
void set(Kind kind)
Definition: TargetCXXABI.h:140
unsigned getUnsignedLongAccumScale() const
getUnsignedLongAccumScale/IBits - Return the number of fractional/integral bits in a &#39;unsigned long _...
Definition: TargetInfo.h:517
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:110
unsigned getUnsignedShortAccumIBits() const
Definition: TargetInfo.h:499
Dataflow Directional Tag Classes.
unsigned ZeroLengthBitfieldBoundary
If non-zero, specifies a fixed alignment value for bitfields that follow zero length bitfield...
Definition: TargetInfo.h:162
static const char * getTypeFormatModifier(IntType T)
Return the printf format modifier for the specified integer type enum.
Definition: TargetInfo.cpp:206
static std::string getName(const CallEvent &Call)
unsigned[(unsigned) LangAS::FirstTargetAddressSpace] LangASMap
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
Definition: AddressSpaces.h:58
unsigned getLongFractScale() const
getLongFractScale - Return the number of fractional bits in a &#39;signed long _Fract&#39; type...
Definition: TargetInfo.h:536
unsigned getUnsignedFractScale() const
getUnsignedFractScale - Return the number of fractional bits in a &#39;unsigned _Fract&#39; type...
Definition: TargetInfo.h:547
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
Definition: TargetInfo.h:941
Fields controlling how types are laid out in memory; these may need to be copied for targets like AMD...
Definition: TargetInfo.h:59
const std::string & getConstraintStr() const
Definition: TargetInfo.h:925
unsigned getUnsignedShortAccumScale() const
getUnsignedShortAccumScale/IBits - Return the number of fractional/integral bits in a &#39;unsigned short...
Definition: TargetInfo.h:496
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
Definition: TargetInfo.cpp:240
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Definition: CharInfo.h:93
bool resolveSymbolicName(const char *&Name, ArrayRef< ConstraintInfo > OutputConstraints, unsigned &Index) const
Definition: TargetInfo.cpp:641
RealType getRealTypeByWidth(unsigned BitWidth, bool ExplicitIEEE) const
Return floating point type with specified width.
Definition: TargetInfo.cpp:270
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.
Definition: TargetInfo.h:405
unsigned getShortFractScale() const
getShortFractScale - Return the number of fractional bits in a &#39;signed short _Fract&#39; type...
Definition: TargetInfo.h:528
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
Definition: TargetInfo.h:573
void copyAuxTarget(const TargetInfo *Aux)
Copy type and layout related info.
Definition: TargetInfo.cpp:841
unsigned getUnsignedLongFractScale() const
getUnsignedLongFractScale - Return the number of fractional bits in a &#39;unsigned long _Fract&#39; type...
Definition: TargetInfo.h:553
unsigned getFractScale() const
getFractScale - Return the number of fractional bits in a &#39;signed _Fract&#39; type.
Definition: TargetInfo.h:532
unsigned getUnsignedShortFractScale() const
getUnsignedShortFractScale - Return the number of fractional bits in a &#39;unsigned short _Fract&#39; type...
Definition: TargetInfo.h:540
const llvm::fltSemantics * DoubleFormat
Definition: TargetInfo.h:106
TargetCXXABI TheCXXABI
Definition: TargetInfo.h:202
Defines the clang::TargetInfo interface.
unsigned char MaxAtomicInlineWidth
Definition: TargetInfo.h:197
void setTiedOperand(unsigned N, ConstraintInfo &Output)
Indicate that this is an input operand that is tied to the specified output operand.
Definition: TargetInfo.h:986
std::unique_ptr< llvm::DataLayout > DataLayout
Definition: TargetInfo.h:199
void resetDataLayout(StringRef DL)
Definition: TargetInfo.cpp:145
virtual ArrayRef< const char * > getGCCRegNames() const =0
bool UseAddrSpaceMapMangling
Specify if mangling based on address space map should be used or not for language specific address sp...
Definition: TargetInfo.h:299