Skip to content

Commit bb60d93

Browse files
committed
Revert "[Flang[[OpenMP] Initial Allocatables/Pointers (Descriptor Types) mapping PR"
This reverts commit 5a09b1e.
1 parent 3acfccb commit bb60d93

26 files changed

+113
-1523
lines changed

flang/include/flang/Optimizer/CodeGen/CodeGenOpenMP.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,6 @@ bool isBoxNone(mlir::Type ty);
321321
/// e.g. !fir.box<!fir.type<derived>>
322322
bool isBoxedRecordType(mlir::Type ty);
323323

324-
/// Return true iff `ty` is a type that contains descriptor information.
325-
bool isTypeWithDescriptor(mlir::Type ty);
326-
327324
/// Return true iff `ty` is a scalar boxed record type.
328325
/// e.g. !fir.box<!fir.type<derived>>
329326
/// !fir.box<!fir.heap<!fir.type<derived>>>

flang/lib/Lower/OpenMP.cpp

Lines changed: 61 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,76 +1864,30 @@ bool ClauseProcessor::processLink(
18641864

18651865
static mlir::omp::MapInfoOp
18661866
createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
1867-
mlir::Value baseAddr, mlir::Value varPtrPtr, std::string name,
1868-
mlir::SmallVector<mlir::Value> bounds,
1869-
mlir::SmallVector<mlir::Value> members, uint64_t mapType,
1870-
mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
1871-
bool isVal = false) {
1867+
mlir::Value baseAddr, std::stringstream &name,
1868+
mlir::SmallVector<mlir::Value> bounds, uint64_t mapType,
1869+
mlir::omp::VariableCaptureKind mapCaptureType,
1870+
mlir::Type retTy) {
1871+
mlir::Value varPtr, varPtrPtr;
1872+
mlir::TypeAttr varType;
1873+
18721874
if (auto boxTy = baseAddr.getType().dyn_cast<fir::BaseBoxType>()) {
18731875
baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr);
18741876
retTy = baseAddr.getType();
18751877
}
18761878

1877-
mlir::TypeAttr varType = mlir::TypeAttr::get(
1879+
varPtr = baseAddr;
1880+
varType = mlir::TypeAttr::get(
18781881
llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType());
18791882

18801883
mlir::omp::MapInfoOp op = builder.create<mlir::omp::MapInfoOp>(
1881-
loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
1884+
loc, retTy, varPtr, varType, varPtrPtr, bounds,
18821885
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
18831886
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType),
1884-
builder.getStringAttr(name));
1885-
1887+
builder.getStringAttr(name.str()));
18861888
return op;
18871889
}
18881890

