[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 17 14:21:38 PDT 2025
================
@@ -0,0 +1,538 @@
+//===- ABI/Types.h ----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file defines the Types and related helper methods concerned to the
+/// LLVMABI library which mirrors ABI related type information from
+/// the LLVM frontend.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_ABI_TYPES_H
+#define LLVM_ABI_TYPES_H
+
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/IR/CallingConv.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/Support/Alignment.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/TypeSize.h"
+#include <algorithm>
+#include <cstdint>
+
+namespace llvm {
+namespace abi {
+
+enum class TypeKind {
+ Void,
+ MemberPointer,
+ Complex,
+ Integer,
+ Float,
+ Pointer,
+ Array,
+ Vector,
+ Struct,
+};
+
+class Type {
+private:
+ TypeSize getTypeStoreSize() const {
+ TypeSize StoreSizeInBits = getTypeStoreSizeInBits();
+ return {StoreSizeInBits.getKnownMinValue() / 8,
+ StoreSizeInBits.isScalable()};
+ }
+ TypeSize getTypeStoreSizeInBits() const {
+ TypeSize BaseSize = getSizeInBits();
+ uint64_t AlignedSizeInBits =
+ alignToPowerOf2(BaseSize.getKnownMinValue(), 8);
+ return {AlignedSizeInBits, BaseSize.isScalable()};
+ }
+
+protected:
+ TypeKind Kind;
+ TypeSize SizeInBits;
+ Align ABIAlignment;
+ Align PreferredAlignment;
+ bool IsExplicitlyAligned;
+
+ Type(TypeKind K, TypeSize Size, Align Align, bool ExplicitAlign = false)
+ : Kind(K), SizeInBits(Size), ABIAlignment(Align),
+ IsExplicitlyAligned(ExplicitAlign) {}
+
+public:
+ TypeKind getKind() const { return Kind; }
+ TypeSize getSizeInBits() const { return SizeInBits; }
+ Align getAlignment() const { return ABIAlignment; }
+ Align getPrefferedAlign() const { return PreferredAlignment; }
+ bool hasExplicitAlignment() const { return IsExplicitlyAligned; }
+
+ void setExplicitAlignment(Align Align) {
+ ABIAlignment = Align;
+ IsExplicitlyAligned = true;
+ }
+ TypeSize getTypeAllocSize() const {
+ return alignTo(getTypeStoreSize(), getAlignment().value());
+ }
+
+ 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 isMemberPointer() const { return Kind == TypeKind::MemberPointer; }
+ bool isComplex() const { return Kind == TypeKind::Complex; }
+};
+
+class VoidType : public Type {
+public:
+ VoidType() : Type(TypeKind::Void, TypeSize::getFixed(0), Align(1)) {}
+
+ static bool classof(const Type *T) { return T->getKind() == TypeKind::Void; }
+};
+
+class ComplexType : public Type {
+public:
+ ComplexType(const Type *ElementType, uint64_t SizeInBits, Align Alignment)
+ : Type(TypeKind::Complex, TypeSize::getFixed(SizeInBits), Alignment),
+ ElementType(ElementType) {}
+
+ const Type *getElementType() const { return ElementType; }
+
+ static bool classof(const Type *T) {
+ return T->getKind() == TypeKind::Complex;
+ }
+
+private:
+ const Type *ElementType;
+};
+
+class IntegerType : public Type {
+private:
+ bool IsSigned;
+ bool IsBoolean;
----------------
vortex73 wrote:
Wouldn't `__BitInt(1)` also have SizeInBits = 1?
https://github.com/llvm/llvm-project/pull/140112
More information about the cfe-commits
mailing list