1 //===---- TargetInfo.h - Encapsulate target details -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes wrap the information about a call or function
11 // definition used to handle ABI compliancy.
13 //===----------------------------------------------------------------------===//
15 #ifndef CLANG_CODEGEN_TARGETINFO_H
16 #define CLANG_CODEGEN_TARGETINFO_H
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/LLVM.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/SmallString.h"
37 class CodeGenFunction;
41 /// TargetCodeGenInfo - This class organizes various target-specific
42 /// codegeneration issues, like target-specific attributes, builtins and so
44 class TargetCodeGenInfo {
47 // WARNING: Acquires the ownership of ABIInfo.
48 TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
49 virtual ~TargetCodeGenInfo();
51 /// getABIInfo() - Returns ABI info helper for the target.
52 const ABIInfo& getABIInfo() const { return *Info; }
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,
57 CodeGen::CodeGenModule &M) const { }
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;
67 virtual unsigned getSizeOfUnwindException() const;
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; }
78 /// Determines the DWARF register number for the stack pointer, for
79 /// exception-handling purposes. Implements __builtin_dwarf_sp_column.
81 /// Returns -1 if the operation is unsupported by this target.
82 virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
86 /// Initializes the given DWARF EH register-size table, a char*.
87 /// Implements __builtin_init_dwarf_reg_size_table.
89 /// Returns true if the operation is unsupported by this target.
90 virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
91 llvm::Value *Address) const {
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.
99 /// Used by __builtin_extract_return_addr().
100 virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
101 llvm::Value *Address) const {
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.
109 /// Used by __builtin_frob_return_addr().
110 virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
111 llvm::Value *Address) const {
115 /// Corrects the low-level LLVM type for a given constraint and "usual"
118 /// \returns A pointer to a new LLVM type, possibly the same as the original
119 /// on success; 0 on failure.
120 virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
121 StringRef Constraint,
122 llvm::Type* Ty) const {
126 /// Retrieve the address of a function to call immediately before
127 /// calling objc_retainAutoreleasedReturnValue. The
128 /// implementation of objc_autoreleaseReturnValue sniffs the
129 /// instruction stream following its return address to decide
130 /// whether it's a call to objc_retainAutoreleasedReturnValue.
131 /// This can be prohibitively expensive, depending on the
132 /// relocation model, and so on some targets it instead sniffs for
133 /// a particular instruction sequence. This functions returns
134 /// that instruction sequence in inline assembly, which will be
135 /// empty if none is required.
136 virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
140 /// Return a constant used by UBSan as a signature to identify functions
141 /// possessing type information, or 0 if the platform is unsupported.
142 virtual llvm::Constant *getUBSanFunctionSignature(
143 CodeGen::CodeGenModule &CGM) const {
147 /// Determine whether a call to an unprototyped functions under
148 /// the given calling convention should use the variadic
149 /// convention or the non-variadic convention.
151 /// There's a good reason to make a platform's variadic calling
152 /// convention be different from its non-variadic calling
153 /// convention: the non-variadic arguments can be passed in
154 /// registers (better for performance), and the variadic arguments
155 /// can be passed on the stack (also better for performance). If
156 /// this is done, however, unprototyped functions *must* use the
157 /// non-variadic convention, because C99 states that a call
158 /// through an unprototyped function type must succeed if the
159 /// function was defined with a non-variadic prototype with
160 /// compatible parameters. Therefore, splitting the conventions
161 /// makes it impossible to call a variadic function through an
162 /// unprototyped type. Since function prototypes came out in the
163 /// late 1970s, this is probably an acceptable trade-off.
164 /// Nonetheless, not all platforms are willing to make it, and in
165 /// particularly x86-64 bends over backwards to make the
166 /// conventions compatible.
168 /// The default is false. This is correct whenever:
169 /// - the conventions are exactly the same, because it does not
170 /// matter and the resulting IR will be somewhat prettier in
171 /// certain cases; or
172 /// - the conventions are substantively different in how they pass
173 /// arguments, because in this case using the variadic convention
174 /// will lead to C99 violations.
176 /// However, some platforms make the conventions identical except
177 /// for passing additional out-of-band information to a variadic
178 /// function: for example, x86-64 passes the number of SSE
179 /// arguments in %al. On these platforms, it is desireable to
180 /// call unprototyped functions using the variadic convention so
181 /// that unprototyped calls to varargs functions still succeed.
183 /// Relatedly, platforms which pass the fixed arguments to this:
185 /// differently than they would pass them to this:
186 /// A foo(B, C, D, ...);
187 /// may need to adjust the debugger-support code in Sema to do the
188 /// right thing when calling a function with no know signature.
189 virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args,
190 const FunctionNoProtoType *fnType) const;
192 /// Gets the linker options necessary to link a dependent library on this
194 virtual void getDependentLibraryOption(llvm::StringRef Lib,
195 llvm::SmallString<24> &Opt) const;
197 /// Gets the linker options necessary to detect object file mismatches on
199 virtual void getDetectMismatchOption(llvm::StringRef Name,
200 llvm::StringRef Value,
201 llvm::SmallString<32> &Opt) const {}
205 #endif // CLANG_CODEGEN_TARGETINFO_H