[clang] [llvm] [clang] Integrate LLVMABI for function call ABI lowering (PR #194460)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 03:49:24 PDT 2026
================
@@ -0,0 +1,178 @@
+//===---- ABITypeMapper.cpp - Maps LLVM ABI Types to LLVM IR Types ------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ABI/ABITypeMapper.h"
+#include "llvm/ABI/Types.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Type.h"
+
+using namespace llvm::abi;
+
+llvm::Type *ABITypeMapper::convertType(const abi::Type *ABIType) {
+ if (!ABIType)
+ return nullptr;
+
+ auto It = TypeCache.find(ABIType);
+ if (It != TypeCache.end())
+ return It->second;
+
+ llvm::Type *Result = nullptr;
+
+ switch (ABIType->getKind()) {
+ case abi::TypeKind::Void:
+ Result = llvm::Type::getVoidTy(Context);
+ break;
+ case abi::TypeKind::Integer: {
+ const auto *IT = cast<abi::IntegerType>(ABIType);
+ Result =
+ llvm::IntegerType::get(Context, IT->getSizeInBits().getFixedValue());
+ break;
+ }
+ case abi::TypeKind::Float: {
+ const llvm::fltSemantics *Semantics =
+ cast<abi::FloatType>(ABIType)->getSemantics();
+ Result = llvm::Type::getFloatingPointTy(Context, *Semantics);
+ break;
+ }
+ case abi::TypeKind::Pointer:
+ Result = llvm::PointerType::get(
+ Context, cast<abi::PointerType>(ABIType)->getAddrSpace());
+ break;
+ case abi::TypeKind::Array:
+ Result = convertArrayType(cast<abi::ArrayType>(ABIType));
+ break;
+ case abi::TypeKind::Vector:
+ Result = convertVectorType(cast<abi::VectorType>(ABIType));
+ break;
+ case abi::TypeKind::Record:
+ Result = convertRecordType(cast<abi::RecordType>(ABIType));
+ break;
+ case abi::TypeKind::Complex:
+ Result = convertComplexType(cast<abi::ComplexType>(ABIType));
+ break;
+ case abi::TypeKind::MemberPointer:
+ Result = convertMemberPointerType(cast<abi::MemberPointerType>(ABIType));
+ break;
+ }
+
+ if (Result)
+ TypeCache[ABIType] = Result;
+ return Result;
+}
+
+llvm::Type *ABITypeMapper::convertArrayType(const abi::ArrayType *AT) {
+ llvm::Type *ElementType = convertType(AT->getElementType());
+ if (!ElementType)
+ return nullptr;
----------------
nikic wrote:
Should convertType() be able to return nullptr? I think all places that return nullptr just pass a nullptr on from a recursive call, but I don't think we'd ever return nullptr in the first place?
https://github.com/llvm/llvm-project/pull/194460
More information about the cfe-commits
mailing list