17#ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
18#define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_RTBUILDER_H
20#include "flang/Common/Fortran.h"
21#include "flang/Common/uint128.h"
22#include "flang/Optimizer/Builder/FIRBuilder.h"
23#include "flang/Optimizer/Dialect/FIRDialect.h"
24#include "flang/Optimizer/Dialect/FIRType.h"
25#include "flang/Runtime/reduce.h"
26#include "mlir/IR/BuiltinTypes.h"
27#include "mlir/IR/MLIRContext.h"
28#include "llvm/ADT/SmallVector.h"
34typedef std::uint32_t pid_t;
41struct c_float_complex_t;
42struct c_double_complex_t;
44namespace Fortran::runtime {
51namespace fir::runtime {
53using TypeBuilderFunc = mlir::Type (*)(mlir::MLIRContext *);
54using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *);
56#define REDUCTION_REF_OPERATION_MODEL(T) \
58 constexpr TypeBuilderFunc \
59 getModel<Fortran::runtime::ReferenceReductionOperation<T>>() { \
60 return [](mlir::MLIRContext *context) -> mlir::Type { \
61 TypeBuilderFunc f{getModel<T>()}; \
62 auto refTy = fir::ReferenceType::get(f(context)); \
63 return mlir::FunctionType::get(context, {refTy, refTy}, refTy); \
67#define REDUCTION_VALUE_OPERATION_MODEL(T) \
69 constexpr TypeBuilderFunc \
70 getModel<Fortran::runtime::ValueReductionOperation<T>>() { \
71 return [](mlir::MLIRContext *context) -> mlir::Type { \
72 TypeBuilderFunc f{getModel<T>()}; \
73 auto refTy = fir::ReferenceType::get(f(context)); \
74 return mlir::FunctionType::get(context, {f(context), f(context)}, \
79#define REDUCTION_CHAR_OPERATION_MODEL(T) \
81 constexpr TypeBuilderFunc \
82 getModel<Fortran::runtime::ReductionCharOperation<T>>() { \
83 return [](mlir::MLIRContext *context) -> mlir::Type { \
84 TypeBuilderFunc f{getModel<T>()}; \
85 auto voidTy = fir::LLVMPointerType::get( \
86 context, mlir::IntegerType::get(context, 8)); \
88 mlir::IntegerType::get(context, 8 * sizeof(std::size_t)); \
89 auto refTy = fir::ReferenceType::get(f(context)); \
90 return mlir::FunctionType::get( \
91 context, {refTy, size_tTy, refTy, refTy, size_tTy, size_tTy}, \
111static constexpr TypeBuilderFunc getModel();
114constexpr TypeBuilderFunc getModel<unsigned int>() {
115 return [](mlir::MLIRContext *context) -> mlir::Type {
116 return mlir::IntegerType::get(context, 8 *
sizeof(
unsigned int));
120constexpr TypeBuilderFunc getModel<short int>() {
121 return [](mlir::MLIRContext *context) -> mlir::Type {
122 return mlir::IntegerType::get(context, 8 *
sizeof(
short int));
126constexpr TypeBuilderFunc getModel<short int *>() {
127 return [](mlir::MLIRContext *context) -> mlir::Type {
128 TypeBuilderFunc f{getModel<short int>()};
129 return fir::ReferenceType::get(f(context));
133constexpr TypeBuilderFunc getModel<const short int *>() {
134 return getModel<short int *>();
137constexpr TypeBuilderFunc getModel<int>() {
138 return [](mlir::MLIRContext *context) -> mlir::Type {
139 return mlir::IntegerType::get(context, 8 *
sizeof(
int));
143constexpr TypeBuilderFunc getModel<int &>() {
144 return [](mlir::MLIRContext *context) -> mlir::Type {
145 TypeBuilderFunc f{getModel<int>()};
146 return fir::ReferenceType::get(f(context));
150constexpr TypeBuilderFunc getModel<int *>() {
151 return getModel<int &>();
154constexpr TypeBuilderFunc getModel<const int *>() {
155 return [](mlir::MLIRContext *context) -> mlir::Type {
156 TypeBuilderFunc f{getModel<int>()};
157 return fir::ReferenceType::get(f(context));
161constexpr TypeBuilderFunc getModel<char *>() {
162 return [](mlir::MLIRContext *context) -> mlir::Type {
163 return fir::ReferenceType::get(mlir::IntegerType::get(context, 8));
167constexpr TypeBuilderFunc getModel<const char *>() {
168 return getModel<char *>();
171constexpr TypeBuilderFunc getModel<const char16_t *>() {
172 return [](mlir::MLIRContext *context) -> mlir::Type {
173 return fir::ReferenceType::get(mlir::IntegerType::get(context, 16));
177constexpr TypeBuilderFunc getModel<const char32_t *>() {
178 return [](mlir::MLIRContext *context) -> mlir::Type {
179 return fir::ReferenceType::get(mlir::IntegerType::get(context, 32));
183constexpr TypeBuilderFunc getModel<char>() {
184 return [](mlir::MLIRContext *context) -> mlir::Type {
185 return mlir::IntegerType::get(context, 8 *
sizeof(
char));
189constexpr TypeBuilderFunc getModel<signed char>() {
190 return [](mlir::MLIRContext *context) -> mlir::Type {
191 return mlir::IntegerType::get(context, 8 *
sizeof(
signed char));
195constexpr TypeBuilderFunc getModel<signed char *>() {
196 return [](mlir::MLIRContext *context) -> mlir::Type {
197 TypeBuilderFunc f{getModel<signed char>()};
198 return fir::ReferenceType::get(f(context));
202constexpr TypeBuilderFunc getModel<const signed char *>() {
203 return getModel<signed char *>();
206constexpr TypeBuilderFunc getModel<char16_t>() {
207 return [](mlir::MLIRContext *context) -> mlir::Type {
208 return mlir::IntegerType::get(context, 8 *
sizeof(
char16_t));
212constexpr TypeBuilderFunc getModel<char16_t *>() {
213 return [](mlir::MLIRContext *context) -> mlir::Type {
214 TypeBuilderFunc f{getModel<char16_t>()};
215 return fir::ReferenceType::get(f(context));
219constexpr TypeBuilderFunc getModel<char32_t>() {
220 return [](mlir::MLIRContext *context) -> mlir::Type {
221 return mlir::IntegerType::get(context, 8 *
sizeof(
char32_t));
225constexpr TypeBuilderFunc getModel<char32_t *>() {
226 return [](mlir::MLIRContext *context) -> mlir::Type {
227 TypeBuilderFunc f{getModel<char32_t>()};
228 return fir::ReferenceType::get(f(context));
232constexpr TypeBuilderFunc getModel<unsigned char>() {
233 return [](mlir::MLIRContext *context) -> mlir::Type {
234 return mlir::IntegerType::get(context, 8 *
sizeof(
unsigned char));
238constexpr TypeBuilderFunc getModel<void *>() {
239 return [](mlir::MLIRContext *context) -> mlir::Type {
240 return fir::LLVMPointerType::get(context,
241 mlir::IntegerType::get(context, 8));
245constexpr TypeBuilderFunc getModel<void (*)(int)>() {
246 return [](mlir::MLIRContext *context) -> mlir::Type {
247 return fir::LLVMPointerType::get(
249 mlir::FunctionType::get(context, {}, {}));
253constexpr TypeBuilderFunc getModel<void **>() {
254 return [](mlir::MLIRContext *context) -> mlir::Type {
255 return fir::ReferenceType::get(
256 fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8)));
260constexpr TypeBuilderFunc getModel<long>() {
261 return [](mlir::MLIRContext *context) -> mlir::Type {
262 return mlir::IntegerType::get(context, 8 *
sizeof(
long));
266constexpr TypeBuilderFunc getModel<long &>() {
267 return [](mlir::MLIRContext *context) -> mlir::Type {
268 TypeBuilderFunc f{getModel<long>()};
269 return fir::ReferenceType::get(f(context));
273constexpr TypeBuilderFunc getModel<long *>() {
274 return getModel<long &>();
277constexpr TypeBuilderFunc getModel<const long *>() {
278 return getModel<long *>();
281constexpr TypeBuilderFunc getModel<long long>() {
282 return [](mlir::MLIRContext *context) -> mlir::Type {
283 return mlir::IntegerType::get(context, 8 *
sizeof(
long long));
287constexpr TypeBuilderFunc getModel<Fortran::common::int128_t>() {
288 return [](mlir::MLIRContext *context) -> mlir::Type {
289 return mlir::IntegerType::get(context,
294constexpr TypeBuilderFunc getModel<long long &>() {
295 return [](mlir::MLIRContext *context) -> mlir::Type {
296 TypeBuilderFunc f{getModel<long long>()};
297 return fir::ReferenceType::get(f(context));
301constexpr TypeBuilderFunc getModel<long long *>() {
302 return getModel<long long &>();
305constexpr TypeBuilderFunc getModel<const long long *>() {
306 return getModel<long long *>();
309constexpr TypeBuilderFunc getModel<unsigned long>() {
310 return [](mlir::MLIRContext *context) -> mlir::Type {
311 return mlir::IntegerType::get(context, 8 *
sizeof(
unsigned long));
315constexpr TypeBuilderFunc getModel<unsigned long long>() {
316 return [](mlir::MLIRContext *context) -> mlir::Type {
317 return mlir::IntegerType::get(context, 8 *
sizeof(
unsigned long long));
321constexpr TypeBuilderFunc getModel<double>() {
322 return [](mlir::MLIRContext *context) -> mlir::Type {
323 return mlir::Float64Type::get(context);
327constexpr TypeBuilderFunc getModel<double &>() {
328 return [](mlir::MLIRContext *context) -> mlir::Type {
329 TypeBuilderFunc f{getModel<double>()};
330 return fir::ReferenceType::get(f(context));
334constexpr TypeBuilderFunc getModel<double *>() {
335 return getModel<double &>();
338constexpr TypeBuilderFunc getModel<const double *>() {
339 return getModel<double *>();
342constexpr TypeBuilderFunc getModel<long double>() {
343 return [](mlir::MLIRContext *context) -> mlir::Type {
346 constexpr size_t size =
sizeof(
long double);
347 static_assert(size == 16 || size == 10 || size == 8,
348 "unsupported long double size");
349 if constexpr (size == 16)
350 return mlir::Float128Type::get(context);
351 if constexpr (size == 10)
352 return mlir::Float80Type::get(context);
353 if constexpr (size == 8)
354 return mlir::Float64Type::get(context);
355 llvm_unreachable(
"failed static assert");
359constexpr TypeBuilderFunc getModel<long double *>() {
360 return [](mlir::MLIRContext *context) -> mlir::Type {
361 TypeBuilderFunc f{getModel<long double>()};
362 return fir::ReferenceType::get(f(context));
366constexpr TypeBuilderFunc getModel<const long double *>() {
367 return getModel<long double *>();
370constexpr TypeBuilderFunc getModel<float>() {
371 return [](mlir::MLIRContext *context) -> mlir::Type {
372 return mlir::Float32Type::get(context);
376constexpr TypeBuilderFunc getModel<float &>() {
377 return [](mlir::MLIRContext *context) -> mlir::Type {
378 TypeBuilderFunc f{getModel<float>()};
379 return fir::ReferenceType::get(f(context));
383constexpr TypeBuilderFunc getModel<float *>() {
384 return getModel<float &>();
387constexpr TypeBuilderFunc getModel<const float *>() {
388 return getModel<float *>();
391constexpr TypeBuilderFunc getModel<bool>() {
392 return [](mlir::MLIRContext *context) -> mlir::Type {
393 return mlir::IntegerType::get(context, 1);
397constexpr TypeBuilderFunc getModel<bool &>() {
398 return [](mlir::MLIRContext *context) -> mlir::Type {
399 TypeBuilderFunc f{getModel<bool>()};
400 return fir::ReferenceType::get(f(context));
404constexpr TypeBuilderFunc getModel<unsigned short>() {
405 return [](mlir::MLIRContext *context) -> mlir::Type {
406 return mlir::IntegerType::get(
407 context, 8 *
sizeof(
unsigned short),
408 mlir::IntegerType::SignednessSemantics::Unsigned);
412constexpr TypeBuilderFunc getModel<unsigned char *>() {
413 return [](mlir::MLIRContext *context) -> mlir::Type {
414 return fir::ReferenceType::get(mlir::IntegerType::get(context, 8));
418constexpr TypeBuilderFunc getModel<const unsigned char *>() {
419 return getModel<unsigned char *>();
422constexpr TypeBuilderFunc getModel<unsigned short *>() {
423 return [](mlir::MLIRContext *context) -> mlir::Type {
424 return fir::ReferenceType::get(
425 mlir::IntegerType::get(context, 8 *
sizeof(
unsigned short)));
429constexpr TypeBuilderFunc getModel<const unsigned short *>() {
430 return getModel<unsigned short *>();
433constexpr TypeBuilderFunc getModel<unsigned *>() {
434 return getModel<int *>();
437constexpr TypeBuilderFunc getModel<const unsigned *>() {
438 return getModel<unsigned *>();
441constexpr TypeBuilderFunc getModel<unsigned long *>() {
442 return [](mlir::MLIRContext *context) -> mlir::Type {
443 return fir::ReferenceType::get(
444 mlir::IntegerType::get(context, 8 *
sizeof(
unsigned long)));
448constexpr TypeBuilderFunc getModel<const unsigned long *>() {
449 return getModel<unsigned long *>();
452constexpr TypeBuilderFunc getModel<unsigned long long *>() {
453 return [](mlir::MLIRContext *context) -> mlir::Type {
454 return fir::ReferenceType::get(
455 mlir::IntegerType::get(context, 8 *
sizeof(
unsigned long long)));
459constexpr TypeBuilderFunc getModel<const unsigned long long *>() {
460 return getModel<unsigned long long *>();
463constexpr TypeBuilderFunc getModel<Fortran::common::uint128_t>() {
464 return getModel<Fortran::common::int128_t>();
467constexpr TypeBuilderFunc getModel<Fortran::common::int128_t *>() {
468 return [](mlir::MLIRContext *context) -> mlir::Type {
469 TypeBuilderFunc f{getModel<Fortran::common::int128_t>()};
470 return fir::ReferenceType::get(f(context));
474constexpr TypeBuilderFunc getModel<Fortran::common::uint128_t *>() {
475 return getModel<Fortran::common::int128_t *>();
478constexpr TypeBuilderFunc getModel<const Fortran::common::uint128_t *>() {
479 return getModel<Fortran::common::uint128_t *>();
490constexpr TypeBuilderFunc getModel<std::complex<float> &>() {
491 return [](mlir::MLIRContext *context) -> mlir::Type {
492 mlir::Type floatTy = getModel<float>()(context);
493 return fir::ReferenceType::get(mlir::ComplexType::get(floatTy));
497constexpr TypeBuilderFunc getModel<std::complex<float> *>() {
498 return getModel<std::complex<float> &>();
501constexpr TypeBuilderFunc getModel<const std::complex<float> *>() {
502 return getModel<std::complex<float> *>();
505constexpr TypeBuilderFunc getModel<std::complex<double> &>() {
506 return [](mlir::MLIRContext *context) -> mlir::Type {
507 mlir::Type floatTy = getModel<double>()(context);
508 return fir::ReferenceType::get(mlir::ComplexType::get(floatTy));
512constexpr TypeBuilderFunc getModel<std::complex<double> *>() {
513 return getModel<std::complex<double> &>();
516constexpr TypeBuilderFunc getModel<const std::complex<double> *>() {
517 return getModel<std::complex<double> *>();
520constexpr TypeBuilderFunc getModel<c_float_complex_t>() {
521 return [](mlir::MLIRContext *context) -> mlir::Type {
522 mlir::Type floatTy = getModel<float>()(context);
523 return mlir::ComplexType::get(floatTy);
527constexpr TypeBuilderFunc getModel<c_double_complex_t>() {
528 return [](mlir::MLIRContext *context) -> mlir::Type {
529 mlir::Type floatTy = getModel<double>()(context);
530 return mlir::ComplexType::get(floatTy);
534constexpr TypeBuilderFunc getModel<const Fortran::runtime::Descriptor &>() {
535 return [](mlir::MLIRContext *context) -> mlir::Type {
536 return fir::BoxType::get(mlir::NoneType::get(context));
540constexpr TypeBuilderFunc getModel<Fortran::runtime::Descriptor &>() {
541 return [](mlir::MLIRContext *context) -> mlir::Type {
542 return fir::ReferenceType::get(
543 fir::BoxType::get(mlir::NoneType::get(context)));
547constexpr TypeBuilderFunc getModel<const Fortran::runtime::Descriptor *>() {
548 return getModel<const Fortran::runtime::Descriptor &>();
551constexpr TypeBuilderFunc getModel<Fortran::runtime::Descriptor *>() {
552 return getModel<Fortran::runtime::Descriptor &>();
555constexpr TypeBuilderFunc getModel<Fortran::common::TypeCategory>() {
556 return [](mlir::MLIRContext *context) -> mlir::Type {
557 return mlir::IntegerType::get(context,
558 sizeof(Fortran::common::TypeCategory) * 8);
562constexpr TypeBuilderFunc
563getModel<const Fortran::runtime::typeInfo::DerivedType &>() {
564 return [](mlir::MLIRContext *context) -> mlir::Type {
565 return fir::ReferenceType::get(mlir::NoneType::get(context));
569constexpr TypeBuilderFunc
570getModel<const Fortran::runtime::typeInfo::DerivedType *>() {
571 return [](mlir::MLIRContext *context) -> mlir::Type {
572 return fir::ReferenceType::get(mlir::NoneType::get(context));
576constexpr TypeBuilderFunc getModel<void>() {
577 return [](mlir::MLIRContext *context) -> mlir::Type {
578 return mlir::NoneType::get(context);
582REDUCTION_REF_OPERATION_MODEL(std::int8_t)
583REDUCTION_VALUE_OPERATION_MODEL(std::int8_t)
584REDUCTION_REF_OPERATION_MODEL(std::int16_t)
585REDUCTION_VALUE_OPERATION_MODEL(std::int16_t)
586REDUCTION_REF_OPERATION_MODEL(std::int32_t)
587REDUCTION_VALUE_OPERATION_MODEL(std::int32_t)
588REDUCTION_REF_OPERATION_MODEL(std::int64_t)
589REDUCTION_VALUE_OPERATION_MODEL(std::int64_t)
593REDUCTION_REF_OPERATION_MODEL(std::uint8_t)
594REDUCTION_VALUE_OPERATION_MODEL(std::uint8_t)
595REDUCTION_REF_OPERATION_MODEL(std::uint16_t)
596REDUCTION_VALUE_OPERATION_MODEL(std::uint16_t)
597REDUCTION_REF_OPERATION_MODEL(std::uint32_t)
598REDUCTION_VALUE_OPERATION_MODEL(std::uint32_t)
599REDUCTION_REF_OPERATION_MODEL(std::uint64_t)
600REDUCTION_VALUE_OPERATION_MODEL(std::uint64_t)
604REDUCTION_REF_OPERATION_MODEL(
float)
605REDUCTION_VALUE_OPERATION_MODEL(
float)
606REDUCTION_REF_OPERATION_MODEL(
double)
607REDUCTION_VALUE_OPERATION_MODEL(
double)
608REDUCTION_REF_OPERATION_MODEL(
long double)
609REDUCTION_VALUE_OPERATION_MODEL(
long double)
615constexpr TypeBuilderFunc
616getModel<Fortran::runtime::ValueReductionOperation<std::complex<float>>>() {
617 return [](mlir::MLIRContext *context) -> mlir::Type {
618 mlir::Type cplx = mlir::ComplexType::get(getModel<float>()(context));
619 auto refTy = fir::ReferenceType::get(cplx);
620 return mlir::FunctionType::get(context, {cplx, cplx}, refTy);
624constexpr TypeBuilderFunc
625getModel<Fortran::runtime::ValueReductionOperation<std::complex<double>>>() {
626 return [](mlir::MLIRContext *context) -> mlir::Type {
627 mlir::Type cplx = mlir::ComplexType::get(getModel<double>()(context));
628 auto refTy = fir::ReferenceType::get(cplx);
629 return mlir::FunctionType::get(context, {cplx, cplx}, refTy);
633constexpr TypeBuilderFunc
634getModel<Fortran::runtime::ReferenceReductionOperation<std::complex<float>>>() {
635 return [](mlir::MLIRContext *context) -> mlir::Type {
636 mlir::Type cplx = mlir::ComplexType::get(getModel<float>()(context));
637 auto refTy = fir::ReferenceType::get(cplx);
638 return mlir::FunctionType::get(context, {refTy, refTy}, refTy);
642constexpr TypeBuilderFunc getModel<
643 Fortran::runtime::ReferenceReductionOperation<std::complex<double>>>() {
644 return [](mlir::MLIRContext *context) -> mlir::Type {
645 mlir::Type cplx = mlir::ComplexType::get(getModel<double>()(context));
646 auto refTy = fir::ReferenceType::get(cplx);
647 return mlir::FunctionType::get(context, {refTy, refTy}, refTy);
651REDUCTION_CHAR_OPERATION_MODEL(
char)
652REDUCTION_CHAR_OPERATION_MODEL(
char16_t)
653REDUCTION_CHAR_OPERATION_MODEL(
char32_t)
656constexpr TypeBuilderFunc
657getModel<Fortran::runtime::ReductionDerivedTypeOperation>() {
658 return [](mlir::MLIRContext *context) -> mlir::Type {
660 fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8));
661 return mlir::FunctionType::get(context, {voidTy, voidTy, voidTy}, voidTy);
665template <
typename...>
667template <
typename RT,
typename... ATs>
669 static constexpr FuncTypeBuilderFunc getTypeModel() {
670 return [](mlir::MLIRContext *ctxt) {
671 TypeBuilderFunc ret = getModel<RT>();
672 std::array<TypeBuilderFunc,
sizeof...(ATs)> args = {getModel<ATs>()...};
673 mlir::Type retTy = ret(ctxt);
676 argTys.push_back(f(ctxt));
677 if (mlir::isa<mlir::NoneType>(retTy))
678 return mlir::FunctionType::get(ctxt, argTys, {});
679 return mlir::FunctionType::get(ctxt, argTys, {retTy});
689using RuntimeIdentifier = std::integer_sequence<char, Cs...>;
692template <
typename T, T... As, T... Bs>
693static constexpr std::integer_sequence<T, As..., Bs...>
694concat(std::integer_sequence<T, As...>, std::integer_sequence<T, Bs...>) {
697template <
typename T, T... As, T... Bs,
typename... Cs>
698static constexpr auto concat(std::integer_sequence<T, As...>,
699 std::integer_sequence<T, Bs...>, Cs...) {
700 return concat(std::integer_sequence<T, As..., Bs...>{}, Cs{}...);
703static constexpr std::integer_sequence<T> concat(std::integer_sequence<T>) {
706template <
typename T, T a>
707static constexpr auto filterZero(std::integer_sequence<T, a>) {
708 if constexpr (a != 0) {
709 return std::integer_sequence<T, a>{};
711 return std::integer_sequence<T>{};
714template <
typename T, T... b>
715static constexpr auto filter(std::integer_sequence<T, b...>) {
716 if constexpr (
sizeof...(b) > 0) {
717 return details::concat(filterZero(std::integer_sequence<T, b>{})...);
719 return std::integer_sequence<T>{};
724template <
typename...>
726template <
typename KT,
char... Cs>
728 static constexpr FuncTypeBuilderFunc getTypeModel() {
731 static constexpr const char name[
sizeof...(Cs) + 1] = {Cs...,
'\0'};
746#define FirE(L, I) (I < sizeof(L) / sizeof(*L) ? L[I] : 0)
747#define FirQuoteKey(X) #X
748#define ExpandAndQuoteKey(X) FirQuoteKey(X)
749#define FirMacroExpandKey(X) \
750 FirE(X, 0), FirE(X, 1), FirE(X, 2), FirE(X, 3), FirE(X, 4), FirE(X, 5), \
751 FirE(X, 6), FirE(X, 7), FirE(X, 8), FirE(X, 9), FirE(X, 10), \
752 FirE(X, 11), FirE(X, 12), FirE(X, 13), FirE(X, 14), FirE(X, 15), \
753 FirE(X, 16), FirE(X, 17), FirE(X, 18), FirE(X, 19), FirE(X, 20), \
754 FirE(X, 21), FirE(X, 22), FirE(X, 23), FirE(X, 24), FirE(X, 25), \
755 FirE(X, 26), FirE(X, 27), FirE(X, 28), FirE(X, 29), FirE(X, 30), \
756 FirE(X, 31), FirE(X, 32), FirE(X, 33), FirE(X, 34), FirE(X, 35), \
757 FirE(X, 36), FirE(X, 37), FirE(X, 38), FirE(X, 39), FirE(X, 40), \
758 FirE(X, 41), FirE(X, 42), FirE(X, 43), FirE(X, 44), FirE(X, 45), \
759 FirE(X, 46), FirE(X, 47), FirE(X, 48), FirE(X, 49)
760#define FirExpandKey(X) FirMacroExpandKey(FirQuoteKey(X))
761#define FirFullSeq(X) std::integer_sequence<char, FirExpandKey(X)>
762#define FirAsSequence(X) \
763 decltype(fir::runtime::details::filter(FirFullSeq(X){}))
765 fir::runtime::RuntimeTableEntry<fir::runtime::RuntimeTableKey<decltype(X)>, \
767#define mkRTKey(X) FirmkKey(RTNAME(X))
768#define EXPAND_AND_QUOTE_KEY(S) ExpandAndQuoteKey(RTNAME(S))
772template <
typename RuntimeEntry>
773static mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
775 using namespace Fortran::runtime;
776 auto name = RuntimeEntry::name;
780 auto funTy = RuntimeEntry::getTypeModel()(builder.getContext());
782 func->setAttr(FIROpsDialect::getFirRuntimeAttrName(), builder.getUnitAttr());
787template <
int N,
typename A>
788void createArguments(llvm::SmallVectorImpl<mlir::Value> &result,
790 mlir::FunctionType fTy, A arg) {
791 result.emplace_back(builder.
createConvert(loc, fTy.getInput(N), arg));
794template <
int N,
typename A,
typename... As>
795void createArguments(llvm::SmallVectorImpl<mlir::Value> &result,
797 mlir::FunctionType fTy, A arg, As... args) {
798 result.emplace_back(builder.
createConvert(loc, fTy.getInput(N), arg));
799 createArguments<N + 1>(result, builder, loc, fTy, args...);
804template <
typename... As>
807 mlir::FunctionType fTy, As... args) {
809 helper::createArguments<0>(result, builder, loc, fTy, args...);
Definition: FIRBuilder.h:55
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition: FIRBuilder.cpp:511
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition: FIRBuilder.h:332
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition: FIRBuilder.h:371
Definition: RTBuilder.h:725