10b57cec5SDimitry Andric //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // These classes wrap the information about a call or function 100b57cec5SDimitry Andric // definition used to handle ABI compliancy. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H 150b57cec5SDimitry Andric #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H 160b57cec5SDimitry Andric 17fe6060f1SDimitry Andric #include "CGBuilder.h" 180b57cec5SDimitry Andric #include "CodeGenModule.h" 190b57cec5SDimitry Andric #include "CGValue.h" 200b57cec5SDimitry Andric #include "clang/AST/Type.h" 210b57cec5SDimitry Andric #include "clang/Basic/LLVM.h" 220b57cec5SDimitry Andric #include "clang/Basic/SyncScope.h" 230b57cec5SDimitry Andric #include "llvm/ADT/SmallString.h" 240b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric namespace llvm { 270b57cec5SDimitry Andric class Constant; 280b57cec5SDimitry Andric class GlobalValue; 290b57cec5SDimitry Andric class Type; 300b57cec5SDimitry Andric class Value; 310b57cec5SDimitry Andric } 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric namespace clang { 340b57cec5SDimitry Andric class Decl; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric namespace CodeGen { 370b57cec5SDimitry Andric class ABIInfo; 380b57cec5SDimitry Andric class CallArgList; 390b57cec5SDimitry Andric class CodeGenFunction; 400b57cec5SDimitry Andric class CGBlockInfo; 41bdd1243dSDimitry Andric class SwiftABIInfo; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric /// TargetCodeGenInfo - This class organizes various target-specific 440b57cec5SDimitry Andric /// codegeneration issues, like target-specific attributes, builtins and so 450b57cec5SDimitry Andric /// on. 460b57cec5SDimitry Andric class TargetCodeGenInfo { 47fcaf7f86SDimitry Andric std::unique_ptr<ABIInfo> Info; 480b57cec5SDimitry Andric 49bdd1243dSDimitry Andric protected: 50bdd1243dSDimitry Andric // Target hooks supporting Swift calling conventions. The target must 51bdd1243dSDimitry Andric // initialize this field if it claims to support these calling conventions 52bdd1243dSDimitry Andric // by returning true from TargetInfo::checkCallingConvention for them. 53bdd1243dSDimitry Andric std::unique_ptr<SwiftABIInfo> SwiftInfo; 54bdd1243dSDimitry Andric 5506c3fb27SDimitry Andric // Returns ABI info helper for the target. This is for use by derived classes. 5606c3fb27SDimitry Andric template <typename T> const T &getABIInfo() const { 5706c3fb27SDimitry Andric return static_cast<const T &>(*Info); 5806c3fb27SDimitry Andric } 5906c3fb27SDimitry Andric 600b57cec5SDimitry Andric public: 61fcaf7f86SDimitry Andric TargetCodeGenInfo(std::unique_ptr<ABIInfo> Info); 620b57cec5SDimitry Andric virtual ~TargetCodeGenInfo(); 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric /// getABIInfo() - Returns ABI info helper for the target. 650b57cec5SDimitry Andric const ABIInfo &getABIInfo() const { return *Info; } 660b57cec5SDimitry Andric 67bdd1243dSDimitry Andric /// Returns Swift ABI info helper for the target. 68bdd1243dSDimitry Andric const SwiftABIInfo &getSwiftABIInfo() const { 69bdd1243dSDimitry Andric assert(SwiftInfo && "Swift ABI info has not been initialized"); 70bdd1243dSDimitry Andric return *SwiftInfo; 71bdd1243dSDimitry Andric } 72bdd1243dSDimitry Andric 730b57cec5SDimitry Andric /// setTargetAttributes - Provides a convenient hook to handle extra 740b57cec5SDimitry Andric /// target-specific attributes for the given global. 750b57cec5SDimitry Andric virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, 760b57cec5SDimitry Andric CodeGen::CodeGenModule &M) const {} 770b57cec5SDimitry Andric 785ffd83dbSDimitry Andric /// emitTargetMetadata - Provides a convenient hook to handle extra 795ffd83dbSDimitry Andric /// target-specific metadata for the given globals. 805ffd83dbSDimitry Andric virtual void emitTargetMetadata( 815ffd83dbSDimitry Andric CodeGen::CodeGenModule &CGM, 825ffd83dbSDimitry Andric const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames) const {} 835ffd83dbSDimitry Andric 84*5f757f3fSDimitry Andric /// Provides a convenient hook to handle extra target-specific globals. 85*5f757f3fSDimitry Andric virtual void emitTargetGlobals(CodeGen::CodeGenModule &CGM) const {} 86*5f757f3fSDimitry Andric 875ffd83dbSDimitry Andric /// Any further codegen related checks that need to be done on a function call 885ffd83dbSDimitry Andric /// in a target specific manner. 895ffd83dbSDimitry Andric virtual void checkFunctionCallABI(CodeGenModule &CGM, SourceLocation CallLoc, 905ffd83dbSDimitry Andric const FunctionDecl *Caller, 915ffd83dbSDimitry Andric const FunctionDecl *Callee, 925ffd83dbSDimitry Andric const CallArgList &Args) const {} 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric /// Determines the size of struct _Unwind_Exception on this platform, 950b57cec5SDimitry Andric /// in 8-bit units. The Itanium ABI defines this as: 960b57cec5SDimitry Andric /// struct _Unwind_Exception { 970b57cec5SDimitry Andric /// uint64 exception_class; 980b57cec5SDimitry Andric /// _Unwind_Exception_Cleanup_Fn exception_cleanup; 990b57cec5SDimitry Andric /// uint64 private_1; 1000b57cec5SDimitry Andric /// uint64 private_2; 1010b57cec5SDimitry Andric /// }; 1020b57cec5SDimitry Andric virtual unsigned getSizeOfUnwindException() const; 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric /// Controls whether __builtin_extend_pointer should sign-extend 1050b57cec5SDimitry Andric /// pointers to uint64_t or zero-extend them (the default). Has 1060b57cec5SDimitry Andric /// no effect for targets: 1070b57cec5SDimitry Andric /// - that have 64-bit pointers, or 1080b57cec5SDimitry Andric /// - that cannot address through registers larger than pointers, or 1090b57cec5SDimitry Andric /// - that implicitly ignore/truncate the top bits when addressing 1100b57cec5SDimitry Andric /// through such registers. 1110b57cec5SDimitry Andric virtual bool extendPointerWithSExt() const { return false; } 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric /// Determines the DWARF register number for the stack pointer, for 1140b57cec5SDimitry Andric /// exception-handling purposes. Implements __builtin_dwarf_sp_column. 1150b57cec5SDimitry Andric /// 1160b57cec5SDimitry Andric /// Returns -1 if the operation is unsupported by this target. 1170b57cec5SDimitry Andric virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { 1180b57cec5SDimitry Andric return -1; 1190b57cec5SDimitry Andric } 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric /// Initializes the given DWARF EH register-size table, a char*. 1220b57cec5SDimitry Andric /// Implements __builtin_init_dwarf_reg_size_table. 1230b57cec5SDimitry Andric /// 1240b57cec5SDimitry Andric /// Returns true if the operation is unsupported by this target. 1250b57cec5SDimitry Andric virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, 1260b57cec5SDimitry Andric llvm::Value *Address) const { 1270b57cec5SDimitry Andric return true; 1280b57cec5SDimitry Andric } 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andric /// Performs the code-generation required to convert a return 1310b57cec5SDimitry Andric /// address as stored by the system into the actual address of the 1320b57cec5SDimitry Andric /// next instruction that will be executed. 1330b57cec5SDimitry Andric /// 1340b57cec5SDimitry Andric /// Used by __builtin_extract_return_addr(). 1350b57cec5SDimitry Andric virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF, 1360b57cec5SDimitry Andric llvm::Value *Address) const { 1370b57cec5SDimitry Andric return Address; 1380b57cec5SDimitry Andric } 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric /// Performs the code-generation required to convert the address 1410b57cec5SDimitry Andric /// of an instruction into a return address suitable for storage 1420b57cec5SDimitry Andric /// by the system in a return slot. 1430b57cec5SDimitry Andric /// 1440b57cec5SDimitry Andric /// Used by __builtin_frob_return_addr(). 1450b57cec5SDimitry Andric virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF, 1460b57cec5SDimitry Andric llvm::Value *Address) const { 1470b57cec5SDimitry Andric return Address; 1480b57cec5SDimitry Andric } 1490b57cec5SDimitry Andric 150fe6060f1SDimitry Andric /// Performs a target specific test of a floating point value for things 151fe6060f1SDimitry Andric /// like IsNaN, Infinity, ... Nullptr is returned if no implementation 152fe6060f1SDimitry Andric /// exists. 153fe6060f1SDimitry Andric virtual llvm::Value * 154fe6060f1SDimitry Andric testFPKind(llvm::Value *V, unsigned BuiltinID, CGBuilderTy &Builder, 155fe6060f1SDimitry Andric CodeGenModule &CGM) const { 156fe6060f1SDimitry Andric assert(V->getType()->isFloatingPointTy() && "V should have an FP type."); 157fe6060f1SDimitry Andric return nullptr; 158fe6060f1SDimitry Andric } 159fe6060f1SDimitry Andric 1600b57cec5SDimitry Andric /// Corrects the low-level LLVM type for a given constraint and "usual" 1610b57cec5SDimitry Andric /// type. 1620b57cec5SDimitry Andric /// 1630b57cec5SDimitry Andric /// \returns A pointer to a new LLVM type, possibly the same as the original 1640b57cec5SDimitry Andric /// on success; 0 on failure. 1650b57cec5SDimitry Andric virtual llvm::Type *adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, 1660b57cec5SDimitry Andric StringRef Constraint, 1670b57cec5SDimitry Andric llvm::Type *Ty) const { 1680b57cec5SDimitry Andric return Ty; 1690b57cec5SDimitry Andric } 1700b57cec5SDimitry Andric 1716e75b2fbSDimitry Andric /// Target hook to decide whether an inline asm operand can be passed 1726e75b2fbSDimitry Andric /// by value. 1736e75b2fbSDimitry Andric virtual bool isScalarizableAsmOperand(CodeGen::CodeGenFunction &CGF, 1746e75b2fbSDimitry Andric llvm::Type *Ty) const { 1756e75b2fbSDimitry Andric return false; 1766e75b2fbSDimitry Andric } 1776e75b2fbSDimitry Andric 1780b57cec5SDimitry Andric /// Adds constraints and types for result registers. 1790b57cec5SDimitry Andric virtual void addReturnRegisterOutputs( 1800b57cec5SDimitry Andric CodeGen::CodeGenFunction &CGF, CodeGen::LValue ReturnValue, 1810b57cec5SDimitry Andric std::string &Constraints, std::vector<llvm::Type *> &ResultRegTypes, 1820b57cec5SDimitry Andric std::vector<llvm::Type *> &ResultTruncRegTypes, 1830b57cec5SDimitry Andric std::vector<CodeGen::LValue> &ResultRegDests, std::string &AsmString, 1840b57cec5SDimitry Andric unsigned NumOutputs) const {} 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric /// doesReturnSlotInterfereWithArgs - Return true if the target uses an 1870b57cec5SDimitry Andric /// argument slot for an 'sret' type. 1880b57cec5SDimitry Andric virtual bool doesReturnSlotInterfereWithArgs() const { return true; } 1890b57cec5SDimitry Andric 1900b57cec5SDimitry Andric /// Retrieve the address of a function to call immediately before 1910b57cec5SDimitry Andric /// calling objc_retainAutoreleasedReturnValue. The 1920b57cec5SDimitry Andric /// implementation of objc_autoreleaseReturnValue sniffs the 1930b57cec5SDimitry Andric /// instruction stream following its return address to decide 1940b57cec5SDimitry Andric /// whether it's a call to objc_retainAutoreleasedReturnValue. 1950b57cec5SDimitry Andric /// This can be prohibitively expensive, depending on the 1960b57cec5SDimitry Andric /// relocation model, and so on some targets it instead sniffs for 1970b57cec5SDimitry Andric /// a particular instruction sequence. This functions returns 1980b57cec5SDimitry Andric /// that instruction sequence in inline assembly, which will be 1990b57cec5SDimitry Andric /// empty if none is required. 2000b57cec5SDimitry Andric virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const { 2010b57cec5SDimitry Andric return ""; 2020b57cec5SDimitry Andric } 2030b57cec5SDimitry Andric 204e8d8bef9SDimitry Andric /// Determine whether a call to objc_retainAutoreleasedReturnValue or 205e8d8bef9SDimitry Andric /// objc_unsafeClaimAutoreleasedReturnValue should be marked as 'notail'. 206e8d8bef9SDimitry Andric virtual bool markARCOptimizedReturnCallsAsNoTail() const { return false; } 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andric /// Return a constant used by UBSan as a signature to identify functions 2090b57cec5SDimitry Andric /// possessing type information, or 0 if the platform is unsupported. 21006c3fb27SDimitry Andric /// This magic number is invalid instruction encoding in many targets. 2110b57cec5SDimitry Andric virtual llvm::Constant * 2120b57cec5SDimitry Andric getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const { 21306c3fb27SDimitry Andric return llvm::ConstantInt::get(CGM.Int32Ty, 0xc105cafe); 2140b57cec5SDimitry Andric } 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric /// Determine whether a call to an unprototyped functions under 2170b57cec5SDimitry Andric /// the given calling convention should use the variadic 2180b57cec5SDimitry Andric /// convention or the non-variadic convention. 2190b57cec5SDimitry Andric /// 2200b57cec5SDimitry Andric /// There's a good reason to make a platform's variadic calling 2210b57cec5SDimitry Andric /// convention be different from its non-variadic calling 2220b57cec5SDimitry Andric /// convention: the non-variadic arguments can be passed in 2230b57cec5SDimitry Andric /// registers (better for performance), and the variadic arguments 2240b57cec5SDimitry Andric /// can be passed on the stack (also better for performance). If 2250b57cec5SDimitry Andric /// this is done, however, unprototyped functions *must* use the 2260b57cec5SDimitry Andric /// non-variadic convention, because C99 states that a call 2270b57cec5SDimitry Andric /// through an unprototyped function type must succeed if the 2280b57cec5SDimitry Andric /// function was defined with a non-variadic prototype with 2290b57cec5SDimitry Andric /// compatible parameters. Therefore, splitting the conventions 2300b57cec5SDimitry Andric /// makes it impossible to call a variadic function through an 2310b57cec5SDimitry Andric /// unprototyped type. Since function prototypes came out in the 2320b57cec5SDimitry Andric /// late 1970s, this is probably an acceptable trade-off. 2330b57cec5SDimitry Andric /// Nonetheless, not all platforms are willing to make it, and in 2340b57cec5SDimitry Andric /// particularly x86-64 bends over backwards to make the 2350b57cec5SDimitry Andric /// conventions compatible. 2360b57cec5SDimitry Andric /// 2370b57cec5SDimitry Andric /// The default is false. This is correct whenever: 2380b57cec5SDimitry Andric /// - the conventions are exactly the same, because it does not 2390b57cec5SDimitry Andric /// matter and the resulting IR will be somewhat prettier in 2400b57cec5SDimitry Andric /// certain cases; or 2410b57cec5SDimitry Andric /// - the conventions are substantively different in how they pass 2420b57cec5SDimitry Andric /// arguments, because in this case using the variadic convention 2430b57cec5SDimitry Andric /// will lead to C99 violations. 2440b57cec5SDimitry Andric /// 2450b57cec5SDimitry Andric /// However, some platforms make the conventions identical except 2460b57cec5SDimitry Andric /// for passing additional out-of-band information to a variadic 2470b57cec5SDimitry Andric /// function: for example, x86-64 passes the number of SSE 2480b57cec5SDimitry Andric /// arguments in %al. On these platforms, it is desirable to 2490b57cec5SDimitry Andric /// call unprototyped functions using the variadic convention so 2500b57cec5SDimitry Andric /// that unprototyped calls to varargs functions still succeed. 2510b57cec5SDimitry Andric /// 2520b57cec5SDimitry Andric /// Relatedly, platforms which pass the fixed arguments to this: 2530b57cec5SDimitry Andric /// A foo(B, C, D); 2540b57cec5SDimitry Andric /// differently than they would pass them to this: 2550b57cec5SDimitry Andric /// A foo(B, C, D, ...); 2560b57cec5SDimitry Andric /// may need to adjust the debugger-support code in Sema to do the 2570b57cec5SDimitry Andric /// right thing when calling a function with no know signature. 2580b57cec5SDimitry Andric virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, 2590b57cec5SDimitry Andric const FunctionNoProtoType *fnType) const; 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andric /// Gets the linker options necessary to link a dependent library on this 2620b57cec5SDimitry Andric /// platform. 2630b57cec5SDimitry Andric virtual void getDependentLibraryOption(llvm::StringRef Lib, 2640b57cec5SDimitry Andric llvm::SmallString<24> &Opt) const; 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andric /// Gets the linker options necessary to detect object file mismatches on 2670b57cec5SDimitry Andric /// this platform. 2680b57cec5SDimitry Andric virtual void getDetectMismatchOption(llvm::StringRef Name, 2690b57cec5SDimitry Andric llvm::StringRef Value, 2700b57cec5SDimitry Andric llvm::SmallString<32> &Opt) const {} 2710b57cec5SDimitry Andric 2720b57cec5SDimitry Andric /// Get LLVM calling convention for OpenCL kernel. 2730b57cec5SDimitry Andric virtual unsigned getOpenCLKernelCallingConv() const; 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andric /// Get target specific null pointer. 2760b57cec5SDimitry Andric /// \param T is the LLVM type of the null pointer. 2770b57cec5SDimitry Andric /// \param QT is the clang QualType of the null pointer. 2780b57cec5SDimitry Andric /// \return ConstantPointerNull with the given type \p T. 2790b57cec5SDimitry Andric /// Each target can override it to return its own desired constant value. 2800b57cec5SDimitry Andric virtual llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM, 2810b57cec5SDimitry Andric llvm::PointerType *T, QualType QT) const; 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andric /// Get target favored AST address space of a global variable for languages 2840b57cec5SDimitry Andric /// other than OpenCL and CUDA. 2850b57cec5SDimitry Andric /// If \p D is nullptr, returns the default target favored address space 2860b57cec5SDimitry Andric /// for global variable. 2870b57cec5SDimitry Andric virtual LangAS getGlobalVarAddressSpace(CodeGenModule &CGM, 2880b57cec5SDimitry Andric const VarDecl *D) const; 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric /// Get the AST address space for alloca. 2910b57cec5SDimitry Andric virtual LangAS getASTAllocaAddressSpace() const { return LangAS::Default; } 2920b57cec5SDimitry Andric 2930b57cec5SDimitry Andric /// Perform address space cast of an expression of pointer type. 2940b57cec5SDimitry Andric /// \param V is the LLVM value to be casted to another address space. 2950b57cec5SDimitry Andric /// \param SrcAddr is the language address space of \p V. 2960b57cec5SDimitry Andric /// \param DestAddr is the targeted language address space. 2970b57cec5SDimitry Andric /// \param DestTy is the destination LLVM pointer type. 2980b57cec5SDimitry Andric /// \param IsNonNull is the flag indicating \p V is known to be non null. 2990b57cec5SDimitry Andric virtual llvm::Value *performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, 3000b57cec5SDimitry Andric llvm::Value *V, LangAS SrcAddr, 3010b57cec5SDimitry Andric LangAS DestAddr, llvm::Type *DestTy, 3020b57cec5SDimitry Andric bool IsNonNull = false) const; 3030b57cec5SDimitry Andric 3040b57cec5SDimitry Andric /// Perform address space cast of a constant expression of pointer type. 3050b57cec5SDimitry Andric /// \param V is the LLVM constant to be casted to another address space. 3060b57cec5SDimitry Andric /// \param SrcAddr is the language address space of \p V. 3070b57cec5SDimitry Andric /// \param DestAddr is the targeted language address space. 3080b57cec5SDimitry Andric /// \param DestTy is the destination LLVM pointer type. 3090b57cec5SDimitry Andric virtual llvm::Constant *performAddrSpaceCast(CodeGenModule &CGM, 3100b57cec5SDimitry Andric llvm::Constant *V, 3110b57cec5SDimitry Andric LangAS SrcAddr, LangAS DestAddr, 3120b57cec5SDimitry Andric llvm::Type *DestTy) const; 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andric /// Get address space of pointer parameter for __cxa_atexit. 3150b57cec5SDimitry Andric virtual LangAS getAddrSpaceOfCxaAtexitPtrParam() const { 3160b57cec5SDimitry Andric return LangAS::Default; 3170b57cec5SDimitry Andric } 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric /// Get the syncscope used in LLVM IR. 3200b57cec5SDimitry Andric virtual llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts, 3210b57cec5SDimitry Andric SyncScope Scope, 3220b57cec5SDimitry Andric llvm::AtomicOrdering Ordering, 3230b57cec5SDimitry Andric llvm::LLVMContext &Ctx) const; 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andric /// Interface class for filling custom fields of a block literal for OpenCL. 3260b57cec5SDimitry Andric class TargetOpenCLBlockHelper { 3270b57cec5SDimitry Andric public: 3280b57cec5SDimitry Andric typedef std::pair<llvm::Value *, StringRef> ValueTy; 3290b57cec5SDimitry Andric TargetOpenCLBlockHelper() {} 3300b57cec5SDimitry Andric virtual ~TargetOpenCLBlockHelper() {} 3310b57cec5SDimitry Andric /// Get the custom field types for OpenCL blocks. 3320b57cec5SDimitry Andric virtual llvm::SmallVector<llvm::Type *, 1> getCustomFieldTypes() = 0; 3330b57cec5SDimitry Andric /// Get the custom field values for OpenCL blocks. 3340b57cec5SDimitry Andric virtual llvm::SmallVector<ValueTy, 1> 3350b57cec5SDimitry Andric getCustomFieldValues(CodeGenFunction &CGF, const CGBlockInfo &Info) = 0; 3360b57cec5SDimitry Andric virtual bool areAllCustomFieldValuesConstant(const CGBlockInfo &Info) = 0; 3370b57cec5SDimitry Andric /// Get the custom field values for OpenCL blocks if all values are LLVM 3380b57cec5SDimitry Andric /// constants. 3390b57cec5SDimitry Andric virtual llvm::SmallVector<llvm::Constant *, 1> 3400b57cec5SDimitry Andric getCustomFieldValues(CodeGenModule &CGM, const CGBlockInfo &Info) = 0; 3410b57cec5SDimitry Andric }; 3420b57cec5SDimitry Andric virtual TargetOpenCLBlockHelper *getTargetOpenCLBlockHelper() const { 3430b57cec5SDimitry Andric return nullptr; 3440b57cec5SDimitry Andric } 3450b57cec5SDimitry Andric 3460b57cec5SDimitry Andric /// Create an OpenCL kernel for an enqueued block. The kernel function is 3470b57cec5SDimitry Andric /// a wrapper for the block invoke function with target-specific calling 3480b57cec5SDimitry Andric /// convention and ABI as an OpenCL kernel. The wrapper function accepts 3490b57cec5SDimitry Andric /// block context and block arguments in target-specific way and calls 3500b57cec5SDimitry Andric /// the original block invoke function. 35106c3fb27SDimitry Andric virtual llvm::Value * 3520b57cec5SDimitry Andric createEnqueuedBlockKernel(CodeGenFunction &CGF, 3530b57cec5SDimitry Andric llvm::Function *BlockInvokeFunc, 35481ad6265SDimitry Andric llvm::Type *BlockTy) const; 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andric /// \return true if the target supports alias from the unmangled name to the 3570b57cec5SDimitry Andric /// mangled name of functions declared within an extern "C" region and marked 3580b57cec5SDimitry Andric /// as 'used', and having internal linkage. 3590b57cec5SDimitry Andric virtual bool shouldEmitStaticExternCAliases() const { return true; } 3600b57cec5SDimitry Andric 36106c3fb27SDimitry Andric /// \return true if annonymous zero-sized bitfields should be emitted to 36206c3fb27SDimitry Andric /// correctly distinguish between struct types whose memory layout is the 36306c3fb27SDimitry Andric /// same, but whose layout may differ when used as argument passed by value 36406c3fb27SDimitry Andric virtual bool shouldEmitDWARFBitFieldSeparators() const { return false; } 36506c3fb27SDimitry Andric 3660b57cec5SDimitry Andric virtual void setCUDAKernelCallingConvention(const FunctionType *&FT) const {} 3675ffd83dbSDimitry Andric 3685ffd83dbSDimitry Andric /// Return the device-side type for the CUDA device builtin surface type. 3695ffd83dbSDimitry Andric virtual llvm::Type *getCUDADeviceBuiltinSurfaceDeviceType() const { 3705ffd83dbSDimitry Andric // By default, no change from the original one. 3715ffd83dbSDimitry Andric return nullptr; 3725ffd83dbSDimitry Andric } 3735ffd83dbSDimitry Andric /// Return the device-side type for the CUDA device builtin texture type. 3745ffd83dbSDimitry Andric virtual llvm::Type *getCUDADeviceBuiltinTextureDeviceType() const { 3755ffd83dbSDimitry Andric // By default, no change from the original one. 3765ffd83dbSDimitry Andric return nullptr; 3775ffd83dbSDimitry Andric } 3785ffd83dbSDimitry Andric 37906c3fb27SDimitry Andric /// Return the WebAssembly externref reference type. 38006c3fb27SDimitry Andric virtual llvm::Type *getWasmExternrefReferenceType() const { return nullptr; } 38106c3fb27SDimitry Andric 38206c3fb27SDimitry Andric /// Return the WebAssembly funcref reference type. 38306c3fb27SDimitry Andric virtual llvm::Type *getWasmFuncrefReferenceType() const { return nullptr; } 38406c3fb27SDimitry Andric 3855ffd83dbSDimitry Andric /// Emit the device-side copy of the builtin surface type. 3865ffd83dbSDimitry Andric virtual bool emitCUDADeviceBuiltinSurfaceDeviceCopy(CodeGenFunction &CGF, 3875ffd83dbSDimitry Andric LValue Dst, 3885ffd83dbSDimitry Andric LValue Src) const { 3895ffd83dbSDimitry Andric // DO NOTHING by default. 3905ffd83dbSDimitry Andric return false; 3915ffd83dbSDimitry Andric } 3925ffd83dbSDimitry Andric /// Emit the device-side copy of the builtin texture type. 3935ffd83dbSDimitry Andric virtual bool emitCUDADeviceBuiltinTextureDeviceCopy(CodeGenFunction &CGF, 3945ffd83dbSDimitry Andric LValue Dst, 3955ffd83dbSDimitry Andric LValue Src) const { 3965ffd83dbSDimitry Andric // DO NOTHING by default. 3975ffd83dbSDimitry Andric return false; 3985ffd83dbSDimitry Andric } 39906c3fb27SDimitry Andric 40006c3fb27SDimitry Andric /// Return an LLVM type that corresponds to an OpenCL type. 40106c3fb27SDimitry Andric virtual llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const { 40206c3fb27SDimitry Andric return nullptr; 40306c3fb27SDimitry Andric } 40406c3fb27SDimitry Andric 40506c3fb27SDimitry Andric protected: 40606c3fb27SDimitry Andric static std::string qualifyWindowsLibrary(StringRef Lib); 40706c3fb27SDimitry Andric 40806c3fb27SDimitry Andric void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV, 40906c3fb27SDimitry Andric CodeGen::CodeGenModule &CGM) const; 4100b57cec5SDimitry Andric }; 4110b57cec5SDimitry Andric 41206c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 41306c3fb27SDimitry Andric createDefaultTargetCodeGenInfo(CodeGenModule &CGM); 41406c3fb27SDimitry Andric 41506c3fb27SDimitry Andric enum class AArch64ABIKind { 41606c3fb27SDimitry Andric AAPCS = 0, 41706c3fb27SDimitry Andric DarwinPCS, 41806c3fb27SDimitry Andric Win64, 41906c3fb27SDimitry Andric }; 42006c3fb27SDimitry Andric 42106c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 42206c3fb27SDimitry Andric createAArch64TargetCodeGenInfo(CodeGenModule &CGM, AArch64ABIKind Kind); 42306c3fb27SDimitry Andric 42406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 42506c3fb27SDimitry Andric createWindowsAArch64TargetCodeGenInfo(CodeGenModule &CGM, AArch64ABIKind K); 42606c3fb27SDimitry Andric 42706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 42806c3fb27SDimitry Andric createAMDGPUTargetCodeGenInfo(CodeGenModule &CGM); 42906c3fb27SDimitry Andric 43006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 43106c3fb27SDimitry Andric createARCTargetCodeGenInfo(CodeGenModule &CGM); 43206c3fb27SDimitry Andric 43306c3fb27SDimitry Andric enum class ARMABIKind { 43406c3fb27SDimitry Andric APCS = 0, 43506c3fb27SDimitry Andric AAPCS = 1, 43606c3fb27SDimitry Andric AAPCS_VFP = 2, 43706c3fb27SDimitry Andric AAPCS16_VFP = 3, 43806c3fb27SDimitry Andric }; 43906c3fb27SDimitry Andric 44006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 44106c3fb27SDimitry Andric createARMTargetCodeGenInfo(CodeGenModule &CGM, ARMABIKind Kind); 44206c3fb27SDimitry Andric 44306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 44406c3fb27SDimitry Andric createWindowsARMTargetCodeGenInfo(CodeGenModule &CGM, ARMABIKind K); 44506c3fb27SDimitry Andric 44606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 44706c3fb27SDimitry Andric createAVRTargetCodeGenInfo(CodeGenModule &CGM, unsigned NPR, unsigned NRR); 44806c3fb27SDimitry Andric 44906c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 45006c3fb27SDimitry Andric createBPFTargetCodeGenInfo(CodeGenModule &CGM); 45106c3fb27SDimitry Andric 45206c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 45306c3fb27SDimitry Andric createCSKYTargetCodeGenInfo(CodeGenModule &CGM, unsigned FLen); 45406c3fb27SDimitry Andric 45506c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 45606c3fb27SDimitry Andric createHexagonTargetCodeGenInfo(CodeGenModule &CGM); 45706c3fb27SDimitry Andric 45806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 45906c3fb27SDimitry Andric createLanaiTargetCodeGenInfo(CodeGenModule &CGM); 46006c3fb27SDimitry Andric 46106c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 46206c3fb27SDimitry Andric createLoongArchTargetCodeGenInfo(CodeGenModule &CGM, unsigned GRLen, 46306c3fb27SDimitry Andric unsigned FLen); 46406c3fb27SDimitry Andric 46506c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 46606c3fb27SDimitry Andric createM68kTargetCodeGenInfo(CodeGenModule &CGM); 46706c3fb27SDimitry Andric 46806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 46906c3fb27SDimitry Andric createMIPSTargetCodeGenInfo(CodeGenModule &CGM, bool IsOS32); 47006c3fb27SDimitry Andric 47106c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 47206c3fb27SDimitry Andric createMSP430TargetCodeGenInfo(CodeGenModule &CGM); 47306c3fb27SDimitry Andric 47406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 47506c3fb27SDimitry Andric createNVPTXTargetCodeGenInfo(CodeGenModule &CGM); 47606c3fb27SDimitry Andric 47706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 47806c3fb27SDimitry Andric createPNaClTargetCodeGenInfo(CodeGenModule &CGM); 47906c3fb27SDimitry Andric 48006c3fb27SDimitry Andric enum class PPC64_SVR4_ABIKind { 48106c3fb27SDimitry Andric ELFv1 = 0, 48206c3fb27SDimitry Andric ELFv2, 48306c3fb27SDimitry Andric }; 48406c3fb27SDimitry Andric 48506c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 48606c3fb27SDimitry Andric createAIXTargetCodeGenInfo(CodeGenModule &CGM, bool Is64Bit); 48706c3fb27SDimitry Andric 48806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 48906c3fb27SDimitry Andric createPPC32TargetCodeGenInfo(CodeGenModule &CGM, bool SoftFloatABI); 49006c3fb27SDimitry Andric 49106c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 49206c3fb27SDimitry Andric createPPC64TargetCodeGenInfo(CodeGenModule &CGM); 49306c3fb27SDimitry Andric 49406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 49506c3fb27SDimitry Andric createPPC64_SVR4_TargetCodeGenInfo(CodeGenModule &CGM, PPC64_SVR4_ABIKind Kind, 49606c3fb27SDimitry Andric bool SoftFloatABI); 49706c3fb27SDimitry Andric 49806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 49906c3fb27SDimitry Andric createRISCVTargetCodeGenInfo(CodeGenModule &CGM, unsigned XLen, unsigned FLen); 50006c3fb27SDimitry Andric 50106c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 50206c3fb27SDimitry Andric createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM); 50306c3fb27SDimitry Andric 50406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 50506c3fb27SDimitry Andric createSPIRVTargetCodeGenInfo(CodeGenModule &CGM); 50606c3fb27SDimitry Andric 50706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 50806c3fb27SDimitry Andric createSparcV8TargetCodeGenInfo(CodeGenModule &CGM); 50906c3fb27SDimitry Andric 51006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 51106c3fb27SDimitry Andric createSparcV9TargetCodeGenInfo(CodeGenModule &CGM); 51206c3fb27SDimitry Andric 51306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 51406c3fb27SDimitry Andric createSystemZTargetCodeGenInfo(CodeGenModule &CGM, bool HasVector, 51506c3fb27SDimitry Andric bool SoftFloatABI); 51606c3fb27SDimitry Andric 51706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 51806c3fb27SDimitry Andric createTCETargetCodeGenInfo(CodeGenModule &CGM); 51906c3fb27SDimitry Andric 52006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 52106c3fb27SDimitry Andric createVETargetCodeGenInfo(CodeGenModule &CGM); 52206c3fb27SDimitry Andric 52306c3fb27SDimitry Andric enum class WebAssemblyABIKind { 52406c3fb27SDimitry Andric MVP = 0, 52506c3fb27SDimitry Andric ExperimentalMV = 1, 52606c3fb27SDimitry Andric }; 52706c3fb27SDimitry Andric 52806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 52906c3fb27SDimitry Andric createWebAssemblyTargetCodeGenInfo(CodeGenModule &CGM, WebAssemblyABIKind K); 53006c3fb27SDimitry Andric 53106c3fb27SDimitry Andric /// The AVX ABI level for X86 targets. 53206c3fb27SDimitry Andric enum class X86AVXABILevel { 53306c3fb27SDimitry Andric None, 53406c3fb27SDimitry Andric AVX, 53506c3fb27SDimitry Andric AVX512, 53606c3fb27SDimitry Andric }; 53706c3fb27SDimitry Andric 53806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> createX86_32TargetCodeGenInfo( 53906c3fb27SDimitry Andric CodeGenModule &CGM, bool DarwinVectorABI, bool Win32StructABI, 54006c3fb27SDimitry Andric unsigned NumRegisterParameters, bool SoftFloatABI); 54106c3fb27SDimitry Andric 54206c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 54306c3fb27SDimitry Andric createWinX86_32TargetCodeGenInfo(CodeGenModule &CGM, bool DarwinVectorABI, 54406c3fb27SDimitry Andric bool Win32StructABI, 54506c3fb27SDimitry Andric unsigned NumRegisterParameters); 54606c3fb27SDimitry Andric 54706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 54806c3fb27SDimitry Andric createX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel); 54906c3fb27SDimitry Andric 55006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 55106c3fb27SDimitry Andric createWinX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel); 55206c3fb27SDimitry Andric 55306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> 55406c3fb27SDimitry Andric createXCoreTargetCodeGenInfo(CodeGenModule &CGM); 55506c3fb27SDimitry Andric 5560b57cec5SDimitry Andric } // namespace CodeGen 5570b57cec5SDimitry Andric } // namespace clang 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H 560