diff options
Diffstat (limited to 'flang/lib/Optimizer/Builder/IntrinsicCall.cpp')
-rw-r--r-- | flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 1739 |
1 files changed, 914 insertions, 825 deletions
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index d77a656..4753d0a 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -246,6 +246,7 @@ static constexpr IntrinsicHandler handlers[]{ {"abs", &I::genAbs}, {"achar", &I::genChar}, {"acosd", &I::genAcosd}, + {"acospi", &I::genAcospi}, {"adjustl", &I::genAdjustRtCall<fir::runtime::genAdjustL>, {{{"string", asAddr}}}, @@ -278,6 +279,7 @@ static constexpr IntrinsicHandler handlers[]{ {{{"mask", asValue}, {"pred", asValue}}}, /*isElemental=*/false}, {"asind", &I::genAsind}, + {"asinpi", &I::genAsinpi}, {"associated", &I::genAssociated, {{{"pointer", asInquired}, {"target", asInquired}}}, @@ -901,6 +903,7 @@ static constexpr IntrinsicHandler handlers[]{ {{{"number", asValue}, {"handler", asAddr}, {"status", asAddr}}}, /*isElemental=*/false}, {"sind", &I::genSind}, + {"sinpi", &I::genSinpi}, {"size", &I::genSize, {{{"array", asBox}, @@ -941,6 +944,7 @@ static constexpr IntrinsicHandler handlers[]{ {{{"count", asAddr}, {"count_rate", asAddr}, {"count_max", asAddr}}}, /*isElemental=*/false}, {"tand", &I::genTand}, + {"tanpi", &I::genTanpi}, {"this_grid", &I::genThisGrid, {}, /*isElemental=*/false}, {"this_thread_block", &I::genThisThreadBlock, {}, /*isElemental=*/false}, {"this_warp", &I::genThisWarp, {}, /*isElemental=*/false}, @@ -1110,7 +1114,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, // was just created from user functions with the same name. funcOp->setAttr(fir::FIROpsDialect::getFirRuntimeAttrName(), builder.getUnitAttr()); - auto libCall = builder.create<fir::CallOp>(loc, funcOp, args); + auto libCall = fir::CallOp::create(builder, loc, funcOp, args); // TODO: ensure 'strictfp' setting on the call for "precise/strict" // FP mode. Set appropriate Fast-Math Flags otherwise. // TODO: we should also mark as many libm function as possible @@ -1124,7 +1128,7 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type soughtFuncType = funcOp.getFunctionType(); if (soughtFuncType == libFuncType) { - libCall = builder.create<fir::CallOp>(loc, funcOp, args); + libCall = fir::CallOp::create(builder, loc, funcOp, args); } else { // A function with the same name might have been declared // before (e.g. with an explicit interface and a binding label). @@ -1138,13 +1142,13 @@ mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, llvm::Twine("' may lead to undefined behavior."))); mlir::SymbolRefAttr funcSymbolAttr = builder.getSymbolRefAttr(libFuncName); mlir::Value funcPointer = - builder.create<fir::AddrOfOp>(loc, soughtFuncType, funcSymbolAttr); + fir::AddrOfOp::create(builder, loc, soughtFuncType, funcSymbolAttr); funcPointer = builder.createConvert(loc, libFuncType, funcPointer); llvm::SmallVector<mlir::Value, 3> operands{funcPointer}; operands.append(args.begin(), args.end()); - libCall = builder.create<fir::CallOp>(loc, mlir::SymbolRefAttr{}, - libFuncType.getResults(), operands); + libCall = fir::CallOp::create(builder, loc, mlir::SymbolRefAttr{}, + libFuncType.getResults(), operands); } LLVM_DEBUG(libCall.dump(); llvm::dbgs() << "\n"); @@ -1220,7 +1224,7 @@ mlir::Value genMathOp(fir::FirOpBuilder &builder, mlir::Location loc, LLVM_DEBUG(llvm::dbgs() << "Generating '" << mathLibFuncName << "' operation with type "; mathLibFuncType.dump(); llvm::dbgs() << "\n"); - result = builder.create<T>(loc, args); + result = T::create(builder, loc, args); } LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n"); return result; @@ -1258,12 +1262,12 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc, // the argument types for an operation if constexpr (T::template hasTrait< mlir::OpTrait::SameOperandsAndResultType>()) { - result = builder.create<T>(loc, args); + result = T::create(builder, loc, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } else { auto complexTy = mlir::cast<mlir::ComplexType>(mathLibFuncType.getInput(0)); auto realTy = complexTy.getElementType(); - result = builder.create<T>(loc, realTy, args); + result = T::create(builder, loc, realTy, args); result = builder.createConvert(loc, mathLibFuncType.getResult(0), result); } @@ -2461,7 +2465,7 @@ IntrinsicLibrary::outlineInWrapper(GeneratorType generator, nameOS << '.' << fmfString; } mlir::func::FuncOp wrapper = getWrapper(generator, funcName, funcType); - return builder.create<fir::CallOp>(loc, wrapper, args).getResult(0); + return fir::CallOp::create(builder, loc, wrapper, args).getResult(0); } template <typename GeneratorType> @@ -2477,7 +2481,7 @@ fir::ExtendedValue IntrinsicLibrary::outlineInExtendedWrapper( mlirArgs.emplace_back(toValue(extendedVal, builder, loc)); mlir::FunctionType funcType = getFunctionType(resultType, mlirArgs, builder); mlir::func::FuncOp wrapper = getWrapper(generator, name, funcType); - auto call = builder.create<fir::CallOp>(loc, wrapper, mlirArgs); + auto call = fir::CallOp::create(builder, loc, wrapper, mlirArgs); if (resultType) return toExtendedValue(call.getResult(0), builder, loc); // Subroutine calls @@ -2595,9 +2599,9 @@ IntrinsicLibrary::readAndAddCleanUp(fir::MutableBoxValue resultMutableBox, return box; }, [&](const mlir::Value &tempAddr) -> fir::ExtendedValue { - auto load = builder.create<fir::LoadOp>(loc, resultType, tempAddr); + auto load = fir::LoadOp::create(builder, loc, resultType, tempAddr); // Temp can be freed right away since it was loaded. - builder.create<fir::FreeMemOp>(loc, tempAddr); + fir::FreeMemOp::create(builder, loc, tempAddr); return load; }, [&](const fir::CharBoxValue &box) -> fir::ExtendedValue { @@ -2650,9 +2654,9 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType, // So, implement abs here without branching. mlir::Value shift = builder.createIntegerConstant(loc, intType, intType.getWidth() - 1); - auto mask = builder.create<mlir::arith::ShRSIOp>(loc, arg, shift); - auto xored = builder.create<mlir::arith::XOrIOp>(loc, arg, mask); - return builder.create<mlir::arith::SubIOp>(loc, xored, mask); + auto mask = mlir::arith::ShRSIOp::create(builder, loc, arg, shift); + auto xored = mlir::arith::XOrIOp::create(builder, loc, arg, mask); + return mlir::arith::SubIOp::create(builder, loc, xored, mask); } llvm_unreachable("unexpected type in ABS argument"); } @@ -2671,7 +2675,22 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create<mlir::arith::MulFOp>(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); +} + +// ACOSPI +mlir::Value IntrinsicLibrary::genAcospi(mlir::Type resultType, + llvm::ArrayRef<mlir::Value> args) { + assert(args.size() == 1); + mlir::MLIRContext *context = builder.getContext(); + mlir::FunctionType ftype = + mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); + mlir::Value acos = getRuntimeCallGenerator("acos", ftype)(builder, loc, args); + llvm::APFloat inv_pi = llvm::APFloat(llvm::numbers::inv_pi); + mlir::Value dfactor = + builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi); + mlir::Value factor = builder.createConvert(loc, resultType, dfactor); + return mlir::arith::MulFOp::create(builder, loc, acos, factor); } // ADJUSTL & ADJUSTR @@ -2824,7 +2843,22 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - return builder.create<mlir::arith::MulFOp>(loc, result, factor); + return mlir::arith::MulFOp::create(builder, loc, result, factor); +} + +// ASINPI +mlir::Value IntrinsicLibrary::genAsinpi(mlir::Type resultType, + llvm::ArrayRef<mlir::Value> args) { + assert(args.size() == 1); + mlir::MLIRContext *context = builder.getContext(); + mlir::FunctionType ftype = + mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); + mlir::Value asin = getRuntimeCallGenerator("asin", ftype)(builder, loc, args); + llvm::APFloat inv_pi = llvm::APFloat(llvm::numbers::inv_pi); + mlir::Value dfactor = + builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi); + mlir::Value factor = builder.createConvert(loc, resultType, dfactor); + return mlir::arith::MulFOp::create(builder, loc, asin, factor); } // ATAND, ATAN2D @@ -2838,8 +2872,8 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, // atand = atan * 180/pi if (args.size() == 2) { - atan = builder.create<mlir::math::Atan2Op>(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2849,7 +2883,7 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create<mlir::arith::MulFOp>(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } // ATANPI, ATAN2PI @@ -2863,8 +2897,8 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, // atanpi = atan / pi if (args.size() == 2) { - atan = builder.create<mlir::math::Atan2Op>(loc, fir::getBase(args[0]), - fir::getBase(args[1])); + atan = mlir::math::Atan2Op::create(builder, loc, fir::getBase(args[0]), + fir::getBase(args[1])); } else { mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); @@ -2874,7 +2908,7 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi); mlir::Value factor = builder.createConvert(loc, resultType, dfactor); - return builder.create<mlir::arith::MulFOp>(loc, atan, factor); + return mlir::arith::MulFOp::create(builder, loc, atan, factor); } static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, @@ -2882,8 +2916,8 @@ static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, mlir::Value arg1) { auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); arg0 = builder.createConvert(loc, llvmPointerType, arg0); - return builder.create<mlir::LLVM::AtomicRMWOp>( - loc, binOp, arg0, arg1, mlir::LLVM::AtomicOrdering::seq_cst); + return mlir::LLVM::AtomicRMWOp::create(builder, loc, binOp, arg0, arg1, + mlir::LLVM::AtomicOrdering::seq_cst); } mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType, @@ -2941,11 +2975,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, auto bitCastFloat = [&](mlir::Value arg) -> mlir::Value { if (mlir::isa<mlir::Float32Type>(arg.getType())) - return builder.create<mlir::LLVM::BitcastOp>(loc, builder.getI32Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI32Type(), + arg); if (mlir::isa<mlir::Float64Type>(arg.getType())) - return builder.create<mlir::LLVM::BitcastOp>(loc, builder.getI64Type(), - arg); + return mlir::LLVM::BitcastOp::create(builder, loc, builder.getI64Type(), + arg); return arg; }; @@ -2958,11 +2992,11 @@ IntrinsicLibrary::genAtomicCas(mlir::Type resultType, } auto address = - builder.create<mlir::UnrealizedConversionCastOp>(loc, llvmPtrTy, arg0) + mlir::UnrealizedConversionCastOp::create(builder, loc, llvmPtrTy, arg0) .getResult(0); - auto cmpxchg = builder.create<mlir::LLVM::AtomicCmpXchgOp>( - loc, address, arg1, arg2, successOrdering, failureOrdering); - return builder.create<mlir::LLVM::ExtractValueOp>(loc, cmpxchg, 1); + auto cmpxchg = mlir::LLVM::AtomicCmpXchgOp::create( + builder, loc, address, arg1, arg2, successOrdering, failureOrdering); + return mlir::LLVM::ExtractValueOp::create(builder, loc, cmpxchg, 1); } mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType, @@ -3038,31 +3072,31 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::isa<fir::BoxProcType>(ptrTy))) { mlir::Value pointerBoxProc = fir::isBoxProcAddressType(ptrTy) - ? builder.create<fir::LoadOp>(loc, fir::getBase(args[0])) + ? fir::LoadOp::create(builder, loc, fir::getBase(args[0])) : fir::getBase(args[0]); mlir::Value pointerTarget = - builder.create<fir::BoxAddrOp>(loc, pointerBoxProc); + fir::BoxAddrOp::create(builder, loc, pointerBoxProc); if (isStaticallyAbsent(args[1])) return builder.genIsNotNullAddr(loc, pointerTarget); mlir::Value target = fir::getBase(args[1]); if (fir::isBoxProcAddressType(target.getType())) - target = builder.create<fir::LoadOp>(loc, target); + target = fir::LoadOp::create(builder, loc, target); if (mlir::isa<fir::BoxProcType>(target.getType())) - target = builder.create<fir::BoxAddrOp>(loc, target); + target = fir::BoxAddrOp::create(builder, loc, target); mlir::Type intPtrTy = builder.getIntPtrType(); mlir::Value pointerInt = builder.createConvert(loc, intPtrTy, pointerTarget); mlir::Value targetInt = builder.createConvert(loc, intPtrTy, target); - mlir::Value sameTarget = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, pointerInt, targetInt); + mlir::Value sameTarget = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, pointerInt, targetInt); mlir::Value zero = builder.createIntegerConstant(loc, intPtrTy, 0); - mlir::Value notNull = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, zero, pointerInt); + mlir::Value notNull = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, zero, pointerInt); // The not notNull test covers the following two cases: // - TARGET is a procedure that is OPTIONAL and absent at runtime. // - TARGET is a procedure pointer that is NULL. // In both cases, ASSOCIATED should be false if POINTER is NULL. - return builder.create<mlir::arith::AndIOp>(loc, sameTarget, notNull); + return mlir::arith::AndIOp::create(builder, loc, sameTarget, notNull); } auto *pointer = args[0].match([&](const fir::MutableBoxValue &x) { return &x; }, @@ -3075,7 +3109,7 @@ IntrinsicLibrary::genAssociated(mlir::Type resultType, mlir::Value targetBox = builder.createBox(loc, target); mlir::Value pointerBoxRef = fir::factory::getMutableIRBox(builder, loc, *pointer); - auto pointerBox = builder.create<fir::LoadOp>(loc, pointerBoxRef); + auto pointerBox = fir::LoadOp::create(builder, loc, pointerBoxRef); return fir::runtime::genAssociated(builder, loc, pointerBox, targetBox); } @@ -3106,12 +3140,12 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselJnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3123,7 +3157,7 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_JN(n2) and BESSEL_JN(n2 - 1) since they // are the anchors of the recursion. - mlir::Value n2_1 = builder.create<mlir::arith::SubIOp>(loc, n2, one); + mlir::Value n2_1 = mlir::arith::SubIOp::create(builder, loc, n2, one); mlir::Value bn2 = genRuntimeCall("bessel_jn", resultType, {n2, x}); mlir::Value bn2_1 = genRuntimeCall("bessel_jn", resultType, {n2_1, x}); fir::runtime::genBesselJn(builder, loc, resultBox, n1, n2, x, bn2, bn2_1); @@ -3191,12 +3225,12 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, mlir::Value resultBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); - mlir::Value cmpXEq0 = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, x, zero); - mlir::Value cmpN1LtN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, n1, n2); - mlir::Value cmpN1EqN2 = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, n1, n2); + mlir::Value cmpXEq0 = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UEQ, x, zero); + mlir::Value cmpN1LtN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, n1, n2); + mlir::Value cmpN1EqN2 = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, n1, n2); auto genXEq0 = [&]() { fir::runtime::genBesselYnX0(builder, loc, floatTy, resultBox, n1, n2); @@ -3208,7 +3242,7 @@ IntrinsicLibrary::genBesselYn(mlir::Type resultType, // https://dlmf.nist.gov/10.6.E1). When n1 < n2, this requires // the values of BESSEL_YN(n1) and BESSEL_YN(n1 + 1) since they // are the anchors of the recursion. - mlir::Value n1_1 = builder.create<mlir::arith::AddIOp>(loc, n1, one); + mlir::Value n1_1 = mlir::arith::AddIOp::create(builder, loc, n1, one); mlir::Value bn1 = genRuntimeCall("bessel_yn", resultType, {n1, x}); mlir::Value bn1_1 = genRuntimeCall("bessel_yn", resultType, {n1_1, x}); fir::runtime::genBesselYn(builder, loc, resultBox, n1, n2, x, bn1, bn1_1); @@ -3280,12 +3314,12 @@ IntrinsicLibrary::genBitwiseCompare(mlir::Type resultType, if (arg0Ty.isUnsignedInteger()) arg0 = builder.createConvert(loc, signlessType, arg0); else if (bits0 < widest) - arg0 = builder.create<mlir::arith::ExtUIOp>(loc, signlessType, arg0); + arg0 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg0); if (arg1Ty.isUnsignedInteger()) arg1 = builder.createConvert(loc, signlessType, arg1); else if (bits1 < widest) - arg1 = builder.create<mlir::arith::ExtUIOp>(loc, signlessType, arg1); - return builder.create<mlir::arith::CmpIOp>(loc, pred, arg0, arg1); + arg1 = mlir::arith::ExtUIOp::create(builder, loc, signlessType, arg1); + return mlir::arith::CmpIOp::create(builder, loc, pred, arg0, arg1); } // BTEST @@ -3304,9 +3338,9 @@ mlir::Value IntrinsicLibrary::genBtest(mlir::Type resultType, word = builder.createConvert(loc, signlessType, word); mlir::Value shiftCount = builder.createConvert(loc, signlessType, args[1]); mlir::Value shifted = - builder.create<mlir::arith::ShRUIOp>(loc, word, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, word, shiftCount); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); - mlir::Value bit = builder.create<mlir::arith::AndIOp>(loc, shifted, one); + mlir::Value bit = mlir::arith::AndIOp::create(builder, loc, shifted, one); return builder.createConvert(loc, resultType, bit); } @@ -3317,11 +3351,11 @@ static mlir::Value getAddrFromBox(fir::FirOpBuilder &builder, mlir::Value addr{nullptr}; if (isFunc) { auto funcTy = mlir::cast<fir::BoxProcType>(argValue.getType()).getEleTy(); - addr = builder.create<fir::BoxAddrOp>(loc, funcTy, argValue); + addr = fir::BoxAddrOp::create(builder, loc, funcTy, argValue); } else { const auto *box = arg.getBoxOf<fir::BoxValue>(); - addr = builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), - fir::getBase(*box)); + addr = fir::BoxAddrOp::create(builder, loc, box->getMemTy(), + fir::getBase(*box)); } return addr; } @@ -3331,7 +3365,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args, bool isFunc = false, bool isDevLoc = false) { assert(args.size() == 1); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Value resAddr; if (isDevLoc) resAddr = fir::factory::genCDevPtrAddr(builder, loc, res, resultType); @@ -3342,7 +3376,7 @@ genCLocOrCFunLoc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value argAddrVal = builder.createConvert( loc, fir::unwrapRefType(resAddr.getType()), argAddr); - builder.create<fir::StoreOp>(loc, argAddrVal, resAddr); + fir::StoreOp::create(builder, loc, argAddrVal, resAddr); return res; } @@ -3355,8 +3389,8 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtrVal1 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr1); mlir::Value zero = builder.createIntegerConstant(loc, cPtrVal1.getType(), 0); - mlir::Value res = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); + mlir::Value res = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, cPtrVal1, zero); if (isStaticallyPresent(args[1])) { mlir::Type i1Ty = builder.getI1Type(); @@ -3365,15 +3399,16 @@ genCAssociated(fir::FirOpBuilder &builder, mlir::Location loc, res = builder .genIfOp(loc, {i1Ty}, isDynamicallyAbsent, /*withElseRegion=*/true) - .genThen([&]() { builder.create<fir::ResultOp>(loc, res); }) + .genThen([&]() { fir::ResultOp::create(builder, loc, res); }) .genElse([&]() { mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); - mlir::Value cmpVal = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, cPtrVal1, cPtrVal2); + mlir::Value cmpVal = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, cPtrVal1, + cPtrVal2); mlir::Value newRes = - builder.create<mlir::arith::AndIOp>(loc, res, cmpVal); - builder.create<fir::ResultOp>(loc, newRes); + mlir::arith::AndIOp::create(builder, loc, res, cmpVal); + fir::ResultOp::create(builder, loc, newRes); }) .getResults()[0]; } @@ -3428,9 +3463,9 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type idxType = builder.getIndexType(); for (int i = 0; i < arrayRank; ++i) { mlir::Value index = builder.createIntegerConstant(loc, idxType, i); - mlir::Value var = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(shapeElementType), shape, index); - mlir::Value load = builder.create<fir::LoadOp>(loc, var); + mlir::Value var = fir::CoordinateOp::create( + builder, loc, builder.getRefType(shapeElementType), shape, index); + mlir::Value load = fir::LoadOp::create(builder, loc, var); extents.push_back(builder.createConvert(loc, idxType, load)); } } @@ -3474,8 +3509,8 @@ void IntrinsicLibrary::genCFProcPointer( mlir::Value cptrCast = builder.createConvert(loc, boxProcType.getEleTy(), cptr); mlir::Value cptrBox = - builder.create<fir::EmboxProcOp>(loc, boxProcType, cptrCast); - builder.create<fir::StoreOp>(loc, cptrBox, fptr); + fir::EmboxProcOp::create(builder, loc, boxProcType, cptrCast); + fir::StoreOp::create(builder, loc, cptrBox, fptr); } // C_FUNLOC @@ -3505,7 +3540,7 @@ IntrinsicLibrary::genCPtrCompare(mlir::Type resultType, mlir::Value cPtrVal2 = fir::factory::genCPtrOrCFunptrValue(builder, loc, cPtr2); mlir::Value cmp = - builder.create<mlir::arith::CmpIOp>(loc, pred, cPtrVal1, cPtrVal2); + mlir::arith::CmpIOp::create(builder, loc, pred, cPtrVal1, cPtrVal2); return builder.createConvert(loc, resultType, cmp); } @@ -3604,7 +3639,7 @@ mlir::Value IntrinsicLibrary::genConjg(mlir::Type resultType, mlir::Value cplx = args[0]; auto imag = fir::factory::Complex{builder, loc}.extractComplexPart( cplx, /*isImagPart=*/true); - auto negImag = builder.create<mlir::arith::NegFOp>(loc, imag); + auto negImag = mlir::arith::NegFOp::create(builder, loc, imag); return fir::factory::Complex{builder, loc}.insertComplexPart( cplx, negImag, /*isImagPart=*/true); } @@ -3620,7 +3655,7 @@ mlir::Value IntrinsicLibrary::genCosd(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3635,7 +3670,7 @@ mlir::Value IntrinsicLibrary::genCospi(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); - mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg}); } @@ -3696,7 +3731,7 @@ void IntrinsicLibrary::genCpuTime(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value res1 = fir::runtime::genCpuTime(builder, loc); mlir::Value res2 = builder.createConvert(loc, fir::dyn_cast_ptrEleTy(arg->getType()), res1); - builder.create<fir::StoreOp>(loc, res2, *arg); + fir::StoreOp::create(builder, loc, res2, *arg); } // CSHIFT @@ -3723,7 +3758,7 @@ IntrinsicLibrary::genCshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar CSHIFT argument"); - auto shift = builder.create<fir::LoadOp>(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genCshiftVector(builder, loc, resultIrBox, array, shift); } else { @@ -3749,9 +3784,9 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, assert(args.size() == 1); mlir::Type resTy = fir::SequenceType::get(extent, resultType); mlir::Value arg = fir::getBase(args[0]); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resTy); + mlir::Value res = fir::AllocaOp::create(builder, loc, resTy); if (mlir::isa<fir::BaseBoxType>(arg.getType())) - arg = builder.create<fir::BoxAddrOp>(loc, arg); + arg = fir::BoxAddrOp::create(builder, loc, arg); mlir::Type refResTy = fir::ReferenceType::get(resTy); mlir::FunctionType ftype = mlir::FunctionType::get(arg.getContext(), {refResTy, refResTy}, {}); @@ -3759,7 +3794,7 @@ IntrinsicLibrary::genCUDALDXXFunc(mlir::Type resultType, llvm::SmallVector<mlir::Value> funcArgs; funcArgs.push_back(res); funcArgs.push_back(arg); - builder.create<fir::CallOp>(loc, funcOp, funcArgs); + fir::CallOp::create(builder, loc, funcOp, funcArgs); mlir::Value ext = builder.createIntegerConstant(loc, builder.getIndexType(), extent); return fir::ArrayBoxValue(res, {ext}); @@ -3775,8 +3810,8 @@ void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value values = fir::getBase(args[3]); if (!values) - values = builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getNoneType())); + values = fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())); fir::runtime::genDateAndTime(builder, loc, charArgs[0], charArgs[1], charArgs[2], values); @@ -3788,17 +3823,17 @@ mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType, assert(args.size() == 2); if (mlir::isa<mlir::IntegerType>(resultType)) { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto diff = builder.create<mlir::arith::SubIOp>(loc, args[0], args[1]); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, diff, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); + auto diff = mlir::arith::SubIOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } assert(fir::isa_real(resultType) && "Only expects real and integer in DIM"); mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - auto diff = builder.create<mlir::arith::SubFOp>(loc, args[0], args[1]); - auto cmp = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, diff, zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, diff, zero); + auto diff = mlir::arith::SubFOp::create(builder, loc, args[0], args[1]); + auto cmp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, diff, zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, diff, zero); } // DOT_PRODUCT @@ -3816,12 +3851,13 @@ IntrinsicLibrary::genDotProduct(mlir::Type resultType, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, result); - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } // This operation is only used to pass the result type // information to the DotProduct generator. - auto resultBox = builder.create<fir::AbsentOp>(loc, fir::BoxType::get(eleTy)); + auto resultBox = + fir::AbsentOp::create(builder, loc, fir::BoxType::get(eleTy)); return fir::runtime::genDotProduct(builder, loc, vectorA, vectorB, resultBox); } @@ -3833,7 +3869,7 @@ mlir::Value IntrinsicLibrary::genDprod(mlir::Type resultType, "Result must be double precision in DPROD"); mlir::Value a = builder.createConvert(loc, resultType, args[0]); mlir::Value b = builder.createConvert(loc, resultType, args[1]); - return builder.create<mlir::arith::MulFOp>(loc, a, b); + return mlir::arith::MulFOp::create(builder, loc, a, b); } // DSHIFTL @@ -3856,14 +3892,14 @@ mlir::Value IntrinsicLibrary::genDshiftl(mlir::Type resultType, // Per the standard, the value of DSHIFTL(I, J, SHIFT) is equal to // IOR (SHIFTL(I, SHIFT), SHIFTR(J, BIT_SIZE(J) - SHIFT)) - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, shift}; mlir::Value lft = genShift<mlir::arith::ShLIOp>(signlessType, lArgs); mlir::Value rArgs[2]{j, diff}; mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(signlessType, rArgs); - mlir::Value result = builder.create<mlir::arith::OrIOp>(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3889,14 +3925,14 @@ mlir::Value IntrinsicLibrary::genDshiftr(mlir::Type resultType, // Per the standard, the value of DSHIFTR(I, J, SHIFT) is equal to // IOR (SHIFTL(I, BIT_SIZE(I) - SHIFT), SHIFTR(J, SHIFT)) - mlir::Value diff = builder.create<mlir::arith::SubIOp>(loc, bitSize, shift); + mlir::Value diff = mlir::arith::SubIOp::create(builder, loc, bitSize, shift); mlir::Value lArgs[2]{i, diff}; mlir::Value lft = genShift<mlir::arith::ShLIOp>(signlessType, lArgs); mlir::Value rArgs[2]{j, shift}; mlir::Value rgt = genShift<mlir::arith::ShRUIOp>(signlessType, rArgs); - mlir::Value result = builder.create<mlir::arith::OrIOp>(loc, lft, rgt); + mlir::Value result = mlir::arith::OrIOp::create(builder, loc, lft, rgt); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -3924,8 +3960,8 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle optional BOUNDARY argument mlir::Value boundary = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getNoneType())) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getNoneType())) : builder.createBox(loc, args[2]); if (arrayRank == 1) { @@ -3933,7 +3969,7 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType, // Handle required SHIFT argument as a scalar const mlir::Value *shiftAddr = args[1].getUnboxed(); assert(shiftAddr && "nonscalar EOSHIFT SHIFT argument"); - auto shift = builder.create<fir::LoadOp>(loc, *shiftAddr); + auto shift = fir::LoadOp::create(builder, loc, *shiftAddr); fir::runtime::genEoshiftVector(builder, loc, resultIrBox, array, shift, boundary); } else { @@ -3981,14 +4017,15 @@ void IntrinsicLibrary::genExecuteCommandLine( .genIfOp(loc, {i1Ty}, waitIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto waitLoad = builder.create<fir::LoadOp>(loc, waitAddr); + auto waitLoad = + fir::LoadOp::create(builder, loc, waitAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, waitLoad); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create<fir::ResultOp>(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -3996,15 +4033,15 @@ void IntrinsicLibrary::genExecuteCommandLine( mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdstatBox = isStaticallyPresent(cmdstat) ? fir::getBase(cmdstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value cmdmsgBox = isStaticallyPresent(cmdmsg) ? fir::getBase(cmdmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); } @@ -4025,7 +4062,7 @@ IntrinsicLibrary::genEtime(std::optional<mlir::Type> resultType, auto timeAddr = builder.createTemporary(loc, *resultType); auto timeBox = builder.createBox(loc, timeAddr); fir::runtime::genEtime(builder, loc, values, timeBox); - return builder.create<fir::LoadOp>(loc, timeAddr); + return fir::LoadOp::create(builder, loc, timeAddr); } else { // subroutine form mlir::Value time = fir::getBase(args[1]); @@ -4098,8 +4135,8 @@ IntrinsicLibrary::genFindloc(mlir::Type resultType, // Handle optional mask argument auto mask = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); // Handle optional kind argument @@ -4288,15 +4325,15 @@ void IntrinsicLibrary::genGetCommand(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value commandBox = isStaticallyPresent(command) ? fir::getBase(command) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommand(builder, loc, commandBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4355,15 +4392,15 @@ void IntrinsicLibrary::genGetCommandArgument( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetCommandArgument( builder, loc, number, valBox, lenBox, errBox); if (isStaticallyPresent(status)) { @@ -4408,13 +4445,14 @@ void IntrinsicLibrary::genGetEnvironmentVariable( .genIfOp(loc, {i1Ty}, trimNameIsPresentAtRuntime, /*withElseRegion=*/true) .genThen([&]() { - auto trimLoad = builder.create<fir::LoadOp>(loc, trimNameAddr); + auto trimLoad = + fir::LoadOp::create(builder, loc, trimNameAddr); mlir::Value cast = builder.createConvert(loc, i1Ty, trimLoad); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value trueVal = builder.createBool(loc, true); - builder.create<fir::ResultOp>(loc, trueVal); + fir::ResultOp::create(builder, loc, trueVal); }) .getResults()[0]; } @@ -4423,15 +4461,15 @@ void IntrinsicLibrary::genGetEnvironmentVariable( mlir::Value valBox = isStaticallyPresent(value) ? fir::getBase(value) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value lenBox = isStaticallyPresent(length) ? fir::getBase(length) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value errBox = isStaticallyPresent(errmsg) ? fir::getBase(errmsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); mlir::Value stat = fir::runtime::genGetEnvVariable(builder, loc, name, valBox, lenBox, trim, errBox); if (isStaticallyPresent(status)) { @@ -4516,8 +4554,8 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -4531,10 +4569,10 @@ IntrinsicLibrary::genReduction(FN func, FD funcDim, llvm::StringRef errMsg, if (fir::isa_complex(eleTy)) { mlir::Value result = builder.createTemporary(loc, eleTy); func(builder, loc, array, mask, result); - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } - auto resultBox = builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + auto resultBox = fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())); return func(builder, loc, array, mask, resultBox); } // Handle Product/Sum cases that have an array result. @@ -4581,8 +4619,8 @@ mlir::Value IntrinsicLibrary::genIbclr(mlir::Type resultType, mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value bit = builder.create<mlir::arith::ShLIOp>(loc, one, pos); - mlir::Value mask = builder.create<mlir::arith::XOrIOp>(loc, ones, bit); + mlir::Value bit = mlir::arith::ShLIOp::create(builder, loc, one, pos); + mlir::Value mask = mlir::arith::XOrIOp::create(builder, loc, ones, bit); return builder.createUnsigned<mlir::arith::AndIOp>(loc, resultType, args[0], mask); } @@ -4610,18 +4648,18 @@ mlir::Value IntrinsicLibrary::genIbits(mlir::Type resultType, mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast<mlir::IntegerType>(resultType).getWidth()); mlir::Value shiftCount = - builder.create<mlir::arith::SubIOp>(loc, bitSize, len); + mlir::arith::SubIOp::create(builder, loc, bitSize, len); mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value mask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); + mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); mlir::Value res1 = builder.createUnsigned<mlir::arith::ShRSIOp>( loc, signlessType, word, pos); - mlir::Value res2 = builder.create<mlir::arith::AndIOp>(loc, res1, mask); - mlir::Value lenIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, len, zero); + mlir::Value res2 = mlir::arith::AndIOp::create(builder, loc, res1, mask); + mlir::Value lenIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, len, zero); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, lenIsZero, zero, res2); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, zero, res2); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -4640,7 +4678,7 @@ mlir::Value IntrinsicLibrary::genIbset(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value one = builder.createIntegerConstant(loc, signlessType, 1); mlir::Value pos = builder.createConvert(loc, signlessType, args[1]); - mlir::Value mask = builder.create<mlir::arith::ShLIOp>(loc, one, pos); + mlir::Value mask = mlir::arith::ShLIOp::create(builder, loc, one, pos); return builder.createUnsigned<mlir::arith::OrIOp>(loc, resultType, args[0], mask); } @@ -4674,13 +4712,13 @@ IntrinsicLibrary::genIchar(mlir::Type resultType, fir::CharacterType::get(builder.getContext(), eleType.getFKind(), 1); mlir::Type toTy = builder.getRefType(charType); mlir::Value cast = builder.createConvert(loc, toTy, buffer); - charVal = builder.create<fir::LoadOp>(loc, cast); + charVal = fir::LoadOp::create(builder, loc, cast); } LLVM_DEBUG(llvm::dbgs() << "ichar(" << charVal << ")\n"); auto code = helper.extractCodeFromSingleton(charVal); if (code.getType() == resultType) return code; - return builder.create<mlir::arith::ExtUIOp>(loc, resultType, code); + return mlir::arith::ExtUIOp::create(builder, loc, resultType, code); } // llvm floating point class intrinsic test values @@ -4710,7 +4748,7 @@ mlir::Value IntrinsicLibrary::genIsFPClass(mlir::Type resultType, assert(args.size() == 1); mlir::Type i1Ty = builder.getI1Type(); mlir::Value isfpclass = - builder.create<mlir::LLVM::IsFPClass>(loc, i1Ty, args[0], fpclass); + mlir::LLVM::IsFPClass::create(builder, loc, i1Ty, args[0], fpclass); return builder.createConvert(loc, resultType, isfpclass); } @@ -4725,7 +4763,7 @@ mlir::Value IntrinsicLibrary::genQNan(mlir::Type resultType) { void IntrinsicLibrary::genRaiseExcept(int excepts, mlir::Value cond) { fir::IfOp ifOp; if (cond) { - ifOp = builder.create<fir::IfOp>(loc, cond, /*withElseRegion=*/false); + ifOp = fir::IfOp::create(builder, loc, cond, /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); } mlir::Type i32Ty = builder.getIntegerType(32); @@ -4746,11 +4784,11 @@ getFieldRef(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value rec, mlir::dyn_cast<fir::RecordType>(fir::unwrapPassByRefType(rec.getType())); assert(index < recType.getTypeList().size() && "not enough components"); auto [fieldName, fieldTy] = recType.getTypeList()[index]; - mlir::Value field = builder.create<fir::FieldIndexOp>( - loc, fir::FieldType::get(recType.getContext()), fieldName, recType, - fir::getTypeParams(rec)); - return {builder.create<fir::CoordinateOp>(loc, builder.getRefType(fieldTy), - rec, field), + mlir::Value field = fir::FieldIndexOp::create( + builder, loc, fir::FieldType::get(recType.getContext()), fieldName, + recType, fir::getTypeParams(rec)); + return {fir::CoordinateOp::create(builder, loc, builder.getRefType(fieldTy), + rec, field), fieldTy}; } @@ -4763,9 +4801,9 @@ IntrinsicLibrary::genIeeeTypeCompare(mlir::Type resultType, assert(args.size() == 2); auto [leftRef, fieldTy] = getFieldRef(builder, loc, args[0]); auto [rightRef, ignore] = getFieldRef(builder, loc, args[1]); - mlir::Value left = builder.create<fir::LoadOp>(loc, fieldTy, leftRef); - mlir::Value right = builder.create<fir::LoadOp>(loc, fieldTy, rightRef); - return builder.create<mlir::arith::CmpIOp>(loc, pred, left, right); + mlir::Value left = fir::LoadOp::create(builder, loc, fieldTy, leftRef); + mlir::Value right = fir::LoadOp::create(builder, loc, fieldTy, rightRef); + return mlir::arith::CmpIOp::create(builder, loc, pred, left, right); } // IEEE_CLASS @@ -4796,7 +4834,7 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, const unsigned intWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(intWidth); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); llvm::StringRef tableName = RTNAME_STRING(IeeeClassTable); uint64_t highSignificandSize = (realType.getWidth() == 80) + 1; @@ -4806,8 +4844,8 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, return builder.createIntegerConstant(loc, intType, k); }; auto createIntegerConstantAPI = [&](const llvm::APInt &apInt) { - return builder.create<mlir::arith::ConstantOp>( - loc, intType, builder.getIntegerAttr(intType, apInt)); + return mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr(intType, apInt)); }; auto getMasksAndShifts = [&](uint64_t totalSize, uint64_t exponentSize, uint64_t significandSize, @@ -4854,50 +4892,52 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, // [s] sign bit int pos = 3 + highSignificandSize; - mlir::Value index = builder.create<mlir::arith::AndIOp>( - loc, builder.create<mlir::arith::ShRUIOp>(loc, intVal, signShift), + mlir::Value index = mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, signShift), createIntegerConstant(1ULL << pos)); // [e] exponent != 0 mlir::Value exponent = - builder.create<mlir::arith::AndIOp>(loc, intVal, exponentMask); + mlir::arith::AndIOp::create(builder, loc, intVal, exponentMask); mlir::Value zero = createIntegerConstant(0); - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, exponent, zero), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, exponent, zero), createIntegerConstant(1ULL << --pos), zero)); // [m] exponent == 1..1 (max exponent) - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, exponent, exponentMask), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, exponent, + exponentMask), createIntegerConstant(1ULL << --pos), zero)); // [l] low-order significand != 0 - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, - builder.create<mlir::arith::AndIOp>(loc, intVal, - lowSignificandMask), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, + mlir::arith::AndIOp::create(builder, loc, intVal, + lowSignificandMask), zero), createIntegerConstant(1ULL << --pos), zero)); // [h] high-order significand (1 or 2 bits) - index = builder.create<mlir::arith::OrIOp>( - loc, index, - builder.create<mlir::arith::AndIOp>( - loc, - builder.create<mlir::arith::ShRUIOp>(loc, intVal, - highSignificandShift), + index = mlir::arith::OrIOp::create( + builder, loc, index, + mlir::arith::AndIOp::create( + builder, loc, + mlir::arith::ShRUIOp::create(builder, loc, intVal, + highSignificandShift), createIntegerConstant((1 << highSignificandSize) - 1))); int tableSize = 1 << (4 + highSignificandSize); @@ -5025,10 +5065,10 @@ mlir::Value IntrinsicLibrary::genIeeeClass(mlir::Type resultType, mlir::RankedTensorType::get(tableSize, int8Ty), values)); } - return builder.create<fir::CoordinateOp>( - loc, builder.getRefType(resultType), - builder.create<fir::AddrOfOp>(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + return fir::CoordinateOp::create( + builder, loc, builder.getRefType(resultType), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), index); } @@ -5055,34 +5095,36 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType, // Args have the same type. if (xRealType == yRealType) - return builder.create<mlir::math::CopySignOp>(loc, xRealVal, yRealVal); + return mlir::math::CopySignOp::create(builder, loc, xRealVal, yRealVal); // Args have different types. mlir::Type xIntType = builder.getIntegerType(xRealType.getWidth()); mlir::Type yIntType = builder.getIntegerType(yRealType.getWidth()); mlir::Value xIntVal = - builder.create<mlir::arith::BitcastOp>(loc, xIntType, xRealVal); + mlir::arith::BitcastOp::create(builder, loc, xIntType, xRealVal); mlir::Value yIntVal = - builder.create<mlir::arith::BitcastOp>(loc, yIntType, yRealVal); + mlir::arith::BitcastOp::create(builder, loc, yIntType, yRealVal); mlir::Value xZero = builder.createIntegerConstant(loc, xIntType, 0); mlir::Value yZero = builder.createIntegerConstant(loc, yIntType, 0); mlir::Value xOne = builder.createIntegerConstant(loc, xIntType, 1); - mlir::Value ySign = builder.create<mlir::arith::ShRUIOp>( - loc, yIntVal, + mlir::Value ySign = mlir::arith::ShRUIOp::create( + builder, loc, yIntVal, builder.createIntegerConstant(loc, yIntType, yRealType.getWidth() - 1)); - mlir::Value xAbs = builder.create<mlir::arith::ShRUIOp>( - loc, builder.create<mlir::arith::ShLIOp>(loc, xIntVal, xOne), xOne); - mlir::Value xSign = builder.create<mlir::arith::SelectOp>( - loc, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::eq, - ySign, yZero), + mlir::Value xAbs = mlir::arith::ShRUIOp::create( + builder, loc, mlir::arith::ShLIOp::create(builder, loc, xIntVal, xOne), + xOne); + mlir::Value xSign = mlir::arith::SelectOp::create( + builder, loc, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::eq, + ySign, yZero), xZero, - builder.create<mlir::arith::ShLIOp>( - loc, xOne, + mlir::arith::ShLIOp::create( + builder, loc, xOne, builder.createIntegerConstant(loc, xIntType, xRealType.getWidth() - 1))); - return builder.create<mlir::arith::BitcastOp>( - loc, xRealType, builder.create<mlir::arith::OrIOp>(loc, xAbs, xSign)); + return mlir::arith::BitcastOp::create( + builder, loc, xRealType, + mlir::arith::OrIOp::create(builder, loc, xAbs, xSign)); } // IEEE_GET_FLAG @@ -5096,16 +5138,16 @@ void IntrinsicLibrary::genIeeeGetFlag(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value excepts = fir::runtime::genFetestexcept( builder, loc, fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create<fir::ConvertOp>( - loc, resultTy, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, - excepts, zero)); - builder.create<fir::StoreOp>(loc, logicalResult, flagValue); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + excepts, zero)); + fir::StoreOp::create(builder, loc, logicalResult, flagValue); } // IEEE_GET_HALTING_MODE @@ -5120,17 +5162,17 @@ void IntrinsicLibrary::genIeeeGetHaltingMode( mlir::Type i32Ty = builder.getIntegerType(32); mlir::Value zero = builder.createIntegerConstant(loc, i32Ty, 0); auto [fieldRef, ignore] = getFieldRef(builder, loc, flag); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value haltSet = fir::runtime::genFegetexcept(builder, loc); - mlir::Value intResult = builder.create<mlir::arith::AndIOp>( - loc, haltSet, + mlir::Value intResult = mlir::arith::AndIOp::create( + builder, loc, haltSet, fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); - mlir::Value logicalResult = builder.create<fir::ConvertOp>( - loc, resultTy, - builder.create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::ne, - intResult, zero)); - builder.create<fir::StoreOp>(loc, logicalResult, halting); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); + mlir::Value logicalResult = fir::ConvertOp::create( + builder, loc, resultTy, + mlir::arith::CmpIOp::create(builder, loc, mlir::arith::CmpIPredicate::ne, + intResult, zero)); + fir::StoreOp::create(builder, loc, logicalResult, halting); } // IEEE_GET_MODES, IEEE_SET_MODES @@ -5155,34 +5197,34 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // allotment. Allocate data space from the heap. auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0]), 1); - addr = builder.create<fir::BoxAddrOp>( - loc, builder.create<fir::LoadOp>(loc, fieldRef)); + addr = fir::BoxAddrOp::create(builder, loc, + fir::LoadOp::create(builder, loc, fieldRef)); mlir::Type heapTy = addr.getType(); - mlir::Value allocated = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, + mlir::Value allocated = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, builder.createConvert(loc, i64Ty, addr), builder.createIntegerConstant(loc, i64Ty, 0)); - auto ifOp = builder.create<fir::IfOp>(loc, heapTy, allocated, - /*withElseRegion=*/true); + auto ifOp = fir::IfOp::create(builder, loc, heapTy, allocated, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, addr); + fir::ResultOp::create(builder, loc, addr); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); mlir::Value byteSize = isModes ? fir::runtime::genGetModesTypeSize(builder, loc) : fir::runtime::genGetStatusTypeSize(builder, loc); byteSize = builder.createConvert(loc, builder.getIndexType(), byteSize); - addr = builder.create<fir::AllocMemOp>(loc, extractSequenceType(heapTy), - /*typeparams=*/mlir::ValueRange(), - byteSize); - mlir::Value shape = builder.create<fir::ShapeOp>(loc, byteSize); - builder.create<fir::StoreOp>( - loc, builder.create<fir::EmboxOp>(loc, fieldTy, addr, shape), fieldRef); - builder.create<fir::ResultOp>(loc, addr); + addr = fir::AllocMemOp::create(builder, loc, extractSequenceType(heapTy), + /*typeparams=*/mlir::ValueRange(), byteSize); + mlir::Value shape = fir::ShapeOp::create(builder, loc, byteSize); + fir::StoreOp::create( + builder, loc, fir::EmboxOp::create(builder, loc, fieldTy, addr, shape), + fieldRef); + fir::ResultOp::create(builder, loc, addr); builder.setInsertionPointAfter(ifOp); - addr = builder.create<fir::ConvertOp>(loc, ptrTy, ifOp.getResult(0)); + addr = fir::ConvertOp::create(builder, loc, ptrTy, ifOp.getResult(0)); } else { // Place floating point environment data in __data storage. - addr = builder.create<fir::ConvertOp>(loc, ptrTy, getBase(args[0])); + addr = fir::ConvertOp::create(builder, loc, ptrTy, getBase(args[0])); } llvm::StringRef func = isModes ? (isGet ? "fegetmode" : "fesetmode") : (isGet ? "fegetenv" : "fesetenv"); @@ -5193,11 +5235,11 @@ void IntrinsicLibrary::genIeeeGetOrSetModesOrStatus( // Check that an explicit ieee_[get|set]_rounding_mode call radix value is 2. static void checkRadix(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value radix, std::string procName) { - mlir::Value notTwo = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, radix, + mlir::Value notTwo = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, radix, builder.createIntegerConstant(loc, radix.getType(), 2)); - auto ifOp = builder.create<fir::IfOp>(loc, notTwo, - /*withElseRegion=*/false); + auto ifOp = fir::IfOp::create(builder, loc, notTwo, + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError(builder, loc, procName + " radix argument must be 2"); @@ -5215,9 +5257,9 @@ void IntrinsicLibrary::genIeeeGetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_get_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mode = builder.createConvert(loc, fieldTy, mode); - builder.create<fir::StoreOp>(loc, mode, fieldRef); + fir::StoreOp::create(builder, loc, mode, fieldRef); } // IEEE_GET_UNDERFLOW_MODE @@ -5242,44 +5284,45 @@ mlir::Value IntrinsicLibrary::genIeeeInt(mlir::Type resultType, mlir::FloatType realType = mlir::cast<mlir::FloatType>(args[0].getType()); mlir::Value realResult = genIeeeRint(realType, {args[0], args[1]}); int intWidth = mlir::cast<mlir::IntegerType>(resultType).getWidth(); - mlir::Value intLBound = builder.create<mlir::arith::ConstantOp>( - loc, resultType, + mlir::Value intLBound = mlir::arith::ConstantOp::create( + builder, loc, resultType, builder.getIntegerAttr(resultType, llvm::APInt::getBitsSet(intWidth, /*lo=*/intWidth - 1, /*hi=*/intWidth))); - mlir::Value intUBound = builder.create<mlir::arith::ConstantOp>( - loc, resultType, + mlir::Value intUBound = mlir::arith::ConstantOp::create( + builder, loc, resultType, builder.getIntegerAttr(resultType, llvm::APInt::getBitsSet(intWidth, /*lo=*/0, /*hi=*/intWidth - 1))); mlir::Value realLBound = - builder.create<fir::ConvertOp>(loc, realType, intLBound); - mlir::Value realUBound = builder.create<mlir::arith::NegFOp>(loc, realLBound); - mlir::Value aGreaterThanLBound = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); - mlir::Value aLessThanUBound = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); - mlir::Value resultIsValid = builder.create<mlir::arith::AndIOp>( - loc, aGreaterThanLBound, aLessThanUBound); + fir::ConvertOp::create(builder, loc, realType, intLBound); + mlir::Value realUBound = + mlir::arith::NegFOp::create(builder, loc, realLBound); + mlir::Value aGreaterThanLBound = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGE, realResult, realLBound); + mlir::Value aLessThanUBound = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, realResult, realUBound); + mlir::Value resultIsValid = mlir::arith::AndIOp::create( + builder, loc, aGreaterThanLBound, aLessThanUBound); // Result is valid. It may be exact or inexact. mlir::Value result; - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, resultType, resultIsValid, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, resultType, resultIsValid, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - mlir::Value inexact = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::ONE, args[0], realResult); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], realResult); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); - result = builder.create<fir::ConvertOp>(loc, resultType, realResult); - builder.create<fir::ResultOp>(loc, result); + result = fir::ConvertOp::create(builder, loc, resultType, realResult); + fir::ResultOp::create(builder, loc, result); // Result is invalid. builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID); - result = builder.create<mlir::arith::SelectOp>(loc, aGreaterThanLBound, - intUBound, intLBound); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, aGreaterThanLBound, + intUBound, intLBound); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); } @@ -5334,7 +5377,7 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, int bitWidth = realType.getWidth(); mlir::Type intType = builder.getIntegerType(realType.getWidth()); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Type i1Ty = builder.getI1Type(); int exponentBias, significandSize, nonSignificandSize; @@ -5381,72 +5424,72 @@ mlir::Value IntrinsicLibrary::genIeeeLogb(mlir::Type resultType, llvm_unreachable("unknown real type"); } - mlir::Value isZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, realVal, + mlir::Value isZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, realVal, builder.createRealZeroConstant(loc, resultType)); - auto outerIfOp = builder.create<fir::IfOp>(loc, resultType, isZero, - /*withElseRegion=*/true); + auto outerIfOp = fir::IfOp::create(builder, loc, resultType, isZero, + /*withElseRegion=*/true); // X is zero -- result is -infinity builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO); mlir::Value ones = builder.createAllOnesInteger(loc, intType); - mlir::Value result = builder.create<mlir::arith::ShLIOp>( - loc, ones, + mlir::Value result = mlir::arith::ShLIOp::create( + builder, loc, ones, builder.createIntegerConstant(loc, intType, // kind=10 high-order bit is explicit significandSize - (bitWidth == 80))); - result = builder.create<mlir::arith::BitcastOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::BitcastOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointToStart(&outerIfOp.getElseRegion().front()); mlir::Value one = builder.createIntegerConstant(loc, intType, 1); mlir::Value shiftLeftOne = - builder.create<mlir::arith::ShLIOp>(loc, intVal, one); + mlir::arith::ShLIOp::create(builder, loc, intVal, one); mlir::Value isFinite = genIsFPClass(i1Ty, args, finiteTest); - auto innerIfOp = builder.create<fir::IfOp>(loc, resultType, isFinite, - /*withElseRegion=*/true); + auto innerIfOp = fir::IfOp::create(builder, loc, resultType, isFinite, + /*withElseRegion=*/true); // X is non-zero finite -- result is unbiased exponent of X builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value isNormal = genIsFPClass(i1Ty, args, normalTest); - auto normalIfOp = builder.create<fir::IfOp>(loc, resultType, isNormal, - /*withElseRegion=*/true); + auto normalIfOp = fir::IfOp::create(builder, loc, resultType, isNormal, + /*withElseRegion=*/true); // X is normal builder.setInsertionPointToStart(&normalIfOp.getThenRegion().front()); - mlir::Value biasedExponent = builder.create<mlir::arith::ShRUIOp>( - loc, shiftLeftOne, + mlir::Value biasedExponent = mlir::arith::ShRUIOp::create( + builder, loc, shiftLeftOne, builder.createIntegerConstant(loc, intType, significandSize + 1)); - result = builder.create<mlir::arith::SubIOp>( - loc, biasedExponent, + result = mlir::arith::SubIOp::create( + builder, loc, biasedExponent, builder.createIntegerConstant(loc, intType, exponentBias)); - result = builder.create<fir::ConvertOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = fir::ConvertOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); // X is denormal -- result is (-exponentBias - ctlz(significand)) builder.setInsertionPointToStart(&normalIfOp.getElseRegion().front()); - mlir::Value significand = builder.create<mlir::arith::ShLIOp>( - loc, intVal, + mlir::Value significand = mlir::arith::ShLIOp::create( + builder, loc, intVal, builder.createIntegerConstant(loc, intType, nonSignificandSize)); mlir::Value ctlz = - builder.create<mlir::math::CountLeadingZerosOp>(loc, significand); + mlir::math::CountLeadingZerosOp::create(builder, loc, significand); mlir::Type i32Ty = builder.getI32Type(); - result = builder.create<mlir::arith::SubIOp>( - loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), - builder.create<fir::ConvertOp>(loc, i32Ty, ctlz)); - result = builder.create<fir::ConvertOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SubIOp::create( + builder, loc, builder.createIntegerConstant(loc, i32Ty, -exponentBias), + fir::ConvertOp::create(builder, loc, i32Ty, ctlz)); + result = fir::ConvertOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); builder.setInsertionPointToEnd(&innerIfOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, normalIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, normalIfOp.getResult(0)); // X is infinity or NaN -- result is +infinity or NaN builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); - result = builder.create<mlir::arith::ShRUIOp>(loc, shiftLeftOne, one); - result = builder.create<mlir::arith::BitcastOp>(loc, resultType, result); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::ShRUIOp::create(builder, loc, shiftLeftOne, one); + result = mlir::arith::BitcastOp::create(builder, loc, resultType, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointToEnd(&outerIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -5480,8 +5523,8 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, mlir::Value x1, y1; // X or ABS(X), Y or ABS(Y) if constexpr (isMag) { mlir::Value zero = builder.createRealZeroConstant(loc, resultType); - x1 = builder.create<mlir::math::CopySignOp>(loc, x, zero); - y1 = builder.create<mlir::math::CopySignOp>(loc, y, zero); + x1 = mlir::math::CopySignOp::create(builder, loc, x, zero); + y1 = mlir::math::CopySignOp::create(builder, loc, y, zero); } else { x1 = x; y1 = y; @@ -5492,56 +5535,56 @@ mlir::Value IntrinsicLibrary::genIeeeMaxMin(mlir::Type resultType, // X1 < Y1 -- MAX result is Y; MIN result is X. pred = mlir::arith::CmpFPredicate::OLT; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp1 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp1 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); result = isMax ? y : x; - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // X1 > Y1 -- MAX result is X; MIN result is Y. builder.setInsertionPointToStart(&ifOp1.getElseRegion().front()); pred = mlir::arith::CmpFPredicate::OGT; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp2 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp2 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp2.getThenRegion().front()); result = isMax ? x : y; - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // X1 == Y1 -- MAX favors a positive result; MIN favors a negative result. builder.setInsertionPointToStart(&ifOp2.getElseRegion().front()); pred = mlir::arith::CmpFPredicate::OEQ; - cmp = builder.create<mlir::arith::CmpFOp>(loc, pred, x1, y1); - auto ifOp3 = builder.create<fir::IfOp>(loc, resultType, cmp, true); + cmp = mlir::arith::CmpFOp::create(builder, loc, pred, x1, y1); + auto ifOp3 = fir::IfOp::create(builder, loc, resultType, cmp, true); builder.setInsertionPointToStart(&ifOp3.getThenRegion().front()); resultIsX = isMax ? genIsFPClass(i1Ty, x, positiveTest) : genIsFPClass(i1Ty, x, negativeTest); - result = builder.create<mlir::arith::SelectOp>(loc, resultIsX, x, y); - builder.create<fir::ResultOp>(loc, result); + result = mlir::arith::SelectOp::create(builder, loc, resultIsX, x, y); + fir::ResultOp::create(builder, loc, result); // X or Y or both are NaNs -- result may be X, Y, or a qNaN builder.setInsertionPointToStart(&ifOp3.getElseRegion().front()); if constexpr (isNum) { pred = mlir::arith::CmpFPredicate::ORD; // check for a non-NaN - resultIsX = builder.create<mlir::arith::CmpFOp>(loc, pred, x, x); - resultIsY = builder.create<mlir::arith::CmpFOp>(loc, pred, y, y); + resultIsX = mlir::arith::CmpFOp::create(builder, loc, pred, x, x); + resultIsY = mlir::arith::CmpFOp::create(builder, loc, pred, y, y); } else { resultIsX = resultIsY = builder.createBool(loc, false); } - result = builder.create<mlir::arith::SelectOp>( - loc, resultIsX, x, - builder.create<mlir::arith::SelectOp>(loc, resultIsY, y, - genQNan(resultType))); - mlir::Value hasSNaNOp = builder.create<mlir::arith::OrIOp>( - loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), + result = mlir::arith::SelectOp::create( + builder, loc, resultIsX, x, + mlir::arith::SelectOp::create(builder, loc, resultIsY, y, + genQNan(resultType))); + mlir::Value hasSNaNOp = mlir::arith::OrIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), genIsFPClass(builder.getI1Type(), args[1], snanTest)); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasSNaNOp); - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // Unwind the if nest. builder.setInsertionPointAfter(ifOp3); - builder.create<fir::ResultOp>(loc, ifOp3.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp3.getResult(0)); builder.setInsertionPointAfter(ifOp2); - builder.create<fir::ResultOp>(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5554,13 +5597,13 @@ IntrinsicLibrary::genIeeeQuietCompare(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { // Compare X and Y with special case treatment of NaN operands. assert(args.size() == 2); - mlir::Value hasSNaNOp = builder.create<mlir::arith::OrIOp>( - loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), + mlir::Value hasSNaNOp = mlir::arith::OrIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), args[0], snanTest), genIsFPClass(builder.getI1Type(), args[1], snanTest)); mlir::Value res = - builder.create<mlir::arith::CmpFOp>(loc, pred, args[0], args[1]); + mlir::arith::CmpFOp::create(builder, loc, pred, args[0], args[1]); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasSNaNOp); - return builder.create<fir::ConvertOp>(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_REAL @@ -5612,14 +5655,14 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, // If the argument is an sNaN, raise an invalid exception and return a qNaN. // Otherwise return the argument. auto processSnan = [&](mlir::Value x) { - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, resultType, - genIsFPClass(i1Ty, x, snanTest), - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, resultType, + genIsFPClass(i1Ty, x, snanTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID); - builder.create<fir::ResultOp>(loc, genQNan(resultType)); + fir::ResultOp::create(builder, loc, genQNan(resultType)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, x); + fir::ResultOp::create(builder, loc, x); builder.setInsertionPointAfter(ifOp); return ifOp.getResult(0); }; @@ -5635,7 +5678,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, a = builder.createConvert(loc, f32Ty, a); aType = f32Ty; } - r = builder.create<fir::ConvertOp>(loc, resultType, a); + r = fir::ConvertOp::create(builder, loc, resultType, a); mlir::IntegerType aIntType = mlir::dyn_cast<mlir::IntegerType>(aType); mlir::FloatType aFloatType = mlir::dyn_cast<mlir::FloatType>(aType); @@ -5647,142 +5690,144 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, return aIntType ? r : processSnan(r); // A possibly inexact conversion result may need to be rounded up or down. - mlir::Value b = builder.create<fir::ConvertOp>(loc, aType, r); + mlir::Value b = fir::ConvertOp::create(builder, loc, aType, r); mlir::Value aEqB; if (aIntType) - aEqB = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, a, b); + aEqB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::eq, a, b); else - aEqB = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UEQ, a, b); + aEqB = mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::UEQ, a, b); // [a == b] a is a NaN or r is exact (a may be -0, +0, -inf, +inf) -- return r - fir::IfOp ifOp1 = builder.create<fir::IfOp>(loc, resultType, aEqB, - /*withElseRegion=*/true); + fir::IfOp ifOp1 = fir::IfOp::create(builder, loc, resultType, aEqB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp1.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, aIntType ? r : processSnan(r)); + fir::ResultOp::create(builder, loc, aIntType ? r : processSnan(r)); // Code common to (a < b) and (a > b) branches. builder.setInsertionPointToStart(&ifOp1.getElseRegion().front()); mlir::func::FuncOp getRound = fir::factory::getLlvmGetRounding(builder); - mlir::Value mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mlir::Value mode = fir::CallOp::create(builder, loc, getRound).getResult(0); mlir::Value aIsNegative, aIsPositive; if (aIntType) { mlir::Value zero = builder.createIntegerConstant(loc, aIntType, 0); - aIsNegative = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, zero); - aIsPositive = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, a, zero); + aIsNegative = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, a, zero); + aIsPositive = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, a, zero); } else { mlir::Value zero = builder.createRealZeroConstant(loc, aFloatType); - aIsNegative = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, a, zero); - aIsPositive = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OGT, a, zero); + aIsNegative = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, a, zero); + aIsPositive = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OGT, a, zero); } mlir::Type resultIntType = builder.getIntegerType(resultFloatType.getWidth()); mlir::Value resultCast = - builder.create<mlir::arith::BitcastOp>(loc, resultIntType, r); + mlir::arith::BitcastOp::create(builder, loc, resultIntType, r); mlir::Value one = builder.createIntegerConstant(loc, resultIntType, 1); - mlir::Value rIsOdd = builder.create<fir::ConvertOp>( - loc, i1Ty, builder.create<mlir::arith::AndIOp>(loc, resultCast, one)); + mlir::Value rIsOdd = fir::ConvertOp::create( + builder, loc, i1Ty, + mlir::arith::AndIOp::create(builder, loc, resultCast, one)); // Check for a rounding mode match. auto match = [&](int m) { - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, mode, + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, mode, builder.createIntegerConstant(loc, mode.getType(), m)); }; - mlir::Value roundToNearestBit = builder.create<mlir::arith::OrIOp>( - loc, + mlir::Value roundToNearestBit = mlir::arith::OrIOp::create( + builder, loc, // IEEE_OTHER is an alias for IEEE_NEAREST. match(_FORTRAN_RUNTIME_IEEE_NEAREST), match(_FORTRAN_RUNTIME_IEEE_OTHER)); mlir::Value roundToNearest = - builder.create<mlir::arith::AndIOp>(loc, roundToNearestBit, rIsOdd); + mlir::arith::AndIOp::create(builder, loc, roundToNearestBit, rIsOdd); mlir::Value roundToZeroBit = match(_FORTRAN_RUNTIME_IEEE_TO_ZERO); mlir::Value roundAwayBit = match(_FORTRAN_RUNTIME_IEEE_AWAY); mlir::Value roundToZero, roundAway, mustAdjust; fir::IfOp adjustIfOp; mlir::Value aLtB; if (aIntType) - aLtB = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, a, b); + aLtB = mlir::arith::CmpIOp::create(builder, loc, + mlir::arith::CmpIPredicate::slt, a, b); else - aLtB = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, a, b); + aLtB = mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::OLT, a, b); mlir::Value upResult = - builder.create<mlir::arith::AddIOp>(loc, resultCast, one); + mlir::arith::AddIOp::create(builder, loc, resultCast, one); mlir::Value downResult = - builder.create<mlir::arith::SubIOp>(loc, resultCast, one); + mlir::arith::SubIOp::create(builder, loc, resultCast, one); // (a < b): r is inexact -- return r or ieee_next_down(r) - fir::IfOp ifOp2 = builder.create<fir::IfOp>(loc, resultType, aLtB, - /*withElseRegion=*/true); + fir::IfOp ifOp2 = fir::IfOp::create(builder, loc, resultType, aLtB, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp2.getThenRegion().front()); roundToZero = - builder.create<mlir::arith::AndIOp>(loc, roundToZeroBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsPositive); roundAway = - builder.create<mlir::arith::AndIOp>(loc, roundAwayBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsNegative); mlir::Value roundDown = match(_FORTRAN_RUNTIME_IEEE_DOWN); mustAdjust = - builder.create<mlir::arith::OrIOp>(loc, roundToNearest, roundToZero); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundAway); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundDown); - adjustIfOp = builder.create<fir::IfOp>(loc, resultType, mustAdjust, - /*withElseRegion=*/true); + mlir::arith::OrIOp::create(builder, loc, roundToNearest, roundToZero); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundAway); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundDown); + adjustIfOp = fir::IfOp::create(builder, loc, resultType, mustAdjust, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&adjustIfOp.getThenRegion().front()); if (resultType.isF80()) r1 = fir::runtime::genNearest(builder, loc, r, builder.createBool(loc, false)); else - r1 = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, aIsNegative, upResult, - downResult)); - builder.create<fir::ResultOp>(loc, r1); + r1 = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, aIsNegative, upResult, + downResult)); + fir::ResultOp::create(builder, loc, r1); builder.setInsertionPointToStart(&adjustIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create<fir::ResultOp>(loc, adjustIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, adjustIfOp.getResult(0)); // (a > b): r is inexact -- return r or ieee_next_up(r) builder.setInsertionPointToStart(&ifOp2.getElseRegion().front()); roundToZero = - builder.create<mlir::arith::AndIOp>(loc, roundToZeroBit, aIsNegative); + mlir::arith::AndIOp::create(builder, loc, roundToZeroBit, aIsNegative); roundAway = - builder.create<mlir::arith::AndIOp>(loc, roundAwayBit, aIsPositive); + mlir::arith::AndIOp::create(builder, loc, roundAwayBit, aIsPositive); mlir::Value roundUp = match(_FORTRAN_RUNTIME_IEEE_UP); mustAdjust = - builder.create<mlir::arith::OrIOp>(loc, roundToNearest, roundToZero); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundAway); - mustAdjust = builder.create<mlir::arith::OrIOp>(loc, mustAdjust, roundUp); - adjustIfOp = builder.create<fir::IfOp>(loc, resultType, mustAdjust, - /*withElseRegion=*/true); + mlir::arith::OrIOp::create(builder, loc, roundToNearest, roundToZero); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundAway); + mustAdjust = mlir::arith::OrIOp::create(builder, loc, mustAdjust, roundUp); + adjustIfOp = fir::IfOp::create(builder, loc, resultType, mustAdjust, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&adjustIfOp.getThenRegion().front()); if (resultType.isF80()) r1 = fir::runtime::genNearest(builder, loc, r, builder.createBool(loc, true)); else - r1 = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, aIsPositive, upResult, - downResult)); - builder.create<fir::ResultOp>(loc, r1); + r1 = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, aIsPositive, upResult, + downResult)); + fir::ResultOp::create(builder, loc, r1); builder.setInsertionPointToStart(&adjustIfOp.getElseRegion().front()); - builder.create<fir::ResultOp>(loc, r); + fir::ResultOp::create(builder, loc, r); builder.setInsertionPointAfter(adjustIfOp); - builder.create<fir::ResultOp>(loc, adjustIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, adjustIfOp.getResult(0)); // Generate exceptions for (a < b) and (a > b) branches. builder.setInsertionPointAfter(ifOp2); r = ifOp2.getResult(0); - fir::IfOp exceptIfOp1 = builder.create<fir::IfOp>( - loc, genIsFPClass(i1Ty, r, infiniteTest), /*withElseRegion=*/true); + fir::IfOp exceptIfOp1 = + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, r, infiniteTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp1.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointToStart(&exceptIfOp1.getElseRegion().front()); - fir::IfOp exceptIfOp2 = builder.create<fir::IfOp>( - loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), + fir::IfOp exceptIfOp2 = fir::IfOp::create( + builder, loc, genIsFPClass(i1Ty, r, subnormalTest | zeroTest), /*withElseRegion=*/true); builder.setInsertionPointToStart(&exceptIfOp2.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | @@ -5790,7 +5835,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType, builder.setInsertionPointToStart(&exceptIfOp2.getElseRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointAfter(exceptIfOp1); - builder.create<fir::ResultOp>(loc, ifOp2.getResult(0)); + fir::ResultOp::create(builder, loc, ifOp2.getResult(0)); builder.setInsertionPointAfter(ifOp1); return ifOp1.getResult(0); } @@ -5806,19 +5851,19 @@ mlir::Value IntrinsicLibrary::genIeeeRem(mlir::Type resultType, mlir::Value y = args[1]; if (mlir::dyn_cast<mlir::FloatType>(resultType).getWidth() < 32) { mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext()); - x = builder.create<fir::ConvertOp>(loc, f32Ty, x); - y = builder.create<fir::ConvertOp>(loc, f32Ty, y); + x = fir::ConvertOp::create(builder, loc, f32Ty, x); + y = fir::ConvertOp::create(builder, loc, f32Ty, y); } else { - x = builder.create<fir::ConvertOp>(loc, resultType, x); - y = builder.create<fir::ConvertOp>(loc, resultType, y); + x = fir::ConvertOp::create(builder, loc, resultType, x); + y = fir::ConvertOp::create(builder, loc, resultType, y); } // remainder calls do not signal IEEE_UNDERFLOW. - mlir::Value underflow = builder.create<mlir::arith::AndIOp>( - loc, genIsFPClass(builder.getI1Type(), x, subnormalTest), + mlir::Value underflow = mlir::arith::AndIOp::create( + builder, loc, genIsFPClass(builder.getI1Type(), x, subnormalTest), genIsFPClass(builder.getI1Type(), y, infiniteTest)); mlir::Value result = genRuntimeCall("remainder", x.getType(), {x, y}); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW, underflow); - return builder.create<fir::ConvertOp>(loc, resultType, result); + return fir::ConvertOp::create(builder, loc, resultType, result); } // IEEE_RINT @@ -5834,19 +5879,19 @@ mlir::Value IntrinsicLibrary::genIeeeRint(mlir::Type resultType, mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); mlir::Value mode; if (isStaticallyPresent(args[1])) { - mode = builder.create<fir::CallOp>(loc, getRound).getResult(0); + mode = fir::CallOp::create(builder, loc, getRound).getResult(0); genIeeeSetRoundingMode({args[1]}); } if (mlir::cast<mlir::FloatType>(resultType).getWidth() == 16) - a = builder.create<fir::ConvertOp>( - loc, mlir::Float32Type::get(builder.getContext()), a); - mlir::Value result = builder.create<fir::ConvertOp>( - loc, resultType, genRuntimeCall("nearbyint", a.getType(), a)); + a = fir::ConvertOp::create(builder, loc, + mlir::Float32Type::get(builder.getContext()), a); + mlir::Value result = fir::ConvertOp::create( + builder, loc, resultType, genRuntimeCall("nearbyint", a.getType(), a)); if (isStaticallyPresent(args[1])) { - builder.create<fir::CallOp>(loc, setRound, mode); + fir::CallOp::create(builder, loc, setRound, mode); } else { - mlir::Value inexact = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::ONE, args[0], result); + mlir::Value inexact = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::ONE, args[0], result); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INEXACT, inexact); } return result; @@ -5862,18 +5907,19 @@ void IntrinsicLibrary::genIeeeSetFlagOrHaltingMode( mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value except = fir::runtime::genMapExcept( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field)); - auto ifOp = builder.create<fir::IfOp>( - loc, builder.create<fir::ConvertOp>(loc, i1Ty, getBase(args[1])), + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field)); + auto ifOp = fir::IfOp::create( + builder, loc, + fir::ConvertOp::create(builder, loc, i1Ty, getBase(args[1])), /*withElseRegion=*/true); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); (isFlag ? fir::runtime::genFeraiseexcept : fir::runtime::genFeenableexcept)( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointToStart(&ifOp.getElseRegion().front()); (isFlag ? fir::runtime::genFeclearexcept : fir::runtime::genFedisableexcept)( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, except)); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, except)); builder.setInsertionPointAfter(ifOp); } @@ -5890,7 +5936,7 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( checkRadix(builder, loc, fir::getBase(args[1]), "ieee_set_rounding_mode"); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0])); mlir::func::FuncOp setRound = fir::factory::getLlvmSetRounding(builder); - mlir::Value mode = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); static_assert( _FORTRAN_RUNTIME_IEEE_TO_ZERO >= 0 && _FORTRAN_RUNTIME_IEEE_TO_ZERO <= 3 && @@ -5898,28 +5944,28 @@ void IntrinsicLibrary::genIeeeSetRoundingMode( _FORTRAN_RUNTIME_IEEE_NEAREST <= 3 && _FORTRAN_RUNTIME_IEEE_UP >= 0 && _FORTRAN_RUNTIME_IEEE_UP <= 3 && _FORTRAN_RUNTIME_IEEE_DOWN >= 0 && _FORTRAN_RUNTIME_IEEE_DOWN <= 3 && "unexpected rounding mode mapping"); - mlir::Value mask = builder.create<mlir::arith::ShLIOp>( - loc, builder.createAllOnesInteger(loc, fieldTy), + mlir::Value mask = mlir::arith::ShLIOp::create( + builder, loc, builder.createAllOnesInteger(loc, fieldTy), builder.createIntegerConstant(loc, fieldTy, 2)); - mlir::Value modeIsSupported = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, - builder.create<mlir::arith::AndIOp>(loc, mode, mask), + mlir::Value modeIsSupported = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, + mlir::arith::AndIOp::create(builder, loc, mode, mask), builder.createIntegerConstant(loc, fieldTy, 0)); mlir::Value nearest = builder.createIntegerConstant( loc, fieldTy, _FORTRAN_RUNTIME_IEEE_NEAREST); - mode = builder.create<mlir::arith::SelectOp>(loc, modeIsSupported, mode, - nearest); - mode = builder.create<fir::ConvertOp>( - loc, setRound.getFunctionType().getInput(0), mode); - builder.create<fir::CallOp>(loc, setRound, mode); + mode = mlir::arith::SelectOp::create(builder, loc, modeIsSupported, mode, + nearest); + mode = fir::ConvertOp::create(builder, loc, + setRound.getFunctionType().getInput(0), mode); + fir::CallOp::create(builder, loc, setRound, mode); } // IEEE_SET_UNDERFLOW_MODE void IntrinsicLibrary::genIeeeSetUnderflowMode( llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); - mlir::Value gradual = builder.create<fir::ConvertOp>(loc, builder.getI1Type(), - getBase(args[0])); + mlir::Value gradual = fir::ConvertOp::create( + builder, loc, builder.getI1Type(), getBase(args[0])); fir::runtime::genSetUnderflowMode(builder, loc, {gradual}); } @@ -5933,9 +5979,9 @@ IntrinsicLibrary::genIeeeSignalingCompare(mlir::Type resultType, assert(args.size() == 2); mlir::Value hasNaNOp = genIeeeUnordered(mlir::Type{}, args); mlir::Value res = - builder.create<mlir::arith::CmpFOp>(loc, pred, args[0], args[1]); + mlir::arith::CmpFOp::create(builder, loc, pred, args[0], args[1]); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, hasNaNOp); - return builder.create<fir::ConvertOp>(loc, resultType, res); + return fir::ConvertOp::create(builder, loc, resultType, res); } // IEEE_SIGNBIT @@ -5954,9 +6000,9 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType, } mlir::Type intType = builder.getIntegerType(bitWidth); mlir::Value intVal = - builder.create<mlir::arith::BitcastOp>(loc, intType, realVal); + mlir::arith::BitcastOp::create(builder, loc, intType, realVal); mlir::Value shift = builder.createIntegerConstant(loc, intType, bitWidth - 1); - mlir::Value sign = builder.create<mlir::arith::ShRUIOp>(loc, intVal, shift); + mlir::Value sign = mlir::arith::ShRUIOp::create(builder, loc, intVal, shift); return builder.createConvert(loc, resultType, sign); } @@ -5969,21 +6015,21 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, mlir::Type i1Ty = builder.getI1Type(); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value flag = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value flag = fir::LoadOp::create(builder, loc, fieldRef); mlir::Value standardFlagMask = builder.createIntegerConstant( loc, fieldTy, _FORTRAN_RUNTIME_IEEE_INVALID | _FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO | _FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); - mlir::Value isStandardFlag = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, - builder.create<mlir::arith::AndIOp>(loc, flag, standardFlagMask), + mlir::Value isStandardFlag = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, + mlir::arith::AndIOp::create(builder, loc, flag, standardFlagMask), builder.createIntegerConstant(loc, fieldTy, 0)); - fir::IfOp ifOp = builder.create<fir::IfOp>(loc, i1Ty, isStandardFlag, - /*withElseRegion=*/true); + fir::IfOp ifOp = fir::IfOp::create(builder, loc, i1Ty, isStandardFlag, + /*withElseRegion=*/true); // Standard flags are supported. builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); - builder.create<fir::ResultOp>(loc, builder.createBool(loc, true)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, true)); // TargetCharacteristics information for the nonstandard ieee_denorm flag // is not available here. So use a runtime check restricted to possibly @@ -6007,17 +6053,17 @@ IntrinsicLibrary::genIeeeSupportFlag(mlir::Type resultType, } } if (mayBeSupported) { - mlir::Value isDenorm = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, flag, + mlir::Value isDenorm = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, flag, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_DENORM)); - mlir::Value result = builder.create<mlir::arith::AndIOp>( - loc, isDenorm, + mlir::Value result = mlir::arith::AndIOp::create( + builder, loc, isDenorm, fir::runtime::genSupportHalting( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, flag))); - builder.create<fir::ResultOp>(loc, result); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, flag))); + fir::ResultOp::create(builder, loc, result); } else { - builder.create<fir::ResultOp>(loc, builder.createBool(loc, false)); + fir::ResultOp::create(builder, loc, builder.createBool(loc, false)); } builder.setInsertionPointAfter(ifOp); return builder.createConvert(loc, resultType, ifOp.getResult(0)); @@ -6032,11 +6078,11 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportHalting( assert(args.size() == 1); mlir::Type i32Ty = builder.getIntegerType(32); auto [fieldRef, ignore] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value field = builder.create<fir::LoadOp>(loc, fieldRef); + mlir::Value field = fir::LoadOp::create(builder, loc, fieldRef); return builder.createConvert( loc, resultType, fir::runtime::genSupportHalting( - builder, loc, builder.create<fir::ConvertOp>(loc, i32Ty, field))); + builder, loc, fir::ConvertOp::create(builder, loc, i32Ty, field))); } // IEEE_SUPPORT_ROUNDING @@ -6053,16 +6099,16 @@ fir::ExtendedValue IntrinsicLibrary::genIeeeSupportRounding( // 4 - to nearest, ties away from zero [not supported] assert(args.size() == 1 || args.size() == 2); auto [fieldRef, fieldTy] = getFieldRef(builder, loc, getBase(args[0])); - mlir::Value mode = builder.create<fir::LoadOp>(loc, fieldRef); - mlir::Value lbOk = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, mode, + mlir::Value mode = fir::LoadOp::create(builder, loc, fieldRef); + mlir::Value lbOk = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, mode, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_TO_ZERO)); - mlir::Value ubOk = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sle, mode, + mlir::Value ubOk = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sle, mode, builder.createIntegerConstant(loc, fieldTy, _FORTRAN_RUNTIME_IEEE_DOWN)); return builder.createConvert( - loc, resultType, builder.create<mlir::arith::AndIOp>(loc, lbOk, ubOk)); + loc, resultType, mlir::arith::AndIOp::create(builder, loc, lbOk, ubOk)); } // IEEE_SUPPORT_STANDARD @@ -6086,15 +6132,15 @@ IntrinsicLibrary::genIeeeUnordered(mlir::Type resultType, // If there is no result type return an i1 result. assert(args.size() == 2); if (args[0].getType() == args[1].getType()) { - mlir::Value res = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNO, args[0], args[1]); + mlir::Value res = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNO, args[0], args[1]); return resultType ? builder.createConvert(loc, resultType, res) : res; } assert(resultType && "expecting a (mixed arg type) unordered result type"); mlir::Type i1Ty = builder.getI1Type(); mlir::Value xIsNan = genIsFPClass(i1Ty, args[0], nanTest); mlir::Value yIsNan = genIsFPClass(i1Ty, args[1], nanTest); - mlir::Value res = builder.create<mlir::arith::OrIOp>(loc, xIsNan, yIsNan); + mlir::Value res = mlir::arith::OrIOp::create(builder, loc, xIsNan, yIsNan); return builder.createConvert(loc, resultType, res); } @@ -6219,22 +6265,22 @@ mlir::Value IntrinsicLibrary::genIeeeValue(mlir::Type resultType, mlir::Value which; if (args.size() == 2) { // user call auto [index, ignore] = getFieldRef(builder, loc, args[1]); - which = builder.create<fir::LoadOp>(loc, index); + which = fir::LoadOp::create(builder, loc, index); } else { // compiler generated call which = args[0]; } - mlir::Value bits = builder.create<fir::LoadOp>( - loc, - builder.create<fir::CoordinateOp>( - loc, builder.getRefType(valueTy), - builder.create<fir::AddrOfOp>(loc, builder.getRefType(tableTy), - builder.getSymbolRefAttr(tableName)), + mlir::Value bits = fir::LoadOp::create( + builder, loc, + fir::CoordinateOp::create( + builder, loc, builder.getRefType(valueTy), + fir::AddrOfOp::create(builder, loc, builder.getRefType(tableTy), + builder.getSymbolRefAttr(tableName)), which)); if (bitWidth > 64) - bits = builder.create<mlir::arith::ShLIOp>( - loc, builder.createConvert(loc, intType, bits), + bits = mlir::arith::ShLIOp::create( + builder, loc, builder.createConvert(loc, intType, bits), builder.createIntegerConstant(loc, intType, bitWidth - 64)); - return builder.create<mlir::arith::BitcastOp>(loc, realType, bits); + return mlir::arith::BitcastOp::create(builder, loc, realType, bits); } // IEOR @@ -6276,13 +6322,14 @@ IntrinsicLibrary::genIndex(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value backOpt = isStaticallyAbsent(args, 2) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : makeRefThenEmbox(fir::getBase(args[2])); + mlir::Value backOpt = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : makeRefThenEmbox(fir::getBase(args[2])); mlir::Value kindVal = isStaticallyAbsent(args, 3) ? builder.createIntegerConstant( loc, builder.getIndexType(), @@ -6331,8 +6378,8 @@ mlir::Value IntrinsicLibrary::genIsIostatValue(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 1); - return builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, args[0], + return mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, args[0], builder.createIntegerConstant(loc, args[0].getType(), value)); } @@ -6359,16 +6406,16 @@ mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - auto left = builder.create<mlir::arith::ShLIOp>(loc, word, absShift); - auto right = builder.create<mlir::arith::ShRUIOp>(loc, word, absShift); - auto shiftIsLarge = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); - auto shiftIsNegative = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); + auto left = mlir::arith::ShLIOp::create(builder, loc, word, absShift); + auto right = mlir::arith::ShRUIOp::create(builder, loc, word, absShift); + auto shiftIsLarge = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, absShift, bitSize); + auto shiftIsNegative = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, shift, zero); auto sel = - builder.create<mlir::arith::SelectOp>(loc, shiftIsNegative, right, left); + mlir::arith::SelectOp::create(builder, loc, shiftIsNegative, right, left); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, shiftIsLarge, zero, sel); + mlir::arith::SelectOp::create(builder, loc, shiftIsLarge, zero, sel); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6409,42 +6456,42 @@ mlir::Value IntrinsicLibrary::genIshftc(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value absShift = genAbs(signlessType, {shift}); - auto elseSize = builder.create<mlir::arith::SubIOp>(loc, size, absShift); - auto shiftIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, shift, zero); - auto shiftEqualsSize = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, absShift, size); + auto elseSize = mlir::arith::SubIOp::create(builder, loc, size, absShift); + auto shiftIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, shift, zero); + auto shiftEqualsSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, absShift, size); auto shiftIsNop = - builder.create<mlir::arith::OrIOp>(loc, shiftIsZero, shiftEqualsSize); - auto shiftIsPositive = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sgt, shift, zero); - auto leftSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, - absShift, elseSize); - auto rightSize = builder.create<mlir::arith::SelectOp>(loc, shiftIsPositive, - elseSize, absShift); - auto hasUnchanged = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, size, bitSize); - auto unchangedTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, word, size); + mlir::arith::OrIOp::create(builder, loc, shiftIsZero, shiftEqualsSize); + auto shiftIsPositive = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sgt, shift, zero); + auto leftSize = mlir::arith::SelectOp::create(builder, loc, shiftIsPositive, + absShift, elseSize); + auto rightSize = mlir::arith::SelectOp::create(builder, loc, shiftIsPositive, + elseSize, absShift); + auto hasUnchanged = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, size, bitSize); + auto unchangedTmp1 = mlir::arith::ShRUIOp::create(builder, loc, word, size); auto unchangedTmp2 = - builder.create<mlir::arith::ShLIOp>(loc, unchangedTmp1, size); - auto unchanged = builder.create<mlir::arith::SelectOp>(loc, hasUnchanged, - unchangedTmp2, zero); + mlir::arith::ShLIOp::create(builder, loc, unchangedTmp1, size); + auto unchanged = mlir::arith::SelectOp::create(builder, loc, hasUnchanged, + unchangedTmp2, zero); auto leftMaskShift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, leftSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, leftSize); auto leftMask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, leftMaskShift); - auto leftTmp = builder.create<mlir::arith::ShRUIOp>(loc, word, rightSize); - auto left = builder.create<mlir::arith::AndIOp>(loc, leftTmp, leftMask); + mlir::arith::ShRUIOp::create(builder, loc, ones, leftMaskShift); + auto leftTmp = mlir::arith::ShRUIOp::create(builder, loc, word, rightSize); + auto left = mlir::arith::AndIOp::create(builder, loc, leftTmp, leftMask); auto rightMaskShift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, rightSize); + mlir::arith::SubIOp::create(builder, loc, bitSize, rightSize); auto rightMask = - builder.create<mlir::arith::ShRUIOp>(loc, ones, rightMaskShift); - auto rightTmp = builder.create<mlir::arith::AndIOp>(loc, word, rightMask); - auto right = builder.create<mlir::arith::ShLIOp>(loc, rightTmp, leftSize); - auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, left); - auto res = builder.create<mlir::arith::OrIOp>(loc, resTmp, right); + mlir::arith::ShRUIOp::create(builder, loc, ones, rightMaskShift); + auto rightTmp = mlir::arith::AndIOp::create(builder, loc, word, rightMask); + auto right = mlir::arith::ShLIOp::create(builder, loc, rightTmp, leftSize); + auto resTmp = mlir::arith::OrIOp::create(builder, loc, unchanged, left); + auto res = mlir::arith::OrIOp::create(builder, loc, resTmp, right); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, shiftIsNop, word, res); + mlir::arith::SelectOp::create(builder, loc, shiftIsNop, word, res); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6456,7 +6503,7 @@ mlir::Value IntrinsicLibrary::genLeadz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create<mlir::math::CountLeadingZerosOp>(loc, args); + mlir::math::CountLeadingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -6524,18 +6571,18 @@ IntrinsicLibrary::genLoc(mlir::Type resultType, // created when preparing the argument cases, but the box can be safely be // used for all those cases and the address will be null if absent. mlir::Value isPresent = - builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), box); + fir::IsPresentOp::create(builder, loc, builder.getI1Type(), box); return builder .genIfOp(loc, {resultType}, isPresent, /*withElseRegion=*/true) .genThen([&]() { mlir::Value argAddr = getAddrFromBox(builder, loc, args[0], isFunc); mlir::Value cast = builder.createConvert(loc, resultType, argAddr); - builder.create<fir::ResultOp>(loc, cast); + fir::ResultOp::create(builder, loc, cast); }) .genElse([&]() { mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - builder.create<fir::ResultOp>(loc, zero); + fir::ResultOp::create(builder, loc, zero); }) .getResults()[0]; } @@ -6568,12 +6615,12 @@ mlir::Value IntrinsicLibrary::genMask(mlir::Type resultType, // non-deterministic result. Other compilers don't produce a consistent result // in this case either, so we choose the most efficient implementation. mlir::Value shift = - builder.create<mlir::arith::SubIOp>(loc, bitSize, bitsToSet); - mlir::Value shifted = builder.create<Shift>(loc, ones, shift); - mlir::Value isZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, bitsToSet, zero); + mlir::arith::SubIOp::create(builder, loc, bitSize, bitsToSet); + mlir::Value shifted = Shift::create(builder, loc, ones, shift); + mlir::Value isZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, bitsToSet, zero); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, isZero, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, isZero, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -6591,8 +6638,8 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create<fir::ConvertOp>( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); mlir::Type retTy = mlir::LLVM::LLVMStructType::getLiteral(context, {resultType, i1Ty}); @@ -6601,10 +6648,10 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType, .create<mlir::NVVM::MatchSyncOp>(loc, retTy, args[0], arg1, mlir::NVVM::MatchSyncKind::all) .getResult(); - auto value = builder.create<mlir::LLVM::ExtractValueOp>(loc, match, 0); - auto pred = builder.create<mlir::LLVM::ExtractValueOp>(loc, match, 1); - auto conv = builder.create<mlir::LLVM::ZExtOp>(loc, resultType, pred); - builder.create<fir::StoreOp>(loc, conv, args[2]); + auto value = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 0); + auto pred = mlir::LLVM::ExtractValueOp::create(builder, loc, match, 1); + auto conv = mlir::LLVM::ZExtOp::create(builder, loc, resultType, pred); + fir::StoreOp::create(builder, loc, conv, args[2]); return value; } @@ -6614,14 +6661,14 @@ mlir::Value IntrinsicLibrary::genVoteSync(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 2); mlir::Value arg1 = - builder.create<fir::ConvertOp>(loc, builder.getI1Type(), args[1]); + fir::ConvertOp::create(builder, loc, builder.getI1Type(), args[1]); mlir::Type resTy = kind == mlir::NVVM::VoteSyncKind::ballot ? builder.getI32Type() : builder.getI1Type(); auto voteRes = - builder.create<mlir::NVVM::VoteSyncOp>(loc, resTy, args[0], arg1, kind) + mlir::NVVM::VoteSyncOp::create(builder, loc, resTy, args[0], arg1, kind) .getResult(); - return builder.create<fir::ConvertOp>(loc, resultType, voteRes); + return fir::ConvertOp::create(builder, loc, resultType, voteRes); } // MATCH_ANY_SYNC @@ -6633,8 +6680,8 @@ IntrinsicLibrary::genMatchAnySync(mlir::Type resultType, mlir::Value arg1 = args[1]; if (arg1.getType().isF32() || arg1.getType().isF64()) - arg1 = builder.create<fir::ConvertOp>( - loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); + arg1 = fir::ConvertOp::create( + builder, loc, is32 ? builder.getI32Type() : builder.getI64Type(), arg1); return builder .create<mlir::NVVM::MatchSyncOp>(loc, resultType, args[0], arg1, @@ -6718,10 +6765,10 @@ IntrinsicLibrary::genMerge(mlir::Type, mlir::Value other) -> mlir::Value { mlir::Type otherType = other.getType(); if (mlir::isa<fir::BaseBoxType>(otherType)) - return builder.create<fir::ReboxOp>(loc, otherType, polymorphic, - /*shape*/ mlir::Value{}, - /*slice=*/mlir::Value{}); - return builder.create<fir::BoxAddrOp>(loc, otherType, polymorphic); + return fir::ReboxOp::create(builder, loc, otherType, polymorphic, + /*shape*/ mlir::Value{}, + /*slice=*/mlir::Value{}); + return fir::BoxAddrOp::create(builder, loc, otherType, polymorphic); }; if (fir::isPolymorphicType(tsource.getType()) && !fir::isPolymorphicType(fsource.getType())) { @@ -6737,8 +6784,8 @@ IntrinsicLibrary::genMerge(mlir::Type, // fulfill mlir::SelectOp constraint that the MLIR types must be the same. fsourceCast = builder.createConvert(loc, tsource.getType(), fsource); } - auto rslt = builder.create<mlir::arith::SelectOp>(loc, mask, tsourceCast, - fsourceCast); + auto rslt = mlir::arith::SelectOp::create(builder, loc, mask, tsourceCast, + fsourceCast); if (isCharRslt) { // Need a CharBoxValue for character results const fir::CharBoxValue *charBox = args[0].getCharBox(); @@ -6779,7 +6826,7 @@ mlir::Value IntrinsicLibrary::genMod(mlir::Type resultType, args[0], args[1]); } if (mlir::isa<mlir::IntegerType>(resultType)) - return builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); + return mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); // Use runtime. return builder.createConvert( @@ -6809,19 +6856,19 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, } if (mlir::isa<mlir::IntegerType>(resultType)) { auto remainder = - builder.create<mlir::arith::RemSIOp>(loc, args[0], args[1]); - auto argXor = builder.create<mlir::arith::XOrIOp>(loc, args[0], args[1]); + mlir::arith::RemSIOp::create(builder, loc, args[0], args[1]); + auto argXor = mlir::arith::XOrIOp::create(builder, loc, args[0], args[1]); mlir::Value zero = builder.createIntegerConstant(loc, argXor.getType(), 0); - auto argSignDifferent = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, argXor, zero); - auto remainderIsNotZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, remainder, zero); - auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, - argSignDifferent); + auto argSignDifferent = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, argXor, zero); + auto remainderIsNotZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, remainder, zero); + auto mustAddP = mlir::arith::AndIOp::create( + builder, loc, remainderIsNotZero, argSignDifferent); auto remPlusP = - builder.create<mlir::arith::AddIOp>(loc, remainder, args[1]); - return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, - remainder); + mlir::arith::AddIOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } auto fastMathFlags = builder.getFastMathFlags(); @@ -6834,21 +6881,21 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType, loc, resultType, fir::runtime::genModulo(builder, loc, args[0], args[1])); - auto remainder = builder.create<mlir::arith::RemFOp>(loc, args[0], args[1]); + auto remainder = mlir::arith::RemFOp::create(builder, loc, args[0], args[1]); mlir::Value zero = builder.createRealZeroConstant(loc, remainder.getType()); - auto remainderIsNotZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); - auto aLessThanZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); - auto pLessThanZero = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); + auto remainderIsNotZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, remainder, zero); + auto aLessThanZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, args[0], zero); + auto pLessThanZero = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, args[1], zero); auto argSignDifferent = - builder.create<mlir::arith::XOrIOp>(loc, aLessThanZero, pLessThanZero); - auto mustAddP = builder.create<mlir::arith::AndIOp>(loc, remainderIsNotZero, - argSignDifferent); - auto remPlusP = builder.create<mlir::arith::AddFOp>(loc, remainder, args[1]); - return builder.create<mlir::arith::SelectOp>(loc, mustAddP, remPlusP, - remainder); + mlir::arith::XOrIOp::create(builder, loc, aLessThanZero, pLessThanZero); + auto mustAddP = mlir::arith::AndIOp::create(builder, loc, remainderIsNotZero, + argSignDifferent); + auto remPlusP = mlir::arith::AddFOp::create(builder, loc, remainder, args[1]); + return mlir::arith::SelectOp::create(builder, loc, mustAddP, remPlusP, + remainder); } void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef<fir::ExtendedValue> args) { @@ -6863,7 +6910,7 @@ void IntrinsicLibrary::genMoveAlloc(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value errBox = isStaticallyPresent(errMsg) ? fir::getBase(errMsg) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); const fir::MutableBoxValue *fromBox = from.getBoxOf<fir::MutableBoxValue>(); const fir::MutableBoxValue *toBox = to.getBoxOf<fir::MutableBoxValue>(); @@ -6920,33 +6967,34 @@ void IntrinsicLibrary::genMvbits(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Type toType{fir::dyn_cast_ptrEleTy(toAddr.getType())}; assert(toType.getIntOrFloatBitWidth() == fromType.getIntOrFloatBitWidth() && "mismatched mvbits types"); - auto to = builder.create<fir::LoadOp>(loc, signlessType, toAddr); + auto to = fir::LoadOp::create(builder, loc, signlessType, toAddr); mlir::Value topos = builder.createConvert(loc, signlessType, unbox(args[4])); mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value ones = builder.createAllOnesInteger(loc, signlessType); mlir::Value bitSize = builder.createIntegerConstant( loc, signlessType, mlir::cast<mlir::IntegerType>(signlessType).getWidth()); - auto shiftCount = builder.create<mlir::arith::SubIOp>(loc, bitSize, len); - auto mask = builder.create<mlir::arith::ShRUIOp>(loc, ones, shiftCount); - auto unchangedTmp1 = builder.create<mlir::arith::ShLIOp>(loc, mask, topos); + auto shiftCount = mlir::arith::SubIOp::create(builder, loc, bitSize, len); + auto mask = mlir::arith::ShRUIOp::create(builder, loc, ones, shiftCount); + auto unchangedTmp1 = mlir::arith::ShLIOp::create(builder, loc, mask, topos); auto unchangedTmp2 = - builder.create<mlir::arith::XOrIOp>(loc, unchangedTmp1, ones); - auto unchanged = builder.create<mlir::arith::AndIOp>(loc, unchangedTmp2, to); + mlir::arith::XOrIOp::create(builder, loc, unchangedTmp1, ones); + auto unchanged = mlir::arith::AndIOp::create(builder, loc, unchangedTmp2, to); if (fromType.isUnsignedInteger()) from = builder.createConvert(loc, signlessType, from); - auto frombitsTmp1 = builder.create<mlir::arith::ShRUIOp>(loc, from, frompos); + auto frombitsTmp1 = mlir::arith::ShRUIOp::create(builder, loc, from, frompos); auto frombitsTmp2 = - builder.create<mlir::arith::AndIOp>(loc, frombitsTmp1, mask); - auto frombits = builder.create<mlir::arith::ShLIOp>(loc, frombitsTmp2, topos); - auto resTmp = builder.create<mlir::arith::OrIOp>(loc, unchanged, frombits); - auto lenIsZero = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, len, zero); + mlir::arith::AndIOp::create(builder, loc, frombitsTmp1, mask); + auto frombits = + mlir::arith::ShLIOp::create(builder, loc, frombitsTmp2, topos); + auto resTmp = mlir::arith::OrIOp::create(builder, loc, unchanged, frombits); + auto lenIsZero = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, len, zero); mlir::Value res = - builder.create<mlir::arith::SelectOp>(loc, lenIsZero, to, resTmp); + mlir::arith::SelectOp::create(builder, loc, lenIsZero, to, resTmp); if (toType.isUnsignedInteger()) res = builder.createConvert(loc, toType, res); - builder.create<fir::StoreOp>(loc, res, toAddr); + fir::StoreOp::create(builder, loc, res, toAddr); } // NEAREST, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP @@ -6988,7 +7036,7 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, // If isNan(Y), set X to a qNaN that will propagate to the resultIsX result. mlir::Value qNan = genQNan(xType); mlir::Value isFPClass = genIsFPClass(i1Ty, args[1], nanTest); - x = builder.create<mlir::arith::SelectOp>(loc, isFPClass, qNan, x); + x = mlir::arith::SelectOp::create(builder, loc, isFPClass, qNan, x); } mlir::Value resultIsX = genIsFPClass(i1Ty, x, nanTest); mlir::Type intType = builder.getIntegerType(xBitWidth); @@ -6999,15 +7047,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if constexpr (proc == NearestProc::Nearest) { // Arg S must not be zero. fir::IfOp ifOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, args[1], zeroTest), - /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, args[1], zeroTest), + /*withElseRegion=*/false); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); fir::runtime::genReportFatalUserError( builder, loc, "intrinsic nearest S argument is zero"); builder.setInsertionPointAfter(ifOp); mlir::Value sSign = IntrinsicLibrary::genIeeeSignbit(intType, {args[1]}); - valueUp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, sSign, one); + valueUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, sSign, one); } else if constexpr (proc == NearestProc::NextAfter) { // Convert X and Y to a common type to allow comparison. Direct conversions // between kinds 2, 3, 10, and 16 are not all supported. These conversions @@ -7028,58 +7076,58 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, if (xBitWidth > 32 && xBitWidth > yBitWidth) y = builder.createConvert(loc, xType, y); } - resultIsX = builder.create<mlir::arith::OrIOp>( - loc, resultIsX, - builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, x1, y)); - valueUp = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OLT, x1, y); + resultIsX = mlir::arith::OrIOp::create( + builder, loc, resultIsX, + mlir::arith::CmpFOp::create(builder, loc, + mlir::arith::CmpFPredicate::OEQ, x1, y)); + valueUp = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OLT, x1, y); } else if constexpr (proc == NearestProc::NextDown) { valueUp = builder.createBool(loc, false); } else if constexpr (proc == NearestProc::NextUp) { valueUp = builder.createBool(loc, true); } - mlir::Value magnitudeUp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::ne, valueUp, + mlir::Value magnitudeUp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::ne, valueUp, IntrinsicLibrary::genIeeeSignbit(i1Ty, {args[0]})); - resultIsX = builder.create<mlir::arith::OrIOp>( - loc, resultIsX, - builder.create<mlir::arith::AndIOp>( - loc, genIsFPClass(i1Ty, x, infiniteTest), magnitudeUp)); + resultIsX = mlir::arith::OrIOp::create( + builder, loc, resultIsX, + mlir::arith::AndIOp::create( + builder, loc, genIsFPClass(i1Ty, x, infiniteTest), magnitudeUp)); // Result is X. (For ieee_next_after with isNan(Y), X has been set to a NaN.) - fir::IfOp outerIfOp = builder.create<fir::IfOp>(loc, resultType, resultIsX, - /*withElseRegion=*/true); + fir::IfOp outerIfOp = fir::IfOp::create(builder, loc, resultType, resultIsX, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); if constexpr (proc == NearestProc::NextDown || proc == NearestProc::NextUp) genRaiseExcept(_FORTRAN_RUNTIME_IEEE_INVALID, genIsFPClass(i1Ty, x, snanTest)); - builder.create<fir::ResultOp>(loc, x); + fir::ResultOp::create(builder, loc, x); // Result is minPositiveSubnormal or minNegativeSubnormal. (X is zero.) builder.setInsertionPointToStart(&outerIfOp.getElseRegion().front()); - mlir::Value resultIsMinSubnormal = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::OEQ, x, + mlir::Value resultIsMinSubnormal = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::OEQ, x, builder.createRealZeroConstant(loc, xType)); fir::IfOp innerIfOp = - builder.create<fir::IfOp>(loc, resultType, resultIsMinSubnormal, - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, resultType, resultIsMinSubnormal, + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); mlir::Value minPositiveSubnormal = - builder.create<mlir::arith::BitcastOp>(loc, resultType, one); - mlir::Value minNegativeSubnormal = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::ConstantOp>( - loc, intType, + mlir::arith::BitcastOp::create(builder, loc, resultType, one); + mlir::Value minNegativeSubnormal = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::ConstantOp::create( + builder, loc, intType, builder.getIntegerAttr( intType, llvm::APInt::getBitsSetWithWrap( xBitWidth, /*lo=*/xBitWidth - 1, /*hi=*/1)))); - mlir::Value result = builder.create<mlir::arith::SelectOp>( - loc, valueUp, minPositiveSubnormal, minNegativeSubnormal); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, valueUp, minPositiveSubnormal, minNegativeSubnormal); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) genRaiseExcept(_FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); // Result is (X + minPositiveSubnormal) or (X - minPositiveSubnormal). builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); @@ -7105,15 +7153,15 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, genRuntimeCall("feraiseexcept", i32Ty, excepts); genRuntimeCall("feenableexcept", i32Ty, mask); } - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); } else { // Kind 2, 3, 4, 8, 16. Increment or decrement X cast to integer. - mlir::Value intX = builder.create<mlir::arith::BitcastOp>(loc, intType, x); - mlir::Value add = builder.create<mlir::arith::AddIOp>(loc, intX, one); - mlir::Value sub = builder.create<mlir::arith::SubIOp>(loc, intX, one); - result = builder.create<mlir::arith::BitcastOp>( - loc, resultType, - builder.create<mlir::arith::SelectOp>(loc, magnitudeUp, add, sub)); + mlir::Value intX = mlir::arith::BitcastOp::create(builder, loc, intType, x); + mlir::Value add = mlir::arith::AddIOp::create(builder, loc, intX, one); + mlir::Value sub = mlir::arith::SubIOp::create(builder, loc, intX, one); + result = mlir::arith::BitcastOp::create( + builder, loc, resultType, + mlir::arith::SelectOp::create(builder, loc, magnitudeUp, add, sub)); if constexpr (proc == NearestProc::Nearest || proc == NearestProc::NextAfter) { genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | @@ -7123,11 +7171,11 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType, _FORTRAN_RUNTIME_IEEE_INEXACT, genIsFPClass(i1Ty, result, subnormalTest)); } - builder.create<fir::ResultOp>(loc, result); + fir::ResultOp::create(builder, loc, result); } builder.setInsertionPointAfter(innerIfOp); - builder.create<fir::ResultOp>(loc, innerIfOp.getResult(0)); + fir::ResultOp::create(builder, loc, innerIfOp.getResult(0)); builder.setInsertionPointAfter(outerIfOp); return outerIfOp.getResult(0); } @@ -7209,7 +7257,7 @@ IntrinsicLibrary::genNull(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value boxStorage = builder.createTemporary(loc, boxType); mlir::Value box = fir::factory::createUnallocatedBox( builder, loc, boxType, mold->nonDeferredLenParams()); - builder.create<fir::StoreOp>(loc, box, boxStorage); + fir::StoreOp::create(builder, loc, box, boxStorage); return fir::MutableBoxValue(boxStorage, mold->nonDeferredLenParams(), {}); } @@ -7218,7 +7266,7 @@ template <typename OpTy> mlir::Value IntrinsicLibrary::genNVVMTime(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 0 && "expect no arguments"); - return builder.create<OpTy>(loc, resultType).getResult(); + return OpTy::create(builder, loc, resultType).getResult(); } // PACK @@ -7235,10 +7283,11 @@ IntrinsicLibrary::genPack(mlir::Type resultType, mlir::Value mask = builder.createBox(loc, args[1]); // Handle optional vector argument - mlir::Value vector = isStaticallyAbsent(args, 2) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value vector = + isStaticallyAbsent(args, 2) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, 1); @@ -7298,7 +7347,7 @@ void IntrinsicLibrary::genPerror(llvm::ArrayRef<fir::ExtendedValue> args) { fir::ExtendedValue str = args[0]; const auto *box = str.getBoxOf<fir::BoxValue>(); mlir::Value addr = - builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), fir::getBase(*box)); + fir::BoxAddrOp::create(builder, loc, box->getMemTy(), fir::getBase(*box)); fir::runtime::genPerror(builder, loc, addr); } @@ -7307,7 +7356,7 @@ mlir::Value IntrinsicLibrary::genPopcnt(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { assert(args.size() == 1); - mlir::Value count = builder.create<mlir::math::CtPopOp>(loc, args); + mlir::Value count = mlir::math::CtPopOp::create(builder, loc, args); return builder.createConvert(loc, resultType, count); } @@ -7320,7 +7369,7 @@ mlir::Value IntrinsicLibrary::genPoppar(mlir::Type resultType, mlir::Value count = genPopcnt(resultType, args); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - return builder.create<mlir::arith::AndIOp>(loc, count, one); + return mlir::arith::AndIOp::create(builder, loc, count, one); } // PRESENT @@ -7328,8 +7377,8 @@ fir::ExtendedValue IntrinsicLibrary::genPresent(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); - return builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), - fir::getBase(args[0])); + return fir::IsPresentOp::create(builder, loc, builder.getI1Type(), + fir::getBase(args[0])); } // PRODUCT @@ -7394,7 +7443,7 @@ void IntrinsicLibrary::genRandomSeed(llvm::ArrayRef<fir::ExtendedValue> args) { auto getDesc = [&](int i) { return isStaticallyPresent(args[i]) ? fir::getBase(args[i]) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); }; mlir::Value size = getDesc(0); mlir::Value put = getDesc(1); @@ -7438,13 +7487,13 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, bool absentDim = isStaticallyAbsent(args[2]); auto mask = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[3]); mlir::Value identity = isStaticallyAbsent(args[4]) - ? builder.create<fir::AbsentOp>(loc, fir::ReferenceType::get(eleTy)) + ? fir::AbsentOp::create(builder, loc, fir::ReferenceType::get(eleTy)) : fir::getBase(args[4]); mlir::Value ordered = isStaticallyAbsent(args[5]) @@ -7460,7 +7509,7 @@ IntrinsicLibrary::genReduce(mlir::Type resultType, ordered, result, argByRef); if (fir::isa_derived(eleTy)) return result; - return builder.create<fir::LoadOp>(loc, result); + return fir::LoadOp::create(builder, loc, result); } if (fir::isa_char(eleTy)) { auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(resultType); @@ -7510,7 +7559,7 @@ IntrinsicLibrary::genRename(std::optional<mlir::Type> resultType, auto statusAddr = builder.createTemporary(loc, *resultType); auto statusBox = builder.createBox(loc, statusAddr); fir::runtime::genRename(builder, loc, path1, path2, statusBox); - return builder.create<fir::LoadOp>(loc, statusAddr); + return fir::LoadOp::create(builder, loc, statusAddr); } else { // code-gen for the procedure form of RENAME mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType()); @@ -7518,7 +7567,7 @@ IntrinsicLibrary::genRename(std::optional<mlir::Type> resultType, mlir::Value statusBox = isStaticallyPresent(status) ? fir::getBase(status) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genRename(builder, loc, path1, path2, statusBox); return {}; } @@ -7563,16 +7612,18 @@ IntrinsicLibrary::genReshape(mlir::Type resultType, TODO(loc, "intrinsic: reshape requires computing rank of result"); // Handle optional pad argument - mlir::Value pad = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[2]); + mlir::Value pad = + isStaticallyAbsent(args[2]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[2]); // Handle optional order argument - mlir::Value order = isStaticallyAbsent(args[3]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) - : builder.createBox(loc, args[3]); + mlir::Value order = + isStaticallyAbsent(args[3]) + ? fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())) + : builder.createBox(loc, args[3]); // Create mutable fir.box to be passed to the runtime for the result. mlir::Type type = builder.getVarLenSeqTy(resultType, resultRank); @@ -7643,26 +7694,27 @@ mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType, // If X is finite and result is infinite, signal IEEE_OVERFLOW // If X is finite and scale(result, -I) != X, signal IEEE_UNDERFLOW fir::IfOp outerIfOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, args[0], finiteTest), - /*withElseRegion=*/false); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, args[0], finiteTest), + /*withElseRegion=*/false); builder.setInsertionPointToStart(&outerIfOp.getThenRegion().front()); fir::IfOp innerIfOp = - builder.create<fir::IfOp>(loc, genIsFPClass(i1Ty, result, infiniteTest), - /*withElseRegion=*/true); + fir::IfOp::create(builder, loc, genIsFPClass(i1Ty, result, infiniteTest), + /*withElseRegion=*/true); builder.setInsertionPointToStart(&innerIfOp.getThenRegion().front()); genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT); builder.setInsertionPointToStart(&innerIfOp.getElseRegion().front()); - mlir::Value minusI = builder.create<mlir::arith::MulIOp>( - loc, args[1], builder.createAllOnesInteger(loc, args[1].getType())); + mlir::Value minusI = mlir::arith::MulIOp::create( + builder, loc, args[1], + builder.createAllOnesInteger(loc, args[1].getType())); mlir::Value reverseResult = builder.createConvert( loc, resultType, fir::runtime::genScale( builder, loc, builder.createConvert(loc, f32Ty, result), minusI)); genRaiseExcept( _FORTRAN_RUNTIME_IEEE_UNDERFLOW | _FORTRAN_RUNTIME_IEEE_INEXACT, - builder.create<mlir::arith::CmpFOp>(loc, mlir::arith::CmpFPredicate::ONE, - args[0], reverseResult)); + mlir::arith::CmpFOp::create(builder, loc, mlir::arith::CmpFPredicate::ONE, + args[0], reverseResult)); builder.setInsertionPointAfter(outerIfOp); return result; } @@ -7714,13 +7766,14 @@ IntrinsicLibrary::genScan(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value back = fir::isUnboxedValue(args[2]) - ? makeRefThenEmbox(*args[2].getUnboxed()) - : builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -7761,7 +7814,7 @@ IntrinsicLibrary::genSecond(std::optional<mlir::Type> resultType, genCpuTime(subroutineArgs); if (resultType) - return builder.create<fir::LoadOp>(loc, fir::getBase(result)); + return fir::LoadOp::create(builder, loc, fir::getBase(result)); return {}; } @@ -7808,22 +7861,22 @@ IntrinsicLibrary::genSelectedRealKind(mlir::Type resultType, // Handle optional precision(P) argument mlir::Value precision = isStaticallyAbsent(args[0]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[0]); // Handle optional range(R) argument mlir::Value range = isStaticallyAbsent(args[1]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[1]); // Handle optional radix(RADIX) argument mlir::Value radix = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::ReferenceType::get(builder.getI1Type())) + ? fir::AbsentOp::create(builder, loc, + fir::ReferenceType::get(builder.getI1Type())) : fir::getBase(args[2]); return builder.createConvert( @@ -7861,9 +7914,9 @@ createBoxForRuntimeBoundInquiry(mlir::Location loc, fir::FirOpBuilder &builder, // shape information. mlir::Value localShape = builder.createShape(loc, array); mlir::Value oldBox = boxValue.getAddr(); - return builder.create<fir::ReboxOp>(loc, oldBox.getType(), oldBox, - localShape, - /*slice=*/mlir::Value{}); + return fir::ReboxOp::create(builder, loc, oldBox.getType(), oldBox, + localShape, + /*slice=*/mlir::Value{}); }, [&](const auto &) -> mlir::Value { // This is a pointer/allocatable, or an entity not yet tracked with a @@ -7909,7 +7962,7 @@ genBoundInquiry(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value resultBase = builder.createConvert(loc, baseType, resultStorage); mlir::Value rankValue = - builder.create<fir::BoxRankOp>(loc, builder.getIndexType(), arrayBox); + fir::BoxRankOp::create(builder, loc, builder.getIndexType(), arrayBox); return fir::ArrayBoxValue{resultBase, {rankValue}}; } // Result extent is a compile time constant in the other cases. @@ -7939,9 +7992,9 @@ IntrinsicLibrary::genShape(mlir::Type resultType, mlir::Value extent = fir::factory::readExtent(builder, loc, array, dim); extent = builder.createConvert(loc, extentType, extent); auto index = builder.createIntegerConstant(loc, indexType, dim); - auto shapeAddr = builder.create<fir::CoordinateOp>(loc, shapeAddrType, - shapeArray, index); - builder.create<fir::StoreOp>(loc, extent, shapeAddr); + auto shapeAddr = fir::CoordinateOp::create(builder, loc, shapeAddrType, + shapeArray, index); + fir::StoreOp::create(builder, loc, extent, shapeAddr); } mlir::Value shapeArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -7967,18 +8020,18 @@ mlir::Value IntrinsicLibrary::genShift(mlir::Type resultType, mlir::Value zero = builder.createIntegerConstant(loc, signlessType, 0); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value tooSmall = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, shift, zero); - mlir::Value tooLarge = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); + mlir::Value tooSmall = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, shift, zero); + mlir::Value tooLarge = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::sge, shift, bitSize); mlir::Value outOfBounds = - builder.create<mlir::arith::OrIOp>(loc, tooSmall, tooLarge); + mlir::arith::OrIOp::create(builder, loc, tooSmall, tooLarge); mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value shifted = builder.create<Shift>(loc, word, shift); + mlir::Value shifted = Shift::create(builder, loc, word, shift); mlir::Value result = - builder.create<mlir::arith::SelectOp>(loc, outOfBounds, zero, shifted); + mlir::arith::SelectOp::create(builder, loc, outOfBounds, zero, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -7993,8 +8046,8 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::IntegerType::SignednessSemantics::Signless); mlir::Value bitSize = builder.createIntegerConstant(loc, signlessType, bits); mlir::Value shift = builder.createConvert(loc, signlessType, args[1]); - mlir::Value shiftGeBitSize = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); + mlir::Value shiftGeBitSize = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::uge, shift, bitSize); // Lowering of mlir::arith::ShRSIOp is using `ashr`. `ashr` is undefined when // the shift amount is equal to the element size. @@ -8006,13 +8059,13 @@ mlir::Value IntrinsicLibrary::genShiftA(mlir::Type resultType, mlir::Value word = args[0]; if (word.getType().isUnsignedInteger()) word = builder.createConvert(loc, signlessType, word); - mlir::Value valueIsNeg = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, word, zero); + mlir::Value valueIsNeg = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, word, zero); mlir::Value specialRes = - builder.create<mlir::arith::SelectOp>(loc, valueIsNeg, minusOne, zero); - mlir::Value shifted = builder.create<mlir::arith::ShRSIOp>(loc, word, shift); - mlir::Value result = builder.create<mlir::arith::SelectOp>( - loc, shiftGeBitSize, specialRes, shifted); + mlir::arith::SelectOp::create(builder, loc, valueIsNeg, minusOne, zero); + mlir::Value shifted = mlir::arith::ShRSIOp::create(builder, loc, word, shift); + mlir::Value result = mlir::arith::SelectOp::create( + builder, loc, shiftGeBitSize, specialRes, shifted); if (resultType.isUnsignedInteger()) return builder.createConvert(loc, resultType, result); return result; @@ -8037,10 +8090,10 @@ mlir::Value IntrinsicLibrary::genSign(mlir::Type resultType, if (mlir::isa<mlir::IntegerType>(resultType)) { mlir::Value abs = genAbs(resultType, {args[0]}); mlir::Value zero = builder.createIntegerConstant(loc, resultType, 0); - auto neg = builder.create<mlir::arith::SubIOp>(loc, zero, abs); - auto cmp = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::slt, args[1], zero); - return builder.create<mlir::arith::SelectOp>(loc, cmp, neg, abs); + auto neg = mlir::arith::SubIOp::create(builder, loc, zero, abs); + auto cmp = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::slt, args[1], zero); + return mlir::arith::SelectOp::create(builder, loc, cmp, neg, abs); } return genRuntimeCall("sign", resultType, args); } @@ -8056,6 +8109,21 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); + return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); +} + +// SINPI +mlir::Value IntrinsicLibrary::genSinpi(mlir::Type resultType, + llvm::ArrayRef<mlir::Value> args) { + assert(args.size() == 1); + mlir::MLIRContext *context = builder.getContext(); + mlir::FunctionType ftype = + mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); + llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi); + mlir::Value dfactor = + builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); + mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg}); } @@ -8100,14 +8168,14 @@ IntrinsicLibrary::genSize(mlir::Type resultType, .genThen([&]() { mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, array)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .genElse([&]() { - mlir::Value dimValue = builder.create<fir::LoadOp>(loc, dim); + mlir::Value dimValue = fir::LoadOp::create(builder, loc, dim); mlir::Value size = builder.createConvert( loc, resultType, fir::runtime::genSizeDim(builder, loc, array, dimValue)); - builder.create<fir::ResultOp>(loc, size); + fir::ResultOp::create(builder, loc, size); }) .getResults()[0]; } @@ -8118,12 +8186,13 @@ IntrinsicLibrary::genSizeOf(mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) { assert(args.size() == 1); mlir::Value box = fir::getBase(args[0]); - mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, resultType, box); + mlir::Value eleSize = + fir::BoxEleSizeOp::create(builder, loc, resultType, box); if (!fir::isArray(args[0])) return eleSize; mlir::Value arraySize = builder.createConvert( loc, resultType, fir::runtime::genSize(builder, loc, box)); - return builder.create<mlir::arith::MulIOp>(loc, eleSize, arraySize); + return mlir::arith::MulIOp::create(builder, loc, eleSize, arraySize); } // TAND @@ -8137,6 +8206,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType, mlir::Value dfactor = builder.createRealConstant( loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0)); mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); + mlir::Value arg = mlir::arith::MulFOp::create(builder, loc, args[0], factor); + return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); +} + +// TANPI +mlir::Value IntrinsicLibrary::genTanpi(mlir::Type resultType, + llvm::ArrayRef<mlir::Value> args) { + assert(args.size() == 1); + mlir::MLIRContext *context = builder.getContext(); + mlir::FunctionType ftype = + mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); + llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi); + mlir::Value dfactor = + builder.createRealConstant(loc, mlir::Float64Type::get(context), pi); + mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor); mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor); return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg}); } @@ -8147,81 +8231,83 @@ mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); - mlir::Value threadIdY = builder.create<mlir::NVVM::ThreadIdYOp>(loc, i32Ty); - mlir::Value threadIdZ = builder.create<mlir::NVVM::ThreadIdZOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); + mlir::Value threadIdY = mlir::NVVM::ThreadIdYOp::create(builder, loc, i32Ty); + mlir::Value threadIdZ = mlir::NVVM::ThreadIdZOp::create(builder, loc, i32Ty); - mlir::Value blockIdX = builder.create<mlir::NVVM::BlockIdXOp>(loc, i32Ty); - mlir::Value blockIdY = builder.create<mlir::NVVM::BlockIdYOp>(loc, i32Ty); - mlir::Value blockIdZ = builder.create<mlir::NVVM::BlockIdZOp>(loc, i32Ty); + mlir::Value blockIdX = mlir::NVVM::BlockIdXOp::create(builder, loc, i32Ty); + mlir::Value blockIdY = mlir::NVVM::BlockIdYOp::create(builder, loc, i32Ty); + mlir::Value blockIdZ = mlir::NVVM::BlockIdZOp::create(builder, loc, i32Ty); - mlir::Value blockDimX = builder.create<mlir::NVVM::BlockDimXOp>(loc, i32Ty); - mlir::Value blockDimY = builder.create<mlir::NVVM::BlockDimYOp>(loc, i32Ty); - mlir::Value blockDimZ = builder.create<mlir::NVVM::BlockDimZOp>(loc, i32Ty); - mlir::Value gridDimX = builder.create<mlir::NVVM::GridDimXOp>(loc, i32Ty); - mlir::Value gridDimY = builder.create<mlir::NVVM::GridDimYOp>(loc, i32Ty); - mlir::Value gridDimZ = builder.create<mlir::NVVM::GridDimZOp>(loc, i32Ty); + mlir::Value blockDimX = mlir::NVVM::BlockDimXOp::create(builder, loc, i32Ty); + mlir::Value blockDimY = mlir::NVVM::BlockDimYOp::create(builder, loc, i32Ty); + mlir::Value blockDimZ = mlir::NVVM::BlockDimZOp::create(builder, loc, i32Ty); + mlir::Value gridDimX = mlir::NVVM::GridDimXOp::create(builder, loc, i32Ty); + mlir::Value gridDimY = mlir::NVVM::GridDimYOp::create(builder, loc, i32Ty); + mlir::Value gridDimZ = mlir::NVVM::GridDimZOp::create(builder, loc, i32Ty); // this_grid.size = ((blockDim.z * gridDim.z) * (blockDim.y * gridDim.y)) * // (blockDim.x * gridDim.x); mlir::Value resZ = - builder.create<mlir::arith::MulIOp>(loc, blockDimZ, gridDimZ); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, gridDimZ); mlir::Value resY = - builder.create<mlir::arith::MulIOp>(loc, blockDimY, gridDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimY, gridDimY); mlir::Value resX = - builder.create<mlir::arith::MulIOp>(loc, blockDimX, gridDimX); - mlir::Value resZY = builder.create<mlir::arith::MulIOp>(loc, resZ, resY); - mlir::Value size = builder.create<mlir::arith::MulIOp>(loc, resZY, resX); + mlir::arith::MulIOp::create(builder, loc, blockDimX, gridDimX); + mlir::Value resZY = mlir::arith::MulIOp::create(builder, loc, resZ, resY); + mlir::Value size = mlir::arith::MulIOp::create(builder, loc, resZY, resX); // tmp = ((blockIdx.z * gridDim.y * gridDim.x) + (blockIdx.y * gridDim.x)) + // blockIdx.x; // this_group.rank = tmp * ((blockDim.x * blockDim.y) * blockDim.z) + // ((threadIdx.z * blockDim.y) * blockDim.x) + // (threadIdx.y * blockDim.x) + threadIdx.x + 1; - mlir::Value r1 = builder.create<mlir::arith::MulIOp>(loc, blockIdZ, gridDimY); - mlir::Value r2 = builder.create<mlir::arith::MulIOp>(loc, r1, gridDimX); - mlir::Value r3 = builder.create<mlir::arith::MulIOp>(loc, blockIdY, gridDimX); - mlir::Value r2r3 = builder.create<mlir::arith::AddIOp>(loc, r2, r3); - mlir::Value tmp = builder.create<mlir::arith::AddIOp>(loc, r2r3, blockIdX); + mlir::Value r1 = + mlir::arith::MulIOp::create(builder, loc, blockIdZ, gridDimY); + mlir::Value r2 = mlir::arith::MulIOp::create(builder, loc, r1, gridDimX); + mlir::Value r3 = + mlir::arith::MulIOp::create(builder, loc, blockIdY, gridDimX); + mlir::Value r2r3 = mlir::arith::AddIOp::create(builder, loc, r2, r3); + mlir::Value tmp = mlir::arith::AddIOp::create(builder, loc, r2r3, blockIdX); mlir::Value bXbY = - builder.create<mlir::arith::MulIOp>(loc, blockDimX, blockDimY); + mlir::arith::MulIOp::create(builder, loc, blockDimX, blockDimY); mlir::Value bXbYbZ = - builder.create<mlir::arith::MulIOp>(loc, bXbY, blockDimZ); + mlir::arith::MulIOp::create(builder, loc, bXbY, blockDimZ); mlir::Value tZbY = - builder.create<mlir::arith::MulIOp>(loc, threadIdZ, blockDimY); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); mlir::Value tZbYbX = - builder.create<mlir::arith::MulIOp>(loc, tZbY, blockDimX); + mlir::arith::MulIOp::create(builder, loc, tZbY, blockDimX); mlir::Value tYbX = - builder.create<mlir::arith::MulIOp>(loc, threadIdY, blockDimX); - mlir::Value rank = builder.create<mlir::arith::MulIOp>(loc, tmp, bXbYbZ); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, tZbYbX); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, tYbX); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, threadIdX); + mlir::arith::MulIOp::create(builder, loc, threadIdY, blockDimX); + mlir::Value rank = mlir::arith::MulIOp::create(builder, loc, tmp, bXbYbZ); + rank = mlir::arith::AddIOp::create(builder, loc, rank, tZbYbX); + rank = mlir::arith::AddIOp::create(builder, loc, rank, tYbX); + rank = mlir::arith::AddIOp::create(builder, loc, rank, threadIdX); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, one); + rank = mlir::arith::AddIOp::create(builder, loc, rank, one); auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8232,50 +8318,50 @@ IntrinsicLibrary::genThisThreadBlock(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // this_thread_block%size = blockDim.z * blockDim.y * blockDim.x; - mlir::Value blockDimX = builder.create<mlir::NVVM::BlockDimXOp>(loc, i32Ty); - mlir::Value blockDimY = builder.create<mlir::NVVM::BlockDimYOp>(loc, i32Ty); - mlir::Value blockDimZ = builder.create<mlir::NVVM::BlockDimZOp>(loc, i32Ty); + mlir::Value blockDimX = mlir::NVVM::BlockDimXOp::create(builder, loc, i32Ty); + mlir::Value blockDimY = mlir::NVVM::BlockDimYOp::create(builder, loc, i32Ty); + mlir::Value blockDimZ = mlir::NVVM::BlockDimZOp::create(builder, loc, i32Ty); mlir::Value size = - builder.create<mlir::arith::MulIOp>(loc, blockDimZ, blockDimY); - size = builder.create<mlir::arith::MulIOp>(loc, size, blockDimX); + mlir::arith::MulIOp::create(builder, loc, blockDimZ, blockDimY); + size = mlir::arith::MulIOp::create(builder, loc, size, blockDimX); // this_thread_block%rank = ((threadIdx.z * blockDim.y) * blockDim.x) + // (threadIdx.y * blockDim.x) + threadIdx.x + 1; - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); - mlir::Value threadIdY = builder.create<mlir::NVVM::ThreadIdYOp>(loc, i32Ty); - mlir::Value threadIdZ = builder.create<mlir::NVVM::ThreadIdZOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); + mlir::Value threadIdY = mlir::NVVM::ThreadIdYOp::create(builder, loc, i32Ty); + mlir::Value threadIdZ = mlir::NVVM::ThreadIdZOp::create(builder, loc, i32Ty); mlir::Value r1 = - builder.create<mlir::arith::MulIOp>(loc, threadIdZ, blockDimY); - mlir::Value r2 = builder.create<mlir::arith::MulIOp>(loc, r1, blockDimX); + mlir::arith::MulIOp::create(builder, loc, threadIdZ, blockDimY); + mlir::Value r2 = mlir::arith::MulIOp::create(builder, loc, r1, blockDimX); mlir::Value r3 = - builder.create<mlir::arith::MulIOp>(loc, threadIdY, blockDimX); - mlir::Value r2r3 = builder.create<mlir::arith::AddIOp>(loc, r2, r3); - mlir::Value rank = builder.create<mlir::arith::AddIOp>(loc, r2r3, threadIdX); + mlir::arith::MulIOp::create(builder, loc, threadIdY, blockDimX); + mlir::Value r2r3 = mlir::arith::AddIOp::create(builder, loc, r2, r3); + mlir::Value rank = mlir::arith::AddIOp::create(builder, loc, r2r3, threadIdX); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); - rank = builder.create<mlir::arith::AddIOp>(loc, rank, one); + rank = mlir::arith::AddIOp::create(builder, loc, rank, one); auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8285,7 +8371,7 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, assert(args.size() == 0); auto recTy = mlir::cast<fir::RecordType>(resultType); assert(recTy && "RecordType expepected"); - mlir::Value res = builder.create<fir::AllocaOp>(loc, resultType); + mlir::Value res = fir::AllocaOp::create(builder, loc, resultType); mlir::Type i32Ty = builder.getI32Type(); // coalesced_group%size = 32 @@ -8293,28 +8379,28 @@ mlir::Value IntrinsicLibrary::genThisWarp(mlir::Type resultType, auto sizeFieldName = recTy.getTypeList()[1].first; mlir::Type sizeFieldTy = recTy.getTypeList()[1].second; mlir::Type fieldIndexType = fir::FieldType::get(resultType.getContext()); - mlir::Value sizeFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, sizeFieldName, recTy, + mlir::Value sizeFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, sizeFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value sizeCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); - builder.create<fir::StoreOp>(loc, size, sizeCoord); + mlir::Value sizeCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(sizeFieldTy), res, sizeFieldIndex); + fir::StoreOp::create(builder, loc, size, sizeCoord); // coalesced_group%rank = threadIdx.x & 31 + 1 - mlir::Value threadIdX = builder.create<mlir::NVVM::ThreadIdXOp>(loc, i32Ty); + mlir::Value threadIdX = mlir::NVVM::ThreadIdXOp::create(builder, loc, i32Ty); mlir::Value mask = builder.createIntegerConstant(loc, i32Ty, 31); mlir::Value one = builder.createIntegerConstant(loc, i32Ty, 1); mlir::Value masked = - builder.create<mlir::arith::AndIOp>(loc, threadIdX, mask); - mlir::Value rank = builder.create<mlir::arith::AddIOp>(loc, masked, one); + mlir::arith::AndIOp::create(builder, loc, threadIdX, mask); + mlir::Value rank = mlir::arith::AddIOp::create(builder, loc, masked, one); auto rankFieldName = recTy.getTypeList()[2].first; mlir::Type rankFieldTy = recTy.getTypeList()[2].second; - mlir::Value rankFieldIndex = builder.create<fir::FieldIndexOp>( - loc, fieldIndexType, rankFieldName, recTy, + mlir::Value rankFieldIndex = fir::FieldIndexOp::create( + builder, loc, fieldIndexType, rankFieldName, recTy, /*typeParams=*/mlir::ValueRange{}); - mlir::Value rankCoord = builder.create<fir::CoordinateOp>( - loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); - builder.create<fir::StoreOp>(loc, rank, rankCoord); + mlir::Value rankCoord = fir::CoordinateOp::create( + builder, loc, builder.getRefType(rankFieldTy), res, rankFieldIndex); + fir::StoreOp::create(builder, loc, rank, rankCoord); return res; } @@ -8324,7 +8410,7 @@ mlir::Value IntrinsicLibrary::genTrailz(mlir::Type resultType, assert(args.size() == 1); mlir::Value result = - builder.create<mlir::math::CountTrailingZerosOp>(loc, args); + mlir::math::CountTrailingZerosOp::create(builder, loc, args); return builder.createConvert(loc, resultType, result); } @@ -8352,10 +8438,10 @@ static mlir::Value computeLBOUND(fir::FirOpBuilder &builder, mlir::Location loc, zero = builder.createConvert(loc, extent.getType(), zero); // Note: for assumed size, the extent is -1, and the lower bound should // be returned. It is important to test extent == 0 and not extent > 0. - auto dimIsEmpty = builder.create<mlir::arith::CmpIOp>( - loc, mlir::arith::CmpIPredicate::eq, extent, zero); + auto dimIsEmpty = mlir::arith::CmpIOp::create( + builder, loc, mlir::arith::CmpIPredicate::eq, extent, zero); one = builder.createConvert(loc, lb.getType(), one); - return builder.create<mlir::arith::SelectOp>(loc, dimIsEmpty, one, lb); + return mlir::arith::SelectOp::create(builder, loc, dimIsEmpty, one, lb); } // LBOUND @@ -8391,8 +8477,8 @@ IntrinsicLibrary::genLbound(mlir::Type resultType, lb = builder.createConvert(loc, lbType, lb); auto index = builder.createIntegerConstant(loc, indexType, dim); auto lbAddr = - builder.create<fir::CoordinateOp>(loc, lbAddrType, lbArray, index); - builder.create<fir::StoreOp>(loc, lb, lbAddr); + fir::CoordinateOp::create(builder, loc, lbAddrType, lbArray, index); + fir::StoreOp::create(builder, loc, lb, lbAddr); } mlir::Value lbArrayExtent = builder.createIntegerConstant(loc, indexType, rank); @@ -8431,8 +8517,8 @@ IntrinsicLibrary::genUbound(mlir::Type resultType, mlir::Value lbound = fir::getBase(genLbound(resultType, args)); mlir::Value one = builder.createIntegerConstant(loc, resultType, 1); - mlir::Value ubound = builder.create<mlir::arith::SubIOp>(loc, lbound, one); - return builder.create<mlir::arith::AddIOp>(loc, ubound, extent); + mlir::Value ubound = mlir::arith::SubIOp::create(builder, loc, lbound, one); + return mlir::arith::AddIOp::create(builder, loc, ubound, extent); } // Handle calls to UBOUND without the DIM argument, which return an array int kindPos = args.size() == 2 ? 1 : 2; @@ -8526,9 +8612,9 @@ IntrinsicLibrary::genStorageSize(mlir::Type resultType, box = builder.createBox(loc, args[0], /*isPolymorphic=*/args[0].isPolymorphic()); - mlir::Value eleSize = builder.create<fir::BoxEleSizeOp>(loc, kindTy, box); + mlir::Value eleSize = fir::BoxEleSizeOp::create(builder, loc, kindTy, box); mlir::Value c8 = builder.createIntegerConstant(loc, kindTy, 8); - return builder.create<mlir::arith::MulIOp>(loc, eleSize, c8); + return mlir::arith::MulIOp::create(builder, loc, eleSize, c8); } // SUM @@ -8541,7 +8627,7 @@ IntrinsicLibrary::genSum(mlir::Type resultType, // SYNCTHREADS void IntrinsicLibrary::genSyncThreads(llvm::ArrayRef<fir::ExtendedValue> args) { - builder.create<mlir::NVVM::Barrier0Op>(loc); + mlir::NVVM::Barrier0Op::create(builder, loc); } // SYNCTHREADS_AND @@ -8553,7 +8639,7 @@ IntrinsicLibrary::genSyncThreadsAnd(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_COUNT @@ -8565,7 +8651,7 @@ IntrinsicLibrary::genSyncThreadsCount(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCTHREADS_OR @@ -8577,7 +8663,7 @@ IntrinsicLibrary::genSyncThreadsOr(mlir::Type resultType, mlir::FunctionType ftype = mlir::FunctionType::get(context, {resultType}, {args[0].getType()}); auto funcOp = builder.createFunction(loc, funcName, ftype); - return builder.create<fir::CallOp>(loc, funcOp, args).getResult(0); + return fir::CallOp::create(builder, loc, funcOp, args).getResult(0); } // SYNCWARP @@ -8589,7 +8675,7 @@ void IntrinsicLibrary::genSyncWarp(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::FunctionType::get(builder.getContext(), {mask.getType()}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> argsList{mask}; - builder.create<fir::CallOp>(loc, funcOp, argsList); + fir::CallOp::create(builder, loc, funcOp, argsList); } // SYSTEM @@ -8615,25 +8701,26 @@ IntrinsicLibrary::genSystem(std::optional<mlir::Type> resultType, mlir::Value exitstatBox = isStaticallyPresent(exitstat) ? fir::getBase(exitstat) - : builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + : fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); // Create a dummmy cmdstat to prevent EXECUTE_COMMAND_LINE terminate itself // when cmdstat is assigned with a non-zero value but not present mlir::Value tempValue = builder.createIntegerConstant(loc, builder.getI16Type(), 0); mlir::Value temp = builder.createTemporary(loc, builder.getI16Type()); - builder.create<fir::StoreOp>(loc, tempValue, temp); + fir::StoreOp::create(builder, loc, tempValue, temp); mlir::Value cmdstatBox = builder.createBox(loc, temp); mlir::Value cmdmsgBox = - builder.create<fir::AbsentOp>(loc, boxNoneTy).getResult(); + fir::AbsentOp::create(builder, loc, boxNoneTy).getResult(); fir::runtime::genExecuteCommandLine(builder, loc, command, waitBool, exitstatBox, cmdstatBox, cmdmsgBox); if (resultType) { - mlir::Value exitstatAddr = builder.create<fir::BoxAddrOp>(loc, exitstatBox); - return builder.create<fir::LoadOp>(loc, fir::getBase(exitstatAddr)); + mlir::Value exitstatAddr = + fir::BoxAddrOp::create(builder, loc, exitstatBox); + return fir::LoadOp::create(builder, loc, fir::getBase(exitstatAddr)); } return {}; } @@ -8729,7 +8816,7 @@ void IntrinsicLibrary::genThreadFence(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_BLOCK @@ -8740,7 +8827,7 @@ void IntrinsicLibrary::genThreadFenceBlock( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // THREADFENCE_SYSTEM @@ -8751,7 +8838,7 @@ void IntrinsicLibrary::genThreadFenceSystem( mlir::FunctionType::get(builder.getContext(), {}, {}); auto funcOp = builder.createFunction(loc, funcName, funcType); llvm::SmallVector<mlir::Value> noArgs; - builder.create<fir::CallOp>(loc, funcOp, noArgs); + fir::CallOp::create(builder, loc, funcOp, noArgs); } // TIME @@ -8803,29 +8890,30 @@ static mlir::Value createExtremumCompare(mlir::Location loc, // Return the number if one of the inputs is NaN and the other is // a number. auto leftIsResult = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); - auto rightIsNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, right, right); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); + auto rightIsNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, right, right); result = - builder.create<mlir::arith::OrIOp>(loc, leftIsResult, rightIsNan); + mlir::arith::OrIOp::create(builder, loc, leftIsResult, rightIsNan); } else if constexpr (behavior == ExtremumBehavior::IeeeMinMaximum) { // Always return NaNs if one the input is NaNs auto leftIsResult = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); - auto leftIsNan = builder.create<mlir::arith::CmpFOp>( - loc, mlir::arith::CmpFPredicate::UNE, left, left); - result = builder.create<mlir::arith::OrIOp>(loc, leftIsResult, leftIsNan); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); + auto leftIsNan = mlir::arith::CmpFOp::create( + builder, loc, mlir::arith::CmpFPredicate::UNE, left, left); + result = + mlir::arith::OrIOp::create(builder, loc, leftIsResult, leftIsNan); } else if constexpr (behavior == ExtremumBehavior::MinMaxss) { // If the left is a NaN, return the right whatever it is. result = - builder.create<mlir::arith::CmpFOp>(loc, orderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, orderedCmp, left, right); } else if constexpr (behavior == ExtremumBehavior::PgfortranLlvm) { // If one of the operand is a NaN, return left whatever it is. static constexpr auto unorderedCmp = extremum == Extremum::Max ? mlir::arith::CmpFPredicate::UGT : mlir::arith::CmpFPredicate::ULT; result = - builder.create<mlir::arith::CmpFOp>(loc, unorderedCmp, left, right); + mlir::arith::CmpFOp::create(builder, loc, unorderedCmp, left, right); } else { // TODO: ieeeMinNum/ieeeMaxNum static_assert(behavior == ExtremumBehavior::IeeeMinMaxNum, @@ -8839,8 +8927,8 @@ static mlir::Value createExtremumCompare(mlir::Location loc, left = builder.createConvert(loc, signlessType, left); right = builder.createConvert(loc, signlessType, right); } - result = - builder.create<mlir::arith::CmpIOp>(loc, integerPredicate, left, right); + result = mlir::arith::CmpIOp::create(builder, loc, integerPredicate, left, + right); } else if (fir::isa_char(type) || fir::isa_char(fir::unwrapRefType(type))) { // TODO: ! character min and max is tricky because the result // length is the length of the longest argument! @@ -8961,13 +9049,14 @@ IntrinsicLibrary::genVerify(mlir::Type resultType, builder.getContext(), builder.getKindMap().defaultLogicalKind()); mlir::Value temp = builder.createTemporary(loc, logTy); mlir::Value castb = builder.createConvert(loc, logTy, b); - builder.create<fir::StoreOp>(loc, castb, temp); + fir::StoreOp::create(builder, loc, castb, temp); return builder.createBox(loc, temp); }; - mlir::Value back = fir::isUnboxedValue(args[2]) - ? makeRefThenEmbox(*args[2].getUnboxed()) - : builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())); + mlir::Value back = + fir::isUnboxedValue(args[2]) + ? makeRefThenEmbox(*args[2].getUnboxed()) + : fir::AbsentOp::create(builder, loc, + fir::BoxType::get(builder.getI1Type())); // Handle required string argument mlir::Value string = builder.createBox(loc, args[0]); @@ -9007,8 +9096,8 @@ IntrinsicLibrary::genExtremumloc(FN func, FD funcDim, llvm::StringRef errMsg, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); // Handle optional kind argument @@ -9090,8 +9179,8 @@ IntrinsicLibrary::genExtremumVal(FN func, FD funcDim, FC funcChar, // Handle optional mask argument auto mask = isStaticallyAbsent(args[2]) - ? builder.create<fir::AbsentOp>( - loc, fir::BoxType::get(builder.getI1Type())) + ? fir::AbsentOp::create( + builder, loc, fir::BoxType::get(builder.getI1Type())) : builder.createBox(loc, args[2]); bool absentDim = isStaticallyAbsent(args[1]); @@ -9155,7 +9244,7 @@ mlir::Value IntrinsicLibrary::genExtremum(mlir::Type, for (auto arg : args.drop_front()) { mlir::Value mask = createExtremumCompare<extremum, behavior>(loc, builder, result, arg); - result = builder.create<mlir::arith::SelectOp>(loc, mask, result, arg); + result = mlir::arith::SelectOp::create(builder, loc, mask, result, arg); } return result; } |