11#ifndef LLVM_ABI_TYPES_H
22#define LLVM_ABI_TYPES_H
33
4+ #include " llvm/ADT/APFloat.h"
45#include " llvm/ADT/ArrayRef.h"
6+ #include " llvm/Support/Alignment.h"
57#include " llvm/Support/Allocator.h"
8+ #include " llvm/Support/TypeSize.h"
69#include < cstdint>
10+ #include < llvm/IR/CallingConv.h>
711
812namespace llvm {
913namespace abi {
@@ -17,27 +21,26 @@ enum class TypeKind {
1721 Vector,
1822 Struct,
1923 Union,
20- Function
2124};
2225
2326class Type {
2427protected:
2528 TypeKind Kind;
26- uint64_t SizeInBits;
27- uint64_t AlignInBits;
29+ TypeSize SizeInBits;
30+ Align AlignInBits;
2831 bool IsExplicitlyAligned;
2932
30- Type (TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false )
33+ Type (TypeKind K, TypeSize Size, Align Align, bool ExplicitAlign = false )
3134 : Kind(K), SizeInBits(Size), AlignInBits(Align),
3235 IsExplicitlyAligned (ExplicitAlign) {}
3336
3437public:
3538 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; }
3841 bool hasExplicitAlignment () const { return IsExplicitlyAligned; }
3942
40- void setExplicitAlignment (uint64_t Align) {
43+ void setExplicitAlignment (Align Align) {
4144 AlignInBits = Align;
4245 IsExplicitlyAligned = true ;
4346 }
@@ -50,12 +53,11 @@ class Type {
5053 bool isVector () const { return Kind == TypeKind::Vector; }
5154 bool isStruct () const { return Kind == TypeKind::Struct; }
5255 bool isUnion () const { return Kind == TypeKind::Union; }
53- bool isFunction () const { return Kind == TypeKind::Function; }
5456};
5557
5658class VoidType : public Type {
5759public:
58- VoidType () : Type(TypeKind::Void, 0 , 0 ) {}
60+ VoidType () : Type(TypeKind::Void, TypeSize::getFixed( 0 ), Align( 1 ) ) {}
5961
6062 static bool classof (const Type *T) { return T->getKind () == TypeKind::Void; }
6163};
@@ -65,8 +67,9 @@ class IntegerType : public Type {
6567 bool IsSigned;
6668
6769public:
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),
72+ IsSigned (Signed) {}
7073
7174 bool isSigned () const { return IsSigned; }
7275
@@ -76,17 +79,22 @@ class IntegerType : public Type {
7679};
7780
7881class FloatType : public Type {
82+ private:
83+ const fltSemantics *Semantics;
84+
7985public:
80- FloatType (uint64_t BitWidth, uint64_t Align)
81- : Type(TypeKind::Float, BitWidth, Align) {}
86+ FloatType (const fltSemantics &FloatSemantics, Align Align)
87+ : Type(TypeKind::Float,
88+ TypeSize::getFixed (APFloat::getSizeInBits(FloatSemantics)), Align),
89+ Semantics(&FloatSemantics) {}
8290
8391 static bool classof (const Type *T) { return T->getKind () == TypeKind::Float; }
8492};
8593
8694class PointerType : public Type {
8795public:
88- PointerType (uint64_t Size, uint64_t Align)
89- : Type(TypeKind::Pointer, Size, Align) {}
96+ PointerType (uint64_t Size, Align Align)
97+ : Type(TypeKind::Pointer, TypeSize::getFixed( Size) , Align) {}
9098
9199 static bool classof (const Type *T) {
92100 return T->getKind () == TypeKind::Pointer;
@@ -116,7 +124,7 @@ class VectorType : public Type {
116124 uint64_t NumElements;
117125
118126public:
119- VectorType (const Type *ElemType, uint64_t NumElems, uint64_t Align)
127+ VectorType (const Type *ElemType, uint64_t NumElems, Align Align)
120128 : Type(TypeKind::Vector, ElemType->getSizeInBits () * NumElems, Align),
121129 ElementType(ElemType), NumElements(NumElems) {}
122130
@@ -149,8 +157,8 @@ class StructType : public Type {
149157 StructPacking Packing;
150158
151159public:
152- StructType (const FieldInfo *StructFields, uint32_t FieldCount, uint64_t Size,
153- uint64_t Align, StructPacking Pack = StructPacking::Default)
160+ StructType (const FieldInfo *StructFields, uint32_t FieldCount, TypeSize Size,
161+ Align Align, StructPacking Pack = StructPacking::Default)
154162 : Type(TypeKind::Struct, Size, Align), Fields(StructFields),
155163 NumFields (FieldCount), Packing(Pack) {}
156164
@@ -170,8 +178,8 @@ class UnionType : public Type {
170178 StructPacking Packing;
171179
172180public:
173- UnionType (const FieldInfo *UnionFields, uint32_t FieldCount, uint64_t Size,
174- uint64_t Align, StructPacking Pack = StructPacking::Default)
181+ UnionType (const FieldInfo *UnionFields, uint32_t FieldCount, TypeSize Size,
182+ Align Align, StructPacking Pack = StructPacking::Default)
175183 : Type(TypeKind::Union, Size, Align), Fields(UnionFields),
176184 NumFields (FieldCount), Packing(Pack) {}
177185
@@ -182,41 +190,6 @@ class UnionType : public Type {
182190 static bool classof (const Type *T) { return T->getKind () == TypeKind::Union; }
183191};
184192
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-
215- static bool classof (const Type *T) {
216- return T->getKind () == TypeKind::Function;
217- }
218- };
219-
220193// API for creating ABI Types
221194class TypeBuilder {
222195private:
@@ -229,17 +202,17 @@ class TypeBuilder {
229202 return new (Allocator.Allocate <VoidType>()) VoidType ();
230203 }
231204
232- const IntegerType *getIntegerType (uint64_t BitWidth, uint64_t Align,
205+ const IntegerType *getIntegerType (uint64_t BitWidth, Align Align,
233206 bool Signed) {
234207 return new (Allocator.Allocate <IntegerType>())
235208 IntegerType (BitWidth, Align, Signed);
236209 }
237210
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);
240213 }
241214
242- const PointerType *getPointerType (uint64_t Size, uint64_t Align) {
215+ const PointerType *getPointerType (uint64_t Size, Align Align) {
243216 return new (Allocator.Allocate <PointerType>()) PointerType (Size, Align);
244217 }
245218
@@ -249,13 +222,13 @@ class TypeBuilder {
249222 }
250223
251224 const VectorType *getVectorType (const Type *ElementType, uint64_t NumElements,
252- uint64_t Align) {
225+ Align Align) {
253226 return new (Allocator.Allocate <VectorType>())
254227 VectorType (ElementType, NumElements, Align);
255228 }
256229
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,
259232 StructPacking Pack = StructPacking::Default) {
260233 FieldInfo *FieldArray = Allocator.Allocate <FieldInfo>(Fields.size ());
261234
@@ -267,8 +240,8 @@ class TypeBuilder {
267240 FieldArray, static_cast <uint32_t >(Fields.size ()), Size, Align, Pack);
268241 }
269242
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,
272245 StructPacking Pack = StructPacking::Default) {
273246 FieldInfo *FieldArray = Allocator.Allocate <FieldInfo>(Fields.size ());
274247
@@ -279,22 +252,6 @@ class TypeBuilder {
279252 return new (Allocator.Allocate <UnionType>()) UnionType (
280253 FieldArray, static_cast <uint32_t >(Fields.size ()), Size, Align, Pack);
281254 }
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- }
298255};
299256
300257} // namespace abi
0 commit comments