Skip to content

Commit 0f9bedb

Browse files
committed
[flang][OpenMP] Move createMapInfoOp to OpenMP-utils.h
This moves `createMapInfoOp` from `flang/lib/Lower/OpenMP/Utils.h` to `flang/include/flang/Support/OpenMP-utils.h`. Context: I am working on upstreaming (from AMD's downstream fork) support for `do concurrent` mapping to the GPU. This means that `DoConcurrentConversion.cpp` needs access to `createMapInfoOp`. Hence, we moved it downstream to a shared location between that is linked by both `FlangOpenMPTransforms` (where the `do concurrent` pass lives) and `FortranLower` (where `createMapInfoOp` originally were). The issue now is that we have to link in both the FIR and OpenMP MLIR dialects which is not ideal to link with a suport library like `FortranSupport`. Note that, so far, upstream `DoConcurrentConversion.cpp` does not reference `createMapInfoOp` yet. Follow-up PRs will upstream this later.
1 parent 296163f commit 0f9bedb

File tree

6 files changed

+55
-45
lines changed

6 files changed

+55
-45
lines changed

flang/include/flang/Support/OpenMP-utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flang/Semantics/symbol.h"
1313

14+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
1415
#include "mlir/IR/Builders.h"
1516
#include "mlir/IR/Value.h"
1617

@@ -72,6 +73,14 @@ struct EntryBlockArgs {
7273
/// \param [in] region - Empty region in which to create the entry block.
7374
mlir::Block *genEntryBlock(
7475
mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region &region);
76+
77+
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
78+
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
79+
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
80+
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
81+
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
82+
mlir::Type retTy, bool partialMap = false,
83+
mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr());
7584
} // namespace Fortran::common::openmp
7685

7786
#endif // FORTRAN_SUPPORT_OPENMP_UTILS_H_

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "flang/Lower/Support/ReductionProcessor.h"
2020
#include "flang/Parser/tools.h"
2121
#include "flang/Semantics/tools.h"
22+
#include "flang/Support/OpenMP-utils.h"
2223
#include "llvm/Frontend/OpenMP/OMP.h.inc"
2324
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
2425

