@@ -1864,76 +1864,30 @@ bool ClauseProcessor::processLink(
1864
1864
1865
1865
static mlir::omp::MapInfoOp
1866
1866
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
+
1872
1874
if (auto boxTy = baseAddr.getType ().dyn_cast <fir::BaseBoxType>()) {
1873
1875
baseAddr = builder.create <fir::BoxAddrOp>(loc, baseAddr);
1874
1876
retTy = baseAddr.getType ();
1875
1877
}
1876
1878
1877
- mlir::TypeAttr varType = mlir::TypeAttr::get (
1879
+ varPtr = baseAddr;
1880
+ varType = mlir::TypeAttr::get (
1878
1881
llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType ());
1879
1882
1880
1883
mlir::omp::MapInfoOp op = builder.create <mlir::omp::MapInfoOp>(
1881
- loc, retTy, baseAddr , varType, varPtrPtr, members , bounds,
1884
+ loc, retTy, varPtr , varType, varPtrPtr, bounds,
1882
1885
builder.getIntegerAttr (builder.getIntegerType (64 , false ), mapType),
1883
1886
builder.getAttr <mlir::omp::VariableCaptureKindAttr>(mapCaptureType),
1884
- builder.getStringAttr (name));
1885
-
1887
+ builder.getStringAttr (name.str ()));
1886
1888
return op;
1887
1889
}
1888
1890
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
-
1937
1891
bool ClauseProcessor::processMap (
1938
1892
mlir::Location currentLocation, const llvm::omp::Directive &directive,
1939
1893
Fortran::semantics::SemanticsContext &semanticsContext,
@@ -2008,32 +1962,21 @@ bool ClauseProcessor::processMap(
2008
1962
converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
2009
1963
clauseLocation, asFortran, bounds, treatIndexAsSection);
2010
1964
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 ());
2031
1974
2032
1975
mapOperands.push_back (mapOp);
2033
1976
if (mapSymTypes)
2034
- mapSymTypes->push_back (symAddr .getType ());
1977
+ mapSymTypes->push_back (info. addr .getType ());
2035
1978
if (mapSymLocs)
2036
- mapSymLocs->push_back (symAddr .getLoc ());
1979
+ mapSymLocs->push_back (info. addr .getLoc ());
2037
1980
if (mapSymbols)
2038
1981
mapSymbols->push_back (getOmpObjectSymbol (ompObject));
2039
1982
}
@@ -2127,55 +2070,40 @@ bool ClauseProcessor::processMotionClauses(
2127
2070
Fortran::semantics::SemanticsContext &semanticsContext,
2128
2071
Fortran::lower::StatementContext &stmtCtx,
2129
2072
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 ();
2134
2077
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>);
2175
2080
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
+ });
2179
2107
}
2180
2108
2181
2109
template <typename ... Ts>
@@ -3136,8 +3064,7 @@ static void genBodyOfTargetOp(
3136
3064
std::stringstream name;
3137
3065
firOpBuilder.setInsertionPoint (targetOp);
3138
3066
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,
3141
3068
static_cast <
3142
3069
std::underlying_type_t <llvm::omp::OpenMPOffloadMappingFlags>>(
3143
3070
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT),
@@ -3283,20 +3210,12 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
3283
3210
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
3284
3211
}
3285
3212
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 ());
3300
3219
3301
3220
mapOperands.push_back (mapOp);
3302
3221
mapSymTypes.push_back (baseOp.getType ());
0 commit comments