[flang-commits] [flang] [Flang][OpenMP] Align map clause generation and fix issue with non-shared allocations for assumed shape/size descriptor types (PR #97855)
via flang-commits
flang-commits at lists.llvm.org
Fri Jul 5 12:53:51 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 788731cdbd732180639988c9589adbe63bb28afa 8819ac0168b73abcd27536f339cd325beb08b093 -- flang/lib/Lower/OpenMP/ClauseProcessor.cpp flang/lib/Lower/OpenMP/ClauseProcessor.h flang/lib/Lower/OpenMP/OpenMP.cpp flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index f393d1c5fd..908f26838c 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1695,75 +1695,73 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
if (const auto *details =
sym.template detailsIf<semantics::HostAssocDetails>())
converter.copySymbolBinding(details->symbol(), sym);
- llvm::SmallVector<mlir::Value> bounds;
- std::stringstream name;
- fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(sym);
- name << sym.name().ToString();
-
- lower::AddrAndBoundsInfo info = getDataOperandBaseAddr(
- converter, firOpBuilder, sym, converter.getCurrentLocation());
- mlir::Value baseOp = info.rawInput;
- if (mlir::isa<fir::BaseBoxType>(
- fir::unwrapRefType(baseOp.getType())))
- bounds = lower::genBoundsOpsFromBox<mlir::omp::MapBoundsOp,
- mlir::omp::MapBoundsType>(
- firOpBuilder, converter.getCurrentLocation(), dataExv, info);
- if (mlir::isa<fir::SequenceType>(
- fir::unwrapRefType(baseOp.getType()))) {
- bool dataExvIsAssumedSize =
- semantics::IsAssumedSizeArray(sym.GetUltimate());
- bounds = lower::genBaseBoundsOps<mlir::omp::MapBoundsOp,
- mlir::omp::MapBoundsType>(
- firOpBuilder, converter.getCurrentLocation(), dataExv,
- dataExvIsAssumedSize);
- }
+ llvm::SmallVector<mlir::Value> bounds;
+ std::stringstream name;
+ fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(sym);
+ name << sym.name().ToString();
+
+ lower::AddrAndBoundsInfo info = getDataOperandBaseAddr(
+ converter, firOpBuilder, sym, converter.getCurrentLocation());
+ mlir::Value baseOp = info.rawInput;
+ if (mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(baseOp.getType())))
+ bounds = lower::genBoundsOpsFromBox<mlir::omp::MapBoundsOp,
+ mlir::omp::MapBoundsType>(
+ firOpBuilder, converter.getCurrentLocation(), dataExv, info);
+ if (mlir::isa<fir::SequenceType>(fir::unwrapRefType(baseOp.getType()))) {
+ bool dataExvIsAssumedSize =
+ semantics::IsAssumedSizeArray(sym.GetUltimate());
+ bounds = lower::genBaseBoundsOps<mlir::omp::MapBoundsOp,
+ mlir::omp::MapBoundsType>(
+ firOpBuilder, converter.getCurrentLocation(), dataExv,
+ dataExvIsAssumedSize);
+ }
- llvm::omp::OpenMPOffloadMappingFlags mapFlag =
- llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
- mlir::omp::VariableCaptureKind captureKind =
- mlir::omp::VariableCaptureKind::ByRef;
-
- mlir::Type eleType = baseOp.getType();
- if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
- eleType = refType.getElementType();
-
- // If a variable is specified in declare target link and if device
- // type is not specified as `nohost`, it needs to be mapped tofrom
- mlir::ModuleOp mod = firOpBuilder.getModule();
- mlir::Operation *op = mod.lookupSymbol(converter.mangleName(sym));
- auto declareTargetOp =
- llvm::dyn_cast_if_present<mlir::omp::DeclareTargetInterface>(op);
- if (declareTargetOp && declareTargetOp.isDeclareTarget()) {
- if (declareTargetOp.getDeclareTargetCaptureClause() ==
- mlir::omp::DeclareTargetCaptureClause::link &&
- declareTargetOp.getDeclareTargetDeviceType() !=
- mlir::omp::DeclareTargetDeviceType::nohost) {
- mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
- mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
- }
- } else if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
- captureKind = mlir::omp::VariableCaptureKind::ByCopy;
- } else if (!fir::isa_builtin_cptr_type(eleType)) {
+ llvm::omp::OpenMPOffloadMappingFlags mapFlag =
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
+ mlir::omp::VariableCaptureKind captureKind =
+ mlir::omp::VariableCaptureKind::ByRef;
+
+ mlir::Type eleType = baseOp.getType();
+ if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
+ eleType = refType.getElementType();
+
+ // If a variable is specified in declare target link and if device
+ // type is not specified as `nohost`, it needs to be mapped tofrom
+ mlir::ModuleOp mod = firOpBuilder.getModule();
+ mlir::Operation *op = mod.lookupSymbol(converter.mangleName(sym));
+ auto declareTargetOp =
+ llvm::dyn_cast_if_present<mlir::omp::DeclareTargetInterface>(op);
+ if (declareTargetOp && declareTargetOp.isDeclareTarget()) {
+ if (declareTargetOp.getDeclareTargetCaptureClause() ==
+ mlir::omp::DeclareTargetCaptureClause::link &&
+ declareTargetOp.getDeclareTargetDeviceType() !=
+ mlir::omp::DeclareTargetDeviceType::nohost) {
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
}
- auto location =
- mlir::NameLoc::get(mlir::StringAttr::get(firOpBuilder.getContext(),
- sym.name().ToString()),
- baseOp.getLoc());
- mlir::Value mapOp = createMapInfoOp(
- firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{},
- name.str(), bounds, /*members=*/{},
- /*membersIndex=*/mlir::DenseIntElementsAttr{},
- static_cast<
- std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
- mapFlag),
- captureKind, baseOp.getType());
-
- clauseOps.mapVars.push_back(mapOp);
- mapSyms.push_back(&sym);
- mapLocs.push_back(baseOp.getLoc());
- mapTypes.push_back(baseOp.getType());
+ } else if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
+ captureKind = mlir::omp::VariableCaptureKind::ByCopy;
+ } else if (!fir::isa_builtin_cptr_type(eleType)) {
+ mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
+ mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+ }
+ auto location =
+ mlir::NameLoc::get(mlir::StringAttr::get(firOpBuilder.getContext(),
+ sym.name().ToString()),
+ baseOp.getLoc());
+ mlir::Value mapOp = createMapInfoOp(
+ firOpBuilder, location, baseOp, /*varPtrPtr=*/mlir::Value{},
+ name.str(), bounds, /*members=*/{},
+ /*membersIndex=*/mlir::DenseIntElementsAttr{},
+ static_cast<
+ std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
+ mapFlag),
+ captureKind, baseOp.getType());
+
+ clauseOps.mapVars.push_back(mapOp);
+ mapSyms.push_back(&sym);
+ mapLocs.push_back(baseOp.getLoc());
+ mapTypes.push_back(baseOp.getType());
}
};
lower::pft::visitAllSymbols(eval, captureImplicitMap);
diff --git a/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp b/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp
index b871467d57..e20c3a4f33 100644
--- a/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp
+++ b/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp
@@ -55,11 +55,10 @@ class OMPMapInfoFinalizationPass
/// generate for the descriptors of box type dummy arguments, so that
/// we can retrieve it for subsequent reuses within the functions
/// scope
- std::map</*descriptor opaque pointer=*/ void *,
- /*corresponding local alloca=*/ fir::AllocaOp>
+ std::map</*descriptor opaque pointer=*/void *,
+ /*corresponding local alloca=*/fir::AllocaOp>
localBoxAllocas;
-
void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
fir::FirOpBuilder &builder,
mlir::Operation *target) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/97855
More information about the flang-commits
mailing list