@@ -1281,7 +1282,7 @@ void ClauseProcessor::processMapObjects(
12811282
auto location = mlir::NameLoc::get(
12821283
mlir::StringAttr::get(firOpBuilder.getContext(), asFortran.str()),
12831284
baseOp.getLoc());
1284-
mlir::omp::MapInfoOp mapOp = createMapInfoOp(
1285+
mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp(
12851286
firOpBuilder, location, baseOp,
12861287
/*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds,
12871288
/*members=*/{}, /*membersIndex=*/mlir::ArrayAttr{},

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <flang/Parser/parse-tree.h>
2525
#include <flang/Parser/tools.h>
2626
#include <flang/Semantics/tools.h>
27+
#include <flang/Support/OpenMP-utils.h>
2728
#include <llvm/Support/CommandLine.h>
2829

2930
#include <iterator>
@@ -108,38 +109,6 @@ void gatherFuncAndVarSyms(
108109
symbolAndClause.emplace_back(clause, *object.sym(), automap);
109110
}
110111

111-
mlir::omp::MapInfoOp
112-
createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
113-
mlir::Value baseAddr, mlir::Value varPtrPtr,
114-
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
115-
llvm::ArrayRef<mlir::Value> members,
116-
mlir::ArrayAttr membersIndex, uint64_t mapType,
117-
mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
118-
bool partialMap, mlir::FlatSymbolRefAttr mapperId) {
119-
if (auto boxTy = llvm::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) {
120-
baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr);
121-
retTy = baseAddr.getType();
122-
}
123-
124-
mlir::TypeAttr varType = mlir::TypeAttr::get(
125-
llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType());
126-
127-
// For types with unknown extents such as <2x?xi32> we discard the incomplete
128-
// type info and only retain the base type. The correct dimensions are later
129-
// recovered through the bounds info.
130-
if (auto seqType = llvm::dyn_cast<fir::SequenceType>(varType.getValue()))
131-
if (seqType.hasDynamicExtents())
132-
varType = mlir::TypeAttr::get(seqType.getEleTy());
133-
134-
mlir::omp::MapInfoOp op = mlir::omp::MapInfoOp::create(
135-
builder, loc, retTy, baseAddr, varType,
136-
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
137-
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType),
138-
varPtrPtr, members, membersIndex, bounds, mapperId,
139-
builder.getStringAttr(name), builder.getBoolAttr(partialMap));
140-
return op;
141-
}
142-
143112
// This function gathers the individual omp::Object's that make up a
144113
// larger omp::Object symbol.
145114
//
@@ -403,7 +372,7 @@ mlir::Value createParentSymAndGenIntermediateMaps(
403372

404373
// Create a map for the intermediate member and insert it and it's
405374
// indices into the parentMemberIndices list to track it.
406-
mlir::omp::MapInfoOp mapOp = createMapInfoOp(
375+
mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp(
407376
firOpBuilder, clauseLocation, curValue,
408377
/*varPtrPtr=*/mlir::Value{}, asFortran,
409378
/*bounds=*/interimBounds,
@@ -563,7 +532,7 @@ void insertChildMapInfoIntoParent(
563532
converter.getCurrentLocation(), asFortran, bounds,
564533
treatIndexAsSection);
565534

566-
mlir::omp::MapInfoOp mapOp = createMapInfoOp(
535+
mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp(
567536
firOpBuilder, info.rawInput.getLoc(), info.rawInput,
568537
/*varPtrPtr=*/mlir::Value(), asFortran.str(), bounds, members,
569538
firOpBuilder.create2DI64ArrayAttr(

flang/lib/Lower/OpenMP/Utils.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ struct OmpMapParentAndMemberData {
114114
semantics::SemanticsContext &semaCtx);
115115
};
116116

117-
mlir::omp::MapInfoOp
118-
createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
119-
mlir::Value baseAddr, mlir::Value varPtrPtr,
120-
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
121-
llvm::ArrayRef<mlir::Value> members,
122-
mlir::ArrayAttr membersIndex, uint64_t mapType,
123-
mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
124-
bool partialMap = false,
125-
mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr());
126-
127117
void insertChildMapInfoIntoParent(
128118
Fortran::lower::AbstractConverter &converter,
129119
Fortran::semantics::SemanticsContext &semaCtx,

flang/lib/Support/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ add_flang_library(FortranSupport
5454
Version.cpp
5555
${version_inc}
5656

57+
DEPENDS
58+
FIRDialect
59+
60+
LINK_LIBS
61+
FIRDialect
62+
5763
LINK_COMPONENTS
5864
Support
5965

6066
MLIR_LIBS
6167
MLIRIR
6268
MLIRSupport
69+
MLIROpenMPDialect
6370
)

flang/lib/Support/OpenMP-utils.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Support/OpenMP-utils.h"
10+
#include "flang/Optimizer/Dialect/FIROps.h"
11+
#include "flang/Optimizer/Dialect/FIRType.h"
1012

13+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
1114
#include "mlir/IR/OpDefinition.h"
1215

1316
namespace Fortran::common::openmp {
@@ -47,4 +50,35 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args,
4750

4851
return builder.createBlock(&region, {}, types, locs);
4952
}
53+
54+
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
55+
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
56+
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
57+
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
58+
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
59+
mlir::Type retTy, bool partialMap, mlir::FlatSymbolRefAttr mapperId) {
60+
61+
if (auto boxTy = llvm::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) {
62+
baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr);
63+
retTy = baseAddr.getType();
64+
}
65+
66+
mlir::TypeAttr varType = mlir::TypeAttr::get(
67+
llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType());
68+
69+
// For types with unknown extents such as <2x?xi32> we discard the incomplete
70+
// type info and only retain the base type. The correct dimensions are later
71+
// recovered through the bounds info.
72+
if (auto seqType = llvm::dyn_cast<fir::SequenceType>(varType.getValue()))
73+
if (seqType.hasDynamicExtents())
74+
varType = mlir::TypeAttr::get(seqType.getEleTy());
75+
76+
mlir::omp::MapInfoOp op =
77+
mlir::omp::MapInfoOp::create(builder, loc, retTy, baseAddr, varType,
78+
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
79+
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType),
80+
varPtrPtr, members, membersIndex, bounds, mapperId,
81+
builder.getStringAttr(name), builder.getBoolAttr(partialMap));
82+
return op;
83+
}
5084
} // namespace Fortran::common::openmp

0 commit comments

Comments
 (0)