Lines Matching refs:mlir
116 static bool isStaticallyAbsent(llvm::ArrayRef<mlir::Value> args, in isStaticallyAbsent()
134 genFuncDim(FD funcDim, mlir::Type resultType, fir::FirOpBuilder &builder, in genFuncDim()
135 mlir::Location loc, Fortran::lower::StatementContext *stmtCtx, in genFuncDim()
136 llvm::StringRef errMsg, mlir::Value array, fir::ExtendedValue dimArg, in genFuncDim()
137 mlir::Value mask, int rank) { in genFuncDim()
140 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, rank - 1); in genFuncDim()
143 mlir::Value resultIrBox = in genFuncDim()
146 mlir::Value dim = in genFuncDim()
159 mlir::Value temp = box.getAddr(); in genFuncDim()
168 mlir::Value temp = box.getAddr(); in genFuncDim()
181 genProdOrSum(FN func, FD funcDim, mlir::Type resultType, in genProdOrSum()
182 fir::FirOpBuilder &builder, mlir::Location loc, in genProdOrSum()
190 mlir::Value array = fir::getBase(arryTmp); in genProdOrSum()
205 mlir::Type ty = array.getType(); in genProdOrSum()
206 mlir::Type arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty); in genProdOrSum()
209 mlir::Value result = builder.createTemporary(loc, eleTy); in genProdOrSum()
225 genDotProd(FN func, mlir::Type resultType, fir::FirOpBuilder &builder, in genDotProd()
226 mlir::Location loc, Fortran::lower::StatementContext *stmtCtx, in genDotProd()
232 mlir::Value vectorA = fir::getBase(args[0]); in genDotProd()
233 mlir::Value vectorB = fir::getBase(args[1]); in genDotProd()
235 mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy(vectorA.getType()) in genDotProd()
239 mlir::Value result = builder.createTemporary(loc, eleTy); in genDotProd()
252 genExtremumVal(FN func, FD funcDim, FC funcChar, mlir::Type resultType, in genExtremumVal()
253 fir::FirOpBuilder &builder, mlir::Location loc, in genExtremumVal()
262 mlir::Value array = fir::getBase(arryTmp); in genExtremumVal()
284 mlir::Value resultIrBox = in genExtremumVal()
297 mlir::Value temp = box.getAddr(); in genExtremumVal()
315 FN func, FD funcDim, mlir::Type resultType, fir::FirOpBuilder &builder, in genExtremumloc()
316 mlir::Location loc, Fortran::lower::StatementContext *stmtCtx, in genExtremumloc()
322 mlir::Value array = builder.createBox(loc, args[0]); in genExtremumloc()
349 mlir::Value dim = fir::getBase(args[1]); in genExtremumloc()
353 mlir::Value resultIrBox = in genExtremumloc()
362 [&](const mlir::Value &tempAddr) -> fir::ExtendedValue { in genExtremumloc()
378 mlir::Type resultArrayType = in genExtremumloc()
382 mlir::Value resultIrBox = in genExtremumloc()
392 mlir::Value dim = fir::getBase(args[1]); in genExtremumloc()
402 mlir::Value temp = box.getAddr(); in genExtremumloc()
416 explicit IntrinsicLibrary(fir::FirOpBuilder &builder, mlir::Location loc, in IntrinsicLibrary()
425 llvm::Optional<mlir::Type> resultType,
435 mlir::Value genRuntimeCall(llvm::StringRef name, mlir::Type,
436 llvm::ArrayRef<mlir::Value>);
438 using RuntimeCallGenerator = std::function<mlir::Value(
439 fir::FirOpBuilder &, mlir::Location, llvm::ArrayRef<mlir::Value>)>;
442 mlir::FunctionType soughtFuncType);
448 mlir::Value genAbs(mlir::Type, llvm::ArrayRef<mlir::Value>);
449 template <void (*CallRuntime)(fir::FirOpBuilder &, mlir::Location loc,
450 mlir::Value, mlir::Value)>
451 fir::ExtendedValue genAdjustRtCall(mlir::Type,
453 mlir::Value genAimag(mlir::Type, llvm::ArrayRef<mlir::Value>);
454 mlir::Value genAint(mlir::Type, llvm::ArrayRef<mlir::Value>);
455 fir::ExtendedValue genAll(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
456 fir::ExtendedValue genAllocated(mlir::Type,
458 mlir::Value genAnint(mlir::Type, llvm::ArrayRef<mlir::Value>);
459 fir::ExtendedValue genAny(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
461 genCommandArgumentCount(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
462 fir::ExtendedValue genAssociated(mlir::Type,
466 template <mlir::arith::CmpIPredicate pred>
467 mlir::Value genBitwiseCompare(mlir::Type resultType,
468 llvm::ArrayRef<mlir::Value> args);
470 mlir::Value genBtest(mlir::Type, llvm::ArrayRef<mlir::Value>);
471 mlir::Value genCeiling(mlir::Type, llvm::ArrayRef<mlir::Value>);
472 fir::ExtendedValue genChar(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
473 template <mlir::arith::CmpIPredicate pred>
474 fir::ExtendedValue genCharacterCompare(mlir::Type,
476 mlir::Value genCmplx(mlir::Type, llvm::ArrayRef<mlir::Value>);
477 mlir::Value genConjg(mlir::Type, llvm::ArrayRef<mlir::Value>);
478 fir::ExtendedValue genCount(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
480 fir::ExtendedValue genCshift(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
482 mlir::Value genDim(mlir::Type, llvm::ArrayRef<mlir::Value>);
483 fir::ExtendedValue genDotProduct(mlir::Type,
485 mlir::Value genDprod(mlir::Type, llvm::ArrayRef<mlir::Value>);
486 mlir::Value genDshiftl(mlir::Type, llvm::ArrayRef<mlir::Value>);
487 mlir::Value genDshiftr(mlir::Type, llvm::ArrayRef<mlir::Value>);
488 fir::ExtendedValue genEoshift(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
490 mlir::Value genExponent(mlir::Type, llvm::ArrayRef<mlir::Value>);
492 mlir::Value genExtremum(mlir::Type, llvm::ArrayRef<mlir::Value>);
493 mlir::Value genFloor(mlir::Type, llvm::ArrayRef<mlir::Value>);
494 mlir::Value genFraction(mlir::Type resultType,
495 mlir::ArrayRef<mlir::Value> args);
496 void genGetCommandArgument(mlir::ArrayRef<fir::ExtendedValue> args);
500 mlir::Value genIand(mlir::Type, llvm::ArrayRef<mlir::Value>);
501 mlir::Value genIbclr(mlir::Type, llvm::ArrayRef<mlir::Value>);
502 mlir::Value genIbits(mlir::Type, llvm::ArrayRef<mlir::Value>);
503 mlir::Value genIbset(mlir::Type, llvm::ArrayRef<mlir::Value>);
504 fir::ExtendedValue genIchar(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
505 mlir::Value genIeeeIsFinite(mlir::Type, llvm::ArrayRef<mlir::Value>);
506 template <mlir::arith::CmpIPredicate pred>
507 fir::ExtendedValue genIeeeTypeCompare(mlir::Type,
509 mlir::Value genIeor(mlir::Type, llvm::ArrayRef<mlir::Value>);
510 fir::ExtendedValue genIndex(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
511 mlir::Value genIor(mlir::Type, llvm::ArrayRef<mlir::Value>);
512 mlir::Value genIshft(mlir::Type, llvm::ArrayRef<mlir::Value>);
513 mlir::Value genIshftc(mlir::Type, llvm::ArrayRef<mlir::Value>);
514 fir::ExtendedValue genLbound(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
515 mlir::Value genLeadz(mlir::Type, llvm::ArrayRef<mlir::Value>);
516 fir::ExtendedValue genLen(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
517 fir::ExtendedValue genLenTrim(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
519 mlir::Value genMask(mlir::Type, llvm::ArrayRef<mlir::Value>);
520 fir::ExtendedValue genMatmul(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
521 fir::ExtendedValue genMaxloc(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
522 fir::ExtendedValue genMaxval(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
523 fir::ExtendedValue genMerge(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
524 mlir::Value genMergeBits(mlir::Type, llvm::ArrayRef<mlir::Value>);
525 fir::ExtendedValue genMinloc(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
526 fir::ExtendedValue genMinval(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
527 mlir::Value genMod(mlir::Type, llvm::ArrayRef<mlir::Value>);
528 mlir::Value genModulo(mlir::Type, llvm::ArrayRef<mlir::Value>);
530 mlir::Value genNearest(mlir::Type, llvm::ArrayRef<mlir::Value>);
531 mlir::Value genNint(mlir::Type, llvm::ArrayRef<mlir::Value>);
532 mlir::Value genNot(mlir::Type, llvm::ArrayRef<mlir::Value>);
533 fir::ExtendedValue genNull(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
534 fir::ExtendedValue genPack(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
535 mlir::Value genPopcnt(mlir::Type, llvm::ArrayRef<mlir::Value>);
536 mlir::Value genPoppar(mlir::Type, llvm::ArrayRef<mlir::Value>);
537 fir::ExtendedValue genPresent(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
538 fir::ExtendedValue genProduct(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
542 fir::ExtendedValue genRepeat(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
543 fir::ExtendedValue genReshape(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
544 mlir::Value genRRSpacing(mlir::Type resultType,
545 llvm::ArrayRef<mlir::Value> args);
546 mlir::Value genScale(mlir::Type, llvm::ArrayRef<mlir::Value>);
547 fir::ExtendedValue genScan(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
548 mlir::Value genSelectedIntKind(mlir::Type, llvm::ArrayRef<mlir::Value>);
549 mlir::Value genSelectedRealKind(mlir::Type, llvm::ArrayRef<mlir::Value>);
550 mlir::Value genSetExponent(mlir::Type resultType,
551 llvm::ArrayRef<mlir::Value> args);
553 mlir::Value genShift(mlir::Type resultType, llvm::ArrayRef<mlir::Value>);
554 mlir::Value genSign(mlir::Type, llvm::ArrayRef<mlir::Value>);
555 fir::ExtendedValue genSize(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
556 mlir::Value genSpacing(mlir::Type resultType,
557 llvm::ArrayRef<mlir::Value> args);
558 fir::ExtendedValue genSpread(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
559 fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
561 mlir::Value genTrailz(mlir::Type, llvm::ArrayRef<mlir::Value>);
562 fir::ExtendedValue genTransfer(mlir::Type,
564 fir::ExtendedValue genTranspose(mlir::Type,
566 fir::ExtendedValue genTrim(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
567 fir::ExtendedValue genUbound(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
568 fir::ExtendedValue genUnpack(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
569 fir::ExtendedValue genVerify(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
573 mlir::Value genConversion(mlir::Type, llvm::ArrayRef<mlir::Value>);
590 mlir::Value outlineInWrapper(GeneratorType, llvm::StringRef name,
591 mlir::Type resultType,
592 llvm::ArrayRef<mlir::Value> args);
596 llvm::Optional<mlir::Type> resultType,
600 mlir::func::FuncOp getWrapper(GeneratorType, llvm::StringRef name,
601 mlir::FunctionType,
607 genElementalCall(GeneratorType, llvm::StringRef name, mlir::Type resultType,
611 mlir::Value invokeGenerator(ElementalGenerator generator,
612 mlir::Type resultType,
613 llvm::ArrayRef<mlir::Value> args);
614 mlir::Value invokeGenerator(RuntimeCallGenerator generator,
615 mlir::Type resultType,
616 llvm::ArrayRef<mlir::Value> args);
617 mlir::Value invokeGenerator(ExtendedGenerator generator,
618 mlir::Type resultType,
619 llvm::ArrayRef<mlir::Value> args);
620 mlir::Value invokeGenerator(SubroutineGenerator generator,
621 llvm::ArrayRef<mlir::Value> args);
625 mlir::SymbolRefAttr
627 mlir::FunctionType signature);
630 void addCleanUpForTemp(mlir::Location loc, mlir::Value temp);
633 mlir::Type resultType,
637 mlir::Location loc;
714 {"bge", &I::genBitwiseCompare<mlir::arith::CmpIPredicate::uge>},
715 {"bgt", &I::genBitwiseCompare<mlir::arith::CmpIPredicate::ugt>},
716 {"ble", &I::genBitwiseCompare<mlir::arith::CmpIPredicate::ule>},
717 {"blt", &I::genBitwiseCompare<mlir::arith::CmpIPredicate::ult>},
791 {"ieee_class_eq", &I::genIeeeTypeCompare<mlir::arith::CmpIPredicate::eq>},
792 {"ieee_class_ne", &I::genIeeeTypeCompare<mlir::arith::CmpIPredicate::ne>},
794 {"ieee_round_eq", &I::genIeeeTypeCompare<mlir::arith::CmpIPredicate::eq>},
795 {"ieee_round_ne", &I::genIeeeTypeCompare<mlir::arith::CmpIPredicate::ne>},
816 {"lge", &I::genCharacterCompare<mlir::arith::CmpIPredicate::sge>},
817 {"lgt", &I::genCharacterCompare<mlir::arith::CmpIPredicate::sgt>},
818 {"lle", &I::genCharacterCompare<mlir::arith::CmpIPredicate::sle>},
819 {"llt", &I::genCharacterCompare<mlir::arith::CmpIPredicate::slt>},
820 {"maskl", &I::genMask<mlir::arith::ShLIOp>},
821 {"maskr", &I::genMask<mlir::arith::ShRUIOp>},
935 {"shifta", &I::genShift<mlir::arith::ShRSIOp>},
936 {"shiftl", &I::genShift<mlir::arith::ShLIOp>},
937 {"shiftr", &I::genShift<mlir::arith::ShRUIOp>},
1050 static mlir::FunctionType genF32F32FuncType(mlir::MLIRContext *context) { in genF32F32FuncType()
1051 mlir::Type t = mlir::FloatType::getF32(context); in genF32F32FuncType()
1052 return mlir::FunctionType::get(context, {t}, {t}); in genF32F32FuncType()
1055 static mlir::FunctionType genF64F64FuncType(mlir::MLIRContext *context) { in genF64F64FuncType()
1056 mlir::Type t = mlir::FloatType::getF64(context); in genF64F64FuncType()
1057 return mlir::FunctionType::get(context, {t}, {t}); in genF64F64FuncType()
1060 static mlir::FunctionType genF80F80FuncType(mlir::MLIRContext *context) { in genF80F80FuncType()
1061 mlir::Type t = mlir::FloatType::getF80(context); in genF80F80FuncType()
1062 return mlir::FunctionType::get(context, {t}, {t}); in genF80F80FuncType()
1065 static mlir::FunctionType genF128F128FuncType(mlir::MLIRContext *context) { in genF128F128FuncType()
1066 mlir::Type t = mlir::FloatType::getF128(context); in genF128F128FuncType()
1067 return mlir::FunctionType::get(context, {t}, {t}); in genF128F128FuncType()
1070 static mlir::FunctionType genF32F32F32FuncType(mlir::MLIRContext *context) { in genF32F32F32FuncType()
1071 auto t = mlir::FloatType::getF32(context); in genF32F32F32FuncType()
1072 return mlir::FunctionType::get(context, {t, t}, {t}); in genF32F32F32FuncType()
1075 static mlir::FunctionType genF64F64F64FuncType(mlir::MLIRContext *context) { in genF64F64F64FuncType()
1076 auto t = mlir::FloatType::getF64(context); in genF64F64F64FuncType()
1077 return mlir::FunctionType::get(context, {t, t}, {t}); in genF64F64F64FuncType()
1080 static mlir::FunctionType genF80F80F80FuncType(mlir::MLIRContext *context) { in genF80F80F80FuncType()
1081 auto t = mlir::FloatType::getF80(context); in genF80F80F80FuncType()
1082 return mlir::FunctionType::get(context, {t, t}, {t}); in genF80F80F80FuncType()
1085 static mlir::FunctionType genF128F128F128FuncType(mlir::MLIRContext *context) { in genF128F128F128FuncType()
1086 auto t = mlir::FloatType::getF128(context); in genF128F128F128FuncType()
1087 return mlir::FunctionType::get(context, {t, t}, {t}); in genF128F128F128FuncType()
1091 static mlir::FunctionType genIntF64FuncType(mlir::MLIRContext *context) { in genIntF64FuncType()
1092 auto t = mlir::FloatType::getF64(context); in genIntF64FuncType()
1093 auto r = mlir::IntegerType::get(context, Bits); in genIntF64FuncType()
1094 return mlir::FunctionType::get(context, {t}, {r}); in genIntF64FuncType()
1098 static mlir::FunctionType genIntF32FuncType(mlir::MLIRContext *context) { in genIntF32FuncType()
1099 auto t = mlir::FloatType::getF32(context); in genIntF32FuncType()
1100 auto r = mlir::IntegerType::get(context, Bits); in genIntF32FuncType()
1101 return mlir::FunctionType::get(context, {t}, {r}); in genIntF32FuncType()
1105 static mlir::FunctionType genF64F64IntFuncType(mlir::MLIRContext *context) { in genF64F64IntFuncType()
1106 auto ftype = mlir::FloatType::getF64(context); in genF64F64IntFuncType()
1107 auto itype = mlir::IntegerType::get(context, Bits); in genF64F64IntFuncType()
1108 return mlir::FunctionType::get(context, {ftype, itype}, {ftype}); in genF64F64IntFuncType()
1112 static mlir::FunctionType genF32F32IntFuncType(mlir::MLIRContext *context) { in genF32F32IntFuncType()
1113 auto ftype = mlir::FloatType::getF32(context); in genF32F32IntFuncType()
1114 auto itype = mlir::IntegerType::get(context, Bits); in genF32F32IntFuncType()
1115 return mlir::FunctionType::get(context, {ftype, itype}, {ftype}); in genF32F32IntFuncType()
1119 using MathGeneratorTy = mlir::Value (*)(fir::FirOpBuilder &, mlir::Location,
1120 llvm::StringRef, mlir::FunctionType,
1121 llvm::ArrayRef<mlir::Value>);
1142 static mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, in genLibCall()
1144 mlir::FunctionType libFuncType, in genLibCall()
1145 llvm::ArrayRef<mlir::Value> args) { in genLibCall()
1149 mlir::func::FuncOp funcOp = in genLibCall()
1161 static mlir::Value genMathOp(fir::FirOpBuilder &builder, mlir::Location loc, in genMathOp()
1163 mlir::FunctionType mathLibFuncType, in genMathOp()
1164 llvm::ArrayRef<mlir::Value> args) { in genMathOp()
1184 mlir::Value result; in genMathOp()
1203 {"abs", "fabsf", genF32F32FuncType, genMathOp<mlir::math::AbsOp>},
1204 {"abs", "fabs", genF64F64FuncType, genMathOp<mlir::math::AbsOp>},
1206 genMathOp<mlir::math::AbsOp>},
1213 genMathOp<mlir::LLVM::RoundOp>},
1215 genMathOp<mlir::LLVM::RoundOp>},
1217 genMathOp<mlir::LLVM::RoundOp>},
1218 {"atan", "atanf", genF32F32FuncType, genMathOp<mlir::math::AtanOp>},
1219 {"atan", "atan", genF64F64FuncType, genMathOp<mlir::math::AtanOp>},
1220 {"atan2", "atan2f", genF32F32F32FuncType, genMathOp<mlir::math::Atan2Op>},
1221 {"atan2", "atan2", genF64F64F64FuncType, genMathOp<mlir::math::Atan2Op>},
1223 {"ceil", "ceilf", genF32F32FuncType, genMathOp<mlir::math::CeilOp>},
1224 {"ceil", "ceil", genF64F64FuncType, genMathOp<mlir::math::CeilOp>},
1225 {"cos", "cosf", genF32F32FuncType, genMathOp<mlir::math::CosOp>},
1226 {"cos", "cos", genF64F64FuncType, genMathOp<mlir::math::CosOp>},
1229 {"erf", "erff", genF32F32FuncType, genMathOp<mlir::math::ErfOp>},
1230 {"erf", "erf", genF64F64FuncType, genMathOp<mlir::math::ErfOp>},
1231 {"exp", "expf", genF32F32FuncType, genMathOp<mlir::math::ExpOp>},
1232 {"exp", "exp", genF64F64FuncType, genMathOp<mlir::math::ExpOp>},
1234 {"floor", "floorf", genF32F32FuncType, genMathOp<mlir::math::FloorOp>},
1235 {"floor", "floor", genF64F64FuncType, genMathOp<mlir::math::FloorOp>},
1238 {"log", "logf", genF32F32FuncType, genMathOp<mlir::math::LogOp>},
1239 {"log", "log", genF64F64FuncType, genMathOp<mlir::math::LogOp>},
1240 {"log10", "log10f", genF32F32FuncType, genMathOp<mlir::math::Log10Op>},
1241 {"log10", "log10", genF64F64FuncType, genMathOp<mlir::math::Log10Op>},
1247 {"pow", "powf", genF32F32F32FuncType, genMathOp<mlir::math::PowFOp>},
1248 {"pow", "pow", genF64F64F64FuncType, genMathOp<mlir::math::PowFOp>},
1253 genMathOp<mlir::math::CopySignOp>},
1255 genMathOp<mlir::math::CopySignOp>},
1257 genMathOp<mlir::math::CopySignOp>},
1259 genMathOp<mlir::math::CopySignOp>},
1260 {"sin", "sinf", genF32F32FuncType, genMathOp<mlir::math::SinOp>},
1261 {"sin", "sin", genF64F64FuncType, genMathOp<mlir::math::SinOp>},
1264 {"sqrt", "sqrtf", genF32F32FuncType, genMathOp<mlir::math::SqrtOp>},
1265 {"sqrt", "sqrt", genF64F64FuncType, genMathOp<mlir::math::SqrtOp>},
1266 {"tan", "tanf", genF32F32FuncType, genMathOp<mlir::math::TanOp>},
1267 {"tan", "tan", genF64F64FuncType, genMathOp<mlir::math::TanOp>},
1268 {"tanh", "tanhf", genF32F32FuncType, genMathOp<mlir::math::TanhOp>},
1269 {"tanh", "tanh", genF64F64FuncType, genMathOp<mlir::math::TanhOp>},
1286 FunctionDistance(mlir::FunctionType from, mlir::FunctionType to) { in FunctionDistance()
1318 void addArgumentDistance(mlir::Type from, mlir::Type to) { in addArgumentDistance()
1334 void addResultDistance(mlir::Type from, mlir::Type to) { in addResultDistance()
1351 static unsigned getFloatingPointWidth(mlir::Type t) { in getFloatingPointWidth()
1352 if (auto f{t.dyn_cast<mlir::FloatType>()}) in getFloatingPointWidth()
1364 static Conversion conversionBetweenTypes(mlir::Type from, mlir::Type to) { in conversionBetweenTypes()
1368 if (auto fromIntTy{from.dyn_cast<mlir::IntegerType>()}) { in conversionBetweenTypes()
1369 if (auto toIntTy{to.dyn_cast<mlir::IntegerType>()}) { in conversionBetweenTypes()
1414 static mlir::func::FuncOp getFuncOp(mlir::Location loc, in getFuncOp()
1417 mlir::func::FuncOp function = builder.addNamedFunction( in getFuncOp()
1427 static mlir::func::FuncOp searchFunctionInLibrary( in searchFunctionInLibrary()
1428 mlir::Location loc, fir::FirOpBuilder &builder, in searchFunctionInLibrary()
1430 llvm::StringRef name, mlir::FunctionType funcType, in searchFunctionInLibrary()
1437 mlir::FunctionType implType = impl.typeGenerator(builder.getContext()); in searchFunctionInLibrary()
1467 mlir::FunctionType funcType, in searchMathOperation()
1492 mlir::FunctionType funcType, in checkPrecisionLoss()
1494 mlir::Location loc) { in checkPrecisionLoss()
1513 for (mlir::Type argType : funcType.getInputs().drop_front()) in checkPrecisionLoss()
1518 mlir::emitError(loc, message); in checkPrecisionLoss()
1525 static mlir::func::FuncOp getRuntimeFunction(mlir::Location loc, in getRuntimeFunction()
1528 mlir::FunctionType funcType) { in getRuntimeFunction()
1531 mlir::func::FuncOp match; in getRuntimeFunction()
1556 static mlir::FunctionType getFunctionType(llvm::Optional<mlir::Type> resultType, in getFunctionType()
1557 llvm::ArrayRef<mlir::Value> arguments, in getFunctionType()
1559 llvm::SmallVector<mlir::Type> argTypes; in getFunctionType()
1560 for (mlir::Value arg : arguments) in getFunctionType()
1562 llvm::SmallVector<mlir::Type> resTypes; in getFunctionType()
1565 return mlir::FunctionType::get(builder.getModule().getContext(), argTypes, in getFunctionType()
1571 fir::ExtendedValue toExtendedValue(mlir::Value val, fir::FirOpBuilder &builder, in toExtendedValue()
1572 mlir::Location loc) { in toExtendedValue()
1574 mlir::Type type = val.getType(); in toExtendedValue()
1575 mlir::Value base = val; in toExtendedValue()
1576 mlir::IndexType indexType = builder.getIndexType(); in toExtendedValue()
1577 llvm::SmallVector<mlir::Value> extents; in toExtendedValue()
1599 mlir::emitError(loc, "cannot retrieve array extents from type"); in toExtendedValue()
1609 mlir::Value toValue(const fir::ExtendedValue &val, fir::FirOpBuilder &builder, in toValue()
1610 mlir::Location loc) { in toValue()
1612 mlir::Value buffer = charBox->getBuffer(); in toValue()
1614 if (buffTy.isa<mlir::FunctionType>()) in toValue()
1654 void crashOnMissingIntrinsic(mlir::Location loc, llvm::StringRef name) { in crashOnMissingIntrinsic()
1663 GeneratorType generator, llvm::StringRef name, mlir::Type resultType, in genElementalCall()
1665 llvm::SmallVector<mlir::Value> scalarArgs; in genElementalCall()
1679 ExtendedGenerator generator, llvm::StringRef name, mlir::Type resultType, in genElementalCall()
1692 SubroutineGenerator generator, llvm::StringRef name, mlir::Type resultType, in genElementalCall()
1701 return mlir::Value(); in genElementalCall()
1707 llvm::Optional<mlir::Type> resultType, in invokeHandler()
1718 llvm::Optional<mlir::Type> resultType, in invokeHandler()
1734 llvm::Optional<mlir::Type> resultType, in invokeHandler()
1738 return lib.genElementalCall(generator, handler.name, mlir::Type{}, args, in invokeHandler()
1744 return mlir::Value{}; in invokeHandler()
1749 llvm::Optional<mlir::Type> resultType, in genIntrinsicCall()
1772 llvm::SmallVector<mlir::Value> mlirArgs; in genIntrinsicCall()
1774 mlir::Value val = toValue(extendedVal, builder, loc); in genIntrinsicCall()
1781 mlir::FunctionType soughtFuncType = in genIntrinsicCall()
1790 mlir::Value
1792 mlir::Type resultType, in invokeGenerator()
1793 llvm::ArrayRef<mlir::Value> args) { in invokeGenerator()
1797 mlir::Value
1799 mlir::Type resultType, in invokeGenerator()
1800 llvm::ArrayRef<mlir::Value> args) { in invokeGenerator()
1804 mlir::Value
1806 mlir::Type resultType, in invokeGenerator()
1807 llvm::ArrayRef<mlir::Value> args) { in invokeGenerator()
1809 for (mlir::Value arg : args) in invokeGenerator()
1815 mlir::Value
1817 llvm::ArrayRef<mlir::Value> args) { in invokeGenerator()
1819 for (mlir::Value arg : args) in invokeGenerator()
1826 mlir::func::FuncOp IntrinsicLibrary::getWrapper(GeneratorType generator, in getWrapper()
1828 mlir::FunctionType funcType, in getWrapper()
1831 mlir::func::FuncOp function = builder.getNamedFunction(wrapperName); in getWrapper()
1836 auto internalLinkage = mlir::LLVM::linkage::Linkage::Internal; in getWrapper()
1838 mlir::LLVM::LinkageAttr::get(builder.getContext(), internalLinkage); in getWrapper()
1850 mlir::Location localLoc = localBuilder->getUnknownLoc(); in getWrapper()
1851 llvm::SmallVector<mlir::Value> localArguments; in getWrapper()
1852 for (mlir::BlockArgument bArg : function.front().getArguments()) { in getWrapper()
1866 localBuilder->create<mlir::func::ReturnOp>(localLoc); in getWrapper()
1870 mlir::Type resultType = funcType.getResult(0); in getWrapper()
1873 localBuilder->create<mlir::func::ReturnOp>(localLoc, result); in getWrapper()
1884 bool static hasAbsentOptional(llvm::ArrayRef<mlir::Value> args) { in hasAbsentOptional()
1885 for (const mlir::Value &arg : args) in hasAbsentOptional()
1898 mlir::Value
1900 llvm::StringRef name, mlir::Type resultType, in outlineInWrapper()
1901 llvm::ArrayRef<mlir::Value> args) { in outlineInWrapper()
1911 mlir::FunctionType funcType = getFunctionType(resultType, args, builder); in outlineInWrapper()
1912 mlir::func::FuncOp wrapper = getWrapper(generator, name, funcType); in outlineInWrapper()
1919 llvm::Optional<mlir::Type> resultType, in outlineInExtendedWrapper()
1924 llvm::SmallVector<mlir::Value> mlirArgs; in outlineInExtendedWrapper()
1927 mlir::FunctionType funcType = getFunctionType(resultType, mlirArgs, builder); in outlineInExtendedWrapper()
1928 mlir::func::FuncOp wrapper = getWrapper(generator, name, funcType); in outlineInExtendedWrapper()
1933 return mlir::Value{}; in outlineInExtendedWrapper()
1938 mlir::FunctionType soughtFuncType) { in getRuntimeCallGenerator()
1939 mlir::func::FuncOp funcOp; in getRuntimeCallGenerator()
1940 mlir::FunctionType actualFuncType; in getRuntimeCallGenerator()
1960 if (name == "pow" && soughtFuncType.getInput(0).isa<mlir::FloatType>()) in getRuntimeCallGenerator()
1962 soughtFuncType.getInput(1).dyn_cast<mlir::IntegerType>()) in getRuntimeCallGenerator()
1989 soughtFuncType](fir::FirOpBuilder &builder, mlir::Location loc, in getRuntimeCallGenerator()
1990 llvm::ArrayRef<mlir::Value> args) { in getRuntimeCallGenerator()
1991 llvm::SmallVector<mlir::Value> convertedArguments; in getRuntimeCallGenerator()
1994 mlir::Value result; in getRuntimeCallGenerator()
2002 mlir::Type soughtType = soughtFuncType.getResult(0); in getRuntimeCallGenerator()
2007 mlir::SymbolRefAttr IntrinsicLibrary::getUnrestrictedIntrinsicSymbolRefAttr( in getUnrestrictedIntrinsicSymbolRefAttr()
2008 llvm::StringRef name, mlir::FunctionType signature) { in getUnrestrictedIntrinsicSymbolRefAttr()
2014 mlir::func::FuncOp funcOp; in getUnrestrictedIntrinsicSymbolRefAttr()
2023 llvm::SmallVector<mlir::Type> argTypes; in getUnrestrictedIntrinsicSymbolRefAttr()
2024 for (mlir::Type type : signature.getInputs()) { in getUnrestrictedIntrinsicSymbolRefAttr()
2030 mlir::FunctionType soughtFuncType = in getUnrestrictedIntrinsicSymbolRefAttr()
2037 return mlir::SymbolRefAttr::get(funcOp); in getUnrestrictedIntrinsicSymbolRefAttr()
2040 void IntrinsicLibrary::addCleanUpForTemp(mlir::Location loc, mlir::Value temp) { in addCleanUpForTemp()
2048 mlir::Type resultType, in readAndAddCleanUp()
2070 [&](const mlir::Value &tempAddr) -> fir::ExtendedValue { in readAndAddCleanUp()
2089 mlir::Value IntrinsicLibrary::genRuntimeCall(llvm::StringRef name, in genRuntimeCall()
2090 mlir::Type resultType, in genRuntimeCall()
2091 llvm::ArrayRef<mlir::Value> args) { in genRuntimeCall()
2092 mlir::FunctionType soughtFuncType = in genRuntimeCall()
2097 mlir::Value IntrinsicLibrary::genConversion(mlir::Type resultType, in genConversion()
2098 llvm::ArrayRef<mlir::Value> args) { in genConversion()
2105 mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType, in genAbs()
2106 llvm::ArrayRef<mlir::Value> args) { in genAbs()
2108 mlir::Value arg = args[0]; in genAbs()
2109 mlir::Type type = arg.getType(); in genAbs()
2115 if (auto intType = type.dyn_cast<mlir::IntegerType>()) { in genAbs()
2118 mlir::Value shift = in genAbs()
2120 auto mask = builder.create<mlir::arith::ShRSIOp>(loc, arg, shift); in genAbs()
2121 auto xored = builder.create<mlir::arith::XOrIOp>(loc, arg, mask); in genAbs()
2122 return builder.create<mlir::arith::SubIOp>(loc, xored, mask); in genAbs()
2127 llvm::SmallVector<mlir::Value> args = {parts.first, parts.second}; in genAbs()
2134 template <void (*CallRuntime)(fir::FirOpBuilder &, mlir::Location loc,
2135 mlir::Value, mlir::Value)>
2137 IntrinsicLibrary::genAdjustRtCall(mlir::Type resultType, in genAdjustRtCall()
2140 mlir::Value string = builder.createBox(loc, args[0]); in genAdjustRtCall()
2144 mlir::Value resultIrBox = in genAdjustRtCall()
2165 mlir::Value IntrinsicLibrary::genAimag(mlir::Type resultType, in genAimag()
2166 llvm::ArrayRef<mlir::Value> args) { in genAimag()
2173 mlir::Value IntrinsicLibrary::genAint(mlir::Type resultType, in genAint()
2174 llvm::ArrayRef<mlir::Value> args) { in genAint()
2183 IntrinsicLibrary::genAll(mlir::Type resultType, in genAll()
2188 mlir::Value mask = builder.createBox(loc, args[0]); in genAll()
2196 mlir::Value dim = in genAll()
2208 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, rank - 1); in genAll()
2211 mlir::Value resultIrBox = in genAll()
2229 IntrinsicLibrary::genAllocated(mlir::Type resultType, in genAllocated()
2243 mlir::Value IntrinsicLibrary::genAnint(mlir::Type resultType, in genAnint()
2244 llvm::ArrayRef<mlir::Value> args) { in genAnint()
2253 IntrinsicLibrary::genAny(mlir::Type resultType, in genAny()
2258 mlir::Value mask = builder.createBox(loc, args[0]); in genAny()
2266 mlir::Value dim = in genAny()
2278 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, rank - 1); in genAny()
2281 mlir::Value resultIrBox = in genAny()
2299 IntrinsicLibrary::genAssociated(mlir::Type resultType, in genAssociated()
2311 mlir::Value targetBox = builder.createBox(loc, target); in genAssociated()
2326 targetBox = builder.create<mlir::arith::SelectOp>(loc, isPresent, targetBox, in genAssociated()
2329 mlir::Value pointerBoxRef = in genAssociated()
2336 template <mlir::arith::CmpIPredicate pred>
2337 mlir::Value
2338 IntrinsicLibrary::genBitwiseCompare(mlir::Type resultType, in genBitwiseCompare()
2339 llvm::ArrayRef<mlir::Value> args) { in genBitwiseCompare()
2342 mlir::Value arg0 = args[0]; in genBitwiseCompare()
2343 mlir::Value arg1 = args[1]; in genBitwiseCompare()
2344 mlir::Type arg0Ty = arg0.getType(); in genBitwiseCompare()
2345 mlir::Type arg1Ty = arg1.getType(); in genBitwiseCompare()
2361 arg1 = builder.create<mlir::arith::ExtUIOp>(loc, arg0Ty, arg1); in genBitwiseCompare()
2363 arg0 = builder.create<mlir::arith::ExtUIOp>(loc, arg1Ty, arg0); in genBitwiseCompare()
2365 return builder.create<mlir::arith::CmpIOp>(loc, pred, arg0, arg1); in genBitwiseCompare()
2369 mlir::Value IntrinsicLibrary::genBtest(mlir::Type resultType, in genBtest()
2370 llvm::ArrayRef<mlir::Value> args) { in genBtest()
2376 mlir::Type argType = args[0].getType(); in genBtest()
2377 mlir::Value pos = builder.createConvert(loc, argType, args[1]); in genBtest()
2378 auto shift = builder.create<mlir::arith::ShRUIOp>(loc, args[0], pos); in genBtest()
2379 mlir::Value one = builder.createIntegerConstant(loc, argType, 1); in genBtest()
2380 auto res = builder.create<mlir::arith::AndIOp>(loc, shift, one); in genBtest()
2385 mlir::Value IntrinsicLibrary::genCeiling(mlir::Type resultType, in genCeiling()
2386 llvm::ArrayRef<mlir::Value> args) { in genCeiling()
2389 mlir::Value arg = args[0]; in genCeiling()
2393 mlir::Value ceil = genRuntimeCall("ceil", arg.getType(), {arg}); in genCeiling()
2399 IntrinsicLibrary::genChar(mlir::Type type, in genChar()
2403 const mlir::Value *arg = args[0].getUnboxed(); in genChar()
2406 mlir::emitError(loc, "CHAR intrinsic argument not unboxed"); in genChar()
2409 mlir::Value cast = helper.createSingletonFromCode(*arg, kind); in genChar()
2410 mlir::Value len = in genChar()
2416 mlir::Value IntrinsicLibrary::genCmplx(mlir::Type resultType, in genCmplx()
2417 llvm::ArrayRef<mlir::Value> args) { in genCmplx()
2420 mlir::Type partType = complexHelper.getComplexPartType(resultType); in genCmplx()
2421 mlir::Value real = builder.createConvert(loc, partType, args[0]); in genCmplx()
2422 mlir::Value imag = isStaticallyAbsent(args, 1) in genCmplx()
2431 mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) { in genCommandArgumentCount()
2441 mlir::Value IntrinsicLibrary::genConjg(mlir::Type resultType, in genConjg()
2442 llvm::ArrayRef<mlir::Value> args) { in genConjg()
2447 mlir::Value cplx = args[0]; in genConjg()
2450 auto negImag = builder.create<mlir::arith::NegFOp>(loc, imag); in genConjg()
2457 IntrinsicLibrary::genCount(mlir::Type resultType, in genCount()
2469 mlir::Value dim = in genCount()
2485 mlir::Value kind = absentKind ? builder.createIntegerConstant( in genCount()
2491 mlir::Type type = builder.getVarLenSeqTy(resultType, maskRank - 1); in genCount()
2495 mlir::Value resultIrBox = in genCount()
2518 const mlir::Value *arg = args[0].getUnboxed(); in genCpuTime()
2520 mlir::Value res1 = Fortran::lower::genCpuTime(builder, loc); in genCpuTime()
2521 mlir::Value res2 = in genCpuTime()
2528 IntrinsicLibrary::genCshift(mlir::Type resultType, in genCshift()
2534 mlir::Value array = fir::getBase(arrayBox); in genCshift()
2538 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, arrayRank); in genCshift()
2541 mlir::Value resultIrBox = in genCshift()
2547 const mlir::Value *shiftAddr = args[1].getUnboxed(); in genCshift()
2555 mlir::Value shift = builder.createBox(loc, args[1]); in genCshift()
2558 mlir::Value dim = in genCshift()
2575 mlir::Value values = fir::getBase(args[3]); in genDateAndTime()
2585 mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, in genDim()
2586 llvm::ArrayRef<mlir::Value> args) { in genDim()
2588 if (resultType.isa<mlir::IntegerType>()) { in genDim()
2589 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genDim()
2590 auto diff = builder.create<mlir::arith::SubIOp>(loc, args[0], args[1]); in genDim()
2591 auto cmp = builder.create<mlir::arith::CmpIOp>( in genDim()
2592 loc, mlir::arith::CmpIPredicate::sgt, diff, zero); in genDim()
2593 return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); in genDim()
2596 mlir::Value zero = builder.createRealZeroConstant(loc, resultType); in genDim()
2597 auto diff = builder.create<mlir::arith::SubFOp>(loc, args[0], args[1]); in genDim()
2598 auto cmp = builder.create<mlir::arith::CmpFOp>( in genDim()
2599 loc, mlir::arith::CmpFPredicate::OGT, diff, zero); in genDim()
2600 return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); in genDim()
2605 IntrinsicLibrary::genDotProduct(mlir::Type resultType, in genDotProduct()
2612 mlir::Value IntrinsicLibrary::genDprod(mlir::Type resultType, in genDprod()
2613 llvm::ArrayRef<mlir::Value> args) { in genDprod()
2617 mlir::Value a = builder.createConvert(loc, resultType, args[0]); in genDprod()
2618 mlir::Value b = builder.createConvert(loc, resultType, args[1]); in genDprod()
2619 return builder.create<mlir::arith::MulFOp>(loc, a, b); in genDprod()
2623 mlir::Value IntrinsicLibrary::genDshiftl(mlir::Type resultType, in genDshiftl()
2624 llvm::ArrayRef<mlir::Value> args) { in genDshiftl()
2627 mlir::Value i = args[0]; in genDshiftl()
2628 mlir::Value j = args[1]; in genDshiftl()
2629 mlir::Value shift = builder.createConvert(loc, resultType, args[2]); in genDshiftl()
2630 mlir::Value bitSize = builder.createIntegerConstant( in genDshiftl()
2635 mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); in genDshiftl()
2637 mlir::Value lArgs[2]{i, shift}; in genDshiftl()
2638 mlir::Value lft = genShift<mlir::arith::ShLIOp>(resultType, lArgs); in genDshiftl()
2640 mlir::Value rArgs[2]{j, diff}; in genDshiftl()
2641 mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(resultType, rArgs); in genDshiftl()
2643 return builder.create<mlir::arith::OrIOp>(loc, lft, rgt); in genDshiftl()
2647 mlir::Value IntrinsicLibrary::genDshiftr(mlir::Type resultType, in genDshiftr()
2648 llvm::ArrayRef<mlir::Value> args) { in genDshiftr()
2651 mlir::Value i = args[0]; in genDshiftr()
2652 mlir::Value j = args[1]; in genDshiftr()
2653 mlir::Value shift = builder.createConvert(loc, resultType, args[2]); in genDshiftr()
2654 mlir::Value bitSize = builder.createIntegerConstant( in genDshiftr()
2659 mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); in genDshiftr()
2661 mlir::Value lArgs[2]{i, diff}; in genDshiftr()
2662 mlir::Value lft = genShift<mlir::arith::ShLIOp>(resultType, lArgs); in genDshiftr()
2664 mlir::Value rArgs[2]{j, shift}; in genDshiftr()
2665 mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(resultType, rArgs); in genDshiftr()
2667 return builder.create<mlir::arith::OrIOp>(loc, lft, rgt); in genDshiftr()
2672 IntrinsicLibrary::genEoshift(mlir::Type resultType, in genEoshift()
2678 mlir::Value array = fir::getBase(arrayBox); in genEoshift()
2682 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, arrayRank); in genEoshift()
2685 mlir::Value resultIrBox = in genEoshift()
2689 mlir::Value boundary = in genEoshift()
2698 const mlir::Value *shiftAddr = args[1].getUnboxed(); in genEoshift()
2706 mlir::Value shift = builder.createBox(loc, args[1]); in genEoshift()
2709 mlir::Value dim = in genEoshift()
2724 mlir::Value status = in genExit()
2737 mlir::Value IntrinsicLibrary::genExponent(mlir::Type resultType, in genExponent()
2738 llvm::ArrayRef<mlir::Value> args) { in genExponent()
2748 mlir::Value IntrinsicLibrary::genFloor(mlir::Type resultType, in genFloor()
2749 llvm::ArrayRef<mlir::Value> args) { in genFloor()
2752 mlir::Value arg = args[0]; in genFloor()
2754 mlir::Value floor = genRuntimeCall("floor", arg.getType(), {arg}); in genFloor()
2759 mlir::Value IntrinsicLibrary::genFraction(mlir::Type resultType, in genFraction()
2760 llvm::ArrayRef<mlir::Value> args) { in genFraction()
2772 mlir::Value number = fir::getBase(args[0]); in genGetCommandArgument()
2783 mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); in genGetCommandArgument()
2784 mlir::Value valBox = in genGetCommandArgument()
2788 mlir::Value errBox = in genGetCommandArgument()
2792 mlir::Value stat = in genGetCommandArgument()
2795 mlir::Value statAddr = fir::getBase(status); in genGetCommandArgument()
2796 mlir::Value statIsPresentAtRuntime = in genGetCommandArgument()
2805 mlir::Value lenAddr = fir::getBase(length); in genGetCommandArgument()
2806 mlir::Value lenIsPresentAtRuntime = builder.genIsNotNullAddr(loc, lenAddr); in genGetCommandArgument()
2809 mlir::Value len = in genGetCommandArgument()
2821 mlir::Value name = fir::getBase(args[0]); in genGetEnvironmentVariable()
2829 mlir::Value trim; in genGetEnvironmentVariable()
2833 mlir::Type i1Ty = builder.getI1Type(); in genGetEnvironmentVariable()
2834 mlir::Value trimNameAddr = fir::getBase(trimName); in genGetEnvironmentVariable()
2835 mlir::Value trimNameIsPresentAtRuntime = in genGetEnvironmentVariable()
2842 mlir::Value cast = builder.createConvert(loc, i1Ty, trimLoad); in genGetEnvironmentVariable()
2846 mlir::Value trueVal = builder.createBool(loc, true); in genGetEnvironmentVariable()
2854 mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); in genGetEnvironmentVariable()
2855 mlir::Value valBox = in genGetEnvironmentVariable()
2859 mlir::Value errBox = in genGetEnvironmentVariable()
2863 mlir::Value stat = fir::runtime::genEnvVariableValue(builder, loc, name, in genGetEnvironmentVariable()
2866 mlir::Value statAddr = fir::getBase(status); in genGetEnvironmentVariable()
2867 mlir::Value statIsPresentAtRuntime = in genGetEnvironmentVariable()
2877 mlir::Value lenAddr = fir::getBase(length); in genGetEnvironmentVariable()
2878 mlir::Value lenIsPresentAtRuntime = builder.genIsNotNullAddr(loc, lenAddr); in genGetEnvironmentVariable()
2881 mlir::Value len = in genGetEnvironmentVariable()
2890 mlir::Value IntrinsicLibrary::genIand(mlir::Type resultType, in genIand()
2891 llvm::ArrayRef<mlir::Value> args) { in genIand()
2895 return builder.create<mlir::arith::AndIOp>(loc, arg0, arg1); in genIand()
2899 mlir::Value IntrinsicLibrary::genIbclr(mlir::Type resultType, in genIbclr()
2900 llvm::ArrayRef<mlir::Value> args) { in genIbclr()
2906 mlir::Value pos = builder.createConvert(loc, resultType, args[1]); in genIbclr()
2907 mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); in genIbclr()
2908 mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); in genIbclr()
2909 auto mask = builder.create<mlir::arith::ShLIOp>(loc, one, pos); in genIbclr()
2910 auto res = builder.create<mlir::arith::XOrIOp>(loc, ones, mask); in genIbclr()
2911 return builder.create<mlir::arith::AndIOp>(loc, args[0], res); in genIbclr()
2915 mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType, in genIbits()
2916 llvm::ArrayRef<mlir::Value> args) { in genIbits()
2926 mlir::Value pos = builder.createConvert(loc, resultType, args[1]); in genIbits()
2927 mlir::Value len = builder.createConvert(loc, resultType, args[2]); in genIbits()
2928 mlir::Value bitSize = builder.createIntegerConstant( in genIbits()
2929 loc, resultType, resultType.cast<mlir::IntegerType>().getWidth()); in genIbits()
2930 auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len); in genIbits()
2931 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genIbits()
2932 mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); in genIbits()
2933 auto mask = builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); in genIbits()
2934 auto res1 = builder.create<mlir::arith::ShRSIOp>(loc, args[0], pos); in genIbits()
2935 auto res2 = builder.create<mlir::arith::AndIOp>(loc, res1, mask); in genIbits()
2936 auto lenIsZero = builder.create<mlir::arith::CmpIOp>( in genIbits()
2937 loc, mlir::arith::CmpIPredicate::eq, len, zero); in genIbits()
2938 return builder.create<mlir::arith::SelectOp>(loc, lenIsZero, zero, res2); in genIbits()
2942 mlir::Value IntrinsicLibrary::genIbset(mlir::Type resultType, in genIbset()
2943 llvm::ArrayRef<mlir::Value> args) { in genIbset()
2949 mlir::Value pos = builder.createConvert(loc, resultType, args[1]); in genIbset()
2950 mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); in genIbset()
2951 auto mask = builder.create<mlir::arith::ShLIOp>(loc, one, pos); in genIbset()
2952 return builder.create<mlir::arith::OrIOp>(loc, args[0], mask); in genIbset()
2957 IntrinsicLibrary::genIchar(mlir::Type resultType, in genIchar()
2966 mlir::Value buffer = charBox->getBuffer(); in genIchar()
2967 mlir::Type bufferTy = buffer.getType(); in genIchar()
2968 mlir::Value charVal; in genIchar()
2974 mlir::Type ty = fir::dyn_cast_ptrEleTy(bufferTy); in genIchar()
2982 mlir::Type toTy = builder.getRefType(charType); in genIchar()
2983 mlir::Value cast = builder.createConvert(loc, toTy, buffer); in genIchar()
2990 return builder.create<mlir::arith::ExtUIOp>(loc, resultType, code); in genIchar()
2995 template <mlir::arith::CmpIPredicate pred>
2997 IntrinsicLibrary::genIeeeTypeCompare(mlir::Type resultType, in genIeeeTypeCompare()
3000 mlir::Value arg0 = fir::getBase(args[0]); in genIeeeTypeCompare()
3001 mlir::Value arg1 = fir::getBase(args[1]); in genIeeeTypeCompare()
3006 mlir::Type fieldIndexType = fir::FieldType::get(recType.getContext()); in genIeeeTypeCompare()
3007 mlir::Value field = builder.create<fir::FieldIndexOp>( in genIeeeTypeCompare()
3009 mlir::Value left = builder.create<fir::LoadOp>( in genIeeeTypeCompare()
3013 mlir::Value right = builder.create<fir::LoadOp>( in genIeeeTypeCompare()
3017 return builder.create<mlir::arith::CmpIOp>(loc, pred, left, right); in genIeeeTypeCompare()
3021 mlir::Value
3022 IntrinsicLibrary::genIeeeIsFinite(mlir::Type resultType, in genIeeeIsFinite()
3023 llvm::ArrayRef<mlir::Value> args) { in genIeeeIsFinite()
3026 mlir::Value floatVal = fir::getBase(args[0]); in genIeeeIsFinite()
3027 mlir::FloatType floatType = floatVal.getType().dyn_cast<mlir::FloatType>(); in genIeeeIsFinite()
3029 mlir::Type intType = builder.getIntegerType( in genIeeeIsFinite()
3030 floatType.isa<mlir::Float80Type>() ? 128 : floatBits); in genIeeeIsFinite()
3031 mlir::Value intVal = in genIeeeIsFinite()
3032 builder.create<mlir::arith::BitcastOp>(loc, intType, floatVal); in genIeeeIsFinite()
3034 if (floatType.isa<mlir::Float32Type>()) in genIeeeIsFinite()
3036 else if (floatType.isa<mlir::Float64Type>()) in genIeeeIsFinite()
3040 mlir::Value significand = in genIeeeIsFinite()
3043 mlir::Value maxExponent = in genIeeeIsFinite()
3045 mlir::Value exponent = genIbits( in genIeeeIsFinite()
3050 builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, in genIeeeIsFinite()
3055 mlir::Value IntrinsicLibrary::genIeor(mlir::Type resultType, in genIeor()
3056 llvm::ArrayRef<mlir::Value> args) { in genIeor()
3058 return builder.create<mlir::arith::XOrIOp>(loc, args[0], args[1]); in genIeor()
3063 IntrinsicLibrary::genIndex(mlir::Type resultType, in genIndex()
3067 mlir::Value stringBase = fir::getBase(args[0]); in genIndex()
3071 mlir::Value stringLen = fir::getLen(args[0]); in genIndex()
3072 mlir::Value substringBase = fir::getBase(args[1]); in genIndex()
3073 mlir::Value substringLen = fir::getLen(args[1]); in genIndex()
3074 mlir::Value back = in genIndex()
3085 mlir::Value string = builder.createBox(loc, args[0]); in genIndex()
3086 mlir::Value substring = builder.createBox(loc, args[1]); in genIndex()
3087 auto makeRefThenEmbox = [&](mlir::Value b) { in genIndex()
3090 mlir::Value temp = builder.createTemporary(loc, logTy); in genIndex()
3091 mlir::Value castb = builder.createConvert(loc, logTy, b); in genIndex()
3095 mlir::Value backOpt = isStaticallyAbsent(args, 2) in genIndex()
3099 mlir::Value kindVal = isStaticallyAbsent(args, 3) in genIndex()
3107 mlir::Value resBox = fir::factory::getMutableIRBox(builder, loc, mutBox); in genIndex()
3116 mlir::Value IntrinsicLibrary::genIor(mlir::Type resultType, in genIor()
3117 llvm::ArrayRef<mlir::Value> args) { in genIor()
3119 return builder.create<mlir::arith::OrIOp>(loc, args[0], args[1]); in genIor()
3123 mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, in genIshft()
3124 llvm::ArrayRef<mlir::Value> args) { in genIshft()
3133 mlir::Value bitSize = builder.createIntegerConstant( in genIshft()
3134 loc, resultType, resultType.cast<mlir::IntegerType>().getWidth()); in genIshft()
3135 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genIshft()
3136 mlir::Value shift = builder.createConvert(loc, resultType, args[1]); in genIshft()
3137 mlir::Value absShift = genAbs(resultType, {shift}); in genIshft()
3138 auto left = builder.create<mlir::arith::ShLIOp>(loc, args[0], absShift); in genIshft()
3139 auto right = builder.create<mlir::arith::ShRUIOp>(loc, args[0], absShift); in genIshft()
3140 auto shiftIsLarge = builder.create<mlir::arith::CmpIOp>( in genIshft()
3141 loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); in genIshft()
3142 auto shiftIsNegative = builder.create<mlir::arith::CmpIOp>( in genIshft()
3143 loc, mlir::arith::CmpIPredicate::slt, shift, zero); in genIshft()
3145 builder.create<mlir::arith::SelectOp>(loc, shiftIsNegative, right, left); in genIshft()
3146 return builder.create<mlir::arith::SelectOp>(loc, shiftIsLarge, zero, sel); in genIshft()
3150 mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType, in genIshftc()
3151 llvm::ArrayRef<mlir::Value> args) { in genIshftc()
3169 mlir::Value bitSize = builder.createIntegerConstant( in genIshftc()
3170 loc, resultType, resultType.cast<mlir::IntegerType>().getWidth()); in genIshftc()
3171 mlir::Value I = args[0]; in genIshftc()
3172 mlir::Value shift = builder.createConvert(loc, resultType, args[1]); in genIshftc()
3173 mlir::Value size = in genIshftc()
3175 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genIshftc()
3176 mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); in genIshftc()
3177 mlir::Value absShift = genAbs(resultType, {shift}); in genIshftc()
3178 auto elseSize = builder.create<mlir::arith::SubIOp>(loc, size, absShift); in genIshftc()
3179 auto shiftIsZero = builder.create<mlir::arith::CmpIOp>( in genIshftc()
3180 loc, mlir::arith::CmpIPredicate::eq, shift, zero); in genIshftc()
3181 auto shiftEqualsSize = builder.create<mlir::arith::CmpIOp>( in genIshftc()
3182 loc, mlir::arith::CmpIPredicate::eq, absShift, size); in genIshftc()
3184 builder.create<mlir::arith::OrIOp>(loc, shiftIsZero, shiftEqualsSize); in genIshftc()
3185 auto shiftIsPositive = builder.create<mlir::arith::CmpIOp>( in genIshftc()
3186 loc, mlir::arith::CmpIPredicate::sgt, shift, zero); in genIshftc()
3187 auto leftSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, in genIshftc()
3189 auto rightSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, in genIshftc()
3191 auto hasUnchanged = builder.create<mlir::arith::CmpIOp>( in genIshftc()
3192 loc, mlir::arith::CmpIPredicate::ne, size, bitSize); in genIshftc()
3193 auto unchangedTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, I, size); in genIshftc()
3195 builder.create<mlir::arith::ShLIOp>(loc, unchangedTmp1, size); in genIshftc()
3196 auto unchanged = builder.create<mlir::arith::SelectOp>(loc, hasUnchanged, in genIshftc()
3199 builder.create<mlir::arith::SubIOp>(loc, bitSize, leftSize); in genIshftc()
3201 builder.create<mlir::arith::ShRUIOp>(loc, ones, leftMaskShift); in genIshftc()
3202 auto leftTmp = builder.create<mlir::arith::ShRUIOp>(loc, I, rightSize); in genIshftc()
3203 auto left = builder.create<mlir::arith::AndIOp>(loc, leftTmp, leftMask); in genIshftc()
3205 builder.create<mlir::arith::SubIOp>(loc, bitSize, rightSize); in genIshftc()
3207 builder.create<mlir::arith::ShRUIOp>(loc, ones, rightMaskShift); in genIshftc()
3208 auto rightTmp = builder.create<mlir::arith::AndIOp>(loc, I, rightMask); in genIshftc()
3209 auto right = builder.create<mlir::arith::ShLIOp>(loc, rightTmp, leftSize); in genIshftc()
3210 auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, left); in genIshftc()
3211 auto res = builder.create<mlir::arith::OrIOp>(loc, resTmp, right); in genIshftc()
3212 return builder.create<mlir::arith::SelectOp>(loc, shiftIsNop, I, res); in genIshftc()
3216 mlir::Value IntrinsicLibrary::genLeadz(mlir::Type resultType, in genLeadz()
3217 llvm::ArrayRef<mlir::Value> args) { in genLeadz()
3220 mlir::Value result = in genLeadz()
3221 builder.create<mlir::math::CountLeadingZerosOp>(loc, args); in genLeadz()
3230 IntrinsicLibrary::genLen(mlir::Type resultType, in genLen()
3234 mlir::Value len = fir::factory::readCharLen(builder, loc, args[0]); in genLen()
3240 IntrinsicLibrary::genLenTrim(mlir::Type resultType, in genLenTrim()
3253 template <mlir::arith::CmpIPredicate pred>
3255 IntrinsicLibrary::genCharacterCompare(mlir::Type resultType, in genCharacterCompare()
3265 mlir::Value IntrinsicLibrary::genMask(mlir::Type resultType, in genMask()
3266 llvm::ArrayRef<mlir::Value> args) { in genMask()
3269 mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); in genMask()
3270 mlir::Value bitSize = builder.createIntegerConstant( in genMask()
3272 mlir::Value bitsToSet = builder.createConvert(loc, resultType, args[0]); in genMask()
3279 mlir::Value shift = in genMask()
3280 builder.create<mlir::arith::SubIOp>(loc, bitSize, bitsToSet); in genMask()
3286 IntrinsicLibrary::genMatmul(mlir::Type resultType, in genMatmul()
3292 mlir::Value matrixA = fir::getBase(matrixTmpA); in genMatmul()
3294 mlir::Value matrixB = fir::getBase(matrixTmpB); in genMatmul()
3299 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, resultRank); in genMatmul()
3302 mlir::Value resultIrBox = in genMatmul()
3314 IntrinsicLibrary::genMerge(mlir::Type, in genMerge()
3317 mlir::Value tsource = fir::getBase(args[0]); in genMerge()
3318 mlir::Value fsource = fir::getBase(args[1]); in genMerge()
3319 mlir::Value rawMask = fir::getBase(args[2]); in genMerge()
3320 mlir::Type type0 = fir::unwrapRefType(tsource.getType()); in genMerge()
3322 mlir::Value mask = builder.createConvert(loc, builder.getI1Type(), rawMask); in genMerge()
3327 mlir::Value fsourceCast = in genMerge()
3330 builder.create<mlir::arith::SelectOp>(loc, mask, tsource, fsourceCast); in genMerge()
3341 mlir::Value IntrinsicLibrary::genMergeBits(mlir::Type resultType, in genMergeBits()
3342 llvm::ArrayRef<mlir::Value> args) { in genMergeBits()
3345 mlir::Value i = builder.createConvert(loc, resultType, args[0]); in genMergeBits()
3346 mlir::Value j = builder.createConvert(loc, resultType, args[1]); in genMergeBits()
3347 mlir::Value mask = builder.createConvert(loc, resultType, args[2]); in genMergeBits()
3348 mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); in genMergeBits()
3351 mlir::Value notMask = builder.create<mlir::arith::XOrIOp>(loc, mask, ones); in genMergeBits()
3352 mlir::Value lft = builder.create<mlir::arith::AndIOp>(loc, i, mask); in genMergeBits()
3353 mlir::Value rgt = builder.create<mlir::arith::AndIOp>(loc, j, notMask); in genMergeBits()
3355 return builder.create<mlir::arith::OrIOp>(loc, lft, rgt); in genMergeBits()
3359 mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, in genMod()
3360 llvm::ArrayRef<mlir::Value> args) { in genMod()
3362 if (resultType.isa<mlir::IntegerType>()) in genMod()
3363 return builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); in genMod()
3373 mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, in genModulo()
3374 llvm::ArrayRef<mlir::Value> args) { in genModulo()
3384 if (resultType.isa<mlir::IntegerType>()) { in genModulo()
3386 builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); in genModulo()
3387 auto argXor = builder.create<mlir::arith::XOrIOp>(loc, args[0], args[1]); in genModulo()
3388 mlir::Value zero = builder.createIntegerConstant(loc, argXor.getType(), 0); in genModulo()
3389 auto argSignDifferent = builder.create<mlir::arith::CmpIOp>( in genModulo()
3390 loc, mlir::arith::CmpIPredicate::slt, argXor, zero); in genModulo()
3391 auto remainderIsNotZero = builder.create<mlir::arith::CmpIOp>( in genModulo()
3392 loc, mlir::arith::CmpIPredicate::ne, remainder, zero); in genModulo()
3393 auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, in genModulo()
3396 builder.create<mlir::arith::AddIOp>(loc, remainder, args[1]); in genModulo()
3397 return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, in genModulo()
3401 auto remainder = builder.create<mlir::arith::RemFOp>(loc, args[0], args[1]); in genModulo()
3402 mlir::Value zero = builder.createRealZeroConstant(loc, remainder.getType()); in genModulo()
3403 auto remainderIsNotZero = builder.create<mlir::arith::CmpFOp>( in genModulo()
3404 loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); in genModulo()
3405 auto aLessThanZero = builder.create<mlir::arith::CmpFOp>( in genModulo()
3406 loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); in genModulo()
3407 auto pLessThanZero = builder.create<mlir::arith::CmpFOp>( in genModulo()
3408 loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); in genModulo()
3410 builder.create<mlir::arith::XOrIOp>(loc, aLessThanZero, pLessThanZero); in genModulo()
3411 auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, in genModulo()
3413 auto remPlusP = builder.create<mlir::arith::AddFOp>(loc, remainder, args[1]); in genModulo()
3414 return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, in genModulo()
3431 const mlir::Value *arg = exv.getUnboxed(); in genMvbits()
3435 mlir::Value from = unbox(args[0]); in genMvbits()
3436 mlir::Type resultType = from.getType(); in genMvbits()
3437 mlir::Value frompos = builder.createConvert(loc, resultType, unbox(args[1])); in genMvbits()
3438 mlir::Value len = builder.createConvert(loc, resultType, unbox(args[2])); in genMvbits()
3439 mlir::Value toAddr = unbox(args[3]); in genMvbits()
3443 mlir::Value topos = builder.createConvert(loc, resultType, unbox(args[4])); in genMvbits()
3444 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genMvbits()
3445 mlir::Value ones = builder.createIntegerConstant(loc, resultType, -1); in genMvbits()
3446 mlir::Value bitSize = builder.createIntegerConstant( in genMvbits()
3447 loc, resultType, resultType.cast<mlir::IntegerType>().getWidth()); in genMvbits()
3448 auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len); in genMvbits()
3449 auto mask = builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); in genMvbits()
3450 auto unchangedTmp1 = builder.create<mlir::arith::ShLIOp>(loc, mask, topos); in genMvbits()
3452 builder.create<mlir::arith::XOrIOp>(loc, unchangedTmp1, ones); in genMvbits()
3453 auto unchanged = builder.create<mlir::arith::AndIOp>(loc, unchangedTmp2, to); in genMvbits()
3454 auto frombitsTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, from, frompos); in genMvbits()
3456 builder.create<mlir::arith::AndIOp>(loc, frombitsTmp1, mask); in genMvbits()
3457 auto frombits = builder.create<mlir::arith::ShLIOp>(loc, frombitsTmp2, topos); in genMvbits()
3458 auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, frombits); in genMvbits()
3459 auto lenIsZero = builder.create<mlir::arith::CmpIOp>( in genMvbits()
3460 loc, mlir::arith::CmpIPredicate::eq, len, zero); in genMvbits()
3461 auto res = builder.create<mlir::arith::SelectOp>(loc, lenIsZero, to, resTmp); in genMvbits()
3466 mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, in genNearest()
3467 llvm::ArrayRef<mlir::Value> args) { in genNearest()
3470 mlir::Value realX = fir::getBase(args[0]); in genNearest()
3471 mlir::Value realS = fir::getBase(args[1]); in genNearest()
3478 mlir::Value IntrinsicLibrary::genNint(mlir::Type resultType, in genNint()
3479 llvm::ArrayRef<mlir::Value> args) { in genNint()
3487 mlir::Value IntrinsicLibrary::genNot(mlir::Type resultType, in genNot()
3488 llvm::ArrayRef<mlir::Value> args) { in genNot()
3490 mlir::Value allOnes = builder.createIntegerConstant(loc, resultType, -1); in genNot()
3491 return builder.create<mlir::arith::XOrIOp>(loc, args[0], allOnes); in genNot()
3496 IntrinsicLibrary::genNull(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { in genNull()
3504 mlir::Value boxStorage = builder.createTemporary(loc, boxType); in genNull()
3505 mlir::Value box = fir::factory::createUnallocatedBox( in genNull()
3513 IntrinsicLibrary::genPack(mlir::Type resultType, in genPack()
3519 mlir::Value array = builder.createBox(loc, args[0]); in genPack()
3522 mlir::Value mask = builder.createBox(loc, args[1]); in genPack()
3525 mlir::Value vector = isStaticallyAbsent(args, 2) in genPack()
3531 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, 1); in genPack()
3534 mlir::Value resultIrBox = in genPack()
3544 mlir::Value IntrinsicLibrary::genPopcnt(mlir::Type resultType, in genPopcnt()
3545 llvm::ArrayRef<mlir::Value> args) { in genPopcnt()
3548 mlir::Value count = builder.create<mlir::math::CtPopOp>(loc, args); in genPopcnt()
3554 mlir::Value IntrinsicLibrary::genPoppar(mlir::Type resultType, in genPoppar()
3555 llvm::ArrayRef<mlir::Value> args) { in genPoppar()
3558 mlir::Value count = genPopcnt(resultType, args); in genPoppar()
3559 mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); in genPoppar()
3561 return builder.create<mlir::arith::AndIOp>(loc, count, one); in genPoppar()
3566 IntrinsicLibrary::genPresent(mlir::Type, in genPresent()
3575 IntrinsicLibrary::genProduct(mlir::Type resultType, in genProduct()
3604 Fortran::lower::genRandomSeed(builder, loc, -1, mlir::Value{}); in genRandomSeed()
3609 IntrinsicLibrary::genRepeat(mlir::Type resultType, in genRepeat()
3612 mlir::Value string = builder.createBox(loc, args[0]); in genRepeat()
3613 mlir::Value ncopies = fir::getBase(args[1]); in genRepeat()
3617 mlir::Value resultIrBox = in genRepeat()
3628 IntrinsicLibrary::genReshape(mlir::Type resultType, in genReshape()
3633 mlir::Value source = builder.createBox(loc, args[0]); in genReshape()
3636 mlir::Value shape = builder.createBox(loc, args[1]); in genReshape()
3638 mlir::Type shapeTy = shape.getType(); in genReshape()
3639 mlir::Type shapeArrTy = fir::dyn_cast_ptrOrBoxEleTy(shapeTy); in genReshape()
3646 mlir::Value pad = isStaticallyAbsent(args[2]) in genReshape()
3652 mlir::Value order = isStaticallyAbsent(args[3]) in genReshape()
3658 mlir::Type type = builder.getVarLenSeqTy(resultType, resultRank); in genReshape()
3662 mlir::Value resultIrBox = in genReshape()
3673 mlir::Value IntrinsicLibrary::genRRSpacing(mlir::Type resultType, in genRRSpacing()
3674 llvm::ArrayRef<mlir::Value> args) { in genRRSpacing()
3683 mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType, in genScale()
3684 llvm::ArrayRef<mlir::Value> args) { in genScale()
3687 mlir::Value realX = fir::getBase(args[0]); in genScale()
3688 mlir::Value intI = fir::getBase(args[1]); in genScale()
3696 IntrinsicLibrary::genScan(mlir::Type resultType, in genScan()
3706 mlir::Value stringBase = fir::getBase(args[0]); in genScan()
3709 mlir::Value setBase = fir::getBase(args[1]); in genScan()
3717 mlir::Value stringLen = fir::getLen(args[0]); in genScan()
3720 mlir::Value setLen = fir::getLen(args[1]); in genScan()
3723 mlir::Value back = in genScan()
3736 auto makeRefThenEmbox = [&](mlir::Value b) { in genScan()
3739 mlir::Value temp = builder.createTemporary(loc, logTy); in genScan()
3740 mlir::Value castb = builder.createConvert(loc, logTy, b); in genScan()
3744 mlir::Value back = fir::isUnboxedValue(args[2]) in genScan()
3750 mlir::Value string = builder.createBox(loc, args[0]); in genScan()
3753 mlir::Value set = builder.createBox(loc, args[1]); in genScan()
3756 mlir::Value kind = fir::getBase(args[3]); in genScan()
3761 mlir::Value resultIrBox = in genScan()
3772 mlir::Value
3773 IntrinsicLibrary::genSelectedIntKind(mlir::Type resultType, in genSelectedIntKind()
3774 llvm::ArrayRef<mlir::Value> args) { in genSelectedIntKind()
3783 mlir::Value
3784 IntrinsicLibrary::genSelectedRealKind(mlir::Type resultType, in genSelectedRealKind()
3785 llvm::ArrayRef<mlir::Value> args) { in genSelectedRealKind()
3789 mlir::Value precision = in genSelectedRealKind()
3796 mlir::Value range = in genSelectedRealKind()
3803 mlir::Value radix = in genSelectedRealKind()
3815 mlir::Value IntrinsicLibrary::genSetExponent(mlir::Type resultType, in genSetExponent()
3816 llvm::ArrayRef<mlir::Value> args) { in genSetExponent()
3827 mlir::Value IntrinsicLibrary::genShift(mlir::Type resultType, in genShift()
3828 llvm::ArrayRef<mlir::Value> args) { in genShift()
3836 mlir::Value bitSize = builder.createIntegerConstant(loc, resultType, bits); in genShift()
3837 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genShift()
3838 mlir::Value shift = builder.createConvert(loc, resultType, args[1]); in genShift()
3840 mlir::Value tooSmall = builder.create<mlir::arith::CmpIOp>( in genShift()
3841 loc, mlir::arith::CmpIPredicate::slt, shift, zero); in genShift()
3842 mlir::Value tooLarge = builder.create<mlir::arith::CmpIOp>( in genShift()
3843 loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); in genShift()
3844 mlir::Value outOfBounds = in genShift()
3845 builder.create<mlir::arith::OrIOp>(loc, tooSmall, tooLarge); in genShift()
3847 mlir::Value shifted = builder.create<Shift>(loc, args[0], shift); in genShift()
3848 return builder.create<mlir::arith::SelectOp>(loc, outOfBounds, zero, shifted); in genShift()
3852 mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, in genSign()
3853 llvm::ArrayRef<mlir::Value> args) { in genSign()
3855 if (resultType.isa<mlir::IntegerType>()) { in genSign()
3856 mlir::Value abs = genAbs(resultType, {args[0]}); in genSign()
3857 mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); in genSign()
3858 auto neg = builder.create<mlir::arith::SubIOp>(loc, zero, abs); in genSign()
3859 auto cmp = builder.create<mlir::arith::CmpIOp>( in genSign()
3860 loc, mlir::arith::CmpIPredicate::slt, args[1], zero); in genSign()
3861 return builder.create<mlir::arith::SelectOp>(loc, cmp, neg, abs); in genSign()
3868 IntrinsicLibrary::genSize(mlir::Type resultType, in genSize()
3878 mlir::Value array = builder.createBox(loc, args[0]); in genSize()
3888 mlir::Value dim = fir::getBase(args[1]); in genSize()
3893 mlir::Value isDynamicallyAbsent = builder.genIsNullAddr(loc, dim); in genSize()
3898 mlir::Value size = builder.createConvert( in genSize()
3903 mlir::Value dimValue = builder.create<fir::LoadOp>(loc, dim); in genSize()
3904 mlir::Value size = builder.createConvert( in genSize()
3913 mlir::Value IntrinsicLibrary::genTrailz(mlir::Type resultType, in genTrailz()
3914 llvm::ArrayRef<mlir::Value> args) { in genTrailz()
3917 mlir::Value result = in genTrailz()
3918 builder.create<mlir::math::CountTrailingZerosOp>(loc, args); in genTrailz()
3935 static mlir::Value computeLBOUND(fir::FirOpBuilder &builder, mlir::Location loc, in computeLBOUND()
3937 mlir::Value zero, mlir::Value one) { in computeLBOUND()
3941 mlir::Value lb = fir::factory::readLowerBound(builder, loc, array, dim, one); in computeLBOUND()
3944 mlir::Value extent = fir::factory::readExtent(builder, loc, array, dim); in computeLBOUND()
3946 auto dimIsEmpty = builder.create<mlir::arith::CmpIOp>( in computeLBOUND()
3947 loc, mlir::arith::CmpIPredicate::eq, extent, zero); in computeLBOUND()
3949 return builder.create<mlir::arith::SelectOp>(loc, dimIsEmpty, one, lb); in computeLBOUND()
3956 static mlir::Value createBoxForLBOUND(mlir::Location loc, in createBoxForLBOUND()
3961 [&](const fir::BoxValue &boxValue) -> mlir::Value { in createBoxForLBOUND()
3965 mlir::Value localShape = builder.createShape(loc, array); in createBoxForLBOUND()
3966 mlir::Value oldBox = boxValue.getAddr(); in createBoxForLBOUND()
3969 /*slice=*/mlir::Value{}); in createBoxForLBOUND()
3971 [&](const auto &) -> mlir::Value { in createBoxForLBOUND()
3984 llvm::SmallVector<mlir::Value> shape = in createBoxForLBOUND()
4004 IntrinsicLibrary::genLbound(mlir::Type resultType, in genLbound()
4013 mlir::Type indexType = builder.getIndexType(); in genLbound()
4019 mlir::Type lbType = fir::unwrapSequenceType(resultType); in genLbound()
4021 mlir::Type lbArrayType = fir::SequenceType::get( in genLbound()
4023 mlir::Value lbArray = builder.createTemporary(loc, lbArrayType); in genLbound()
4024 mlir::Type lbAddrType = builder.getRefType(lbType); in genLbound()
4025 mlir::Value one = builder.createIntegerConstant(loc, lbType, 1); in genLbound()
4026 mlir::Value zero = builder.createIntegerConstant(loc, indexType, 0); in genLbound()
4028 mlir::Value lb = computeLBOUND(builder, loc, array, dim, zero, one); in genLbound()
4035 mlir::Value lbArrayExtent = in genLbound()
4037 llvm::SmallVector<mlir::Value> extents{lbArrayExtent}; in genLbound()
4041 mlir::Value dim = fir::getBase(args[1]); in genLbound()
4046 mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); in genLbound()
4047 mlir::Value zero = builder.createIntegerConstant(loc, indexType, 0); in genLbound()
4048 mlir::Value lb = computeLBOUND(builder, loc, array, *cstDim - 1, zero, one); in genLbound()
4060 IntrinsicLibrary::genUbound(mlir::Type resultType, in genUbound()
4065 mlir::Value extent = fir::getBase(genSize(resultType, args)); in genUbound()
4066 mlir::Value lbound = fir::getBase(genLbound(resultType, args)); in genUbound()
4068 mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); in genUbound()
4069 mlir::Value ubound = builder.create<mlir::arith::SubIOp>(loc, lbound, one); in genUbound()
4070 return builder.create<mlir::arith::AddIOp>(loc, ubound, extent); in genUbound()
4073 mlir::Value kind = isStaticallyAbsent(args[1]) in genUbound()
4080 mlir::Type type = builder.getVarLenSeqTy(resultType, /*rank=*/1); in genUbound()
4083 mlir::Value resultIrBox = in genUbound()
4091 return mlir::Value(); in genUbound()
4095 mlir::Value IntrinsicLibrary::genSpacing(mlir::Type resultType, in genSpacing()
4096 llvm::ArrayRef<mlir::Value> args) { in genSpacing()
4106 IntrinsicLibrary::genSpread(mlir::Type resultType, in genSpread()
4112 mlir::Value source = builder.createBox(loc, args[0]); in genSpread()
4117 mlir::Value dim = fir::getBase(args[1]); in genSpread()
4120 mlir::Value ncopies = fir::getBase(args[2]); in genSpread()
4123 mlir::Type resultArrayType = in genSpread()
4127 mlir::Value resultIrBox = in genSpread()
4138 IntrinsicLibrary::genSum(mlir::Type resultType, in genSum()
4153 IntrinsicLibrary::genTransfer(mlir::Type resultType, in genTransfer()
4159 mlir::Value source = builder.createBox(loc, args[0]); in genTransfer()
4162 mlir::Value mold = builder.createBox(loc, args[1]); in genTransfer()
4169 mlir::Type type = (moldRank == 0 && absentSize) in genTransfer()
4177 mlir::Value resultIrBox = in genTransfer()
4183 mlir::Value resultIrBox = in genTransfer()
4189 mlir::Value sizeArg = fir::getBase(args[2]); in genTransfer()
4200 IntrinsicLibrary::genTranspose(mlir::Type resultType, in genTranspose()
4206 mlir::Value source = builder.createBox(loc, args[0]); in genTranspose()
4209 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, 2); in genTranspose()
4212 mlir::Value resultIrBox = in genTranspose()
4224 IntrinsicLibrary::genTrim(mlir::Type resultType, in genTrim()
4227 mlir::Value string = builder.createBox(loc, args[0]); in genTrim()
4231 mlir::Value resultIrBox = in genTrim()
4242 static mlir::Value createExtremumCompare(mlir::Location loc, in createExtremumCompare()
4244 mlir::Value left, mlir::Value right) { in createExtremumCompare()
4245 static constexpr mlir::arith::CmpIPredicate integerPredicate = in createExtremumCompare()
4246 extremum == Extremum::Max ? mlir::arith::CmpIPredicate::sgt in createExtremumCompare()
4247 : mlir::arith::CmpIPredicate::slt; in createExtremumCompare()
4248 static constexpr mlir::arith::CmpFPredicate orderedCmp = in createExtremumCompare()
4249 extremum == Extremum::Max ? mlir::arith::CmpFPredicate::OGT in createExtremumCompare()
4250 : mlir::arith::CmpFPredicate::OLT; in createExtremumCompare()
4251 mlir::Type type = left.getType(); in createExtremumCompare()
4252 mlir::Value result; in createExtremumCompare()
4260 builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); in createExtremumCompare()
4261 auto rightIsNan = builder.create<mlir::arith::CmpFOp>( in createExtremumCompare()
4262 loc, mlir::arith::CmpFPredicate::UNE, right, right); in createExtremumCompare()
4264 builder.create<mlir::arith::OrIOp>(loc, leftIsResult, rightIsNan); in createExtremumCompare()
4268 builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); in createExtremumCompare()
4269 auto leftIsNan = builder.create<mlir::arith::CmpFOp>( in createExtremumCompare()
4270 loc, mlir::arith::CmpFPredicate::UNE, left, left); in createExtremumCompare()
4271 result = builder.create<mlir::arith::OrIOp>(loc, leftIsResult, leftIsNan); in createExtremumCompare()
4275 builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); in createExtremumCompare()
4279 extremum == Extremum::Max ? mlir::arith::CmpFPredicate::UGT in createExtremumCompare()
4280 : mlir::arith::CmpFPredicate::ULT; in createExtremumCompare()
4282 builder.create<mlir::arith::CmpFOp>(loc, unorderedCmp, left, right); in createExtremumCompare()
4290 builder.create<mlir::arith::CmpIOp>(loc, integerPredicate, left, right); in createExtremumCompare()
4303 IntrinsicLibrary::genUnpack(mlir::Type resultType, in genUnpack()
4308 mlir::Value vector = builder.createBox(loc, args[0]); in genUnpack()
4312 mlir::Value mask = fir::getBase(maskBox); in genUnpack()
4316 mlir::Value field = builder.createBox(loc, args[2]); in genUnpack()
4319 mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, maskRank); in genUnpack()
4322 mlir::Value resultIrBox = in genUnpack()
4333 IntrinsicLibrary::genVerify(mlir::Type resultType, in genVerify()
4343 mlir::Value stringBase = fir::getBase(args[0]); in genVerify()
4346 mlir::Value setBase = fir::getBase(args[1]); in genVerify()
4354 mlir::Value stringLen = fir::getLen(args[0]); in genVerify()
4357 mlir::Value setLen = fir::getLen(args[1]); in genVerify()
4360 mlir::Value back = in genVerify()
4373 auto makeRefThenEmbox = [&](mlir::Value b) { in genVerify()
4376 mlir::Value temp = builder.createTemporary(loc, logTy); in genVerify()
4377 mlir::Value castb = builder.createConvert(loc, logTy, b); in genVerify()
4381 mlir::Value back = fir::isUnboxedValue(args[2]) in genVerify()
4387 mlir::Value string = builder.createBox(loc, args[0]); in genVerify()
4390 mlir::Value set = builder.createBox(loc, args[1]); in genVerify()
4393 mlir::Value kind = fir::getBase(args[3]); in genVerify()
4398 mlir::Value resultIrBox = in genVerify()
4410 IntrinsicLibrary::genMaxloc(mlir::Type resultType, in genMaxloc()
4419 IntrinsicLibrary::genMaxval(mlir::Type resultType, in genMaxval()
4428 IntrinsicLibrary::genMinloc(mlir::Type resultType, in genMinloc()
4437 IntrinsicLibrary::genMinval(mlir::Type resultType, in genMinval()
4446 mlir::Value IntrinsicLibrary::genExtremum(mlir::Type, in genExtremum()
4447 llvm::ArrayRef<mlir::Value> args) { in genExtremum()
4449 mlir::Value result = args[0]; in genExtremum()
4451 mlir::Value mask = in genExtremum()
4453 result = builder.create<mlir::arith::SelectOp>(loc, mask, result, arg); in genExtremum()
4485 Fortran::lower::genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc, in genIntrinsicCall()
4487 llvm::Optional<mlir::Type> resultType, in genIntrinsicCall()
4494 mlir::Value Fortran::lower::genMax(fir::FirOpBuilder &builder, in genMax()
4495 mlir::Location loc, in genMax()
4496 llvm::ArrayRef<mlir::Value> args) { in genMax()
4503 mlir::Value Fortran::lower::genMin(fir::FirOpBuilder &builder, in genMin()
4504 mlir::Location loc, in genMin()
4505 llvm::ArrayRef<mlir::Value> args) { in genMin()
4512 mlir::Value Fortran::lower::genPow(fir::FirOpBuilder &builder, in genPow()
4513 mlir::Location loc, mlir::Type type, in genPow()
4514 mlir::Value x, mlir::Value y) { in genPow()
4525 mlir::SymbolRefAttr Fortran::lower::getUnrestrictedIntrinsicSymbolRefAttr( in getUnrestrictedIntrinsicSymbolRefAttr()
4526 fir::FirOpBuilder &builder, mlir::Location loc, llvm::StringRef name, in getUnrestrictedIntrinsicSymbolRefAttr()
4527 mlir::FunctionType signature) { in getUnrestrictedIntrinsicSymbolRefAttr()