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