Skip to content

Commit e532241

Browse files
authored
Re-apply (#117867): [flang][OpenMP] Implicitly map allocatable record fields (#120374)
This re-applies #117867 with a small fix that hopefully prevents build bot failures. The fix is avoiding `dyn_cast` for the result of `getOperation()`. Instead we can assign the result to `mlir::ModuleOp` directly since the type of the operation is known statically (`OpT` in `OperationPass`).
1 parent b7a8d95 commit e532241

File tree

12 files changed

+417
-42
lines changed

12 files changed

+417
-42
lines changed

flang/lib/Lower/DirectivesCommon.h renamed to flang/include/flang/Lower/DirectivesCommon.h

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -609,32 +609,22 @@ void createEmptyRegionBlocks(
609609
}
610610
}
611611

612-
inline AddrAndBoundsInfo
613-
getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter,
614-
fir::FirOpBuilder &builder,
615-
Fortran::lower::SymbolRef sym, mlir::Location loc) {
616-
mlir::Value symAddr = converter.getSymbolAddress(sym);
612+
inline AddrAndBoundsInfo getDataOperandBaseAddr(fir::FirOpBuilder &builder,
613+
mlir::Value symAddr,
614+
bool isOptional,
615+
mlir::Location loc) {
617616
mlir::Value rawInput = symAddr;
618617
if (auto declareOp =
619618
mlir::dyn_cast_or_null<hlfir::DeclareOp>(symAddr.getDefiningOp())) {
620619
symAddr = declareOp.getResults()[0];
621620
rawInput = declareOp.getResults()[1];
622621
}
623622

624-
// TODO: Might need revisiting to handle for non-shared clauses
625-
if (!symAddr) {
626-
if (const auto *details =
627-
sym->detailsIf<Fortran::semantics::HostAssocDetails>()) {
628-
symAddr = converter.getSymbolAddress(details->symbol());
629-
rawInput = symAddr;
630-
}
631-
}
632-
633623
if (!symAddr)
634624
llvm::report_fatal_error("could not retrieve symbol address");
635625

636626
mlir::Value isPresent;
637-
if (Fortran::semantics::IsOptional(sym))
627+
if (isOptional)
638628
isPresent =
639629
builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), rawInput);
640630

@@ -648,8 +638,7 @@ getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter,
648638
// all address/dimension retrievals. For Fortran optional though, leave
649639
// the load generation for later so it can be done in the appropriate
650640
// if branches.
651-
if (mlir::isa<fir::ReferenceType>(symAddr.getType()) &&
652-
!Fortran::semantics::IsOptional(sym)) {
641+
if (mlir::isa<fir::ReferenceType>(symAddr.getType()) && !isOptional) {
653642
mlir::Value addr = builder.create<fir::LoadOp>(loc, symAddr);
654643
return AddrAndBoundsInfo(addr, rawInput, isPresent, boxTy);
655644
}
@@ -659,6 +648,14 @@ getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter,
659648
return AddrAndBoundsInfo(symAddr, rawInput, isPresent);
660649
}
661650

651+
inline AddrAndBoundsInfo
652+
getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter,
653+
fir::FirOpBuilder &builder,
654+
Fortran::lower::SymbolRef sym, mlir::Location loc) {
655+
return getDataOperandBaseAddr(builder, converter.getSymbolAddress(sym),
656+
Fortran::semantics::IsOptional(sym), loc);
657+
}
658+
662659
template <typename BoundsOp, typename BoundsType>
663660
llvm::SmallVector<mlir::Value>
664661
gatherBoundsOrBoundValues(fir::FirOpBuilder &builder, mlir::Location loc,
@@ -1224,6 +1221,25 @@ AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
12241221

12251222
return info;
12261223
}
1224+
1225+
template <typename BoundsOp, typename BoundsType>
1226+
llvm::SmallVector<mlir::Value>
1227+
genImplicitBoundsOps(fir::FirOpBuilder &builder, lower::AddrAndBoundsInfo &info,
1228+
fir::ExtendedValue dataExv, bool dataExvIsAssumedSize,
1229+
mlir::Location loc) {
1230+
llvm::SmallVector<mlir::Value> bounds;
1231+
1232+
mlir::Value baseOp = info.rawInput;
1233+
if (mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(baseOp.getType())))
1234+
bounds = lower::genBoundsOpsFromBox<BoundsOp, BoundsType>(builder, loc,
1235+
dataExv, info);
1236+
if (mlir::isa<fir::SequenceType>(fir::unwrapRefType(baseOp.getType()))) {
1237+
bounds = lower::genBaseBoundsOps<BoundsOp, BoundsType>(
1238+
builder, loc, dataExv, dataExvIsAssumedSize);
1239+
}
1240+
1241+
return bounds;
1242+
}
12271243
} // namespace lower
12281244
} // namespace Fortran
12291245

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "flang/Lower/Bridge.h"
14-
#include "DirectivesCommon.h"
14+
1515
#include "flang/Common/Version.h"
1616
#include "flang/Lower/Allocatable.h"
1717
#include "flang/Lower/CallInterface.h"
@@ -22,6 +22,7 @@
2222
#include "flang/Lower/ConvertType.h"
2323
#include "flang/Lower/ConvertVariable.h"
2424
#include "flang/Lower/Cuda.h"
25+
#include "flang/Lower/DirectivesCommon.h"
2526
#include "flang/Lower/HostAssociations.h"
2627
#include "flang/Lower/IO.h"
2728
#include "flang/Lower/IterationSpace.h"