1889-
static mlir::omp::MapInfoOp processDescriptorTypeMappings(
1890-
Fortran::semantics::SemanticsContext &semanticsContext,
1891-
Fortran::lower::StatementContext &stmtCtx,
1892-
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
1893-
mlir::Value descriptorAddr, mlir::Value descDataBaseAddr,
1894-
mlir::ValueRange bounds, std::string asFortran,
1895-
llvm::omp::OpenMPOffloadMappingFlags mapCaptureType) {
1896-
llvm::SmallVector<mlir::Value> descriptorBaseAddrMembers;
1897-
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
1898-
1899-
mlir::Value descriptor = descriptorAddr;
1900-
1901-
// The fir::BoxOffsetOp only works with !fir.ref<!fir.box<...>> types, as
1902-
// allowing it to access non-reference box operations can cause some
1903-
// problematic SSA IR. However, in the case of assumed shape's the type
1904-
// is not a !fir.ref, in these cases to retrieve the appropriate
1905-
// !fir.ref<!fir.box<...>> to access the data we need to map we must
1906-
// perform an alloca and then store to it and retrieve the data from the new
1907-
// alloca.
1908-
if (mlir::isa<fir::BaseBoxType>(descriptorAddr.getType())) {
1909-
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
1910-
firOpBuilder.setInsertionPointToStart(firOpBuilder.getAllocaBlock());
1911-
descriptor =
1912-
firOpBuilder.create<fir::AllocaOp>(loc, descriptorAddr.getType());
1913-
firOpBuilder.restoreInsertionPoint(insPt);
1914-
firOpBuilder.create<fir::StoreOp>(loc, descriptorAddr, descriptor);
1915-
}
1916-
1917-
mlir::Value baseAddrAddr = firOpBuilder.create<fir::BoxOffsetOp>(
1918-
loc, descriptor, fir::BoxFieldAttr::base_addr);
1919-
1920-
descriptorBaseAddrMembers.push_back(createMapInfoOp(
1921-
firOpBuilder, loc, descDataBaseAddr, baseAddrAddr, asFortran, bounds, {},
1922-
static_cast<std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
1923-
mapCaptureType),
1924-
mlir::omp::VariableCaptureKind::ByRef, descDataBaseAddr.getType()));
1925-
1926-
// TODO: map the addendum segment of the descriptor, similarly to the above
1927-
// base address/data pointer member.
1928-
1929-
return createMapInfoOp(
1930-
firOpBuilder, loc, descriptor, mlir::Value{}, asFortran, {},
1931-
descriptorBaseAddrMembers,
1932-
static_cast<std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
1933-
mapCaptureType),
1934-
mlir::omp::VariableCaptureKind::ByRef, descriptor.getType());
1935-
}
1936-
19371891
bool ClauseProcessor::processMap(
19381892
mlir::Location currentLocation, const llvm::omp::Directive &directive,
19391893
Fortran::semantics::SemanticsContext &semanticsContext,
@@ -2008,32 +1962,21 @@ bool ClauseProcessor::processMap(
20081962
converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
20091963
clauseLocation, asFortran, bounds, treatIndexAsSection);
20101964

2011-
auto origSymbol =
2012-
converter.getSymbolAddress(*getOmpObjectSymbol(ompObject));
2013-
mlir::Value mapOp, symAddr;
2014-
if (origSymbol && fir::isTypeWithDescriptor(origSymbol.getType())) {
2015-
symAddr = origSymbol;
2016-
mapOp = processDescriptorTypeMappings(
2017-
semanticsContext, stmtCtx, converter, clauseLocation,
2018-
origSymbol, info.addr, bounds, asFortran.str(), mapTypeBits);
2019-
} else {
2020-
// Explicit map captures are captured ByRef by default,
2021-
// optimisation passes may alter this to ByCopy or other capture
2022-
// types to optimise
2023-
symAddr = info.addr;
2024-
mapOp = createMapInfoOp(
2025-
firOpBuilder, clauseLocation, info.addr, mlir::Value{},
2026-
asFortran.str(), bounds, {},
2027-
static_cast<std::underlying_type_t<
2028-
llvm::omp::OpenMPOffloadMappingFlags>>(mapTypeBits),
2029-
mlir::omp::VariableCaptureKind::ByRef, info.addr.getType());
2030-
}
1965+
// Explicit map captures are captured ByRef by default,
1966+
// optimisation passes may alter this to ByCopy or other capture
1967+
// types to optimise
1968+
mlir::Value mapOp = createMapInfoOp(
1969+
firOpBuilder, clauseLocation, info.addr, asFortran, bounds,
1970+
static_cast<
1971+
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
1972+
mapTypeBits),
1973+
mlir::omp::VariableCaptureKind::ByRef, info.addr.getType());
20311974

