10 #include <llvm/IR/DerivedTypes.h>
11 #include <llvm/IR/Type.h>
21 switch (
type.getTypeID())
23 case ::llvm::Type::HalfTyID:
25 case ::llvm::Type::FloatTyID:
27 case ::llvm::Type::DoubleTyID:
29 case ::llvm::Type::X86_FP80TyID:
31 case ::llvm::Type::FP128TyID:
34 JLM_UNREACHABLE(
"TypeConverter::ExtractFloatingPointSize: Unsupported floating point size.");
41 return ::llvm::Type::getIntNTy(context, bitType.
nbits());
44 ::llvm::FunctionType *
47 ::llvm::LLVMContext & context)
49 bool isVariableArgument =
false;
50 std::vector<::llvm::Type *> argumentTypes;
51 for (
auto & argumentType : functionType.
Arguments())
53 if (rvsdg::is<VariableArgumentType>(argumentType))
55 isVariableArgument =
true;
59 if (rvsdg::is<IOStateType>(argumentType))
61 if (rvsdg::is<MemoryStateType>(argumentType))
69 auto resultType = ::llvm::Type::getVoidTy(context);
73 return ::llvm::FunctionType::get(resultType, argumentTypes, isVariableArgument);
76 std::shared_ptr<const rvsdg::FunctionType>
80 std::vector<std::shared_ptr<const rvsdg::Type>> argumentTypes;
81 for (
size_t n = 0; n < functionType.getNumParams(); n++)
82 argumentTypes.push_back(
ConvertLlvmType(*functionType.getParamType(n)));
83 if (functionType.isVarArg())
89 std::vector<std::shared_ptr<const rvsdg::Type>> resultTypes;
90 if (functionType.getReturnType()->getTypeID() != ::llvm::Type::VoidTyID)
102 return ::llvm::PointerType::get(context, 0);
105 std::shared_ptr<const PointerType>
108 JLM_ASSERT(pointerType.getAddressSpace() == 0);
121 ::llvm::LLVMContext & context)
126 return ::llvm::Type::getHalfTy(context);
128 return ::llvm::Type::getFloatTy(context);
130 return ::llvm::Type::getDoubleTy(context);
132 return ::llvm::Type::getFP128Ty(context);
134 return ::llvm::Type::getX86_FP80Ty(context);
136 JLM_UNREACHABLE(
"TypeConverter::ConvertFloatingPointType: Unhandled floating point size.");
143 const auto sharedPtr = std::shared_ptr<const StructType>(std::shared_ptr<void>(), &
type);
147 const auto llvmStructType =
StructTypeMap_.LookupValue(sharedPtr);
148 JLM_ASSERT(&llvmStructType->getContext() == &context);
149 return llvmStructType;
152 std::vector<::llvm::Type *> elements;
153 for (
size_t n = 0; n <
type.numElements(); n++)
160 ? ::llvm::StructType::get(context, elements,
type.IsPacked())
161 : ::llvm::StructType::create(context, elements,
type.GetName(),
type.IsPacked());
164 return llvmStructType;
185 if (
const auto arrayType =
dynamic_cast<const ArrayType *
>(&
type))
192 return controlType->nalternatives() == 2 ? ::llvm::Type::getInt1Ty(context)
193 : ::llvm::Type::getInt32Ty(context);
201 if (
const auto structType =
dynamic_cast<const StructType *
>(&
type))
208 return ::llvm::VectorType::get(
210 fixedVectorType->size(),
216 return ::llvm::VectorType::get(
218 scalableVectorType->size(),
225 std::shared_ptr<const rvsdg::Type>
228 switch (
type.getTypeID())
230 case ::llvm::Type::IntegerTyID:
232 const auto integerType = ::llvm::cast<::llvm::IntegerType>(&
type);
235 case ::llvm::Type::PointerTyID:
237 case ::llvm::Type::FunctionTyID:
239 case ::llvm::Type::HalfTyID:
241 case ::llvm::Type::FloatTyID:
243 case ::llvm::Type::DoubleTyID:
245 case ::llvm::Type::X86_FP80TyID:
247 case ::llvm::Type::FP128TyID:
249 case ::llvm::Type::StructTyID:
251 const auto structType = ::llvm::cast<::llvm::StructType>(&
type);
257 const auto isPacked = structType->isPacked();
259 std::vector<std::shared_ptr<const rvsdg::Type>> elementTypes;
260 for (
const auto elementType : structType->elements())
265 auto jlmType = structType->isLiteral()
268 structType->getName().str(),
269 std::move(elementTypes),
275 case ::llvm::Type::ArrayTyID:
280 case ::llvm::Type::FixedVectorTyID:
284 std::move(scalarType),
285 ::llvm::cast<::llvm::FixedVectorType>(&
type)->getNumElements());
287 case ::llvm::Type::ScalableVectorTyID:
291 std::move(scalarType),
292 ::llvm::cast<::llvm::ScalableVectorType>(&
type)->getMinNumElements());
295 JLM_UNREACHABLE(
"TypeConverter::ConvertLlvmType: Unhandled llvm type.");
static std::shared_ptr< const ArrayType > Create(std::shared_ptr< const Type > type, size_t nelements)
static std::shared_ptr< const FixedVectorType > Create(std::shared_ptr< const rvsdg::Type > type, size_t size)
static std::shared_ptr< const FloatingPointType > Create(fpsize size)
static std::shared_ptr< const IOStateType > Create()
static std::shared_ptr< const MemoryStateType > Create()
static std::shared_ptr< const PointerType > Create()
static std::shared_ptr< const ScalableVectorType > Create(std::shared_ptr< const rvsdg::Type > type, size_t size)
static std::shared_ptr< const StructType > CreateIdentified(const std::string &name, std::vector< std::shared_ptr< const Type >> types, bool isPacked)
static std::shared_ptr< const StructType > CreateLiteral(std::vector< std::shared_ptr< const Type >> types, bool isPacked)
::llvm::ArrayType * ConvertArrayType(const ArrayType &type, ::llvm::LLVMContext &context)
::llvm::PointerType * ConvertPointerType(const PointerType &type, ::llvm::LLVMContext &context)
::llvm::IntegerType * ConvertBitType(const rvsdg::BitType &bitType, ::llvm::LLVMContext &context)
::llvm::FunctionType * ConvertFunctionType(const rvsdg::FunctionType &functionType, ::llvm::LLVMContext &context)
std::shared_ptr< const rvsdg::Type > ConvertLlvmType(::llvm::Type &type)
::llvm::Type * ConvertFloatingPointType(const FloatingPointType &type, ::llvm::LLVMContext &context)
static fpsize ExtractFloatingPointSize(const ::llvm::Type &type)
util::BijectiveMap<::llvm::StructType *, std::shared_ptr< const StructType > > StructTypeMap_
::llvm::StructType * ConvertStructType(const StructType &type, ::llvm::LLVMContext &context)
::llvm::Type * ConvertJlmType(const rvsdg::Type &type, ::llvm::LLVMContext &context)
static std::shared_ptr< const VariableArgumentType > Create()
static std::shared_ptr< const BitType > Create(std::size_t nbits)
Creates bit type of specified width.
size_t nbits() const noexcept
const std::vector< std::shared_ptr< const jlm::rvsdg::Type > > & Arguments() const noexcept
static std::shared_ptr< const FunctionType > Create(std::vector< std::shared_ptr< const jlm::rvsdg::Type >> argumentTypes, std::vector< std::shared_ptr< const jlm::rvsdg::Type >> resultTypes)
size_t NumResults() const noexcept
const jlm::rvsdg::Type & ResultType(size_t index) const noexcept
virtual TypeKind Kind() const noexcept=0
Return the kind of this type.
#define JLM_UNREACHABLE(msg)
Global memory state passed between functions.
static std::string type(const Node *n)
@ Value
Designate a value type.