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