22#ifndef OPTIMIZER_DESCRIPTOR_MODEL_H
23#define OPTIMIZER_DESCRIPTOR_MODEL_H
25#include "flang/ISO_Fortran_binding_wrapper.h"
26#include "flang/Runtime/descriptor-consts.h"
27#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
28#include "mlir/IR/BuiltinTypes.h"
29#include "llvm/Support/ErrorHandling.h"
34using TypeBuilderFunc = mlir::Type (*)(mlir::MLIRContext *);
38static TypeBuilderFunc getModel();
41constexpr TypeBuilderFunc getModel<void *>() {
42 return [](mlir::MLIRContext *context) -> mlir::Type {
43 return mlir::LLVM::LLVMPointerType::get(context);
47constexpr TypeBuilderFunc getModel<unsigned>() {
48 return [](mlir::MLIRContext *context) -> mlir::Type {
49 return mlir::IntegerType::get(context,
sizeof(
unsigned) * 8);
53constexpr TypeBuilderFunc getModel<int>() {
54 return [](mlir::MLIRContext *context) -> mlir::Type {
55 return mlir::IntegerType::get(context,
sizeof(
int) * 8);
59constexpr TypeBuilderFunc getModel<unsigned long>() {
60 return [](mlir::MLIRContext *context) -> mlir::Type {
61 return mlir::IntegerType::get(context,
sizeof(
unsigned long) * 8);
65constexpr TypeBuilderFunc getModel<unsigned long long>() {
66 return [](mlir::MLIRContext *context) -> mlir::Type {
67 return mlir::IntegerType::get(context,
sizeof(
unsigned long long) * 8);
71constexpr TypeBuilderFunc getModel<long long>() {
72 return [](mlir::MLIRContext *context) -> mlir::Type {
73 return mlir::IntegerType::get(context,
sizeof(
long long) * 8);
77constexpr TypeBuilderFunc getModel<Fortran::ISO::CFI_rank_t>() {
78 return [](mlir::MLIRContext *context) -> mlir::Type {
79 return mlir::IntegerType::get(context,
80 sizeof(Fortran::ISO::CFI_rank_t) * 8);
84constexpr TypeBuilderFunc getModel<Fortran::ISO::CFI_type_t>() {
85 return [](mlir::MLIRContext *context) -> mlir::Type {
86 return mlir::IntegerType::get(context,
87 sizeof(Fortran::ISO::CFI_type_t) * 8);
91constexpr TypeBuilderFunc getModel<long>() {
92 return [](mlir::MLIRContext *context) -> mlir::Type {
93 return mlir::IntegerType::get(context,
sizeof(
long) * 8);
97constexpr TypeBuilderFunc getModel<Fortran::ISO::CFI_dim_t>() {
98 return [](mlir::MLIRContext *context) -> mlir::Type {
99 auto indexTy = getModel<Fortran::ISO::CFI_index_t>()(context);
100 return mlir::LLVM::LLVMArrayType::get(indexTy, 3);
104constexpr TypeBuilderFunc
105getModel<Fortran::ISO::cfi_internal::FlexibleArray<Fortran::ISO::CFI_dim_t>>() {
106 return getModel<Fortran::ISO::CFI_dim_t>();
115static constexpr TypeBuilderFunc getDescFieldTypeModel() {
116 Fortran::ISO::CFI_cdesc_t dummyDesc{};
119 auto [a, b, c, d, e, f, g, h] = dummyDesc;
120 auto tup = std::tie(a, b, c, d, e, f, g, h);
121 auto field = std::get<Field>(tup);
122 return getModel<decltype(field)>();
129static constexpr TypeBuilderFunc getExtendedDescFieldTypeModel() {
130 if constexpr (Field == 8) {
131 return getModel<void *>();
132 }
else if constexpr (Field == 9) {
133 return getModel<Fortran::runtime::typeInfo::TypeParameterValue>();
135 llvm_unreachable(
"extended ISO descriptor only has 10 fields");
Definition: AbstractConverter.h:31