diff options
Diffstat (limited to 'flang/lib/Optimizer/Builder/IntrinsicCall.cpp')
-rw-r--r-- | flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 90 |
1 files changed, 86 insertions, 4 deletions
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 323d2fe..e62ed48 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}}}, @@ -369,7 +371,8 @@ static constexpr IntrinsicHandler handlers[]{ &I::genCFPointer, {{{"cptr", asValue}, {"fptr", asInquired}, - {"shape", asAddr, handleDynamicOptional}}}, + {"shape", asAddr, handleDynamicOptional}, + {"lower", asAddr, handleDynamicOptional}}}, /*isElemental=*/false}, {"c_f_procpointer", &I::genCFProcPointer, @@ -901,6 +904,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 +945,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}, @@ -2674,6 +2679,21 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType, 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 template <void (*CallRuntime)(fir::FirOpBuilder &, mlir::Location loc, mlir::Value, mlir::Value)> @@ -2827,6 +2847,21 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType, 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 mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { @@ -3404,7 +3439,7 @@ IntrinsicLibrary::genCDevLoc(mlir::Type resultType, // C_F_POINTER void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) { - assert(args.size() == 3); + assert(args.size() == 4); // Handle CPTR argument // Get the value of the C address or the result of a reference to C_LOC. mlir::Value cPtr = fir::getBase(args[0]); @@ -3419,9 +3454,12 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value addr = builder.createConvert(loc, fPtr->getMemTy(), cPtrAddrVal); mlir::SmallVector<mlir::Value> extents; + mlir::SmallVector<mlir::Value> lbounds; if (box.hasRank()) { assert(isStaticallyPresent(args[2]) && "FPTR argument must be an array if SHAPE argument exists"); + + // Handle and unpack SHAPE argument mlir::Value shape = fir::getBase(args[2]); int arrayRank = box.rank(); mlir::Type shapeElementType = @@ -3434,17 +3472,31 @@ void IntrinsicLibrary::genCFPointer(llvm::ArrayRef<fir::ExtendedValue> args) { mlir::Value load = fir::LoadOp::create(builder, loc, var); extents.push_back(builder.createConvert(loc, idxType, load)); } + + // Handle and unpack LOWER argument if present + if (isStaticallyPresent(args[3])) { + mlir::Value lower = fir::getBase(args[3]); + mlir::Type lowerElementType = + fir::unwrapSequenceType(fir::unwrapPassByRefType(lower.getType())); + 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(lowerElementType), lower, index); + mlir::Value load = builder.create<fir::LoadOp>(loc, var); + lbounds.push_back(builder.createConvert(loc, idxType, load)); + } + } } if (box.isCharacter()) { mlir::Value len = box.nonDeferredLenParams()[0]; if (box.hasRank()) - return fir::CharArrayBoxValue{addr, len, extents}; + return fir::CharArrayBoxValue{addr, len, extents, lbounds}; return fir::CharBoxValue{addr, len}; } if (box.isDerivedWithLenParameters()) TODO(loc, "get length parameters of derived type"); if (box.hasRank()) - return fir::ArrayBoxValue{addr, extents}; + return fir::ArrayBoxValue{addr, extents, lbounds}; return addr; }; @@ -8079,6 +8131,21 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType, 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}); +} + // SIZE fir::ExtendedValue IntrinsicLibrary::genSize(mlir::Type resultType, @@ -8161,6 +8228,21 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType, 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}); +} + // THIS_GRID mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) { |