]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/lib/CodeGen/ABIInfo.h
MFC r244628:
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / lib / CodeGen / ABIInfo.h
1 //===----- ABIInfo.h - ABI information access & encapsulation ---*- 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 #ifndef CLANG_CODEGEN_ABIINFO_H
11 #define CLANG_CODEGEN_ABIINFO_H
12
13 #include "clang/AST/Type.h"
14 #include "llvm/Type.h"
15
16 namespace llvm {
17   class Value;
18   class LLVMContext;
19   class DataLayout;
20 }
21
22 namespace clang {
23   class ASTContext;
24
25   namespace CodeGen {
26     class CGFunctionInfo;
27     class CodeGenFunction;
28     class CodeGenTypes;
29   }
30
31   // FIXME: All of this stuff should be part of the target interface
32   // somehow. It is currently here because it is not clear how to factor
33   // the targets to support this, since the Targets currently live in a
34   // layer below types n'stuff.
35
36   /// ABIArgInfo - Helper class to encapsulate information about how a
37   /// specific C type should be passed to or returned from a function.
38   class ABIArgInfo {
39   public:
40     enum Kind {
41       /// Direct - Pass the argument directly using the normal converted LLVM
42       /// type, or by coercing to another specified type stored in
43       /// 'CoerceToType').  If an offset is specified (in UIntData), then the
44       /// argument passed is offset by some number of bytes in the memory
45       /// representation. A dummy argument is emitted before the real argument
46       /// if the specified type stored in "PaddingType" is not zero.
47       Direct,
48
49       /// Extend - Valid only for integer argument types. Same as 'direct'
50       /// but also emit a zero/sign extension attribute.
51       Extend,
52
53       /// Indirect - Pass the argument indirectly via a hidden pointer
54       /// with the specified alignment (0 indicates default alignment).
55       Indirect,
56
57       /// Ignore - Ignore the argument (treat as void). Useful for void and
58       /// empty structs.
59       Ignore,
60
61       /// Expand - Only valid for aggregate argument types. The structure should
62       /// be expanded into consecutive arguments for its constituent fields.
63       /// Currently expand is only allowed on structures whose fields
64       /// are all scalar types or are themselves expandable types.
65       Expand,
66
67       KindFirst=Direct, KindLast=Expand
68     };
69
70   private:
71     Kind TheKind;
72     llvm::Type *TypeData;
73     llvm::Type *PaddingType;
74     unsigned UIntData;
75     bool BoolData0;
76     bool BoolData1;
77     bool InReg;
78     bool PaddingInReg;
79
80     ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR,
81                bool PIR, llvm::Type* P)
82       : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
83         BoolData1(B1), InReg(IR), PaddingInReg(PIR) {}
84
85   public:
86     ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
87
88     static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
89                                 llvm::Type *Padding = 0) {
90       return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding);
91     }
92     static ABIArgInfo getDirectInReg(llvm::Type *T = 0) {
93       return ABIArgInfo(Direct, T, 0, false, false, true, false, 0);
94     }
95     static ABIArgInfo getExtend(llvm::Type *T = 0) {
96       return ABIArgInfo(Extend, T, 0, false, false, false, false, 0);
97     }
98     static ABIArgInfo getExtendInReg(llvm::Type *T = 0) {
99       return ABIArgInfo(Extend, T, 0, false, false, true, false, 0);
100     }
101     static ABIArgInfo getIgnore() {
102       return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0);
103     }
104     static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
105                                   , bool Realign = false) {
106       return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false, 0);
107     }
108     static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true
109                                   , bool Realign = false) {
110       return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0);
111     }
112     static ABIArgInfo getExpand() {
113       return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0);
114     }
115     static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
116                                            llvm::Type *Padding) {
117      return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg,
118                        Padding);
119     }
120
121     Kind getKind() const { return TheKind; }
122     bool isDirect() const { return TheKind == Direct; }
123     bool isExtend() const { return TheKind == Extend; }
124     bool isIgnore() const { return TheKind == Ignore; }
125     bool isIndirect() const { return TheKind == Indirect; }
126     bool isExpand() const { return TheKind == Expand; }
127
128     bool canHaveCoerceToType() const {
129       return TheKind == Direct || TheKind == Extend;
130     }
131
132     // Direct/Extend accessors
133     unsigned getDirectOffset() const {
134       assert((isDirect() || isExtend()) && "Not a direct or extend kind");
135       return UIntData;
136     }
137
138     llvm::Type *getPaddingType() const {
139       return PaddingType;
140     }
141
142     bool getPaddingInReg() const {
143       return PaddingInReg;
144     }
145
146     llvm::Type *getCoerceToType() const {
147       assert(canHaveCoerceToType() && "Invalid kind!");
148       return TypeData;
149     }
150
151     void setCoerceToType(llvm::Type *T) {
152       assert(canHaveCoerceToType() && "Invalid kind!");
153       TypeData = T;
154     }
155
156     bool getInReg() const {
157       assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
158       return InReg;
159     }
160
161     // Indirect accessors
162     unsigned getIndirectAlign() const {
163       assert(TheKind == Indirect && "Invalid kind!");
164       return UIntData;
165     }
166
167     bool getIndirectByVal() const {
168       assert(TheKind == Indirect && "Invalid kind!");
169       return BoolData0;
170     }
171
172     bool getIndirectRealign() const {
173       assert(TheKind == Indirect && "Invalid kind!");
174       return BoolData1;
175     }
176
177     void dump() const;
178   };
179
180   /// ABIInfo - Target specific hooks for defining how a type should be
181   /// passed or returned from functions.
182   class ABIInfo {
183   public:
184     CodeGen::CodeGenTypes &CGT;
185
186     ABIInfo(CodeGen::CodeGenTypes &cgt) : CGT(cgt) {}
187     virtual ~ABIInfo();
188
189     ASTContext &getContext() const;
190     llvm::LLVMContext &getVMContext() const;
191     const llvm::DataLayout &getDataLayout() const;
192
193     virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
194
195     /// EmitVAArg - Emit the target dependent code to load a value of
196     /// \arg Ty from the va_list pointed to by \arg VAListAddr.
197
198     // FIXME: This is a gaping layering violation if we wanted to drop
199     // the ABI information any lower than CodeGen. Of course, for
200     // VAArg handling it has to be at this level; there is no way to
201     // abstract this out.
202     virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
203                                    CodeGen::CodeGenFunction &CGF) const = 0;
204   };
205 }  // end namespace clang
206
207 #endif