20321975
mapOperands.push_back(mapOp);
20331976
if (mapSymTypes)
2034-
mapSymTypes->push_back(symAddr.getType());
1977+
mapSymTypes->push_back(info.addr.getType());
20351978
if (mapSymLocs)
2036-
mapSymLocs->push_back(symAddr.getLoc());
1979+
mapSymLocs->push_back(info.addr.getLoc());
20371980
if (mapSymbols)
20381981
mapSymbols->push_back(getOmpObjectSymbol(ompObject));
20391982
}
@@ -2127,55 +2070,40 @@ bool ClauseProcessor::processMotionClauses(
21272070
Fortran::semantics::SemanticsContext &semanticsContext,
21282071
Fortran::lower::StatementContext &stmtCtx,
21292072
llvm::SmallVectorImpl<mlir::Value> &mapOperands) {
2130-
return findRepeatableClause<T>([&](const T *motionClause,
2131-
const Fortran::parser::CharBlock &source) {
2132-
mlir::Location clauseLocation = converter.genLocation(source);
2133-
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
2073+
return findRepeatableClause<T>(
2074+
[&](const T *motionClause, const Fortran::parser::CharBlock &source) {
2075+
mlir::Location clauseLocation = converter.genLocation(source);
2076+
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
21342077

2135-
static_assert(std::is_same_v<T, ClauseProcessor::ClauseTy::To> ||
2136-
std::is_same_v<T, ClauseProcessor::ClauseTy::From>);
2137-
2138-
// TODO Support motion modifiers: present, mapper, iterator.
2139-
constexpr llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
2140-
std::is_same_v<T, ClauseProcessor::ClauseTy::To>
2141-
? llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO
2142-
: llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
2143-
2144-
for (const Fortran::parser::OmpObject &ompObject : motionClause->v.v) {
2145-
llvm::SmallVector<mlir::Value> bounds;
2146-
std::stringstream asFortran;
2147-
Fortran::lower::AddrAndBoundsInfo info =
2148-
Fortran::lower::gatherDataOperandAddrAndBounds<
2149-
Fortran::parser::OmpObject, mlir::omp::DataBoundsOp,
2150-
mlir::omp::DataBoundsType>(
2151-
converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
2152-
clauseLocation, asFortran, bounds, treatIndexAsSection);
2153-
2154-
auto origSymbol =
2155-
converter.getSymbolAddress(*getOmpObjectSymbol(ompObject));
2156-
mlir::Value mapOp, symAddr;
2157-
if (origSymbol && fir::isTypeWithDescriptor(origSymbol.getType())) {
2158-
symAddr = origSymbol;
2159-
mapOp = processDescriptorTypeMappings(
2160-
semanticsContext, stmtCtx, converter, clauseLocation, origSymbol,
2161-
info.addr, bounds, asFortran.str(), mapTypeBits);
2162-
} else {
2163-
// Explicit map captures are captured ByRef by default,
2164-
// optimisation passes may alter this to ByCopy or other capture
2165-
// types to optimise
2166-
symAddr = info.addr;
2167-
mapOp = createMapInfoOp(
2168-
firOpBuilder, clauseLocation, info.addr, mlir::Value{},
2169-
asFortran.str(), bounds, {},
2170-
static_cast<
2171-
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
2172-
mapTypeBits),
2173-
mlir::omp::VariableCaptureKind::ByRef, info.addr.getType());
2174-
}
2078+
static_assert(std::is_same_v<T, ClauseProcessor::ClauseTy::To> ||
2079+
std::is_same_v<T, ClauseProcessor::ClauseTy::From>);
21752080

2176-
mapOperands.push_back(mapOp);
2177-
}
2178-
});
2081+
// TODO Support motion modifiers: present, mapper, iterator.
2082+
constexpr llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
2083+
std::is_same_v<T, ClauseProcessor::ClauseTy::To>
2084+
? llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO
2085+
: llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
2086+
2087+
for (const Fortran::parser::OmpObject &ompObject : motionClause->v.v) {
2088+
llvm::SmallVector<mlir::Value> bounds;
2089+
std::stringstream asFortran;
2090+
Fortran::lower::AddrAndBoundsInfo info =
2091+
Fortran::lower::gatherDataOperandAddrAndBounds<
2092+
Fortran::parser::OmpObject, mlir::omp::DataBoundsOp,
2093+
mlir::omp::DataBoundsType>(
2094+
converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
2095+
clauseLocation, asFortran, bounds, treatIndexAsSection);
2096+
2097+
mlir::Value mapOp = createMapInfoOp(
2098+
firOpBuilder, clauseLocation, info.addr, asFortran, bounds,
2099+
static_cast<
2100+
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
2101+
mapTypeBits),
2102+
mlir::omp::VariableCaptureKind::ByRef, info.addr.getType());
2103+
2104+
mapOperands.push_back(mapOp);
2105+
}
2106+
});
21792107
}
21802108

