blob: a7fb88649a3ea2a9b62d92e4151f4c250a1f1321 [file] [log] [blame]
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001//===---- 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 McCall01f151e2011-09-21 08:08:30 +000018#include "clang/AST/Type.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000019#include "clang/Basic/LLVM.h"
Peter Collingbourne4b93d662011-02-19 23:03:58 +000020#include "llvm/ADT/StringRef.h"
Reid Kleckner3190ca92013-05-08 13:44:39 +000021#include "llvm/ADT/SmallString.h"
Peter Collingbourne4b93d662011-02-19 23:03:58 +000022
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000023namespace llvm {
24 class GlobalValue;
Peter Collingbourne4b93d662011-02-19 23:03:58 +000025 class Type;
John McCall492c4f92010-03-03 04:15:11 +000026 class Value;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000027}
28
29namespace clang {
30 class ABIInfo;
31 class Decl;
32
33 namespace CodeGen {
John McCallde5d3c72012-02-17 03:33:10 +000034 class CallArgList;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000035 class CodeGenModule;
John McCall492c4f92010-03-03 04:15:11 +000036 class CodeGenFunction;
Eli Friedman3ed79032011-12-01 04:53:19 +000037 class CGFunctionInfo;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000038 }
39
40 /// TargetCodeGenInfo - This class organizes various target-specific
41 /// codegeneration issues, like target-specific attributes, builtins and so
42 /// on.
43 class TargetCodeGenInfo {
44 ABIInfo *Info;
45 public:
46 // WARNING: Acquires the ownership of ABIInfo.
Douglas Gregor568bb2d2010-01-22 15:41:14 +000047 TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000048 virtual ~TargetCodeGenInfo();
49
50 /// getABIInfo() - Returns ABI info helper for the target.
51 const ABIInfo& getABIInfo() const { return *Info; }
52
53 /// SetTargetAttributes - Provides a convenient hook to handle extra
54 /// target-specific attributes for the given global.
55 virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
Douglas Gregor568bb2d2010-01-22 15:41:14 +000056 CodeGen::CodeGenModule &M) const { }
John McCalld0b76ca2010-03-02 03:50:12 +000057
John McCall204b0752010-07-20 22:17:55 +000058 /// Determines the size of struct _Unwind_Exception on this platform,
59 /// in 8-bit units. The Itanium ABI defines this as:
60 /// struct _Unwind_Exception {
61 /// uint64 exception_class;
62 /// _Unwind_Exception_Cleanup_Fn exception_cleanup;
63 /// uint64 private_1;
64 /// uint64 private_2;
65 /// };
John McCall49e34be2011-08-30 01:42:09 +000066 virtual unsigned getSizeOfUnwindException() const;
John McCall204b0752010-07-20 22:17:55 +000067
John McCalld0b76ca2010-03-02 03:50:12 +000068 /// Controls whether __builtin_extend_pointer should sign-extend
69 /// pointers to uint64_t or zero-extend them (the default). Has
70 /// no effect for targets:
71 /// - that have 64-bit pointers, or
72 /// - that cannot address through registers larger than pointers, or
73 /// - that implicitly ignore/truncate the top bits when addressing
74 /// through such registers.
75 virtual bool extendPointerWithSExt() const { return false; }
John McCall492c4f92010-03-03 04:15:11 +000076
John McCall6374c332010-03-06 00:35:14 +000077 /// Determines the DWARF register number for the stack pointer, for
78 /// exception-handling purposes. Implements __builtin_dwarf_sp_column.
79 ///
80 /// Returns -1 if the operation is unsupported by this target.
81 virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
82 return -1;
83 }
84
85 /// Initializes the given DWARF EH register-size table, a char*.
86 /// Implements __builtin_init_dwarf_reg_size_table.
87 ///
88 /// Returns true if the operation is unsupported by this target.
89 virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
90 llvm::Value *Address) const {
91 return true;
92 }
93
John McCall492c4f92010-03-03 04:15:11 +000094 /// Performs the code-generation required to convert a return
95 /// address as stored by the system into the actual address of the
96 /// next instruction that will be executed.
97 ///
98 /// Used by __builtin_extract_return_addr().
99 virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
100 llvm::Value *Address) const {
101 return Address;
102 }
103
104 /// Performs the code-generation required to convert the address
105 /// of an instruction into a return address suitable for storage
106 /// by the system in a return slot.
107 ///
108 /// Used by __builtin_frob_return_addr().
109 virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
110 llvm::Value *Address) const {
111 return Address;
112 }
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000113
Tim Northover1bea6532013-06-07 00:04:50 +0000114 /// Corrects the low-level LLVM type for a given constraint and "usual"
115 /// type.
116 ///
117 /// \returns A pointer to a new LLVM type, possibly the same as the original
118 /// on success; 0 on failure.
Jay Foadef6de3d2011-07-11 09:56:20 +0000119 virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
Tim Northover1bea6532013-06-07 00:04:50 +0000120 StringRef Constraint,
Jay Foadef6de3d2011-07-11 09:56:20 +0000121 llvm::Type* Ty) const {
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000122 return Ty;
123 }
John McCallf85e1932011-06-15 23:02:42 +0000124
125 /// Retrieve the address of a function to call immediately before
126 /// calling objc_retainAutoreleasedReturnValue. The
127 /// implementation of objc_autoreleaseReturnValue sniffs the
128 /// instruction stream following its return address to decide
129 /// whether it's a call to objc_retainAutoreleasedReturnValue.
130 /// This can be prohibitively expensive, depending on the
131 /// relocation model, and so on some targets it instead sniffs for
132 /// a particular instruction sequence. This functions returns
133 /// that instruction sequence in inline assembly, which will be
134 /// empty if none is required.
Chris Lattner686775d2011-07-20 06:58:45 +0000135 virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
John McCallf85e1932011-06-15 23:02:42 +0000136 return "";
137 }
John McCall01f151e2011-09-21 08:08:30 +0000138
139 /// Determine whether a call to an unprototyped functions under
140 /// the given calling convention should use the variadic
141 /// convention or the non-variadic convention.
142 ///
143 /// There's a good reason to make a platform's variadic calling
144 /// convention be different from its non-variadic calling
145 /// convention: the non-variadic arguments can be passed in
146 /// registers (better for performance), and the variadic arguments
147 /// can be passed on the stack (also better for performance). If
148 /// this is done, however, unprototyped functions *must* use the
149 /// non-variadic convention, because C99 states that a call
150 /// through an unprototyped function type must succeed if the
151 /// function was defined with a non-variadic prototype with
152 /// compatible parameters. Therefore, splitting the conventions
153 /// makes it impossible to call a variadic function through an
154 /// unprototyped type. Since function prototypes came out in the
155 /// late 1970s, this is probably an acceptable trade-off.
156 /// Nonetheless, not all platforms are willing to make it, and in
157 /// particularly x86-64 bends over backwards to make the
158 /// conventions compatible.
159 ///
160 /// The default is false. This is correct whenever:
161 /// - the conventions are exactly the same, because it does not
162 /// matter and the resulting IR will be somewhat prettier in
163 /// certain cases; or
164 /// - the conventions are substantively different in how they pass
165 /// arguments, because in this case using the variadic convention
166 /// will lead to C99 violations.
John McCalle56bb362012-12-07 07:03:17 +0000167 ///
168 /// However, some platforms make the conventions identical except
169 /// for passing additional out-of-band information to a variadic
170 /// function: for example, x86-64 passes the number of SSE
171 /// arguments in %al. On these platforms, it is desireable to
172 /// call unprototyped functions using the variadic convention so
173 /// that unprototyped calls to varargs functions still succeed.
John McCall02a01fa2013-06-27 22:43:24 +0000174 ///
175 /// Relatedly, platforms which pass the fixed arguments to this:
176 /// A foo(B, C, D);
177 /// differently than they would pass them to this:
178 /// A foo(B, C, D, ...);
179 /// may need to adjust the debugger-support code in Sema to do the
180 /// right thing when calling a function with no know signature.
John McCallde5d3c72012-02-17 03:33:10 +0000181 virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args,
182 const FunctionNoProtoType *fnType) const;
Reid Kleckner3190ca92013-05-08 13:44:39 +0000183
184 /// Gets the linker options necessary to link a dependent library on this
185 /// platform.
186 virtual void getDependentLibraryOption(llvm::StringRef Lib,
187 llvm::SmallString<24> &Opt) const;
Aaron Ballmana7ff62f2013-06-04 02:07:14 +0000188
189 /// Gets the linker options necessary to detect object file mismatches on
190 /// this platform.
191 virtual void getDetectMismatchOption(llvm::StringRef Name,
192 llvm::StringRef Value,
193 llvm::SmallString<32> &Opt) const {}
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000194 };
195}
196
197#endif // CLANG_CODEGEN_TARGETINFO_H