xref: /freebsd/contrib/llvm-project/clang/lib/CodeGen/TargetInfo.h (revision 62987288060ff68c817b7056815aa9fb8ba8ecd7)
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 "CGValue.h"
190fca6ea1SDimitry Andric #include "CodeGenModule.h"
200b57cec5SDimitry Andric #include "clang/AST/Type.h"
210b57cec5SDimitry Andric #include "clang/Basic/LLVM.h"
220b57cec5SDimitry Andric #include "clang/Basic/SyncScope.h"
230fca6ea1SDimitry Andric #include "clang/Basic/TargetInfo.h"
240b57cec5SDimitry Andric #include "llvm/ADT/SmallString.h"
250b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric namespace llvm {
280b57cec5SDimitry Andric class Constant;
290b57cec5SDimitry Andric class GlobalValue;
300b57cec5SDimitry Andric class Type;
310b57cec5SDimitry Andric class Value;
320b57cec5SDimitry Andric }
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric namespace clang {
350b57cec5SDimitry Andric class Decl;
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric namespace CodeGen {
380b57cec5SDimitry Andric class ABIInfo;
390b57cec5SDimitry Andric class CallArgList;
400b57cec5SDimitry Andric class CodeGenFunction;
410b57cec5SDimitry Andric class CGBlockInfo;
42bdd1243dSDimitry Andric class SwiftABIInfo;
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric /// TargetCodeGenInfo - This class organizes various target-specific
450b57cec5SDimitry Andric /// codegeneration issues, like target-specific attributes, builtins and so
460b57cec5SDimitry Andric /// on.
470b57cec5SDimitry Andric class TargetCodeGenInfo {
48fcaf7f86SDimitry Andric   std::unique_ptr<ABIInfo> Info;
490b57cec5SDimitry Andric 
50bdd1243dSDimitry Andric protected:
51bdd1243dSDimitry Andric   // Target hooks supporting Swift calling conventions. The target must
52bdd1243dSDimitry Andric   // initialize this field if it claims to support these calling conventions
53bdd1243dSDimitry Andric   // by returning true from TargetInfo::checkCallingConvention for them.
54bdd1243dSDimitry Andric   std::unique_ptr<SwiftABIInfo> SwiftInfo;
55bdd1243dSDimitry Andric 
5606c3fb27SDimitry Andric   // Returns ABI info helper for the target. This is for use by derived classes.
getABIInfo()5706c3fb27SDimitry Andric   template <typename T> const T &getABIInfo() const {
5806c3fb27SDimitry Andric     return static_cast<const T &>(*Info);
5906c3fb27SDimitry Andric   }
6006c3fb27SDimitry Andric 
610b57cec5SDimitry Andric public:
62fcaf7f86SDimitry Andric   TargetCodeGenInfo(std::unique_ptr<ABIInfo> Info);
630b57cec5SDimitry Andric   virtual ~TargetCodeGenInfo();
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   /// getABIInfo() - Returns ABI info helper for the target.
getABIInfo()660b57cec5SDimitry Andric   const ABIInfo &getABIInfo() const { return *Info; }
670b57cec5SDimitry Andric 
68bdd1243dSDimitry Andric   /// Returns Swift ABI info helper for the target.
getSwiftABIInfo()69bdd1243dSDimitry Andric   const SwiftABIInfo &getSwiftABIInfo() const {
70bdd1243dSDimitry Andric     assert(SwiftInfo && "Swift ABI info has not been initialized");
71bdd1243dSDimitry Andric     return *SwiftInfo;
72bdd1243dSDimitry Andric   }
73bdd1243dSDimitry Andric 
740b57cec5SDimitry Andric   /// setTargetAttributes - Provides a convenient hook to handle extra
750b57cec5SDimitry Andric   /// target-specific attributes for the given global.
setTargetAttributes(const Decl * D,llvm::GlobalValue * GV,CodeGen::CodeGenModule & M)760b57cec5SDimitry Andric   virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
770b57cec5SDimitry Andric                                    CodeGen::CodeGenModule &M) const {}
780b57cec5SDimitry Andric 
795ffd83dbSDimitry Andric   /// emitTargetMetadata - Provides a convenient hook to handle extra
805ffd83dbSDimitry Andric   /// target-specific metadata for the given globals.
emitTargetMetadata(CodeGen::CodeGenModule & CGM,const llvm::MapVector<GlobalDecl,StringRef> & MangledDeclNames)815ffd83dbSDimitry Andric   virtual void emitTargetMetadata(
825ffd83dbSDimitry Andric       CodeGen::CodeGenModule &CGM,
835ffd83dbSDimitry Andric       const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames) const {}
845ffd83dbSDimitry Andric 
855f757f3fSDimitry Andric   /// Provides a convenient hook to handle extra target-specific globals.
emitTargetGlobals(CodeGen::CodeGenModule & CGM)865f757f3fSDimitry Andric   virtual void emitTargetGlobals(CodeGen::CodeGenModule &CGM) const {}
875f757f3fSDimitry Andric 
880fca6ea1SDimitry Andric   /// Any further codegen related checks that need to be done on a function
890fca6ea1SDimitry Andric   /// signature in a target specific manner.
checkFunctionABI(CodeGenModule & CGM,const FunctionDecl * Decl)900fca6ea1SDimitry Andric   virtual void checkFunctionABI(CodeGenModule &CGM,
910fca6ea1SDimitry Andric                                 const FunctionDecl *Decl) const {}
920fca6ea1SDimitry Andric 
935ffd83dbSDimitry Andric   /// Any further codegen related checks that need to be done on a function call
945ffd83dbSDimitry Andric   /// in a target specific manner.
checkFunctionCallABI(CodeGenModule & CGM,SourceLocation CallLoc,const FunctionDecl * Caller,const FunctionDecl * Callee,const CallArgList & Args,QualType ReturnType)955ffd83dbSDimitry Andric   virtual void checkFunctionCallABI(CodeGenModule &CGM, SourceLocation CallLoc,
965ffd83dbSDimitry Andric                                     const FunctionDecl *Caller,
975ffd83dbSDimitry Andric                                     const FunctionDecl *Callee,
980fca6ea1SDimitry Andric                                     const CallArgList &Args,
990fca6ea1SDimitry Andric                                     QualType ReturnType) const {}
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   /// Determines the size of struct _Unwind_Exception on this platform,
1020b57cec5SDimitry Andric   /// in 8-bit units.  The Itanium ABI defines this as:
1030b57cec5SDimitry Andric   ///   struct _Unwind_Exception {
1040b57cec5SDimitry Andric   ///     uint64 exception_class;
1050b57cec5SDimitry Andric   ///     _Unwind_Exception_Cleanup_Fn exception_cleanup;
1060b57cec5SDimitry Andric   ///     uint64 private_1;
1070b57cec5SDimitry Andric   ///     uint64 private_2;
1080b57cec5SDimitry Andric   ///   };
1090b57cec5SDimitry Andric   virtual unsigned getSizeOfUnwindException() const;
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric   /// Controls whether __builtin_extend_pointer should sign-extend
1120b57cec5SDimitry Andric   /// pointers to uint64_t or zero-extend them (the default).  Has
1130b57cec5SDimitry Andric   /// no effect for targets:
1140b57cec5SDimitry Andric   ///   - that have 64-bit pointers, or
1150b57cec5SDimitry Andric   ///   - that cannot address through registers larger than pointers, or
1160b57cec5SDimitry Andric   ///   - that implicitly ignore/truncate the top bits when addressing
1170b57cec5SDimitry Andric   ///     through such registers.
extendPointerWithSExt()1180b57cec5SDimitry Andric   virtual bool extendPointerWithSExt() const { return false; }
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   /// Determines the DWARF register number for the stack pointer, for
1210b57cec5SDimitry Andric   /// exception-handling purposes.  Implements __builtin_dwarf_sp_column.
1220b57cec5SDimitry Andric   ///
1230b57cec5SDimitry Andric   /// Returns -1 if the operation is unsupported by this target.
getDwarfEHStackPointer(CodeGen::CodeGenModule & M)1240b57cec5SDimitry Andric   virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
1250b57cec5SDimitry Andric     return -1;
1260b57cec5SDimitry Andric   }
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric   /// Initializes the given DWARF EH register-size table, a char*.
1290b57cec5SDimitry Andric   /// Implements __builtin_init_dwarf_reg_size_table.
1300b57cec5SDimitry Andric   ///
1310b57cec5SDimitry Andric   /// Returns true if the operation is unsupported by this target.
initDwarfEHRegSizeTable(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)1320b57cec5SDimitry Andric   virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1330b57cec5SDimitry Andric                                        llvm::Value *Address) const {
1340b57cec5SDimitry Andric     return true;
1350b57cec5SDimitry Andric   }
1360b57cec5SDimitry Andric 
1370b57cec5SDimitry Andric   /// Performs the code-generation required to convert a return
1380b57cec5SDimitry Andric   /// address as stored by the system into the actual address of the
1390b57cec5SDimitry Andric   /// next instruction that will be executed.
1400b57cec5SDimitry Andric   ///
1410b57cec5SDimitry Andric   /// Used by __builtin_extract_return_addr().
decodeReturnAddress(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)1420b57cec5SDimitry Andric   virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
1430b57cec5SDimitry Andric                                            llvm::Value *Address) const {
1440b57cec5SDimitry Andric     return Address;
1450b57cec5SDimitry Andric   }
1460b57cec5SDimitry Andric 
1470b57cec5SDimitry Andric   /// Performs the code-generation required to convert the address
1480b57cec5SDimitry Andric   /// of an instruction into a return address suitable for storage
1490b57cec5SDimitry Andric   /// by the system in a return slot.
1500b57cec5SDimitry Andric   ///
1510b57cec5SDimitry Andric   /// Used by __builtin_frob_return_addr().
encodeReturnAddress(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)1520b57cec5SDimitry Andric   virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
1530b57cec5SDimitry Andric                                            llvm::Value *Address) const {
1540b57cec5SDimitry Andric     return Address;
1550b57cec5SDimitry Andric   }
1560b57cec5SDimitry Andric 
157fe6060f1SDimitry Andric   /// Performs a target specific test of a floating point value for things
158fe6060f1SDimitry Andric   /// like IsNaN, Infinity, ... Nullptr is returned if no implementation
159fe6060f1SDimitry Andric   /// exists.
160fe6060f1SDimitry Andric   virtual llvm::Value *
testFPKind(llvm::Value * V,unsigned BuiltinID,CGBuilderTy & Builder,CodeGenModule & CGM)161fe6060f1SDimitry Andric   testFPKind(llvm::Value *V, unsigned BuiltinID, CGBuilderTy &Builder,
162fe6060f1SDimitry Andric              CodeGenModule &CGM) const {
163fe6060f1SDimitry Andric     assert(V->getType()->isFloatingPointTy() && "V should have an FP type.");
164fe6060f1SDimitry Andric     return nullptr;
165fe6060f1SDimitry Andric   }
166fe6060f1SDimitry Andric 
1670b57cec5SDimitry Andric   /// Corrects the low-level LLVM type for a given constraint and "usual"
1680b57cec5SDimitry Andric   /// type.
1690b57cec5SDimitry Andric   ///
1700b57cec5SDimitry Andric   /// \returns A pointer to a new LLVM type, possibly the same as the original
1710b57cec5SDimitry Andric   /// on success; 0 on failure.
adjustInlineAsmType(CodeGen::CodeGenFunction & CGF,StringRef Constraint,llvm::Type * Ty)1720b57cec5SDimitry Andric   virtual llvm::Type *adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
1730b57cec5SDimitry Andric                                           StringRef Constraint,
1740b57cec5SDimitry Andric                                           llvm::Type *Ty) const {
1750b57cec5SDimitry Andric     return Ty;
1760b57cec5SDimitry Andric   }
1770b57cec5SDimitry Andric 
1786e75b2fbSDimitry Andric   /// Target hook to decide whether an inline asm operand can be passed
1796e75b2fbSDimitry Andric   /// by value.
isScalarizableAsmOperand(CodeGen::CodeGenFunction & CGF,llvm::Type * Ty)1806e75b2fbSDimitry Andric   virtual bool isScalarizableAsmOperand(CodeGen::CodeGenFunction &CGF,
1816e75b2fbSDimitry Andric                                         llvm::Type *Ty) const {
1826e75b2fbSDimitry Andric     return false;
1836e75b2fbSDimitry Andric   }
1846e75b2fbSDimitry Andric 
1850b57cec5SDimitry Andric   /// Adds constraints and types for result registers.
addReturnRegisterOutputs(CodeGen::CodeGenFunction & CGF,CodeGen::LValue ReturnValue,std::string & Constraints,std::vector<llvm::Type * > & ResultRegTypes,std::vector<llvm::Type * > & ResultTruncRegTypes,std::vector<CodeGen::LValue> & ResultRegDests,std::string & AsmString,unsigned NumOutputs)1860b57cec5SDimitry Andric   virtual void addReturnRegisterOutputs(
1870b57cec5SDimitry Andric       CodeGen::CodeGenFunction &CGF, CodeGen::LValue ReturnValue,
1880b57cec5SDimitry Andric       std::string &Constraints, std::vector<llvm::Type *> &ResultRegTypes,
1890b57cec5SDimitry Andric       std::vector<llvm::Type *> &ResultTruncRegTypes,
1900b57cec5SDimitry Andric       std::vector<CodeGen::LValue> &ResultRegDests, std::string &AsmString,
1910b57cec5SDimitry Andric       unsigned NumOutputs) const {}
1920b57cec5SDimitry Andric 
1930b57cec5SDimitry Andric   /// doesReturnSlotInterfereWithArgs - Return true if the target uses an
1940b57cec5SDimitry Andric   /// argument slot for an 'sret' type.
doesReturnSlotInterfereWithArgs()1950b57cec5SDimitry Andric   virtual bool doesReturnSlotInterfereWithArgs() const { return true; }
1960b57cec5SDimitry Andric 
1970b57cec5SDimitry Andric   /// Retrieve the address of a function to call immediately before
1980b57cec5SDimitry Andric   /// calling objc_retainAutoreleasedReturnValue.  The
1990b57cec5SDimitry Andric   /// implementation of objc_autoreleaseReturnValue sniffs the
2000b57cec5SDimitry Andric   /// instruction stream following its return address to decide
2010b57cec5SDimitry Andric   /// whether it's a call to objc_retainAutoreleasedReturnValue.
2020b57cec5SDimitry Andric   /// This can be prohibitively expensive, depending on the
2030b57cec5SDimitry Andric   /// relocation model, and so on some targets it instead sniffs for
2040b57cec5SDimitry Andric   /// a particular instruction sequence.  This functions returns
2050b57cec5SDimitry Andric   /// that instruction sequence in inline assembly, which will be
2060b57cec5SDimitry Andric   /// empty if none is required.
getARCRetainAutoreleasedReturnValueMarker()2070b57cec5SDimitry Andric   virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
2080b57cec5SDimitry Andric     return "";
2090b57cec5SDimitry Andric   }
2100b57cec5SDimitry Andric 
211e8d8bef9SDimitry Andric   /// Determine whether a call to objc_retainAutoreleasedReturnValue or
212e8d8bef9SDimitry Andric   /// objc_unsafeClaimAutoreleasedReturnValue should be marked as 'notail'.
markARCOptimizedReturnCallsAsNoTail()213e8d8bef9SDimitry Andric   virtual bool markARCOptimizedReturnCallsAsNoTail() const { return false; }
2140b57cec5SDimitry Andric 
2150b57cec5SDimitry Andric   /// Return a constant used by UBSan as a signature to identify functions
2160b57cec5SDimitry Andric   /// possessing type information, or 0 if the platform is unsupported.
21706c3fb27SDimitry Andric   /// This magic number is invalid instruction encoding in many targets.
2180b57cec5SDimitry Andric   virtual llvm::Constant *
getUBSanFunctionSignature(CodeGen::CodeGenModule & CGM)2190b57cec5SDimitry Andric   getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const {
22006c3fb27SDimitry Andric     return llvm::ConstantInt::get(CGM.Int32Ty, 0xc105cafe);
2210b57cec5SDimitry Andric   }
2220b57cec5SDimitry Andric 
2230b57cec5SDimitry Andric   /// Determine whether a call to an unprototyped functions under
2240b57cec5SDimitry Andric   /// the given calling convention should use the variadic
2250b57cec5SDimitry Andric   /// convention or the non-variadic convention.
2260b57cec5SDimitry Andric   ///
2270b57cec5SDimitry Andric   /// There's a good reason to make a platform's variadic calling
2280b57cec5SDimitry Andric   /// convention be different from its non-variadic calling
2290b57cec5SDimitry Andric   /// convention: the non-variadic arguments can be passed in
2300b57cec5SDimitry Andric   /// registers (better for performance), and the variadic arguments
2310b57cec5SDimitry Andric   /// can be passed on the stack (also better for performance).  If
2320b57cec5SDimitry Andric   /// this is done, however, unprototyped functions *must* use the
2330b57cec5SDimitry Andric   /// non-variadic convention, because C99 states that a call
2340b57cec5SDimitry Andric   /// through an unprototyped function type must succeed if the
2350b57cec5SDimitry Andric   /// function was defined with a non-variadic prototype with
2360b57cec5SDimitry Andric   /// compatible parameters.  Therefore, splitting the conventions
2370b57cec5SDimitry Andric   /// makes it impossible to call a variadic function through an
2380b57cec5SDimitry Andric   /// unprototyped type.  Since function prototypes came out in the
2390b57cec5SDimitry Andric   /// late 1970s, this is probably an acceptable trade-off.
2400b57cec5SDimitry Andric   /// Nonetheless, not all platforms are willing to make it, and in
2410b57cec5SDimitry Andric   /// particularly x86-64 bends over backwards to make the
2420b57cec5SDimitry Andric   /// conventions compatible.
2430b57cec5SDimitry Andric   ///
2440b57cec5SDimitry Andric   /// The default is false.  This is correct whenever:
2450b57cec5SDimitry Andric   ///   - the conventions are exactly the same, because it does not
2460b57cec5SDimitry Andric   ///     matter and the resulting IR will be somewhat prettier in
2470b57cec5SDimitry Andric   ///     certain cases; or
2480b57cec5SDimitry Andric   ///   - the conventions are substantively different in how they pass
2490b57cec5SDimitry Andric   ///     arguments, because in this case using the variadic convention
2500b57cec5SDimitry Andric   ///     will lead to C99 violations.
2510b57cec5SDimitry Andric   ///
2520b57cec5SDimitry Andric   /// However, some platforms make the conventions identical except
2530b57cec5SDimitry Andric   /// for passing additional out-of-band information to a variadic
2540b57cec5SDimitry Andric   /// function: for example, x86-64 passes the number of SSE
2550b57cec5SDimitry Andric   /// arguments in %al.  On these platforms, it is desirable to
2560b57cec5SDimitry Andric   /// call unprototyped functions using the variadic convention so
2570b57cec5SDimitry Andric   /// that unprototyped calls to varargs functions still succeed.
2580b57cec5SDimitry Andric   ///
2590b57cec5SDimitry Andric   /// Relatedly, platforms which pass the fixed arguments to this:
2600b57cec5SDimitry Andric   ///   A foo(B, C, D);
2610b57cec5SDimitry Andric   /// differently than they would pass them to this:
2620b57cec5SDimitry Andric   ///   A foo(B, C, D, ...);
2630b57cec5SDimitry Andric   /// may need to adjust the debugger-support code in Sema to do the
2640b57cec5SDimitry Andric   /// right thing when calling a function with no know signature.
2650b57cec5SDimitry Andric   virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args,
2660b57cec5SDimitry Andric                                      const FunctionNoProtoType *fnType) const;
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   /// Gets the linker options necessary to link a dependent library on this
2690b57cec5SDimitry Andric   /// platform.
2700b57cec5SDimitry Andric   virtual void getDependentLibraryOption(llvm::StringRef Lib,
2710b57cec5SDimitry Andric                                          llvm::SmallString<24> &Opt) const;
2720b57cec5SDimitry Andric 
2730b57cec5SDimitry Andric   /// Gets the linker options necessary to detect object file mismatches on
2740b57cec5SDimitry Andric   /// this platform.
getDetectMismatchOption(llvm::StringRef Name,llvm::StringRef Value,llvm::SmallString<32> & Opt)2750b57cec5SDimitry Andric   virtual void getDetectMismatchOption(llvm::StringRef Name,
2760b57cec5SDimitry Andric                                        llvm::StringRef Value,
2770b57cec5SDimitry Andric                                        llvm::SmallString<32> &Opt) const {}
2780b57cec5SDimitry Andric 
2790b57cec5SDimitry Andric   /// Get LLVM calling convention for OpenCL kernel.
2800b57cec5SDimitry Andric   virtual unsigned getOpenCLKernelCallingConv() const;
2810b57cec5SDimitry Andric 
2820b57cec5SDimitry Andric   /// Get target specific null pointer.
2830b57cec5SDimitry Andric   /// \param T is the LLVM type of the null pointer.
2840b57cec5SDimitry Andric   /// \param QT is the clang QualType of the null pointer.
2850b57cec5SDimitry Andric   /// \return ConstantPointerNull with the given type \p T.
2860b57cec5SDimitry Andric   /// Each target can override it to return its own desired constant value.
2870b57cec5SDimitry Andric   virtual llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
2880b57cec5SDimitry Andric       llvm::PointerType *T, QualType QT) const;
2890b57cec5SDimitry Andric 
2900b57cec5SDimitry Andric   /// Get target favored AST address space of a global variable for languages
2910b57cec5SDimitry Andric   /// other than OpenCL and CUDA.
2920b57cec5SDimitry Andric   /// If \p D is nullptr, returns the default target favored address space
2930b57cec5SDimitry Andric   /// for global variable.
2940b57cec5SDimitry Andric   virtual LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
2950b57cec5SDimitry Andric                                           const VarDecl *D) const;
2960b57cec5SDimitry Andric 
2970b57cec5SDimitry Andric   /// Get the AST address space for alloca.
getASTAllocaAddressSpace()2980b57cec5SDimitry Andric   virtual LangAS getASTAllocaAddressSpace() const { return LangAS::Default; }
2990b57cec5SDimitry Andric 
3000fca6ea1SDimitry Andric   Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr,
3010fca6ea1SDimitry Andric                                LangAS SrcAddr, LangAS DestAddr,
3020fca6ea1SDimitry Andric                                llvm::Type *DestTy,
3030fca6ea1SDimitry Andric                                bool IsNonNull = false) const;
3040fca6ea1SDimitry Andric 
3050b57cec5SDimitry Andric   /// Perform address space cast of an expression of pointer type.
3060b57cec5SDimitry Andric   /// \param V is the LLVM value to be casted to another address space.
3070b57cec5SDimitry Andric   /// \param SrcAddr is the language address space of \p V.
3080b57cec5SDimitry Andric   /// \param DestAddr is the targeted language address space.
3090b57cec5SDimitry Andric   /// \param DestTy is the destination LLVM pointer type.
3100b57cec5SDimitry Andric   /// \param IsNonNull is the flag indicating \p V is known to be non null.
3110b57cec5SDimitry Andric   virtual llvm::Value *performAddrSpaceCast(CodeGen::CodeGenFunction &CGF,
3120b57cec5SDimitry Andric                                             llvm::Value *V, LangAS SrcAddr,
3130b57cec5SDimitry Andric                                             LangAS DestAddr, llvm::Type *DestTy,
3140b57cec5SDimitry Andric                                             bool IsNonNull = false) const;
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric   /// Perform address space cast of a constant expression of pointer type.
3170b57cec5SDimitry Andric   /// \param V is the LLVM constant to be casted to another address space.
3180b57cec5SDimitry Andric   /// \param SrcAddr is the language address space of \p V.
3190b57cec5SDimitry Andric   /// \param DestAddr is the targeted language address space.
3200b57cec5SDimitry Andric   /// \param DestTy is the destination LLVM pointer type.
3210b57cec5SDimitry Andric   virtual llvm::Constant *performAddrSpaceCast(CodeGenModule &CGM,
3220b57cec5SDimitry Andric                                                llvm::Constant *V,
3230b57cec5SDimitry Andric                                                LangAS SrcAddr, LangAS DestAddr,
3240b57cec5SDimitry Andric                                                llvm::Type *DestTy) const;
3250b57cec5SDimitry Andric 
3260b57cec5SDimitry Andric   /// Get address space of pointer parameter for __cxa_atexit.
getAddrSpaceOfCxaAtexitPtrParam()3270b57cec5SDimitry Andric   virtual LangAS getAddrSpaceOfCxaAtexitPtrParam() const {
3280b57cec5SDimitry Andric     return LangAS::Default;
3290b57cec5SDimitry Andric   }
3300b57cec5SDimitry Andric 
3310b57cec5SDimitry Andric   /// Get the syncscope used in LLVM IR.
3320b57cec5SDimitry Andric   virtual llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts,
3330b57cec5SDimitry Andric                                                  SyncScope Scope,
3340b57cec5SDimitry Andric                                                  llvm::AtomicOrdering Ordering,
3350b57cec5SDimitry Andric                                                  llvm::LLVMContext &Ctx) const;
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric   /// Interface class for filling custom fields of a block literal for OpenCL.
3380b57cec5SDimitry Andric   class TargetOpenCLBlockHelper {
3390b57cec5SDimitry Andric   public:
3400b57cec5SDimitry Andric     typedef std::pair<llvm::Value *, StringRef> ValueTy;
TargetOpenCLBlockHelper()3410b57cec5SDimitry Andric     TargetOpenCLBlockHelper() {}
~TargetOpenCLBlockHelper()3420b57cec5SDimitry Andric     virtual ~TargetOpenCLBlockHelper() {}
3430b57cec5SDimitry Andric     /// Get the custom field types for OpenCL blocks.
3440b57cec5SDimitry Andric     virtual llvm::SmallVector<llvm::Type *, 1> getCustomFieldTypes() = 0;
3450b57cec5SDimitry Andric     /// Get the custom field values for OpenCL blocks.
3460b57cec5SDimitry Andric     virtual llvm::SmallVector<ValueTy, 1>
3470b57cec5SDimitry Andric     getCustomFieldValues(CodeGenFunction &CGF, const CGBlockInfo &Info) = 0;
3480b57cec5SDimitry Andric     virtual bool areAllCustomFieldValuesConstant(const CGBlockInfo &Info) = 0;
3490b57cec5SDimitry Andric     /// Get the custom field values for OpenCL blocks if all values are LLVM
3500b57cec5SDimitry Andric     /// constants.
3510b57cec5SDimitry Andric     virtual llvm::SmallVector<llvm::Constant *, 1>
3520b57cec5SDimitry Andric     getCustomFieldValues(CodeGenModule &CGM, const CGBlockInfo &Info) = 0;
3530b57cec5SDimitry Andric   };
getTargetOpenCLBlockHelper()3540b57cec5SDimitry Andric   virtual TargetOpenCLBlockHelper *getTargetOpenCLBlockHelper() const {
3550b57cec5SDimitry Andric     return nullptr;
3560b57cec5SDimitry Andric   }
3570b57cec5SDimitry Andric 
3580b57cec5SDimitry Andric   /// Create an OpenCL kernel for an enqueued block. The kernel function is
3590b57cec5SDimitry Andric   /// a wrapper for the block invoke function with target-specific calling
3600b57cec5SDimitry Andric   /// convention and ABI as an OpenCL kernel. The wrapper function accepts
3610b57cec5SDimitry Andric   /// block context and block arguments in target-specific way and calls
3620b57cec5SDimitry Andric   /// the original block invoke function.
36306c3fb27SDimitry Andric   virtual llvm::Value *
3640b57cec5SDimitry Andric   createEnqueuedBlockKernel(CodeGenFunction &CGF,
3650b57cec5SDimitry Andric                             llvm::Function *BlockInvokeFunc,
36681ad6265SDimitry Andric                             llvm::Type *BlockTy) const;
3670b57cec5SDimitry Andric 
3680b57cec5SDimitry Andric   /// \return true if the target supports alias from the unmangled name to the
3690b57cec5SDimitry Andric   /// mangled name of functions declared within an extern "C" region and marked
3700b57cec5SDimitry Andric   /// as 'used', and having internal linkage.
shouldEmitStaticExternCAliases()3710b57cec5SDimitry Andric   virtual bool shouldEmitStaticExternCAliases() const { return true; }
3720b57cec5SDimitry Andric 
37306c3fb27SDimitry Andric   /// \return true if annonymous zero-sized bitfields should be emitted to
37406c3fb27SDimitry Andric   /// correctly distinguish between struct types whose memory layout is the
37506c3fb27SDimitry Andric   /// same, but whose layout may differ when used as argument passed by value
shouldEmitDWARFBitFieldSeparators()37606c3fb27SDimitry Andric   virtual bool shouldEmitDWARFBitFieldSeparators() const { return false; }
37706c3fb27SDimitry Andric 
setCUDAKernelCallingConvention(const FunctionType * & FT)3780b57cec5SDimitry Andric   virtual void setCUDAKernelCallingConvention(const FunctionType *&FT) const {}
3795ffd83dbSDimitry Andric 
3805ffd83dbSDimitry Andric   /// Return the device-side type for the CUDA device builtin surface type.
getCUDADeviceBuiltinSurfaceDeviceType()3815ffd83dbSDimitry Andric   virtual llvm::Type *getCUDADeviceBuiltinSurfaceDeviceType() const {
3825ffd83dbSDimitry Andric     // By default, no change from the original one.
3835ffd83dbSDimitry Andric     return nullptr;
3845ffd83dbSDimitry Andric   }
3855ffd83dbSDimitry Andric   /// Return the device-side type for the CUDA device builtin texture type.
getCUDADeviceBuiltinTextureDeviceType()3865ffd83dbSDimitry Andric   virtual llvm::Type *getCUDADeviceBuiltinTextureDeviceType() const {
3875ffd83dbSDimitry Andric     // By default, no change from the original one.
3885ffd83dbSDimitry Andric     return nullptr;
3895ffd83dbSDimitry Andric   }
3905ffd83dbSDimitry Andric 
39106c3fb27SDimitry Andric   /// Return the WebAssembly externref reference type.
getWasmExternrefReferenceType()39206c3fb27SDimitry Andric   virtual llvm::Type *getWasmExternrefReferenceType() const { return nullptr; }
39306c3fb27SDimitry Andric 
39406c3fb27SDimitry Andric   /// Return the WebAssembly funcref reference type.
getWasmFuncrefReferenceType()39506c3fb27SDimitry Andric   virtual llvm::Type *getWasmFuncrefReferenceType() const { return nullptr; }
39606c3fb27SDimitry Andric 
3975ffd83dbSDimitry Andric   /// Emit the device-side copy of the builtin surface type.
emitCUDADeviceBuiltinSurfaceDeviceCopy(CodeGenFunction & CGF,LValue Dst,LValue Src)3985ffd83dbSDimitry Andric   virtual bool emitCUDADeviceBuiltinSurfaceDeviceCopy(CodeGenFunction &CGF,
3995ffd83dbSDimitry Andric                                                       LValue Dst,
4005ffd83dbSDimitry Andric                                                       LValue Src) const {
4015ffd83dbSDimitry Andric     // DO NOTHING by default.
4025ffd83dbSDimitry Andric     return false;
4035ffd83dbSDimitry Andric   }
4045ffd83dbSDimitry Andric   /// Emit the device-side copy of the builtin texture type.
emitCUDADeviceBuiltinTextureDeviceCopy(CodeGenFunction & CGF,LValue Dst,LValue Src)4055ffd83dbSDimitry Andric   virtual bool emitCUDADeviceBuiltinTextureDeviceCopy(CodeGenFunction &CGF,
4065ffd83dbSDimitry Andric                                                       LValue Dst,
4075ffd83dbSDimitry Andric                                                       LValue Src) const {
4085ffd83dbSDimitry Andric     // DO NOTHING by default.
4095ffd83dbSDimitry Andric     return false;
4105ffd83dbSDimitry Andric   }
41106c3fb27SDimitry Andric 
41206c3fb27SDimitry Andric   /// Return an LLVM type that corresponds to an OpenCL type.
getOpenCLType(CodeGenModule & CGM,const Type * T)41306c3fb27SDimitry Andric   virtual llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const {
41406c3fb27SDimitry Andric     return nullptr;
41506c3fb27SDimitry Andric   }
41606c3fb27SDimitry Andric 
417*62987288SDimitry Andric   // Set the Branch Protection Attributes of the Function accordingly to the
418*62987288SDimitry Andric   // BPI. Remove attributes that contradict with current BPI.
4190fca6ea1SDimitry Andric   static void
4200fca6ea1SDimitry Andric   setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
4210fca6ea1SDimitry Andric                                   llvm::Function &F);
4220fca6ea1SDimitry Andric 
423*62987288SDimitry Andric   // Add the Branch Protection Attributes of the FuncAttrs.
4240fca6ea1SDimitry Andric   static void
425*62987288SDimitry Andric   initBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
4260fca6ea1SDimitry Andric                                    llvm::AttrBuilder &FuncAttrs);
4270fca6ea1SDimitry Andric 
42806c3fb27SDimitry Andric protected:
42906c3fb27SDimitry Andric   static std::string qualifyWindowsLibrary(StringRef Lib);
43006c3fb27SDimitry Andric 
43106c3fb27SDimitry Andric   void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
43206c3fb27SDimitry Andric                                      CodeGen::CodeGenModule &CGM) const;
4330b57cec5SDimitry Andric };
4340b57cec5SDimitry Andric 
43506c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
43606c3fb27SDimitry Andric createDefaultTargetCodeGenInfo(CodeGenModule &CGM);
43706c3fb27SDimitry Andric 
43806c3fb27SDimitry Andric enum class AArch64ABIKind {
43906c3fb27SDimitry Andric   AAPCS = 0,
44006c3fb27SDimitry Andric   DarwinPCS,
44106c3fb27SDimitry Andric   Win64,
4420fca6ea1SDimitry Andric   AAPCSSoft,
4430fca6ea1SDimitry Andric   PAuthTest,
44406c3fb27SDimitry Andric };
44506c3fb27SDimitry Andric 
44606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
44706c3fb27SDimitry Andric createAArch64TargetCodeGenInfo(CodeGenModule &CGM, AArch64ABIKind Kind);
44806c3fb27SDimitry Andric 
44906c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
45006c3fb27SDimitry Andric createWindowsAArch64TargetCodeGenInfo(CodeGenModule &CGM, AArch64ABIKind K);
45106c3fb27SDimitry Andric 
45206c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
45306c3fb27SDimitry Andric createAMDGPUTargetCodeGenInfo(CodeGenModule &CGM);
45406c3fb27SDimitry Andric 
45506c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
45606c3fb27SDimitry Andric createARCTargetCodeGenInfo(CodeGenModule &CGM);
45706c3fb27SDimitry Andric 
45806c3fb27SDimitry Andric enum class ARMABIKind {
45906c3fb27SDimitry Andric   APCS = 0,
46006c3fb27SDimitry Andric   AAPCS = 1,
46106c3fb27SDimitry Andric   AAPCS_VFP = 2,
46206c3fb27SDimitry Andric   AAPCS16_VFP = 3,
46306c3fb27SDimitry Andric };
46406c3fb27SDimitry Andric 
46506c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
46606c3fb27SDimitry Andric createARMTargetCodeGenInfo(CodeGenModule &CGM, ARMABIKind Kind);
46706c3fb27SDimitry Andric 
46806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
46906c3fb27SDimitry Andric createWindowsARMTargetCodeGenInfo(CodeGenModule &CGM, ARMABIKind K);
47006c3fb27SDimitry Andric 
47106c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
47206c3fb27SDimitry Andric createAVRTargetCodeGenInfo(CodeGenModule &CGM, unsigned NPR, unsigned NRR);
47306c3fb27SDimitry Andric 
47406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
47506c3fb27SDimitry Andric createBPFTargetCodeGenInfo(CodeGenModule &CGM);
47606c3fb27SDimitry Andric 
47706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
47806c3fb27SDimitry Andric createCSKYTargetCodeGenInfo(CodeGenModule &CGM, unsigned FLen);
47906c3fb27SDimitry Andric 
48006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
48106c3fb27SDimitry Andric createHexagonTargetCodeGenInfo(CodeGenModule &CGM);
48206c3fb27SDimitry Andric 
48306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
48406c3fb27SDimitry Andric createLanaiTargetCodeGenInfo(CodeGenModule &CGM);
48506c3fb27SDimitry Andric 
48606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
48706c3fb27SDimitry Andric createLoongArchTargetCodeGenInfo(CodeGenModule &CGM, unsigned GRLen,
48806c3fb27SDimitry Andric                                  unsigned FLen);
48906c3fb27SDimitry Andric 
49006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
49106c3fb27SDimitry Andric createM68kTargetCodeGenInfo(CodeGenModule &CGM);
49206c3fb27SDimitry Andric 
49306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
49406c3fb27SDimitry Andric createMIPSTargetCodeGenInfo(CodeGenModule &CGM, bool IsOS32);
49506c3fb27SDimitry Andric 
49606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
49706c3fb27SDimitry Andric createMSP430TargetCodeGenInfo(CodeGenModule &CGM);
49806c3fb27SDimitry Andric 
49906c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
50006c3fb27SDimitry Andric createNVPTXTargetCodeGenInfo(CodeGenModule &CGM);
50106c3fb27SDimitry Andric 
50206c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
50306c3fb27SDimitry Andric createPNaClTargetCodeGenInfo(CodeGenModule &CGM);
50406c3fb27SDimitry Andric 
50506c3fb27SDimitry Andric enum class PPC64_SVR4_ABIKind {
50606c3fb27SDimitry Andric   ELFv1 = 0,
50706c3fb27SDimitry Andric   ELFv2,
50806c3fb27SDimitry Andric };
50906c3fb27SDimitry Andric 
51006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
51106c3fb27SDimitry Andric createAIXTargetCodeGenInfo(CodeGenModule &CGM, bool Is64Bit);
51206c3fb27SDimitry Andric 
51306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
51406c3fb27SDimitry Andric createPPC32TargetCodeGenInfo(CodeGenModule &CGM, bool SoftFloatABI);
51506c3fb27SDimitry Andric 
51606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
51706c3fb27SDimitry Andric createPPC64TargetCodeGenInfo(CodeGenModule &CGM);
51806c3fb27SDimitry Andric 
51906c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
52006c3fb27SDimitry Andric createPPC64_SVR4_TargetCodeGenInfo(CodeGenModule &CGM, PPC64_SVR4_ABIKind Kind,
52106c3fb27SDimitry Andric                                    bool SoftFloatABI);
52206c3fb27SDimitry Andric 
52306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
5247a6dacacSDimitry Andric createRISCVTargetCodeGenInfo(CodeGenModule &CGM, unsigned XLen, unsigned FLen,
5257a6dacacSDimitry Andric                              bool EABI);
52606c3fb27SDimitry Andric 
52706c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
52806c3fb27SDimitry Andric createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM);
52906c3fb27SDimitry Andric 
53006c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
53106c3fb27SDimitry Andric createSPIRVTargetCodeGenInfo(CodeGenModule &CGM);
53206c3fb27SDimitry Andric 
53306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
53406c3fb27SDimitry Andric createSparcV8TargetCodeGenInfo(CodeGenModule &CGM);
53506c3fb27SDimitry Andric 
53606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
53706c3fb27SDimitry Andric createSparcV9TargetCodeGenInfo(CodeGenModule &CGM);
53806c3fb27SDimitry Andric 
53906c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
54006c3fb27SDimitry Andric createSystemZTargetCodeGenInfo(CodeGenModule &CGM, bool HasVector,
54106c3fb27SDimitry Andric                                bool SoftFloatABI);
54206c3fb27SDimitry Andric 
54306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
54406c3fb27SDimitry Andric createTCETargetCodeGenInfo(CodeGenModule &CGM);
54506c3fb27SDimitry Andric 
54606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
54706c3fb27SDimitry Andric createVETargetCodeGenInfo(CodeGenModule &CGM);
54806c3fb27SDimitry Andric 
54906c3fb27SDimitry Andric enum class WebAssemblyABIKind {
55006c3fb27SDimitry Andric   MVP = 0,
55106c3fb27SDimitry Andric   ExperimentalMV = 1,
55206c3fb27SDimitry Andric };
55306c3fb27SDimitry Andric 
55406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
55506c3fb27SDimitry Andric createWebAssemblyTargetCodeGenInfo(CodeGenModule &CGM, WebAssemblyABIKind K);
55606c3fb27SDimitry Andric 
55706c3fb27SDimitry Andric /// The AVX ABI level for X86 targets.
55806c3fb27SDimitry Andric enum class X86AVXABILevel {
55906c3fb27SDimitry Andric   None,
56006c3fb27SDimitry Andric   AVX,
56106c3fb27SDimitry Andric   AVX512,
56206c3fb27SDimitry Andric };
56306c3fb27SDimitry Andric 
56406c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo> createX86_32TargetCodeGenInfo(
56506c3fb27SDimitry Andric     CodeGenModule &CGM, bool DarwinVectorABI, bool Win32StructABI,
56606c3fb27SDimitry Andric     unsigned NumRegisterParameters, bool SoftFloatABI);
56706c3fb27SDimitry Andric 
56806c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
56906c3fb27SDimitry Andric createWinX86_32TargetCodeGenInfo(CodeGenModule &CGM, bool DarwinVectorABI,
57006c3fb27SDimitry Andric                                  bool Win32StructABI,
57106c3fb27SDimitry Andric                                  unsigned NumRegisterParameters);
57206c3fb27SDimitry Andric 
57306c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
57406c3fb27SDimitry Andric createX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel);
57506c3fb27SDimitry Andric 
57606c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
57706c3fb27SDimitry Andric createWinX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel);
57806c3fb27SDimitry Andric 
57906c3fb27SDimitry Andric std::unique_ptr<TargetCodeGenInfo>
58006c3fb27SDimitry Andric createXCoreTargetCodeGenInfo(CodeGenModule &CGM);
58106c3fb27SDimitry Andric 
5820b57cec5SDimitry Andric } // namespace CodeGen
5830b57cec5SDimitry Andric } // namespace clang
5840b57cec5SDimitry Andric 
5850b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
586