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