]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/llvm/tools/clang/lib/CodeGen/TargetInfo.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / llvm / tools / clang / lib / CodeGen / TargetInfo.h
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
15 #ifndef CLANG_CODEGEN_TARGETINFO_H
16 #define CLANG_CODEGEN_TARGETINFO_H
17
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/LLVM.h"
20 #include "llvm/ADT/StringRef.h"
21
22 namespace llvm {
23   class GlobalValue;
24   class Type;
25   class Value;
26 }
27
28 namespace clang {
29   class ABIInfo;
30   class Decl;
31
32   namespace CodeGen {
33     class CallArgList;
34     class CodeGenModule;
35     class CodeGenFunction;
36     class CGFunctionInfo;
37   }
38
39   /// TargetCodeGenInfo - This class organizes various target-specific
40   /// codegeneration issues, like target-specific attributes, builtins and so
41   /// on.
42   class TargetCodeGenInfo {
43     ABIInfo *Info;
44   public:
45     // WARNING: Acquires the ownership of ABIInfo.
46     TargetCodeGenInfo(ABIInfo *info = 0):Info(info) { }
47     virtual ~TargetCodeGenInfo();
48
49     /// getABIInfo() - Returns ABI info helper for the target.
50     const ABIInfo& getABIInfo() const { return *Info; }
51
52     /// SetTargetAttributes - Provides a convenient hook to handle extra
53     /// target-specific attributes for the given global.
54     virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
55                                      CodeGen::CodeGenModule &M) const { }
56
57     /// Determines the size of struct _Unwind_Exception on this platform,
58     /// in 8-bit units.  The Itanium ABI defines this as:
59     ///   struct _Unwind_Exception {
60     ///     uint64 exception_class;
61     ///     _Unwind_Exception_Cleanup_Fn exception_cleanup;
62     ///     uint64 private_1;
63     ///     uint64 private_2;
64     ///   };
65     virtual unsigned getSizeOfUnwindException() const;
66
67     /// Controls whether __builtin_extend_pointer should sign-extend
68     /// pointers to uint64_t or zero-extend them (the default).  Has
69     /// no effect for targets:
70     ///   - that have 64-bit pointers, or
71     ///   - that cannot address through registers larger than pointers, or
72     ///   - that implicitly ignore/truncate the top bits when addressing
73     ///     through such registers.
74     virtual bool extendPointerWithSExt() const { return false; }
75
76     /// Determines the DWARF register number for the stack pointer, for
77     /// exception-handling purposes.  Implements __builtin_dwarf_sp_column.
78     ///
79     /// Returns -1 if the operation is unsupported by this target.
80     virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
81       return -1;
82     }
83
84     /// Initializes the given DWARF EH register-size table, a char*.
85     /// Implements __builtin_init_dwarf_reg_size_table.
86     ///
87     /// Returns true if the operation is unsupported by this target.
88     virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
89                                          llvm::Value *Address) const {
90       return true;
91     }
92
93     /// Performs the code-generation required to convert a return
94     /// address as stored by the system into the actual address of the
95     /// next instruction that will be executed.
96     ///
97     /// Used by __builtin_extract_return_addr().
98     virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
99                                              llvm::Value *Address) const {
100       return Address;
101     }
102
103     /// Performs the code-generation required to convert the address
104     /// of an instruction into a return address suitable for storage
105     /// by the system in a return slot.
106     ///
107     /// Used by __builtin_frob_return_addr().
108     virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
109                                              llvm::Value *Address) const {
110       return Address;
111     }
112
113     virtual llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
114                                             StringRef Constraint, 
115                                             llvm::Type* Ty) const {
116       return Ty;
117     }
118
119     /// Retrieve the address of a function to call immediately before
120     /// calling objc_retainAutoreleasedReturnValue.  The
121     /// implementation of objc_autoreleaseReturnValue sniffs the
122     /// instruction stream following its return address to decide
123     /// whether it's a call to objc_retainAutoreleasedReturnValue.
124     /// This can be prohibitively expensive, depending on the
125     /// relocation model, and so on some targets it instead sniffs for
126     /// a particular instruction sequence.  This functions returns
127     /// that instruction sequence in inline assembly, which will be
128     /// empty if none is required.
129     virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
130       return "";
131     }
132
133     /// Determine whether a call to an unprototyped functions under
134     /// the given calling convention should use the variadic
135     /// convention or the non-variadic convention.
136     ///
137     /// There's a good reason to make a platform's variadic calling
138     /// convention be different from its non-variadic calling
139     /// convention: the non-variadic arguments can be passed in
140     /// registers (better for performance), and the variadic arguments
141     /// can be passed on the stack (also better for performance).  If
142     /// this is done, however, unprototyped functions *must* use the
143     /// non-variadic convention, because C99 states that a call
144     /// through an unprototyped function type must succeed if the
145     /// function was defined with a non-variadic prototype with
146     /// compatible parameters.  Therefore, splitting the conventions
147     /// makes it impossible to call a variadic function through an
148     /// unprototyped type.  Since function prototypes came out in the
149     /// late 1970s, this is probably an acceptable trade-off.
150     /// Nonetheless, not all platforms are willing to make it, and in
151     /// particularly x86-64 bends over backwards to make the
152     /// conventions compatible.
153     ///
154     /// The default is false.  This is correct whenever:
155     ///   - the conventions are exactly the same, because it does not
156     ///     matter and the resulting IR will be somewhat prettier in
157     ///     certain cases; or
158     ///   - the conventions are substantively different in how they pass
159     ///     arguments, because in this case using the variadic convention
160     ///     will lead to C99 violations.
161     ///
162     /// However, some platforms make the conventions identical except
163     /// for passing additional out-of-band information to a variadic
164     /// function: for example, x86-64 passes the number of SSE
165     /// arguments in %al.  On these platforms, it is desireable to
166     /// call unprototyped functions using the variadic convention so
167     /// that unprototyped calls to varargs functions still succeed.
168     virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args,
169                                        const FunctionNoProtoType *fnType) const;
170   };
171 }
172
173 #endif // CLANG_CODEGEN_TARGETINFO_H