================ @@ -0,0 +1,241 @@ +//===---- 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 +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Maps LLVM ABI type representations back to corresponding LLVM IR types. +/// This reverse mapper translates low-level ABI-specific types back into +/// LLVM IR types suitable for code generation and optimization passes. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/ABI/ABITypeMapper.h" +#include "llvm/ABI/Types.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Type.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; + +Type *ABITypeMapper::convertType(const abi::Type *ABIType) { + if (!ABIType) + return nullptr; + + auto It = TypeCache.find(ABIType); + if (It != TypeCache.end()) + return It->second; + + Type *Result = nullptr; + + switch (ABIType->getKind()) { + case abi::TypeKind::Integer: + Result = convertIntegerType(cast<abi::IntegerType>(ABIType)); + break; + case abi::TypeKind::Float: + Result = convertFloatType(cast<abi::FloatType>(ABIType)); + break; + case abi::TypeKind::Pointer: + Result = convertPointerType(cast<abi::PointerType>(ABIType)); + 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::Struct: + Result = convertStructType(cast<abi::StructType>(ABIType)); + break; + case abi::TypeKind::Union: + Result = convertUnionType(cast<abi::UnionType>(ABIType)); + break; + case abi::TypeKind::Void: + Result = convertVoidType(cast<abi::VoidType>(ABIType)); + break; + default: + llvm_unreachable("Unknown ABI type kind"); + } + + if (Result) + TypeCache[ABIType] = Result; + + return Result; +} + +Type *ABITypeMapper::convertIntegerType(const abi::IntegerType *IT) { + unsigned BitWidth = IT->getSizeInBits(); + return IntegerType::get(Context, BitWidth); +} + +Type *ABITypeMapper::convertFloatType(const abi::FloatType *FT) { + const fltSemantics *Semantics = + const_cast<abi::FloatType *>(FT)->getSemantics(); + return getFloatTypeForSemantics(*Semantics); +} + +Type *ABITypeMapper::convertPointerType(const abi::PointerType *PT) { + return PointerType::get(Context, 0); ---------------- nikic wrote:
We probably need an AddrSpace in abi::PointerType... https://github.com/llvm/llvm-project/pull/140112 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits