diff --git a/flang/include/flang/Support/OpenMP-utils.h b/flang/include/flang/Support/OpenMP-utils.h index 6d9db2b682c5..88b30c376de8 100644 --- a/flang/include/flang/Support/OpenMP-utils.h +++ b/flang/include/flang/Support/OpenMP-utils.h @@ -11,6 +11,7 @@ #include "flang/Semantics/symbol.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Value.h" @@ -72,6 +73,14 @@ struct EntryBlockArgs { /// \param [in] region - Empty region in which to create the entry block. mlir::Block *genEntryBlock( mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region ®ion); + +mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder, + mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr, + llvm::StringRef name, llvm::ArrayRef bounds, + llvm::ArrayRef members, mlir::ArrayAttr membersIndex, + uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, + mlir::Type retTy, bool partialMap = false, + mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr()); } // namespace Fortran::common::openmp #endif // FORTRAN_SUPPORT_OPENMP_UTILS_H_ diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 5d19f589d79f..bf4b66d70e70 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -19,6 +19,7 @@ #include "flang/Lower/Support/ReductionProcessor.h" #include "flang/Parser/tools.h" #include "flang/Semantics/tools.h" +#include "flang/Support/OpenMP-utils.h" #include "llvm/Frontend/OpenMP/OMP.h.inc" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" @@ -1281,7 +1282,7 @@ void ClauseProcessor::processMapObjects( auto location = mlir::NameLoc::get( mlir::StringAttr::get(firOpBuilder.getContext(), asFortran.str()), baseOp.getLoc()); - mlir::omp::MapInfoOp mapOp = createMapInfoOp( + mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp( firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds, /*members=*/{}, /*membersIndex=*/mlir::ArrayAttr{}, diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index 77b1e39083aa..e9c13deb9aae 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -108,38 +109,6 @@ void gatherFuncAndVarSyms( symbolAndClause.emplace_back(clause, *object.sym(), automap); } -mlir::omp::MapInfoOp -createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value baseAddr, mlir::Value varPtrPtr, - llvm::StringRef name, llvm::ArrayRef bounds, - llvm::ArrayRef members, - mlir::ArrayAttr membersIndex, uint64_t mapType, - mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, - bool partialMap, mlir::FlatSymbolRefAttr mapperId) { - if (auto boxTy = llvm::dyn_cast(baseAddr.getType())) { - baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); - retTy = baseAddr.getType(); - } - - mlir::TypeAttr varType = mlir::TypeAttr::get( - llvm::cast(retTy).getElementType()); - - // For types with unknown extents such as <2x?xi32> we discard the incomplete - // type info and only retain the base type. The correct dimensions are later - // recovered through the bounds info. - if (auto seqType = llvm::dyn_cast(varType.getValue())) - if (seqType.hasDynamicExtents()) - varType = mlir::TypeAttr::get(seqType.getEleTy()); - - mlir::omp::MapInfoOp op = mlir::omp::MapInfoOp::create( - builder, loc, retTy, baseAddr, varType, - builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), - builder.getAttr(mapCaptureType), - varPtrPtr, members, membersIndex, bounds, mapperId, - builder.getStringAttr(name), builder.getBoolAttr(partialMap)); - return op; -} - // This function gathers the individual omp::Object's that make up a // larger omp::Object symbol. // @@ -403,7 +372,7 @@ mlir::Value createParentSymAndGenIntermediateMaps( // Create a map for the intermediate member and insert it and it's // indices into the parentMemberIndices list to track it. - mlir::omp::MapInfoOp mapOp = createMapInfoOp( + mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp( firOpBuilder, clauseLocation, curValue, /*varPtrPtr=*/mlir::Value{}, asFortran, /*bounds=*/interimBounds, @@ -563,7 +532,7 @@ void insertChildMapInfoIntoParent( converter.getCurrentLocation(), asFortran, bounds, treatIndexAsSection); - mlir::omp::MapInfoOp mapOp = createMapInfoOp( + mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp( firOpBuilder, info.rawInput.getLoc(), info.rawInput, /*varPtrPtr=*/mlir::Value(), asFortran.str(), bounds, members, firOpBuilder.create2DI64ArrayAttr( diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index 60f44a7f0610..88371ab8bf96 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -114,16 +114,6 @@ struct OmpMapParentAndMemberData { semantics::SemanticsContext &semaCtx); }; -mlir::omp::MapInfoOp -createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value baseAddr, mlir::Value varPtrPtr, - llvm::StringRef name, llvm::ArrayRef bounds, - llvm::ArrayRef members, - mlir::ArrayAttr membersIndex, uint64_t mapType, - mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy, - bool partialMap = false, - mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr()); - void insertChildMapInfoIntoParent( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, diff --git a/flang/lib/Support/CMakeLists.txt b/flang/lib/Support/CMakeLists.txt index 363f57ce97da..b696851fd23a 100644 --- a/flang/lib/Support/CMakeLists.txt +++ b/flang/lib/Support/CMakeLists.txt @@ -54,10 +54,17 @@ add_flang_library(FortranSupport Version.cpp ${version_inc} + DEPENDS + FIRDialect + + LINK_LIBS + FIRDialect + LINK_COMPONENTS Support MLIR_LIBS MLIRIR MLIRSupport + MLIROpenMPDialect ) diff --git a/flang/lib/Support/OpenMP-utils.cpp b/flang/lib/Support/OpenMP-utils.cpp index 97e7723f0be8..b33325042df5 100644 --- a/flang/lib/Support/OpenMP-utils.cpp +++ b/flang/lib/Support/OpenMP-utils.cpp @@ -7,7 +7,10 @@ //===----------------------------------------------------------------------===// #include "flang/Support/OpenMP-utils.h" +#include "flang/Optimizer/Dialect/FIROps.h" +#include "flang/Optimizer/Dialect/FIRType.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/IR/OpDefinition.h" namespace Fortran::common::openmp { @@ -47,4 +50,35 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args, return builder.createBlock(®ion, {}, types, locs); } + +mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder, + mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr, + llvm::StringRef name, llvm::ArrayRef bounds, + llvm::ArrayRef members, mlir::ArrayAttr membersIndex, + uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, + mlir::Type retTy, bool partialMap, mlir::FlatSymbolRefAttr mapperId) { + + if (auto boxTy = llvm::dyn_cast(baseAddr.getType())) { + baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); + retTy = baseAddr.getType(); + } + + mlir::TypeAttr varType = mlir::TypeAttr::get( + llvm::cast(retTy).getElementType()); + + // For types with unknown extents such as <2x?xi32> we discard the incomplete + // type info and only retain the base type. The correct dimensions are later + // recovered through the bounds info. + if (auto seqType = llvm::dyn_cast(varType.getValue())) + if (seqType.hasDynamicExtents()) + varType = mlir::TypeAttr::get(seqType.getEleTy()); + + mlir::omp::MapInfoOp op = + mlir::omp::MapInfoOp::create(builder, loc, retTy, baseAddr, varType, + builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), + builder.getAttr(mapCaptureType), + varPtrPtr, members, membersIndex, bounds, mapperId, + builder.getStringAttr(name), builder.getBoolAttr(partialMap)); + return op; +} } // namespace Fortran::common::openmp