15 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H 16 #define LLVM_CLANG_BASIC_TARGETINFO_H 24 #include "llvm/ADT/APInt.h" 25 #include "llvm/ADT/IntrusiveRefCntPtr.h" 26 #include "llvm/ADT/Optional.h" 27 #include "llvm/ADT/SmallSet.h" 28 #include "llvm/ADT/StringMap.h" 29 #include "llvm/ADT/StringRef.h" 30 #include "llvm/ADT/Triple.h" 31 #include "llvm/IR/DataLayout.h" 32 #include "llvm/Support/DataTypes.h" 42 class DiagnosticsEngine;
50 namespace Builtin {
struct Info; }
55 std::shared_ptr<TargetOptions> TargetOpts;
85 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
106 DataLayout.reset(
new llvm::DataLayout(DL));
117 const std::shared_ptr<TargetOptions> &Opts);
123 assert(TargetOpts &&
"Missing target options");
154 CharPtrBuiltinVaList = 0,
192 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
193 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
238 case UnsignedLongLong:
239 return SignedLongLong;
241 llvm_unreachable(
"Invalid SizeType");
246 return getCorrespondingUnsignedType(IntMaxType);
249 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
252 return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace));
256 return getCorrespondingUnsignedType(IntPtrType);
264 return getCorrespondingUnsignedType(Int64Type);
274 return UnsignedShort;
280 return UnsignedLongLong;
282 llvm_unreachable(
"Unexpected signed integer type");
289 unsigned getTypeWidth(
IntType T)
const;
292 virtual IntType getIntTypeByWidth(
unsigned BitWidth,
bool IsSigned)
const;
295 virtual IntType getLeastIntTypeByWidth(
unsigned BitWidth,
296 bool IsSigned)
const;
299 RealType getRealTypeByWidth(
unsigned BitWidth)
const;
304 unsigned getTypeAlign(
IntType T)
const;
307 static bool isTypeSigned(
IntType T);
312 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
315 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
361 return getPointerWidth(0) >= 64;
374 return DefaultAlignForAttributeAligned;
385 return NewAlign ? NewAlign :
std::max(LongDoubleAlign, LongLongAlign);
423 return *LongDoubleFormat;
431 return *Float128Format;
458 uint64_t AlignmentInBits)
const {
459 return AtomicSizeInBits <= AlignmentInBits &&
460 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
462 llvm::isPowerOf2_64(AtomicSizeInBits /
getCharWidth()));
474 return getTypeWidth(IntMaxType);
499 return UseSignedCharForObjCBool;
502 UseSignedCharForObjCBool =
false;
508 return UseBitFieldTypeAlignment;
514 return UseZeroLengthBitfieldAlignment;
520 return ZeroLengthBitfieldBoundary;
526 return UseExplicitBitFieldAlignment;
531 return HasAlignMac68kSupport;
542 const char *getTypeConstantSuffix(
IntType T)
const;
548 static const char *getTypeFormatModifier(
IntType T);
553 return RealTypeUsesObjCFPRet & (1 <<
T);
559 return ComplexLongDoubleUsesFP2Ret;
573 return UseAddrSpaceMapMangling;
580 virtual void getTargetDefines(
const LangOptions &Opts,
611 bool isValidClobber(StringRef Name)
const;
617 bool isValidGCCRegisterName(StringRef Name)
const;
624 StringRef getNormalizedGCCRegisterName(StringRef Name,
625 bool ReturnCanonical =
false)
const;
628 const StringRef &Expression)
const {
635 CI_AllowsMemory = 0x01,
636 CI_AllowsRegister = 0x02,
638 CI_HasMatchingInput = 0x08,
639 CI_ImmediateConstant = 0x10,
640 CI_EarlyClobber = 0x20,
654 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
656 ImmRange.Min = ImmRange.Max = 0;
660 const std::string &
getName()
const {
return Name; }
677 assert(hasTiedOperand() &&
"Has no tied operand!");
678 return (
unsigned)TiedOperand;
682 return (Flags & CI_ImmediateConstant) != 0;
685 return (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max)) ||
686 ImmSet.count(Value.getZExtValue()) != 0;
695 Flags |= CI_ImmediateConstant;
700 Flags |= CI_ImmediateConstant;
701 for (
int Exact : Exacts)
702 ImmSet.insert(Exact);
705 Flags |= CI_ImmediateConstant;
706 ImmSet.insert(Exact);
709 Flags |= CI_ImmediateConstant;
720 Flags = Output.
Flags;
734 bool &HasSizeMismatch)
const {
735 HasSizeMismatch =
false;
759 std::string &)
const {
763 validateAsmConstraint(
const char *&Name,
766 bool resolveSymbolicName(
const char *&Name,
768 unsigned &Index)
const;
775 if (*Constraint ==
'p')
776 return std::string(
"r");
777 return std::string(1, *Constraint);
781 virtual const char *getClobbers()
const = 0;
795 assert(DataLayout &&
"Uninitialized DataLayout!");
800 const char *
const Aliases[5];
805 const char *
const Names[5];
851 virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
853 const std::vector<std::string> &FeatureVec)
const;
856 virtual StringRef
getABI()
const {
return StringRef(); }
866 virtual bool setCPU(
const std::string &Name) {
878 virtual bool setABI(
const std::string &Name) {
893 bool Enabled)
const {
894 Features[Name] = Enabled;
933 assert(RegParmMax < 7 &&
"RegParmMax value is larger than AST can handle");
955 return getTriple().isOSWindows() &&
956 (getTriple().getArch() == llvm::Triple::x86 ||
957 getTriple().getArch() == llvm::Triple::x86_64);
967 return NoAsmVariants;
990 return LangAS::Default;
1032 return CCCR_Warning;
1052 for (
const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
1053 getTargetOpts().SupportedOpenCLOptions.support(Ext);
1059 return getTargetOpts().SupportedOpenCLOptions;
1064 return getTargetOpts().SupportedOpenCLOptions;
1103 return PointerWidth;
1106 return PointerAlign;
1108 virtual enum IntType getPtrDiffTypeV(
unsigned AddrSpace)
const {
unsigned getRegParmMax() const
TargetOptions & getTargetOpts() const
Retrieve the target options.
IntType getInt64Type() const
unsigned getHalfWidth() const
getHalfWidth/Align/Format - Return the size/align/format of 'half'.
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of 'float'.
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled...
bool hasBuiltinMSVaList() const
Returns whether or not type __builtin_ms_va_list type is available on this target.
Represents a version number in the form major[.minor[.subminor[.build]]].
The basic abstraction for the target C++ ABI.
unsigned getBoolWidth() const
Return the size of '_Bool' and C++ 'bool' for this target, in bits.
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target...
OpenCL supported extensions and optional core features.
unsigned getSuitableAlign() const
Return the alignment that is suitable for storing any object with a fundamental alignment requirement...
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
virtual unsigned getVtblPtrAddressSpace() const
unsigned getMaxVectorAlign() const
Return the maximum vector alignment supported for the given target.
unsigned short MaxVectorAlign
unsigned getLargeArrayAlign() const
unsigned getFloat128Align() const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
__builtin_va_list as defined by the PNaCl ABI: http://www.chromium.org/nativeclient/pnacl/bitcode-abi...
unsigned getLongAlign() const
virtual bool isValidFeatureName(StringRef Feature) const
Determine whether this TargetInfo supports the given feature.
virtual void setMaxAtomicWidth()
Set the maximum inline or promote width lock-free atomic operation for the given target.
unsigned char LongLongWidth
unsigned getDefaultAlignForAttributeAligned() const
Return the default alignment for attribute((aligned)) on this target, to be used if no alignment valu...
__builtin_va_list as defined by the x86-64 ABI: http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf
unsigned getCharWidth() const
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
unsigned short SimdDefaultAlign
unsigned getLargeArrayMinWidth() const
llvm::SmallSet< int, 4 > ImmSet
virtual void adjustTargetOptions(const CodeGenOptions &CGOpts, TargetOptions &TargetOpts) const
Adjust target options based on codegen options.
void setRequiresImmediate(int Min, int Max)
const char *const Register
Options for controlling the target.
unsigned getCharAlign() const
virtual StringRef getConstraintRegister(const StringRef &Constraint, const StringRef &Expression) const
unsigned getWCharAlign() const
const llvm::fltSemantics & getHalfFormat() const
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
__builtin_va_list as defined by the AArch64 ABI http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
virtual bool isCLZForZeroUndef() const
The __builtin_clz* and __builtin_ctz* built-in functions are specified to have undefined results for ...
unsigned char LongDoubleWidth
unsigned char LargeArrayMinWidth
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 ZeroLengthBitfieldBoundary
If non-zero, specifies a fixed alignment value for bitfields that follow zero length bitfield...
unsigned getZeroLengthBitfieldBoundary() const
Get the fixed alignment value in bits for a member that follows a zero length bitfield.
unsigned getLongDoubleAlign() const
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
unsigned char MinGlobalAlign
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
unsigned getIntAlign() const
IntType getUnsignedPtrDiffType(unsigned AddrSpace) const
unsigned getChar32Width() const
getChar32Width/Align - Return the size of 'char32_t' for this target, in bits.
virtual bool validateConstraintModifier(StringRef, char, unsigned, std::string &) const
IntType getChar32Type() const
void setRequiresImmediate()
const std::string & getName() const
virtual bool useFloat128ManglingForLongDouble() const
Return true if the 'long double' type should be mangled like __float128.
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' is g...
IntType getSizeType() const
bool hasNoAsmVariants() const
Return true if {|} are normal characters in the asm string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
virtual void setOpenCLExtensionOpts()
Set supported OpenCL extensions as written on command line.
unsigned getMaxAtomicPromoteWidth() const
Return the maximum width lock-free atomic operation which will ever be supported for the given target...
virtual StringRef getABI() const
Get the ABI currently in use.
virtual std::string isValidSectionSpecifier(StringRef SR) const
An optional hook that targets can implement to perform semantic checking on attribute((section("foo")...
unsigned char MaxAtomicPromoteWidth
bool hasMatchingInput() const
Return true if this output operand has a matching (tied) input operand.
unsigned char DefaultAlignForAttributeAligned
const LangASMap & getAddressSpaceMap() const
unsigned char PointerWidth
unsigned char SSERegParmMax
virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits, uint64_t AlignmentInBits) const
Returns true if the given target supports lock-free atomic operations at the specified width and alig...
virtual bool validateTarget(DiagnosticsEngine &Diags) const
Check the target is valid after it is fully initialized.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
unsigned getShortWidth() const
Return the size of 'signed short' and 'unsigned short' for this target, in bits.
unsigned getChar16Align() const
unsigned LangASMap[(unsigned) LangAS::FirstTargetAddressSpace]
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
unsigned char DoubleWidth
VersionTuple PlatformMinVersion
virtual unsigned getRegisterWidth() const
Return the "preferred" register width on this target.
bool useZeroLengthBitfieldAlignment() const
Check whether zero length bitfields should force alignment of the next member.
unsigned ComplexLongDoubleUsesFP2Ret
unsigned getLongLongAlign() const
bool isSEHTrySupported() const
Whether the target supports SEH __try.
unsigned RealTypeUsesObjCFPRet
bool isLittleEndian() const
Provides definitions for the various language-specific address spaces.
unsigned getMinGlobalAlign() const
getMinGlobalAlign - Return the minimum alignment of a global variable, unless its alignment is explic...
bool useExplicitBitFieldAlignment() const
Check whether explicit bitfield alignment attributes should be.
const llvm::fltSemantics & getDoubleFormat() const
const llvm::fltSemantics & getLongDoubleFormat() const
typedef void* __builtin_va_list;
unsigned HasBuiltinMSVaList
void setRequiresImmediate(int Exact)
Exposes information about the current target.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting...
unsigned HasAlignMac68kSupport
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
virtual bool hasProtectedVisibility() const
Does this target support "protected" visibility?
IntType getSignedSizeType() const
IntType getUIntPtrType() const
const FunctionProtoType * T
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target, in bits.
bool useObjCFPRetForRealType(RealType T) const
Check whether the given real type should use the "fpret" flavor of Objective-C message passing on thi...
virtual bool hasSjLjLowering() const
Controls if __builtin_longjmp / __builtin_setjmp can be lowered to llvm.eh.sjlj.longjmp / llvm...
std::string ConstraintStr
bool requiresImmediateConstant() const
unsigned short getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
IntType getChar16Type() const
virtual bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags)
Perform initialization based on the user configured set of features (e.g., +sse4).
virtual bool validateCpuSupports(StringRef Name) const
virtual Optional< unsigned > getDWARFAddressSpace(unsigned AddressSpace) const
unsigned getShortAlign() const
Return the alignment of 'signed short' and 'unsigned short' for this target.
virtual bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const
Validate register name used for global register variables.
void resetDataLayout(StringRef DL)
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
unsigned getDoubleAlign() const
bool useAddressSpaceMapMangling() const
Specify if mangling based on address space map should be used or not for language specific address sp...
IntType getUIntMaxType() const
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
virtual bool allowsLargerPreferedTypeAlignment() const
Whether target allows to overalign ABI-specified preferred alignment.
unsigned UseExplicitBitFieldAlignment
Whether explicit bit field alignment attributes are honored.
unsigned getWCharWidth() const
getWCharWidth/Align - Return the size of 'wchar_t' for this target, in bits.
virtual bool useFP16ConversionIntrinsics() const
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
virtual uint64_t getPointerAlignV(unsigned AddrSpace) const
IntType getPtrDiffType(unsigned AddrSpace) const
unsigned getIntMaxTWidth() const
Return the size of intmax_t and uintmax_t for this target, in bits.
IntType getSigAtomicType() const
virtual bool setABI(const std::string &Name)
Use the specified ABI.
virtual bool isNan2008() const
Returns true if NaN encoding is IEEE 754-2008.
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
const LangASMap * AddrSpaceMap
unsigned getMaxAtomicInlineWidth() const
Return the maximum width lock-free atomic operation which can be inlined given the supported features...
IntType getWIntType() const
unsigned IsRenderScriptTarget
virtual int getEHDataRegisterNumber(unsigned RegNo) const
Return the register number that __builtin_eh_return_regno would return with the specified argument...
unsigned getChar16Width() const
getChar16Width/Align - Return the size of 'char16_t' for this target, in bits.
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
IntType getIntMaxType() const
unsigned getFloat128Width() const
getFloat128Width/Align/Format - Return the size/align/format of '__float128'.
Defines the clang::TargetOptions class.
unsigned getHalfAlign() const
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const
const llvm::DataLayout & getDataLayout() const
virtual ArrayRef< AddlRegName > getGCCAddlRegNames() const
virtual unsigned getFloatEvalMethod() const
Return the value for the C99 FLT_EVAL_METHOD macro.
__builtin_va_list as defined by the Power ABI: https://www.power.org /resources/downloads/Power-Arch-...
bool useObjCFP2RetForComplexLongDouble() const
Check whether _Complex long double should use the "fp2ret" flavor of Objective-C message passing on t...
bool useBitFieldTypeAlignment() const
Check whether the alignment of bit-field types is respected when laying out structures.
IntType getUInt64Type() const
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
virtual bool validateCpuIs(StringRef Name) const
bool isVLASupported() const
Whether target supports variable-length arrays.
bool isValidAsmImmediate(const llvm::APInt &Value) const
unsigned getLongDoubleWidth() const
getLongDoubleWidth/Align/Format - Return the size/align/format of 'long double'.
__builtin_va_list as defined by ARM AAPCS ABI http://infocenter.arm.com
unsigned char SuitableAlign
Defines various enumerations that describe declaration and type specifiers.
const llvm::fltSemantics & getFloat128Format() const
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Dataflow Directional Tag Classes.
bool allowsMemory() const
ConstraintInfo(StringRef ConstraintStr, StringRef Name)
unsigned UseSignedCharForObjCBool
Whether Objective-C's built-in boolean type should be signed char.
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand...
void setHasMatchingInput()
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
bool allowsRegister() const
const std::string & getConstraintStr() const
virtual llvm::Optional< LangAS > getConstantAddressSpace() const
Return an AST address space which can be used opportunistically for constant global memory...
bool useSignedCharForObjCBool() const
Check if the Objective-C built-in boolean type should be signed char.
unsigned getBoolAlign() const
Return the alignment of '_Bool' and C++ 'bool' for this target.
unsigned getTiedOperand() const
virtual const char * getStaticInitSectionSpecifier() const
Return the section to use for C++ static initialization functions.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
virtual bool isValidCPUName(StringRef Name) const
brief Determine whether this TargetInfo supports the given CPU name.
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
void setRequiresImmediate(llvm::ArrayRef< int > Exacts)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const
Gets the default calling convention for the given target and declaration context. ...
static IntType getCorrespondingUnsignedType(IntType T)
unsigned getFloatAlign() const
virtual bool setCPU(const std::string &Name)
Target the specified CPU.
virtual bool validateOutputSize(StringRef, unsigned) const
const llvm::fltSemantics & getFloatFormat() const
bool isRenderScriptTarget() const
Returns true for RenderScript.
bool isTLSSupported() const
Whether the target supports thread-local storage.
IntType getWCharType() const
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
uint64_t getPointerAlign(unsigned AddrSpace) const
unsigned getSimdDefaultAlign() const
Return default simd alignment for the given target.
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
const llvm::fltSemantics * LongDoubleFormat
virtual void setSupportedOpenCLOpts()
Set supported OpenCL extensions and optional core features.
IntType getIntPtrType() const
void setTiedOperand(unsigned N, ConstraintInfo &Output)
Indicate that this is an input operand that is tied to the specified output operand.
unsigned short MaxTLSAlign
virtual bool validateInputSize(StringRef, unsigned) const
unsigned getChar32Align() const
const OpenCLOptions & getSupportedOpenCLOpts() const
Get const supported OpenCL extensions and optional core features.
virtual bool setFPMath(StringRef Name)
Use the specified unit for FP math.
unsigned UseBitFieldTypeAlignment
Control whether the alignment of bit-field types is respected when laying out structures.
virtual uint64_t getNullPointerValue(LangAS AddrSpace) const
Get integer value for null pointer.
IntType getProcessIDType() const
std::unique_ptr< llvm::DataLayout > DataLayout
OpenCLOptions & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
const char * getMCountName() const
Returns the name of the mcount instrumentation function.
void noSignedCharForObjCBool()
virtual std::string convertConstraint(const char *&Constraint) const
bool UseAddrSpaceMapMangling
Specify if mangling based on address space map should be used or not for language specific address sp...
virtual unsigned getUnwindWordWidth() const