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