1
1
#ifndef LLVM_ABI_TYPES_H
2
2
#define LLVM_ABI_TYPES_H
3
3
4
+ #include " llvm/ADT/APFloat.h"
4
5
#include " llvm/ADT/ArrayRef.h"
6
+ #include < llvm/IR/CallingConv.h>
7
+ #include " llvm/Support/Alignment.h"
5
8
#include " llvm/Support/Allocator.h"
9
+ #include " llvm/Support/TypeSize.h"
6
10
#include < cstdint>
7
11
8
12
namespace llvm {
@@ -17,27 +21,26 @@ enum class TypeKind {
17
21
Vector,
18
22
Struct,
19
23
Union,
20
- Function
21
24
};
22
25
23
26
class Type {
24
27
protected:
25
28
TypeKind Kind;
26
- uint64_t SizeInBits;
27
- uint64_t AlignInBits;
29
+ TypeSize SizeInBits;
30
+ Align AlignInBits;
28
31
bool IsExplicitlyAligned;
29
32
30
- Type (TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false )
33
+ Type (TypeKind K, TypeSize Size, Align Align, bool ExplicitAlign = false )
31
34
: Kind(K), SizeInBits(Size), AlignInBits(Align),
32
35
IsExplicitlyAligned (ExplicitAlign) {}
33
36
34
37
public:
35
38
TypeKind getKind () const { return Kind; }
36
- uint64_t getSizeInBits () const { return SizeInBits; }
37
- uint64_t getAlignInBits () const { return AlignInBits; }
39
+ TypeSize getSizeInBits () const { return SizeInBits; }
40
+ Align getAlignInBits () const { return AlignInBits; }
38
41
bool hasExplicitAlignment () const { return IsExplicitlyAligned; }
39
42
40
- void setExplicitAlignment (uint64_t Align) {
43
+ void setExplicitAlignment (Align Align) {
41
44
AlignInBits = Align;
42
45
IsExplicitlyAligned = true ;
43
46
}
@@ -50,12 +53,11 @@ class Type {
50
53
bool isVector () const { return Kind == TypeKind::Vector; }
51
54
bool isStruct () const { return Kind == TypeKind::Struct; }
52
55
bool isUnion () const { return Kind == TypeKind::Union; }
53
- bool isFunction () const { return Kind == TypeKind::Function; }
54
56
};
55
57
56
58
class VoidType : public Type {
57
59
public:
58
- VoidType () : Type(TypeKind::Void, 0 , 0 ) {}
60
+ VoidType () : Type(TypeKind::Void, TypeSize::getFixed( 0 ), Align( 1 ) ) {}
59
61
60
62
static bool classof (const Type *T) { return T->getKind () == TypeKind::Void; }
61
63
};
@@ -65,8 +67,8 @@ class IntegerType : public Type {
65
67
bool IsSigned;
66
68
67
69
public:
68
- IntegerType (uint64_t BitWidth, uint64_t Align, bool Signed)
69
- : Type(TypeKind::Integer, BitWidth, Align), IsSigned(Signed) {}
70
+ IntegerType (uint64_t BitWidth, Align Align, bool Signed)
71
+ : Type(TypeKind::Integer, TypeSize::getFixed( BitWidth) , Align), IsSigned(Signed) {}
70
72
71
73
bool isSigned () const { return IsSigned; }
72
74
@@ -76,17 +78,21 @@ class IntegerType : public Type {
76
78
};
77
79
78
80
class FloatType : public Type {
81
+ private:
82
+ const fltSemantics *Semantics;
83
+
79
84
public:
80
- FloatType (uint64_t BitWidth, uint64_t Align)
81
- : Type(TypeKind::Float, BitWidth, Align) {}
85
+ FloatType (const fltSemantics &FloatSemantics, Align Align)
86
+ : Type(TypeKind::Float, TypeSize::getFixed(APFloat::getSizeInBits(FloatSemantics)), Align)
87
+ , Semantics(&FloatSemantics){}
82
88
83
89
static bool classof (const Type *T) { return T->getKind () == TypeKind::Float; }
84
90
};
85
91
86
92
class PointerType : public Type {
87
93
public:
88
- PointerType (uint64_t Size, uint64_t Align)
89
- : Type(TypeKind::Pointer, Size, Align) {}
94
+ PointerType (uint64_t Size, Align Align)
95
+ : Type(TypeKind::Pointer, TypeSize::getFixed( Size) , Align) {}
90
96
91
97
static bool classof (const Type *T) {
92
98
return T->getKind () == TypeKind::Pointer;
@@ -116,7 +122,7 @@ class VectorType : public Type {
116
122
uint64_t NumElements;
117
123
118
124
public:
119
- VectorType (const Type *ElemType, uint64_t NumElems, uint64_t Align)
125
+ VectorType (const Type *ElemType, uint64_t NumElems, Align Align)
120
126
: Type(TypeKind::Vector, ElemType->getSizeInBits () * NumElems, Align),
121
127
ElementType(ElemType), NumElements(NumElems) {}
122
128
@@ -149,8 +155,8 @@ class StructType : public Type {
149
155
StructPacking Packing;
150
156
151
157
public:
152
- StructType (const FieldInfo *StructFields, uint32_t FieldCount, uint64_t Size,
153
- uint64_t Align, StructPacking Pack = StructPacking::Default)
158
+ StructType (const FieldInfo *StructFields, uint32_t FieldCount, TypeSize Size,
159
+ Align Align, StructPacking Pack = StructPacking::Default)
154
160
: Type(TypeKind::Struct, Size, Align), Fields(StructFields),
155
161
NumFields (FieldCount), Packing(Pack) {}
156
162
@@ -170,8 +176,8 @@ class UnionType : public Type {
170
176
StructPacking Packing;
171
177
172
178
public:
173
- UnionType (const FieldInfo *UnionFields, uint32_t FieldCount, uint64_t Size,
174
- uint64_t Align, StructPacking Pack = StructPacking::Default)
179
+ UnionType (const FieldInfo *UnionFields, uint32_t FieldCount, TypeSize Size,
180
+ Align Align, StructPacking Pack = StructPacking::Default)
175
181
: Type(TypeKind::Union, Size, Align), Fields(UnionFields),
176
182
NumFields (FieldCount), Packing(Pack) {}
177
183
@@ -182,40 +188,7 @@ class UnionType : public Type {
182
188
static bool classof (const Type *T) { return T->getKind () == TypeKind::Union; }
183
189
};
184
190
185
- enum class CallConv {
186
- C,
187
- // TODO: extend for more CallConvs
188
- };
189
-
190
- class FunctionType : public Type {
191
- private:
192
- const Type *ReturnType;
193
- const Type *const *ParameterTypes;
194
- uint32_t NumParams;
195
- bool IsVarArg;
196
- CallConv CC;
197
-
198
- public:
199
- FunctionType (const Type *RetType, const Type *const *ParamTypes,
200
- uint32_t ParamCount, bool VarArgs, CallConv CallConv)
201
- : Type(TypeKind::Function, 0 , 0 ), ReturnType(RetType),
202
- ParameterTypes (ParamTypes), NumParams(ParamCount), IsVarArg(VarArgs),
203
- CC(CallConv) {}
204
-
205
- const Type *getReturnType () const { return ReturnType; }
206
- const Type *const *getParameterTypes () const { return ParameterTypes; }
207
- uint32_t getNumParameters () const { return NumParams; }
208
- const Type *getParameterType (uint32_t Index) const {
209
- assert (Index < NumParams && " Parameter index out of bounds" );
210
- return ParameterTypes[Index];
211
- }
212
- bool isVarArg () const { return IsVarArg; }
213
- CallConv getCallingConv () const { return CC; }
214
191
215
- static bool classof (const Type *T) {
216
- return T->getKind () == TypeKind::Function;
217
- }
218
- };
219
192
220
193
// API for creating ABI Types
221
194
class TypeBuilder {
@@ -229,17 +202,17 @@ class TypeBuilder {
229
202
return new (Allocator.Allocate <VoidType>()) VoidType ();
230
203
}
231
204
232
- const IntegerType *getIntegerType (uint64_t BitWidth, uint64_t Align,
205
+ const IntegerType *getIntegerType (uint64_t BitWidth, Align Align,
233
206
bool Signed) {
234
207
return new (Allocator.Allocate <IntegerType>())
235
208
IntegerType (BitWidth, Align, Signed);
236
209
}
237
210
238
- const FloatType *getFloatType (uint64_t BitWidth, uint64_t Align) {
239
- return new (Allocator.Allocate <FloatType>()) FloatType (BitWidth , Align);
211
+ const FloatType *getFloatType (const fltSemantics &Semantics, Align Align) {
212
+ return new (Allocator.Allocate <FloatType>()) FloatType (Semantics , Align);
240
213
}
241
214
242
- const PointerType *getPointerType (uint64_t Size, uint64_t Align) {
215
+ const PointerType *getPointerType (uint64_t Size, Align Align) {
243
216
return new (Allocator.Allocate <PointerType>()) PointerType (Size, Align);
244
217
}
245
218
@@ -249,13 +222,13 @@ class TypeBuilder {
249
222
}
250
223
251
224
const VectorType *getVectorType (const Type *ElementType, uint64_t NumElements,
252
- uint64_t Align) {
225
+ Align Align) {
253
226
return new (Allocator.Allocate <VectorType>())
254
227
VectorType (ElementType, NumElements, Align);
255
228
}
256
229
257
- const StructType *getStructType (ArrayRef<FieldInfo> Fields, uint64_t Size,
258
- uint64_t Align,
230
+ const StructType *getStructType (ArrayRef<FieldInfo> Fields, TypeSize Size,
231
+ Align Align,
259
232
StructPacking Pack = StructPacking::Default) {
260
233
FieldInfo *FieldArray = Allocator.Allocate <FieldInfo>(Fields.size ());
261
234
@@ -267,8 +240,8 @@ class TypeBuilder {
267
240
FieldArray, static_cast <uint32_t >(Fields.size ()), Size, Align, Pack);
268
241
}
269
242
270
- const UnionType *getUnionType (ArrayRef<FieldInfo> Fields, uint64_t Size,
271
- uint64_t Align,
243
+ const UnionType *getUnionType (ArrayRef<FieldInfo> Fields, TypeSize Size,
244
+ Align Align,
272
245
StructPacking Pack = StructPacking::Default) {
273
246
FieldInfo *FieldArray = Allocator.Allocate <FieldInfo>(Fields.size ());
274
247
@@ -279,22 +252,6 @@ class TypeBuilder {
279
252
return new (Allocator.Allocate <UnionType>()) UnionType (
280
253
FieldArray, static_cast <uint32_t >(Fields.size ()), Size, Align, Pack);
281
254
}
282
-
283
- const FunctionType *getFunctionType (const Type *ReturnType,
284
- ArrayRef<const Type *> ParamTypes,
285
- bool IsVarArg,
286
- CallConv CC = CallConv::C) {
287
- const Type **ParamArray =
288
- Allocator.Allocate <const Type *>(ParamTypes.size ());
289
-
290
- for (size_t I = 0 ; I < ParamTypes.size (); ++I) {
291
- ParamArray[I] = ParamTypes[I];
292
- }
293
-
294
- return new (Allocator.Allocate <FunctionType>())
295
- FunctionType (ReturnType, ParamArray,
296
- static_cast <uint32_t >(ParamTypes.size ()), IsVarArg, CC);
297
- }
298
255
};
299
256
300
257
} // namespace abi
0 commit comments