19#include "llvm/ADT/APFloat.h"
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringExtras.h"
22#include "llvm/IR/DerivedTypes.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/TargetParser/TargetParser.h"
25#include "llvm/TargetParser/Triple.h"
115 if (
T.isGNUEnvironment() ||
T.isWindowsMSVCEnvironment() ||
T.isAndroid() ||
117 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
118 else if (
T.isOSDarwin() ||
T.isOSOpenBSD())
185 TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment() || Triple.isUEFI()
186 ? TargetCXXABI::Microsoft
187 : TargetCXXABI::GenericItanium);
210 return std::min<size_t>(*
MaxBitIntWidth, llvm::IntegerType::MAX_INT_BITS);
229 Diags.
Report(diag::err_opt_not_valid_on_target) <<
"cf-protection=branch";
236 llvm::report_fatal_error(
"not implemented");
242 Diags.
Report(diag::err_opt_not_valid_on_target)
243 << (Twine(
"mcf-branch-label-scheme=") +
251 Diags.
Report(diag::err_opt_not_valid_on_target) <<
"cf-protection=return";
259 default: llvm_unreachable(
"not an integer!");
277 default: llvm_unreachable(
"not an integer!");
302 default: llvm_unreachable(
"not an integer!");
320 default: llvm_unreachable(
"not an integer!");
335 unsigned BitWidth,
bool IsSigned)
const {
350 bool IsSigned)
const {
402 default: llvm_unreachable(
"not an integer!");
420 default: llvm_unreachable(
"not an integer!");
442 if (Opts.NoBitFieldTypeAlign)
445 switch (Opts.WCharSize) {
446 default: llvm_unreachable(
"invalid wchar_t width");
453 if (Opts.AlignDouble) {
463 if (!Opts.NativeHalfType) {
491 assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
492 bool Is32BitArch = MaxPointerWidth == 32;
516 OpenCLFeaturesMap,
"__opencl_c_generic_address_space");
524 if (Opts.DoubleSize) {
525 if (Opts.DoubleSize == 32) {
530 }
else if (Opts.DoubleSize == 64) {
538 if (Opts.LongDoubleSize) {
543 }
else if (Opts.LongDoubleSize == 128) {
546 }
else if (Opts.LongDoubleSize == 80) {
548 if (
getTriple().isWindowsMSVCEnvironment()) {
552 if (
getTriple().getArch() == llvm::Triple::x86) {
563 if (Opts.NewAlignOverride)
569 CheckFixedPointBits();
572 Diags.
Report(diag::err_opt_not_valid_on_target) <<
"-fprotect-parens";
573 Opts.ProtectParens =
false;
576 if (Opts.MaxBitIntWidth)
579 if (Opts.FakeAddressSpaceMap)
589 const std::vector<std::string> &FeatureVec)
const {
590 for (StringRef Name : FeatureVec) {
594 if (Name[0] !=
'+' && Name[0] !=
'-')
595 Diags.
Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
604 if (Features ==
"default")
607 Features.split(AttrFeatures,
",");
611 for (
auto &
Feature : AttrFeatures) {
619 if (
Feature.starts_with(
"fpmath="))
622 if (
Feature.starts_with(
"branch-protection=")) {
623 Ret.BranchProtection =
Feature.split(
'=').second.trim();
628 if (
Feature.starts_with(
"arch=")) {
629 if (!Ret.CPU.empty())
630 Ret.Duplicate =
"arch=";
632 Ret.CPU =
Feature.split(
"=").second.trim();
633 }
else if (
Feature.starts_with(
"tune=")) {
634 if (!Ret.Tune.empty())
635 Ret.Duplicate =
"tune=";
637 Ret.Tune =
Feature.split(
"=").second.trim();
638 }
else if (
Feature.starts_with(
"no-"))
639 Ret.Features.push_back(
"-" +
Feature.split(
"-").second.str());
641 Ret.Features.push_back(
"+" +
Feature.str());
648 if (
getCXXABI() != TargetCXXABI::Microsoft &&
649 (ClangABICompat4 ||
getTriple().isPS4()))
660 if (
getCXXABI() == TargetCXXABI::Microsoft &&
667 if (
getCXXABI() == TargetCXXABI::Microsoft &&
706 if (Name[0] ==
'%' || Name[0] ==
'#')
707 Name = Name.substr(1);
737 if (!Name.getAsInteger(0, n))
738 return n < Names.size();
742 if (llvm::is_contained(Names, Name))
747 for (
const char *AN : ARN.Names) {
752 if (AN == Name && ARN.RegNum < Names.size())
758 for (
const char *A : GRA.Aliases) {
769 bool ReturnCanonical)
const {
780 if (!Name.getAsInteger(0, n)) {
781 assert(n < Names.size() &&
"Out of bounds register number!");
788 for (
const char *AN : ARN.Names) {
793 if (AN == Name && ARN.RegNum < Names.size())
794 return ReturnCanonical ? Names[ARN.RegNum] : Name;
799 for (
const char *A : RA.Aliases) {
812 if (*Name !=
'=' && *Name !=
'+')
852 if (Name[1] ==
'=' || Name[1] ==
'+')
856 while (Name[1] && Name[1] !=
',')
885 unsigned &Index)
const {
886 assert(*Name ==
'[' &&
"Symbolic name did not start with '['");
888 const char *Start = Name;
889 while (*Name && *Name !=
']')
897 std::string SymbolicName(Start, Name - Start);
899 for (Index = 0; Index != OutputConstraints.size(); ++Index)
900 if (SymbolicName == OutputConstraints[Index].getName())
918 if (*Name >=
'0' && *Name <=
'9') {
919 const char *DigitStart = Name;
920 while (Name[1] >=
'0' && Name[1] <=
'9')
922 const char *DigitEnd = Name;
924 if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
925 .getAsInteger(10, i))
929 if (i >= OutputConstraints.size())
return false;
932 if (OutputConstraints[i].isReadWrite())
961 if (OutputConstraints[Index].isReadWrite())
1008 while (Name[1] && Name[1] !=
',')
1027void TargetInfo::CheckFixedPointBits()
const {
1099 Constraint = Constraint.split(
'\0').first;
1101 for (
const char *I = Constraint.begin(), *E = Constraint.end(); I < E; I++) {
1114 while (I + 1 != E && I[1] !=
',')
1120 while (I + 1 != E && I[1] == *I)
1131 "Must pass output names to constraints with a symbolic name");
1134 assert(ResolveResult &&
"Could not resolve symbolic name");
1135 (void)ResolveResult;
1136 Result += llvm::utostr(Index);
1151 if (TypeSize >= 512)
Provides definitions for the various language-specific address spaces.
Defines the Diagnostic-related interfaces.
static StringRef removeGCCRegisterPrefix(StringRef Name)
static constexpr LangASMap DefaultAddrSpaceMap
static constexpr LangASMap FakeAddrSpaceMap
Defines the clang::LangOptions interface.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
The type of a lookup table which maps from language-specific address spaces to target-specific ones.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompatibleWith(ClangABI Version) const
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
virtual bool validatePointerAuthKey(const llvm::APSInt &value) const
Determine whether the given pointer-authentication key is valid.
unsigned getUnsignedLongFractScale() const
getUnsignedLongFractScale - Return the number of fractional bits in a 'unsigned long _Fract' type.
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
bool resolveSymbolicName(const char *&Name, ArrayRef< ConstraintInfo > OutputConstraints, unsigned &Index) const
void copyAuxTarget(const TargetInfo *Aux)
Copy type and layout related info.
TargetInfo(const llvm::Triple &T)
virtual bool checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection return.
unsigned getShortWidth() const
getShortWidth/Align - Return the size of 'signed short' and 'unsigned short' for this target,...
unsigned getUnsignedAccumScale() const
getUnsignedAccumScale/IBits - Return the number of fractional/integral bits in a 'unsigned _Accum' ty...
unsigned getIntAlign() const
virtual ArrayRef< AddlRegName > getGCCAddlRegNames() const
unsigned getUnsignedAccumIBits() const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
const LangASMap * AddrSpaceMap
const char * UserLabelPrefix
bool HasMicrosoftRecordLayout
unsigned getUnsignedFractScale() const
getUnsignedFractScale - Return the number of fractional bits in a 'unsigned _Fract' type.
virtual bool checkCFBranchLabelSchemeSupported(const CFBranchLabelSchemeKind Scheme, DiagnosticsEngine &Diags) const
unsigned getLongAlign() const
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
unsigned getLongLongAlign() const
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
virtual CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const
Get the target default CFBranchLabelScheme scheme.
virtual ArrayRef< const char * > getGCCRegNames() const =0
unsigned getTypeWidth(IntType T) const
Return the width (in bits) of the specified integer type enum.
virtual bool emitVectorDeletingDtors(const LangOptions &) const
Controls whether to emit MSVC vector deleting destructors.
unsigned getLongFractScale() const
getLongFractScale - Return the number of fractional bits in a 'signed long _Fract' type.
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
std::optional< unsigned > MaxBitIntWidth
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.
unsigned getAccumIBits() const
virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const
std::string simplifyConstraint(StringRef Constraint, SmallVectorImpl< ConstraintInfo > *OutCons=nullptr) const
VersionTuple PlatformMinVersion
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
unsigned getShortAccumIBits() const
unsigned HasBuiltinZOSVaList
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of 'float'.
virtual ArrayRef< GCCRegAlias > getGCCRegAliases() const =0
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
unsigned getLongAccumIBits() const
FloatModeKind getRealTypeByWidth(unsigned BitWidth, FloatModeKind ExplicitType) const
Return floating point type with specified width.
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
unsigned getHalfWidth() const
getHalfWidth/Align/Format - Return the size/align/format of 'half'.
unsigned char SSERegParmMax
unsigned HasUnalignedAccess
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, const TargetInfo *Aux)
Set forced language options.
unsigned char MaxAtomicPromoteWidth
virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const
Get address space for OpenCL type.
static const char * getTypeName(IntType T)
Return the user string for the specified integer type enum.
unsigned getCharAlign() const
unsigned RealTypeUsesObjCFPRetMask
unsigned MaxOpenCLWorkGroupSize
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
virtual bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const =0
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
bool UseAddrSpaceMapMangling
Specify if mangling based on address space map should be used or not for language specific address sp...
void resetDataLayout()
Set the data layout based on current triple and ABI.
virtual void setDependentOpenCLOpts()
Set features that depend on other features.
unsigned ComplexLongDoubleUsesFP2Ret
virtual bool hasIbm128Type() const
Determine whether the __ibm128 type is supported on this target.
unsigned getUnsignedShortAccumIBits() const
std::string DataLayoutString
unsigned getUnsignedLongAccumScale() const
getUnsignedLongAccumScale/IBits - Return the number of fractional/integral bits in a 'unsigned long _...
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
unsigned getUnsignedLongAccumIBits() const
unsigned getUnsignedShortFractScale() const
getUnsignedShortFractScale - Return the number of fractional bits in a 'unsigned short _Fract' type.
unsigned HasAlignMac68kSupport
const llvm::fltSemantics & getLongDoubleFormat() const
bool validateOutputConstraint(ConstraintInfo &Info) const
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
const char * getTypeConstantSuffix(IntType T) const
Return the constant suffix for the specified integer type enum.
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
virtual bool checkArithmeticFenceSupported() const
Controls if __arithmetic_fence is supported in the targeted backend.
virtual StringRef getABI() const
Get the ABI currently in use.
virtual size_t getMaxBitIntWidth() const
unsigned HasAArch64ACLETypes
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
virtual bool areDefaultedSMFStillPOD(const LangOptions &) const
Controls whether explicitly defaulted (= default) special member functions disqualify something from ...
unsigned getCharWidth() const
virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
unsigned getFractScale() const
getFractScale - Return the number of fractional bits in a 'signed _Fract' type.
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 ...
virtual bool checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection branch.
virtual std::string convertConstraint(const char *&Constraint) const
unsigned char MaxAtomicInlineWidth
unsigned AllowAMDGPUUnsafeFPAtomics
unsigned getShortFractScale() const
getShortFractScale - Return the number of fractional bits in a 'signed short _Fract' type.
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.
unsigned ARMCDECoprocMask
static const char * getTypeFormatModifier(IntType T)
Return the printf format modifier for the specified integer type enum.
unsigned getUnsignedShortAccumScale() const
getUnsignedShortAccumScale/IBits - Return the number of fractional/integral bits in a 'unsigned short...
unsigned HasBuiltinMSVaList
virtual VTableUniquenessKind getVTableUniqueness() const
Returns whether the target's ABI guarantees that a class's vtable has a unique address program-wide.
unsigned getTypeAlign(IntType T) const
Return the alignment (in bits) of the specified integer type enum.
unsigned getShortAlign() const
virtual bool callGlobalDeleteInDeletingDtor(const LangOptions &) const
Controls whether global operator delete is called by the deleting destructor or at the point where de...
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
VTableUniquenessKind
A target's ABI policy for whether a class's vtable can be assumed to have a unique address program-wi...
@ AlwaysUnique
Every vtable has a single address program-wide.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
OpenCLTypeKind
OpenCL type kinds.
unsigned Microsoft64BitMinGlobalAlign(uint64_t TypeSize)
@ Result
The result type of a method or function.
const FunctionProtoType * T
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
LangAS
Defines the address space values used by the address space qualifier of QualType.
static const char * getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme)
Contains information gathered from parsing the contents of TargetAttr.
const std::string & getConstraintStr() const
std::string ConstraintStr
unsigned getTiedOperand() const
bool allowsMemory() const
void setTiedOperand(unsigned N, ConstraintInfo &Output)
Indicate that this is an input operand that is tied to the specified output operand.
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand.
bool allowsRegister() const
void setRequiresImmediate(int Min, int Max)
Fields controlling how types are laid out in memory; these may need to be copied for targets like AMD...
const llvm::fltSemantics * DoubleFormat
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
unsigned short SuitableAlign
unsigned char PointerWidth
unsigned UseExplicitBitFieldAlignment
Whether explicit bit field alignment attributes are honored.
IntType
===-— Target Data Type Query Methods ----------------------------—===//
const llvm::fltSemantics * LongDoubleFormat
unsigned char LargeArrayAlign
unsigned char ShortAccumWidth
unsigned ZeroLengthBitfieldBoundary
If non-zero, specifies a fixed alignment value for bitfields that follow zero length bitfield,...
const llvm::fltSemantics * Float128Format
unsigned LargestOverSizedBitfieldContainer
The largest container size which should be used for an over-sized bitfield, in bits.
unsigned char DoubleWidth
unsigned UseLeadingZeroLengthBitfield
Whether zero length bitfield alignment is respected if they are the leading members.
unsigned char LongLongAlign
unsigned char LongAccumAlign
unsigned UseBitFieldTypeAlignment
Control whether the alignment of bit-field types is respected when laying out structures.
bool VectorsAreElementAligned
unsigned char LargeArrayMinWidth
unsigned char PointerAlign
unsigned char LongDoubleAlign
unsigned char LongDoubleWidth
unsigned char Int128Align
unsigned char ShortAccumScale
unsigned MaxAlignedAttribute
If non-zero, specifies a maximum alignment to truncate alignment specified in the aligned attribute o...
unsigned char DoubleAlign
bool PaddingOnUnsignedFixedPoint
const llvm::fltSemantics * Ibm128Format
unsigned char LongFractWidth
unsigned char Ibm128Align
unsigned char ShortFractAlign
unsigned char ShortAccumAlign
unsigned char LongFractAlign
const llvm::fltSemantics * FloatFormat
const llvm::fltSemantics * HalfFormat
unsigned char LongLongWidth
unsigned char LongAccumScale
unsigned char MinGlobalAlign
unsigned UseSignedCharForObjCBool
Whether Objective-C's built-in boolean type should be signed char.
unsigned char Float128Align
unsigned char LongAccumWidth
unsigned char DefaultAlignForAttributeAligned
unsigned char ShortFractWidth