1f4a2713aSLionel Sambuc //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // These classes wrap the information about a call or function 11f4a2713aSLionel Sambuc // definition used to handle ABI compliancy. 12f4a2713aSLionel Sambuc // 13f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 14f4a2713aSLionel Sambuc 15*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H 16*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H 17f4a2713aSLionel Sambuc 18*0a6a1f1dSLionel Sambuc #include "CGValue.h" 19f4a2713aSLionel Sambuc #include "clang/AST/Type.h" 20f4a2713aSLionel Sambuc #include "clang/Basic/LLVM.h" 21f4a2713aSLionel Sambuc #include "llvm/ADT/SmallString.h" 22*0a6a1f1dSLionel Sambuc #include "llvm/ADT/StringRef.h" 23f4a2713aSLionel Sambuc 24f4a2713aSLionel Sambuc namespace llvm { 25f4a2713aSLionel Sambuc class Constant; 26f4a2713aSLionel Sambuc class GlobalValue; 27f4a2713aSLionel Sambuc class Type; 28f4a2713aSLionel Sambuc class Value; 29f4a2713aSLionel Sambuc } 30f4a2713aSLionel Sambuc 31f4a2713aSLionel Sambuc namespace clang { 32f4a2713aSLionel Sambuc class ABIInfo; 33f4a2713aSLionel Sambuc class Decl; 34f4a2713aSLionel Sambuc 35f4a2713aSLionel Sambuc namespace CodeGen { 36f4a2713aSLionel Sambuc class CallArgList; 37f4a2713aSLionel Sambuc class CodeGenModule; 38f4a2713aSLionel Sambuc class CodeGenFunction; 39f4a2713aSLionel Sambuc class CGFunctionInfo; 40f4a2713aSLionel Sambuc } 41f4a2713aSLionel Sambuc 42f4a2713aSLionel Sambuc /// TargetCodeGenInfo - This class organizes various target-specific 43f4a2713aSLionel Sambuc /// codegeneration issues, like target-specific attributes, builtins and so 44f4a2713aSLionel Sambuc /// on. 45f4a2713aSLionel Sambuc class TargetCodeGenInfo { 46f4a2713aSLionel Sambuc ABIInfo *Info; 47*0a6a1f1dSLionel Sambuc 48f4a2713aSLionel Sambuc public: 49f4a2713aSLionel Sambuc // WARNING: Acquires the ownership of ABIInfo. Info(info)50f4a2713aSLionel Sambuc TargetCodeGenInfo(ABIInfo *info = 0) : Info(info) {} 51f4a2713aSLionel Sambuc virtual ~TargetCodeGenInfo(); 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc /// getABIInfo() - Returns ABI info helper for the target. getABIInfo()54f4a2713aSLionel Sambuc const ABIInfo &getABIInfo() const { return *Info; } 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc /// SetTargetAttributes - Provides a convenient hook to handle extra 57f4a2713aSLionel Sambuc /// target-specific attributes for the given global. SetTargetAttributes(const Decl * D,llvm::GlobalValue * GV,CodeGen::CodeGenModule & M)58f4a2713aSLionel Sambuc virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, 59f4a2713aSLionel Sambuc CodeGen::CodeGenModule &M) const {} 60f4a2713aSLionel Sambuc 61*0a6a1f1dSLionel Sambuc /// EmitTargetMD - Provides a convenient hook to handle extra 62*0a6a1f1dSLionel Sambuc /// target-specific metadata for the given global. emitTargetMD(const Decl * D,llvm::GlobalValue * GV,CodeGen::CodeGenModule & M)63*0a6a1f1dSLionel Sambuc virtual void emitTargetMD(const Decl *D, llvm::GlobalValue *GV, 64*0a6a1f1dSLionel Sambuc CodeGen::CodeGenModule &M) const {} 65*0a6a1f1dSLionel Sambuc 66f4a2713aSLionel Sambuc /// Determines the size of struct _Unwind_Exception on this platform, 67f4a2713aSLionel Sambuc /// in 8-bit units. The Itanium ABI defines this as: 68f4a2713aSLionel Sambuc /// struct _Unwind_Exception { 69f4a2713aSLionel Sambuc /// uint64 exception_class; 70f4a2713aSLionel Sambuc /// _Unwind_Exception_Cleanup_Fn exception_cleanup; 71f4a2713aSLionel Sambuc /// uint64 private_1; 72f4a2713aSLionel Sambuc /// uint64 private_2; 73f4a2713aSLionel Sambuc /// }; 74f4a2713aSLionel Sambuc virtual unsigned getSizeOfUnwindException() const; 75f4a2713aSLionel Sambuc 76f4a2713aSLionel Sambuc /// Controls whether __builtin_extend_pointer should sign-extend 77f4a2713aSLionel Sambuc /// pointers to uint64_t or zero-extend them (the default). Has 78f4a2713aSLionel Sambuc /// no effect for targets: 79f4a2713aSLionel Sambuc /// - that have 64-bit pointers, or 80f4a2713aSLionel Sambuc /// - that cannot address through registers larger than pointers, or 81f4a2713aSLionel Sambuc /// - that implicitly ignore/truncate the top bits when addressing 82f4a2713aSLionel Sambuc /// through such registers. extendPointerWithSExt()83f4a2713aSLionel Sambuc virtual bool extendPointerWithSExt() const { return false; } 84f4a2713aSLionel Sambuc 85f4a2713aSLionel Sambuc /// Determines the DWARF register number for the stack pointer, for 86f4a2713aSLionel Sambuc /// exception-handling purposes. Implements __builtin_dwarf_sp_column. 87f4a2713aSLionel Sambuc /// 88f4a2713aSLionel Sambuc /// Returns -1 if the operation is unsupported by this target. getDwarfEHStackPointer(CodeGen::CodeGenModule & M)89f4a2713aSLionel Sambuc virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { 90f4a2713aSLionel Sambuc return -1; 91f4a2713aSLionel Sambuc } 92f4a2713aSLionel Sambuc 93f4a2713aSLionel Sambuc /// Initializes the given DWARF EH register-size table, a char*. 94f4a2713aSLionel Sambuc /// Implements __builtin_init_dwarf_reg_size_table. 95f4a2713aSLionel Sambuc /// 96f4a2713aSLionel Sambuc /// Returns true if the operation is unsupported by this target. initDwarfEHRegSizeTable(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)97f4a2713aSLionel Sambuc virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, 98f4a2713aSLionel Sambuc llvm::Value *Address) const { 99f4a2713aSLionel Sambuc return true; 100f4a2713aSLionel Sambuc } 101f4a2713aSLionel Sambuc 102f4a2713aSLionel Sambuc /// Performs the code-generation required to convert a return 103f4a2713aSLionel Sambuc /// address as stored by the system into the actual address of the 104f4a2713aSLionel Sambuc /// next instruction that will be executed. 105f4a2713aSLionel Sambuc /// 106f4a2713aSLionel Sambuc /// Used by __builtin_extract_return_addr(). decodeReturnAddress(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)107f4a2713aSLionel Sambuc virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF, 108f4a2713aSLionel Sambuc llvm::Value *Address) const { 109f4a2713aSLionel Sambuc return Address; 110f4a2713aSLionel Sambuc } 111f4a2713aSLionel Sambuc 112f4a2713aSLionel Sambuc /// Performs the code-generation required to convert the address 113f4a2713aSLionel Sambuc /// of an instruction into a return address suitable for storage 114f4a2713aSLionel Sambuc /// by the system in a return slot. 115f4a2713aSLionel Sambuc /// 116f4a2713aSLionel Sambuc /// Used by __builtin_frob_return_addr(). encodeReturnAddress(CodeGen::CodeGenFunction & CGF,llvm::Value * Address)117f4a2713aSLionel Sambuc virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF, 118f4a2713aSLionel Sambuc llvm::Value *Address) const { 119f4a2713aSLionel Sambuc return Address; 120f4a2713aSLionel Sambuc } 121f4a2713aSLionel Sambuc 122f4a2713aSLionel Sambuc /// Corrects the low-level LLVM type for a given constraint and "usual" 123f4a2713aSLionel Sambuc /// type. 124f4a2713aSLionel Sambuc /// 125f4a2713aSLionel Sambuc /// \returns A pointer to a new LLVM type, possibly the same as the original 126f4a2713aSLionel Sambuc /// on success; 0 on failure. adjustInlineAsmType(CodeGen::CodeGenFunction & CGF,StringRef Constraint,llvm::Type * Ty)127f4a2713aSLionel Sambuc virtual llvm::Type *adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, 128f4a2713aSLionel Sambuc StringRef Constraint, 129f4a2713aSLionel Sambuc llvm::Type *Ty) const { 130f4a2713aSLionel Sambuc return Ty; 131f4a2713aSLionel Sambuc } 132f4a2713aSLionel Sambuc 133*0a6a1f1dSLionel Sambuc /// 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)134*0a6a1f1dSLionel Sambuc virtual void addReturnRegisterOutputs( 135*0a6a1f1dSLionel Sambuc CodeGen::CodeGenFunction &CGF, CodeGen::LValue ReturnValue, 136*0a6a1f1dSLionel Sambuc std::string &Constraints, std::vector<llvm::Type *> &ResultRegTypes, 137*0a6a1f1dSLionel Sambuc std::vector<llvm::Type *> &ResultTruncRegTypes, 138*0a6a1f1dSLionel Sambuc std::vector<CodeGen::LValue> &ResultRegDests, std::string &AsmString, 139*0a6a1f1dSLionel Sambuc unsigned NumOutputs) const {} 140*0a6a1f1dSLionel Sambuc 141*0a6a1f1dSLionel Sambuc /// doesReturnSlotInterfereWithArgs - Return true if the target uses an 142*0a6a1f1dSLionel Sambuc /// argument slot for an 'sret' type. doesReturnSlotInterfereWithArgs()143*0a6a1f1dSLionel Sambuc virtual bool doesReturnSlotInterfereWithArgs() const { return true; } 144*0a6a1f1dSLionel Sambuc 145f4a2713aSLionel Sambuc /// Retrieve the address of a function to call immediately before 146f4a2713aSLionel Sambuc /// calling objc_retainAutoreleasedReturnValue. The 147f4a2713aSLionel Sambuc /// implementation of objc_autoreleaseReturnValue sniffs the 148f4a2713aSLionel Sambuc /// instruction stream following its return address to decide 149f4a2713aSLionel Sambuc /// whether it's a call to objc_retainAutoreleasedReturnValue. 150f4a2713aSLionel Sambuc /// This can be prohibitively expensive, depending on the 151f4a2713aSLionel Sambuc /// relocation model, and so on some targets it instead sniffs for 152f4a2713aSLionel Sambuc /// a particular instruction sequence. This functions returns 153f4a2713aSLionel Sambuc /// that instruction sequence in inline assembly, which will be 154f4a2713aSLionel Sambuc /// empty if none is required. getARCRetainAutoreleasedReturnValueMarker()155f4a2713aSLionel Sambuc virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const { 156f4a2713aSLionel Sambuc return ""; 157f4a2713aSLionel Sambuc } 158f4a2713aSLionel Sambuc 159f4a2713aSLionel Sambuc /// Return a constant used by UBSan as a signature to identify functions 160f4a2713aSLionel Sambuc /// possessing type information, or 0 if the platform is unsupported. 161*0a6a1f1dSLionel Sambuc virtual llvm::Constant * getUBSanFunctionSignature(CodeGen::CodeGenModule & CGM)162*0a6a1f1dSLionel Sambuc getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const { 163*0a6a1f1dSLionel Sambuc return nullptr; 164f4a2713aSLionel Sambuc } 165f4a2713aSLionel Sambuc 166f4a2713aSLionel Sambuc /// Determine whether a call to an unprototyped functions under 167f4a2713aSLionel Sambuc /// the given calling convention should use the variadic 168f4a2713aSLionel Sambuc /// convention or the non-variadic convention. 169f4a2713aSLionel Sambuc /// 170f4a2713aSLionel Sambuc /// There's a good reason to make a platform's variadic calling 171f4a2713aSLionel Sambuc /// convention be different from its non-variadic calling 172f4a2713aSLionel Sambuc /// convention: the non-variadic arguments can be passed in 173f4a2713aSLionel Sambuc /// registers (better for performance), and the variadic arguments 174f4a2713aSLionel Sambuc /// can be passed on the stack (also better for performance). If 175f4a2713aSLionel Sambuc /// this is done, however, unprototyped functions *must* use the 176f4a2713aSLionel Sambuc /// non-variadic convention, because C99 states that a call 177f4a2713aSLionel Sambuc /// through an unprototyped function type must succeed if the 178f4a2713aSLionel Sambuc /// function was defined with a non-variadic prototype with 179f4a2713aSLionel Sambuc /// compatible parameters. Therefore, splitting the conventions 180f4a2713aSLionel Sambuc /// makes it impossible to call a variadic function through an 181f4a2713aSLionel Sambuc /// unprototyped type. Since function prototypes came out in the 182f4a2713aSLionel Sambuc /// late 1970s, this is probably an acceptable trade-off. 183f4a2713aSLionel Sambuc /// Nonetheless, not all platforms are willing to make it, and in 184f4a2713aSLionel Sambuc /// particularly x86-64 bends over backwards to make the 185f4a2713aSLionel Sambuc /// conventions compatible. 186f4a2713aSLionel Sambuc /// 187f4a2713aSLionel Sambuc /// The default is false. This is correct whenever: 188f4a2713aSLionel Sambuc /// - the conventions are exactly the same, because it does not 189f4a2713aSLionel Sambuc /// matter and the resulting IR will be somewhat prettier in 190f4a2713aSLionel Sambuc /// certain cases; or 191f4a2713aSLionel Sambuc /// - the conventions are substantively different in how they pass 192f4a2713aSLionel Sambuc /// arguments, because in this case using the variadic convention 193f4a2713aSLionel Sambuc /// will lead to C99 violations. 194f4a2713aSLionel Sambuc /// 195f4a2713aSLionel Sambuc /// However, some platforms make the conventions identical except 196f4a2713aSLionel Sambuc /// for passing additional out-of-band information to a variadic 197f4a2713aSLionel Sambuc /// function: for example, x86-64 passes the number of SSE 198*0a6a1f1dSLionel Sambuc /// arguments in %al. On these platforms, it is desirable to 199f4a2713aSLionel Sambuc /// call unprototyped functions using the variadic convention so 200f4a2713aSLionel Sambuc /// that unprototyped calls to varargs functions still succeed. 201f4a2713aSLionel Sambuc /// 202f4a2713aSLionel Sambuc /// Relatedly, platforms which pass the fixed arguments to this: 203f4a2713aSLionel Sambuc /// A foo(B, C, D); 204f4a2713aSLionel Sambuc /// differently than they would pass them to this: 205f4a2713aSLionel Sambuc /// A foo(B, C, D, ...); 206f4a2713aSLionel Sambuc /// may need to adjust the debugger-support code in Sema to do the 207f4a2713aSLionel Sambuc /// right thing when calling a function with no know signature. 208f4a2713aSLionel Sambuc virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, 209f4a2713aSLionel Sambuc const FunctionNoProtoType *fnType) const; 210f4a2713aSLionel Sambuc 211f4a2713aSLionel Sambuc /// Gets the linker options necessary to link a dependent library on this 212f4a2713aSLionel Sambuc /// platform. 213f4a2713aSLionel Sambuc virtual void getDependentLibraryOption(llvm::StringRef Lib, 214f4a2713aSLionel Sambuc llvm::SmallString<24> &Opt) const; 215f4a2713aSLionel Sambuc 216f4a2713aSLionel Sambuc /// Gets the linker options necessary to detect object file mismatches on 217f4a2713aSLionel Sambuc /// this platform. getDetectMismatchOption(llvm::StringRef Name,llvm::StringRef Value,llvm::SmallString<32> & Opt)218f4a2713aSLionel Sambuc virtual void getDetectMismatchOption(llvm::StringRef Name, 219f4a2713aSLionel Sambuc llvm::StringRef Value, 220f4a2713aSLionel Sambuc llvm::SmallString<32> &Opt) const {} 221*0a6a1f1dSLionel Sambuc 222*0a6a1f1dSLionel Sambuc /// Gets the target-specific default alignment used when an 'aligned' clause 223*0a6a1f1dSLionel Sambuc /// is used with a 'simd' OpenMP directive without specifying a specific 224*0a6a1f1dSLionel Sambuc /// alignment. getOpenMPSimdDefaultAlignment(QualType Type)225*0a6a1f1dSLionel Sambuc virtual unsigned getOpenMPSimdDefaultAlignment(QualType Type) const { 226*0a6a1f1dSLionel Sambuc return 0; 227*0a6a1f1dSLionel Sambuc } 228f4a2713aSLionel Sambuc }; 229f4a2713aSLionel Sambuc } 230f4a2713aSLionel Sambuc 231*0a6a1f1dSLionel Sambuc #endif 232