blob: eabc37b464e36341112f5409bd874534c043ac15 [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
Chris Lattner686775d2011-07-20 06:58:45 +000018#include "clang/Basic/LLVM.h"
John McCall01f151e2011-09-21 08:08:30 +000019#include "clang/AST/Type.h"
Peter Collingbourne4b93d662011-02-19 23:03:58 +000020#include "llvm/ADT/StringRef.h"
21
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000022namespace llvm {
23 class GlobalValue;
Peter Collingbourne4b93d662011-02-19 23:03:58 +000024 class Type;
John McCall492c4f92010-03-03 04:15:11 +000025 class Value;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000026}
27
28namespace clang {
29 class ABIInfo;
30 class Decl;
31
32 namespace CodeGen {
33 class CodeGenModule;
John McCall492c4f92010-03-03 04:15:11 +000034 class CodeGenFunction;
Eli Friedman3ed79032011-12-01 04:53:19 +000035 class CGFunctionInfo;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000036 }
37
38 /// TargetCodeGenInfo - This class organizes various target-specific
39 /// codegeneration issues, like target-specific attributes, builtins and so
40 /// on.
41 class TargetCodeGenInfo {
42 ABIInfo *Info;
43 public:
44 // WARNING: Acquires the ownership of ABIInfo.
Douglas Gregor568bb2d2010-01-22 15:41:14 +000045 TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000046 virtual ~TargetCodeGenInfo();
47
48 /// getABIInfo() - Returns ABI info helper for the target.
49 const ABIInfo& getABIInfo() const { return *Info; }
50
51 /// SetTargetAttributes - Provides a convenient hook to handle extra
52 /// target-specific attributes for the given global.
53 virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
Douglas Gregor568bb2d2010-01-22 15:41:14 +000054 CodeGen::CodeGenModule &M) const { }
John McCalld0b76ca2010-03-02 03:50:12 +000055
John McCall204b0752010-07-20 22:17:55 +000056 /// Determines the size of struct _Unwind_Exception on this platform,
57 /// in 8-bit units. The Itanium ABI defines this as:
58 /// struct _Unwind_Exception {
59 /// uint64 exception_class;
60 /// _Unwind_Exception_Cleanup_Fn exception_cleanup;
61 /// uint64 private_1;
62 /// uint64 private_2;
63 /// };
John McCall49e34be2011-08-30 01:42:09 +000064 virtual unsigned getSizeOfUnwindException() const;
John McCall204b0752010-07-20 22:17:55 +000065
John McCalld0b76ca2010-03-02 03:50:12 +000066 /// Controls whether __builtin_extend_pointer should sign-extend
67 /// pointers to uint64_t or zero-extend them (the default). Has
68 /// no effect for targets:
69 /// - that have 64-bit pointers, or
70 /// - that cannot address through registers larger than pointers, or
71 /// - that implicitly ignore/truncate the top bits when addressing
72 /// through such registers.
73 virtual bool extendPointerWithSExt() const { return false; }
John McCall492c4f92010-03-03 04:15:11 +000074
John McCall6374c332010-03-06 00:35:14 +000075 /// Determines the DWARF register number for the stack pointer, for
76 /// exception-handling purposes. Implements __builtin_dwarf_sp_column.
77 ///
78 /// Returns -1 if the operation is unsupported by this target.
79 virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
80 return -1;
81 }
82
83 /// Initializes the given DWARF EH register-size table, a char*.
84 /// Implements __builtin_init_dwarf_reg_size_table.
85 ///
86 /// Returns true if the operation is unsupported by this target.
87 virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
88 llvm::Value *Address) const {
89 return true;
90 }
91
John McCall492c4f92010-03-03 04:15:11 +000092 /// Performs the code-generation required to convert a return
93 /// address as stored by the system into the actual address of the
94 /// next instruction that will be executed.
95 ///
96 /// Used by __builtin_extract_return_addr().
97 virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
98 llvm::Value *Address) const {
99 return Address;
100 }
101
102 /// Performs the code-generation required to convert the address
103 /// of an instruction into a return address suitable for storage
104 /// by the system in a return slot.
105 ///
106 /// Used by __builtin_frob_return_addr().
107 virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
108 llvm::Value *Address) const {
109 return Address;
110 }
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000111
Jay Foadef6de3d2011-07-11 09:56:20 +0000112 virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
Chris Lattner686775d2011-07-20 06:58:45 +0000113 StringRef Constraint,
Jay Foadef6de3d2011-07-11 09:56:20 +0000114 llvm::Type* Ty) const {
Peter Collingbourne4b93d662011-02-19 23:03:58 +0000115 return Ty;
116 }
John McCallf85e1932011-06-15 23:02:42 +0000117
118 /// Retrieve the address of a function to call immediately before
119 /// calling objc_retainAutoreleasedReturnValue. The
120 /// implementation of objc_autoreleaseReturnValue sniffs the
121 /// instruction stream following its return address to decide
122 /// whether it's a call to objc_retainAutoreleasedReturnValue.
123 /// This can be prohibitively expensive, depending on the
124 /// relocation model, and so on some targets it instead sniffs for
125 /// a particular instruction sequence. This functions returns
126 /// that instruction sequence in inline assembly, which will be
127 /// empty if none is required.
Chris Lattner686775d2011-07-20 06:58:45 +0000128 virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
John McCallf85e1932011-06-15 23:02:42 +0000129 return "";
130 }
John McCall01f151e2011-09-21 08:08:30 +0000131
132 /// Determine whether a call to an unprototyped functions under
133 /// the given calling convention should use the variadic
134 /// convention or the non-variadic convention.
135 ///
136 /// There's a good reason to make a platform's variadic calling
137 /// convention be different from its non-variadic calling
138 /// convention: the non-variadic arguments can be passed in
139 /// registers (better for performance), and the variadic arguments
140 /// can be passed on the stack (also better for performance). If
141 /// this is done, however, unprototyped functions *must* use the
142 /// non-variadic convention, because C99 states that a call
143 /// through an unprototyped function type must succeed if the
144 /// function was defined with a non-variadic prototype with
145 /// compatible parameters. Therefore, splitting the conventions
146 /// makes it impossible to call a variadic function through an
147 /// unprototyped type. Since function prototypes came out in the
148 /// late 1970s, this is probably an acceptable trade-off.
149 /// Nonetheless, not all platforms are willing to make it, and in
150 /// particularly x86-64 bends over backwards to make the
151 /// conventions compatible.
152 ///
153 /// The default is false. This is correct whenever:
154 /// - the conventions are exactly the same, because it does not
155 /// matter and the resulting IR will be somewhat prettier in
156 /// certain cases; or
157 /// - the conventions are substantively different in how they pass
158 /// arguments, because in this case using the variadic convention
159 /// will lead to C99 violations.
160 /// It is not necessarily correct when arguments are passed in the
161 /// same way and some out-of-band information is passed for the
162 /// benefit of variadic callees, as is the case for x86-64.
163 /// In this case the ABI should be consulted.
Eli Friedman3ed79032011-12-01 04:53:19 +0000164 virtual bool isNoProtoCallVariadic(const CodeGen::CGFunctionInfo &) const;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000165 };
166}
167
168#endif // CLANG_CODEGEN_TARGETINFO_H