Skip to content

Commit 7613211

Browse files
committed
[Flang][OMPTarget] Changeset required for initial UMT functionality
1 parent c05828f commit 7613211

File tree

22 files changed

+207
-133
lines changed

22 files changed

+207
-133
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ Error handleOverrideImages(
898898
/// be registered by the runtime.
899899
Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
900900
SmallVectorImpl<SmallVector<OffloadFile>> &LinkerInputFiles,
901-
const InputArgList &Args, char **Argv, int Argc) {
901+
InputArgList &Args, char **Argv, int Argc) {
902902
llvm::TimeTraceScope TimeScope("Handle all device input");
903903

904904
std::mutex ImageMtx;
@@ -909,6 +909,9 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
909909
if (Error Err = handleOverrideImages(Args, Images))
910910
return std::move(Err);
911911

912+
bool ExcludeNVPTX = Args.hasArg(OPT_no_nvptx_whole_archive);
913+
bool ExcludeAMDGPU = Args.hasArg(OPT_no_amdgpu_whole_archive);
914+
912915
auto Err = parallelForEachError(LinkerInputFiles, [&](auto &Input) -> Error {
913916
llvm::TimeTraceScope TimeScope("Link device input");
914917

@@ -923,6 +926,13 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
923926
});
924927
auto LinkerArgs = getLinkerArgs(Input, BaseArgs);
925928

929+
const llvm::Triple Triple(LinkerArgs.getLastArgValue(OPT_triple_EQ));
930+
if (Triple.isNVPTX() && ExcludeNVPTX)
931+
return Error::success();
932+
933+
if (Triple.isAMDGPU() && ExcludeAMDGPU)
934+
return Error::success();
935+
926936
DenseSet<OffloadKind> ActiveOffloadKinds;
927937
for (const auto &File : Input)
928938
if (File.getBinary()->getOffloadKind() != OFK_None)
@@ -975,6 +985,13 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
975985
if (Err)
976986
return std::move(Err);
977987

988+
// This option is specific to this link phase and the preceding link tools
989+
// do not understand this option so we remove it now that we're done with it.
990+
if (ExcludeNVPTX)
991+
Args.eraseArg(OPT_no_nvptx_whole_archive);
992+
if (ExcludeAMDGPU)
993+
Args.eraseArg(OPT_no_amdgpu_whole_archive);
994+
978995
// Create a binary image of each offloading image and embed it into a new
979996
// object file.
980997
SmallVector<StringRef> WrappedOutput;

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def version : Flag<["--", "-"], "version">, Flags<[HelpHidden]>, Alias<v>;
119119
def whole_archive : Flag<["--", "-"], "whole-archive">, Flags<[HelpHidden]>;
120120
def no_whole_archive : Flag<["--", "-"], "no-whole-archive">, Flags<[HelpHidden]>;
121121

122+
def no_nvptx_whole_archive : Flag<["--", "-"], "no-nvptx-whole-archive">, Flags<[HelpHidden]>;
123+
def no_amdgpu_whole_archive : Flag<["--", "-"], "no-amdgpu-whole-archive">, Flags<[HelpHidden]>;
124+
122125
def relocatable : Flag<["--", "-"], "relocatable">,
123126
HelpText<"Link device code to create a relocatable offloading application">;
124127
def r : Flag<["-"], "r">, Alias<relocatable>;

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ void ClauseProcessor::processMapObjects(
926926
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
927927
llvm::SmallVectorImpl<mlir::Value> &mapVars,
928928
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
929-
llvm::StringRef mapperIdNameRef) const {
929+
llvm::StringRef mapperIdNameRef, bool isMotionModifier) const {
930930
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
931931

932932
auto getDefaultMapperID = [&](const omp::Object &object,
@@ -977,7 +977,7 @@ void ClauseProcessor::processMapObjects(
977977
treatIndexAsSection);
978978

979979
mlir::Value baseOp = info.rawInput;
980-
if (object.sym()->owner().IsDerivedType()) {
980+
if (object.sym()->owner().IsDerivedType() && !isMotionModifier) {
981981
omp::ObjectList objectList = gatherObjectsOf(object, semaCtx);
982982
assert(!objectList.empty() &&
983983
"could not find parent objects of derived type member");
@@ -1136,7 +1136,8 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
11361136
if (expectation && *expectation == omp::clause::To::Expectation::Present)
11371137
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PRESENT;
11381138
processMapObjects(stmtCtx, clauseLocation, objects, mapTypeBits,
1139-
parentMemberIndices, result.mapVars, mapSymbols);
1139+
parentMemberIndices, result.mapVars, mapSymbols, "",
1140+
true);
11401141
};
11411142

11421143
bool clauseFound = findRepeatableClause<omp::clause::To>(callbackFn);

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class ClauseProcessor {
174174
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
175175
llvm::SmallVectorImpl<mlir::Value> &mapVars,
176176
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
177-
llvm::StringRef mapperIdNameRef = "") const;
177+
llvm::StringRef mapperIdNameRef = "",
178+
bool isMotionModifier = false) const;
178179

179180
lower::AbstractConverter &converter;
180181
semantics::SemanticsContext &semaCtx;

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,12 @@ void insertChildMapInfoIntoParent(
551551
mapOp.setMembersIndexAttr(firOpBuilder.create2DI64ArrayAttr(
552552
indices.second.memberPlacementIndices));
553553
} else {
554-
// NOTE: We take the map type of the first child, this may not
555-
// be the correct thing to do, however, we shall see. For the moment
556-
// it allows this to work with enter and exit without causing MLIR
557-
// verification issues. The more appropriate thing may be to take
558-
// the "main" map type clause from the directive being used.
559-
uint64_t mapType = indices.second.memberMap[0].getMapType();
554+
// NOTE: We do not assign default mapped parents a map type, as
555+
// selecting a childs can result in the incorrect map type being
556+
// applied to the parent and data being incorrectly moved to or
557+
// from device.
558+
uint64_t mapType = llvm::to_underlying(
559+
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE);
560560

561561
llvm::SmallVector<mlir::Value> members;
562562
members.reserve(indices.second.memberMap.size());

flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ class MapInfoFinalizationPass
181181
return builder.create<mlir::omp::MapInfoOp>(
182182
loc, baseAddrAddr.getType(), descriptor,
183183
mlir::TypeAttr::get(underlyingVarType),
184-
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
184+
builder.getIntegerAttr(
185+
builder.getIntegerType(64, false),
186+
llvm::to_underlying(llvm::omp::OpenMPOffloadMappingFlags(mapType) |
187+
llvm::omp::OpenMPOffloadMappingFlags::
188+
OMP_MAP_DESCRIPTOR_BASE_ADDR)),
185189
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(
186190
mlir::omp::VariableCaptureKind::ByRef),
187191
baseAddrAddr, /*members=*/mlir::SmallVector<mlir::Value>{},
@@ -246,7 +250,10 @@ class MapInfoFinalizationPass
246250
using mapFlags = llvm::omp::OpenMPOffloadMappingFlags;
247251
if (llvm::isa_and_nonnull<mlir::omp::TargetExitDataOp,
248252
mlir::omp::TargetUpdateOp>(target))
249-
return mapTypeFlag;
253+
return llvm::to_underlying(
254+
mapFlags(mapTypeFlag) |
255+
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DESCRIPTOR);
256+
250257
mapFlags flags = mapFlags::OMP_MAP_TO |
251258
(mapFlags(mapTypeFlag) & mapFlags::OMP_MAP_IMPLICIT);
252259
// Descriptors for objects will always be copied. This is because the

0 commit comments

Comments
 (0)