[llvm] [WIP] ABI Lowering Library (PR #140112)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri May 23 11:59:44 PDT 2025
================
@@ -0,0 +1,303 @@
+#ifndef LLVM_ABI_TYPES_H
+#define LLVM_ABI_TYPES_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
+#include <cstdint>
+
+namespace llvm {
+namespace abi {
+
+enum class TypeKind {
+ Void,
+ Integer,
+ Float,
+ Pointer,
+ Array,
+ Vector,
+ Struct,
+ Union,
+ Function
+};
+
+class Type {
+protected:
+ TypeKind Kind;
+ uint64_t SizeInBits;
+ uint64_t AlignInBits;
+ bool IsExplicitlyAligned;
+
+ Type(TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false)
+ : Kind(K), SizeInBits(Size), AlignInBits(Align),
+ IsExplicitlyAligned(ExplicitAlign) {}
+
+public:
+ TypeKind getKind() const { return Kind; }
+ uint64_t getSizeInBits() const { return SizeInBits; }
+ uint64_t getAlignInBits() const { return AlignInBits; }
+ bool hasExplicitAlignment() const { return IsExplicitlyAligned; }
+
+ void setExplicitAlignment(uint64_t Align) {
+ AlignInBits = Align;
+ IsExplicitlyAligned = true;
+ }
+
+ bool isVoid() const { return Kind == TypeKind::Void; }
+ bool isInteger() const { return Kind == TypeKind::Integer; }
+ bool isFloat() const { return Kind == TypeKind::Float; }
+ bool isPointer() const { return Kind == TypeKind::Pointer; }
+ bool isArray() const { return Kind == TypeKind::Array; }
+ bool isVector() const { return Kind == TypeKind::Vector; }
+ bool isStruct() const { return Kind == TypeKind::Struct; }
+ bool isUnion() const { return Kind == TypeKind::Union; }
+ bool isFunction() const { return Kind == TypeKind::Function; }
+};
+
+class VoidType : public Type {
+public:
+ VoidType() : Type(TypeKind::Void, 0, 0) {}
+
+ static bool classof(const Type *T) { return T->getKind() == TypeKind::Void; }
+};
+
+class IntegerType : public Type {
+private:
+ bool IsSigned;
+
+public:
+ IntegerType(uint64_t BitWidth, uint64_t Align, bool Signed)
+ : Type(TypeKind::Integer, BitWidth, Align), IsSigned(Signed) {}
+
+ bool isSigned() const { return IsSigned; }
+
+ static bool classof(const Type *T) {
+ return T->getKind() == TypeKind::Integer;
+ }
+};
+
+class FloatType : public Type {
+public:
+ FloatType(uint64_t BitWidth, uint64_t Align)
+ : Type(TypeKind::Float, BitWidth, Align) {}
+
+ static bool classof(const Type *T) { return T->getKind() == TypeKind::Float; }
+};
+
+class PointerType : public Type {
+public:
+ PointerType(uint64_t Size, uint64_t Align)
+ : Type(TypeKind::Pointer, Size, Align) {}
+
+ static bool classof(const Type *T) {
+ return T->getKind() == TypeKind::Pointer;
+ }
+};
+
+class ArrayType : public Type {
+private:
+ const Type *ElementType;
+ uint64_t NumElements;
+
+public:
+ ArrayType(const Type *ElemType, uint64_t NumElems)
+ : Type(TypeKind::Array, ElemType->getSizeInBits() * NumElems,
+ ElemType->getAlignInBits()),
+ ElementType(ElemType), NumElements(NumElems) {}
+
+ const Type *getElementType() const { return ElementType; }
+ uint64_t getNumElements() const { return NumElements; }
+
+ static bool classof(const Type *T) { return T->getKind() == TypeKind::Array; }
+};
+
+class VectorType : public Type {
+private:
+ const Type *ElementType;
+ uint64_t NumElements;
----------------
nikic wrote:
Should probably be ElementCount for scalable vector support.
https://github.com/llvm/llvm-project/pull/140112
More information about the llvm-commits
mailing list