21812109
template <typename... Ts>
@@ -3136,8 +3064,7 @@ static void genBodyOfTargetOp(
31363064
std::stringstream name;
31373065
firOpBuilder.setInsertionPoint(targetOp);
31383066
mlir::Value mapOp = createMapInfoOp(
3139-
firOpBuilder, copyVal.getLoc(), copyVal, mlir::Value{}, name.str(),
3140-
bounds, llvm::SmallVector<mlir::Value>{},
3067+
firOpBuilder, copyVal.getLoc(), copyVal, name, bounds,
31413068
static_cast<
31423069
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
31433070
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT),
@@ -3283,20 +3210,12 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
32833210
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
32843211
}
32853212

3286-
mlir::Value mapOp;
3287-
if (fir::isTypeWithDescriptor(baseOp.getType())) {
3288-
mapOp = processDescriptorTypeMappings(
3289-
semanticsContext, stmtCtx, converter, baseOp.getLoc(), baseOp,
3290-
info.addr, bounds, name.str(), mapFlag);
3291-
} else {
3292-
mapOp = createMapInfoOp(
3293-
converter.getFirOpBuilder(), baseOp.getLoc(), baseOp,
3294-
mlir::Value{}, name.str(), bounds, {},
3295-
static_cast<
3296-
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
3297-
mapFlag),
3298-
captureKind, baseOp.getType());
3299-
}
3213+
mlir::Value mapOp = createMapInfoOp(
3214+
converter.getFirOpBuilder(), baseOp.getLoc(), baseOp, name, bounds,
3215+
static_cast<
3216+
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
3217+
mapFlag),
3218+
captureKind, baseOp.getType());
33003219

33013220
mapOperands.push_back(mapOp);
33023221
mapSymTypes.push_back(baseOp.getType());

flang/lib/Optimizer/CodeGen/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
add_flang_library(FIRCodeGen
2-
CodeGenOpenMP.cpp
32
BoxedProcedure.cpp
43
CGOps.cpp
54
CodeGen.cpp

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "flang/Optimizer/CodeGen/CodeGen.h"
1414

1515
#include "CGOps.h"
16-
#include "flang/Optimizer/CodeGen/CodeGenOpenMP.h"
1716
#include "flang/Optimizer/Dialect/FIRAttr.h"
1817
#include "flang/Optimizer/Dialect/FIROps.h"
1918
#include "flang/Optimizer/Dialect/FIRType.h"
@@ -3960,11 +3959,6 @@ class FIRToLLVMLowering
39603959
mlir::populateMathToLibmConversionPatterns(pattern);
39613960
mlir::populateComplexToLLVMConversionPatterns(typeConverter, pattern);
39623961
mlir::populateVectorToLLVMConversionPatterns(typeConverter, pattern);
3963-
3964-
// Flang specific overloads for OpenMP operations, to allow for special
3965-
// handling of things like Box types.
3966-
fir::populateOpenMPFIRToLLVMConversionPatterns(typeConverter, pattern);
3967-
39683962
mlir::ConversionTarget target{*context};
39693963
target.addLegalDialect<mlir::LLVM::LLVMDialect>();
39703964
// The OpenMP dialect is legal for Operations without regions, for those

0 commit comments

Comments
 (0)