flang/lib/Lower/OpenACC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "flang/Lower/OpenACC.h"
14-
#include "DirectivesCommon.h"
14+
1515
#include "flang/Common/idioms.h"
1616
#include "flang/Lower/Bridge.h"
1717
#include "flang/Lower/ConvertType.h"
18+
#include "flang/Lower/DirectivesCommon.h"
1819
#include "flang/Lower/Mangler.h"
1920
#include "flang/Lower/PFTBuilder.h"
2021
#include "flang/Lower/StatementContext.h"

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
#define FORTRAN_LOWER_CLAUSEPROCESSOR_H
1414

1515
#include "Clauses.h"
16-
#include "DirectivesCommon.h"
1716
#include "ReductionProcessor.h"
1817
#include "Utils.h"
1918
#include "flang/Lower/AbstractConverter.h"
2019
#include "flang/Lower/Bridge.h"
20+
#include "flang/Lower/DirectivesCommon.h"
2121
#include "flang/Optimizer/Builder/Todo.h"
2222
#include "flang/Parser/dump-parse-tree.h"
2323
#include "flang/Parser/parse-tree.h"

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
#include "Clauses.h"
1717
#include "DataSharingProcessor.h"
1818
#include "Decomposer.h"
19-
#include "DirectivesCommon.h"
2019
#include "ReductionProcessor.h"
2120
#include "Utils.h"
2221
#include "flang/Common/OpenMP-utils.h"
2322
#include "flang/Common/idioms.h"
2423
#include "flang/Lower/Bridge.h"
2524
#include "flang/Lower/ConvertExpr.h"
2625
#include "flang/Lower/ConvertVariable.h"
26+
#include "flang/Lower/DirectivesCommon.h"
2727
#include "flang/Lower/StatementContext.h"
2828
#include "flang/Lower/SymbolMap.h"
2929
#include "flang/Optimizer/Builder/BoxValue.h"
@@ -1735,32 +1735,25 @@ genTargetOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
17351735
if (const auto *details =
17361736
sym.template detailsIf<semantics::HostAssocDetails>())
17371737
converter.copySymbolBinding(details->symbol(), sym);
1738-
llvm::SmallVector<mlir::Value> bounds;
17391738
std::stringstream name;
17401739
fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(sym);
17411740
name << sym.name().ToString();
17421741

17431742
lower::AddrAndBoundsInfo info = getDataOperandBaseAddr(
17441743
converter, firOpBuilder, sym, converter.getCurrentLocation());
1745-
mlir::Value baseOp = info.rawInput;
1746-
if (mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(baseOp.getType())))
1747-
bounds = lower::genBoundsOpsFromBox<mlir::omp::MapBoundsOp,
1748-
mlir::omp::MapBoundsType>(
1749-
firOpBuilder, converter.getCurrentLocation(), dataExv, info);
1750-
if (mlir::isa<fir::SequenceType>(fir::unwrapRefType(baseOp.getType()))) {
1751-
bool dataExvIsAssumedSize =
1752-
semantics::IsAssumedSizeArray(sym.GetUltimate());
1753-
bounds = lower::genBaseBoundsOps<mlir::omp::MapBoundsOp,
1754-
mlir::omp::MapBoundsType>(
1755-
firOpBuilder, converter.getCurrentLocation(), dataExv,
1756-
dataExvIsAssumedSize);
1757-
}
1744+
llvm::SmallVector<mlir::Value> bounds =
1745+
lower::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
1746+
mlir::omp::MapBoundsType>(
1747+
firOpBuilder, info, dataExv,
1748+
semantics::IsAssumedSizeArray(sym.GetUltimate()),
1749+
converter.getCurrentLocation());
17581750

17591751
llvm::omp::OpenMPOffloadMappingFlags mapFlag =
17601752
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
17611753
mlir::omp::VariableCaptureKind captureKind =
17621754
mlir::omp::VariableCaptureKind::ByRef;
17631755

1756+
mlir::Value baseOp = info.rawInput;
17641757
mlir::Type eleType = baseOp.getType();
17651758
if (auto refType = mlir::dyn_cast<fir::ReferenceType>(baseOp.getType()))
17661759
eleType = refType.getElementType();

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
#include "Utils.h"
1414

1515
#include "Clauses.h"
16-
#include <DirectivesCommon.h>
1716

1817
#include <flang/Lower/AbstractConverter.h>
1918
#include <flang/Lower/ConvertType.h>
19+
#include <flang/Lower/DirectivesCommon.h>
2020
#include <flang/Lower/PFTBuilder.h>
2121
#include <flang/Optimizer/Builder/FIRBuilder.h>
2222
#include <flang/Optimizer/Builder/Todo.h>

flang/lib/Optimizer/OpenMP/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_flang_library(FlangOpenMPTransforms
1212
FIRDialect
1313
HLFIROpsIncGen
1414
FlangOpenMPPassesIncGen
15+
${dialect_libs}
1516

1617
LINK_LIBS
1718
FIRAnalysis
@@ -27,4 +28,5 @@ add_flang_library(FlangOpenMPTransforms
2728
MLIRIR
2829
MLIRPass
2930
MLIRTransformUtils
31+
${dialect_libs}
3032
)

0 commit comments

Comments
 (0)