Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Squashed Commit Of All Map Changes in amd-trunk-dev-map-b4-squash
Browse files Browse the repository at this point in the history
Consists of:
   1-D array sectioning mapping
   initial declare target mapping
   initial 1-D pointer/alloca/target mapping
   A start at structure lowering with contained pointers (can't test yet due to some required frontned work, but it's utilised to lower pointers etc. at the moment, which is similar in Fortran)
   tidying up of the above
   Sergio's CSE patch
  • Loading branch information
agozillon committed Sep 29, 2023
1 parent 8829a7b commit ddb01b1
Show file tree
Hide file tree
Showing 25 changed files with 1,227 additions and 390 deletions.
68 changes: 27 additions & 41 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7734,30 +7734,6 @@ class MappableExprsHandler {
OpenMPOffloadMappingFlags::OMP_MAP_FROM;
}

static OpenMPOffloadMappingFlags getMemberOfFlag(unsigned Position) {
// Rotate by getFlagMemberOffset() bits.
return static_cast<OpenMPOffloadMappingFlags>(((uint64_t)Position + 1)
<< getFlagMemberOffset());
}

static void setCorrectMemberOfFlag(OpenMPOffloadMappingFlags &Flags,
OpenMPOffloadMappingFlags MemberOfFlag) {
// If the entry is PTR_AND_OBJ but has not been marked with the special
// placeholder value 0xFFFF in the MEMBER_OF field, then it should not be
// marked as MEMBER_OF.
if (static_cast<std::underlying_type_t<OpenMPOffloadMappingFlags>>(
Flags & OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ) &&
static_cast<std::underlying_type_t<OpenMPOffloadMappingFlags>>(
(Flags & OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF) !=
OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF))
return;

// Reset the placeholder value to prepare the flag for the assignment of the
// proper MEMBER_OF value.
Flags &= ~OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF;
Flags |= MemberOfFlag;
}

void getPlainLayout(const CXXRecordDecl *RD,
llvm::SmallVectorImpl<const FieldDecl *> &Layout,
bool AsBase) const {
Expand Down Expand Up @@ -7825,6 +7801,7 @@ class MappableExprsHandler {
/// the device pointers info array.
void generateAllInfoForClauses(
ArrayRef<const OMPClause *> Clauses, MapCombinedInfoTy &CombinedInfo,
llvm::OpenMPIRBuilder &OMPBuilder,
const llvm::DenseSet<CanonicalDeclPtr<const Decl>> &SkipVarSet =
llvm::DenseSet<CanonicalDeclPtr<const Decl>>()) const {
// We have to process the component lists that relate with the same
Expand Down Expand Up @@ -8159,7 +8136,7 @@ class MappableExprsHandler {
if (PartialStruct.Base.isValid()) {
CurInfo.NonContigInfo.Dims.push_back(0);
emitCombinedEntry(CombinedInfo, CurInfo.Types, PartialStruct,
/*IsMapThis*/ !VD, VD);
/*IsMapThis*/ !VD, OMPBuilder, VD);
}

// We need to append the results of this capture to what we already
Expand Down Expand Up @@ -8226,6 +8203,7 @@ class MappableExprsHandler {
void emitCombinedEntry(MapCombinedInfoTy &CombinedInfo,
MapFlagsArrayTy &CurTypes,
const StructRangeInfoTy &PartialStruct, bool IsMapThis,
llvm::OpenMPIRBuilder &OMPBuilder,
const ValueDecl *VD = nullptr,
bool NotTargetParams = true) const {
if (CurTypes.size() == 1 &&
Expand Down Expand Up @@ -8313,9 +8291,11 @@ class MappableExprsHandler {
// (except for PTR_AND_OBJ entries which do not have a placeholder value
// 0xFFFF in the MEMBER_OF field).
OpenMPOffloadMappingFlags MemberOfFlag =
getMemberOfFlag(CombinedInfo.BasePointers.size() - 1);
for (auto &M : CurTypes)
setCorrectMemberOfFlag(M, MemberOfFlag);
OMPBuilder.getMemberOfFlag(CombinedInfo.BasePointers.size() - 1);

for (auto &M : CurTypes) {
OMPBuilder.setCorrectMemberOfFlag(M, MemberOfFlag);
}
}

/// Generate all the base pointers, section pointers, sizes, map types, and
Expand All @@ -8324,23 +8304,26 @@ class MappableExprsHandler {
/// pair of the relevant declaration and index where it occurs is appended to
/// the device pointers info array.
void generateAllInfo(
MapCombinedInfoTy &CombinedInfo,
MapCombinedInfoTy &CombinedInfo, llvm::OpenMPIRBuilder &OMPBuilder,
const llvm::DenseSet<CanonicalDeclPtr<const Decl>> &SkipVarSet =
llvm::DenseSet<CanonicalDeclPtr<const Decl>>()) const {
assert(CurDir.is<const OMPExecutableDirective *>() &&
"Expect a executable directive");
const auto *CurExecDir = CurDir.get<const OMPExecutableDirective *>();
generateAllInfoForClauses(CurExecDir->clauses(), CombinedInfo, SkipVarSet);
generateAllInfoForClauses(CurExecDir->clauses(), CombinedInfo, OMPBuilder,
SkipVarSet);
}

/// Generate all the base pointers, section pointers, sizes, map types, and
/// mappers for the extracted map clauses of user-defined mapper (all included
/// in \a CombinedInfo).
void generateAllInfoForMapper(MapCombinedInfoTy &CombinedInfo) const {
void generateAllInfoForMapper(MapCombinedInfoTy &CombinedInfo,
llvm::OpenMPIRBuilder &OMPBuilder) const {
assert(CurDir.is<const OMPDeclareMapperDecl *>() &&
"Expect a declare mapper directive");
const auto *CurMapperDir = CurDir.get<const OMPDeclareMapperDecl *>();
generateAllInfoForClauses(CurMapperDir->clauses(), CombinedInfo);
generateAllInfoForClauses(CurMapperDir->clauses(), CombinedInfo,
OMPBuilder);
}

/// Emit capture info for lambdas for variables captured by reference.
Expand Down Expand Up @@ -8422,6 +8405,7 @@ class MappableExprsHandler {

/// Set correct indices for lambdas captures.
void adjustMemberOfForLambdaCaptures(
llvm::OpenMPIRBuilder &OMPBuilder,
const llvm::DenseMap<llvm::Value *, llvm::Value *> &LambdaPointers,
MapBaseValuesArrayTy &BasePointers, MapValuesArrayTy &Pointers,
MapFlagsArrayTy &Types) const {
Expand All @@ -8446,8 +8430,9 @@ class MappableExprsHandler {
// All other current entries will be MEMBER_OF the combined entry
// (except for PTR_AND_OBJ entries which do not have a placeholder value
// 0xFFFF in the MEMBER_OF field).
OpenMPOffloadMappingFlags MemberOfFlag = getMemberOfFlag(TgtIdx);
setCorrectMemberOfFlag(Types[I], MemberOfFlag);
OpenMPOffloadMappingFlags MemberOfFlag =
OMPBuilder.getMemberOfFlag(TgtIdx);
OMPBuilder.setCorrectMemberOfFlag(Types[I], MemberOfFlag);
}
}

Expand Down Expand Up @@ -9141,7 +9126,7 @@ void CGOpenMPRuntime::emitUserDefinedMapper(const OMPDeclareMapperDecl *D,
// Get map clause information. Fill up the arrays with all mapped variables.
MappableExprsHandler::MapCombinedInfoTy Info;
MappableExprsHandler MEHandler(*D, MapperCGF);
MEHandler.generateAllInfoForMapper(Info);
MEHandler.generateAllInfoForMapper(Info, OMPBuilder);

// Call the runtime API __tgt_mapper_num_components to get the number of
// pre-existing components.
Expand Down Expand Up @@ -9525,19 +9510,20 @@ static void emitTargetCallKernelLaunch(
CombinedInfo.append(PartialStruct.PreliminaryMapData);
MEHandler.emitCombinedEntry(
CombinedInfo, CurInfo.Types, PartialStruct, CI->capturesThis(),
nullptr, !PartialStruct.PreliminaryMapData.BasePointers.empty());
OMPBuilder, nullptr,
!PartialStruct.PreliminaryMapData.BasePointers.empty());
}

// We need to append the results of this capture to what we already have.
CombinedInfo.append(CurInfo);
}
// Adjust MEMBER_OF flags for the lambdas captures.
MEHandler.adjustMemberOfForLambdaCaptures(
LambdaPointers, CombinedInfo.BasePointers, CombinedInfo.Pointers,
CombinedInfo.Types);
OMPBuilder, LambdaPointers, CombinedInfo.BasePointers,
CombinedInfo.Pointers, CombinedInfo.Types);
// Map any list items in a map clause that were not captures because they
// weren't referenced within the construct.
MEHandler.generateAllInfo(CombinedInfo, MappedVarSet);
MEHandler.generateAllInfo(CombinedInfo, OMPBuilder, MappedVarSet);

CGOpenMPRuntime::TargetDataInfo Info;
// Fill up the arrays and create the arguments.
Expand Down Expand Up @@ -10272,7 +10258,7 @@ void CGOpenMPRuntime::emitTargetDataCalls(
CGF.Builder.restoreIP(CodeGenIP);
// Get map clause information.
MappableExprsHandler MEHandler(D, CGF);
MEHandler.generateAllInfo(CombinedInfo);
MEHandler.generateAllInfo(CombinedInfo, OMPBuilder);

auto FillInfoMap = [&](MappableExprsHandler::MappingExprInfo &MapExpr) {
return emitMappingInformation(CGF, OMPBuilder, MapExpr);
Expand Down Expand Up @@ -10478,7 +10464,7 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(

// Get map clause information.
MappableExprsHandler MEHandler(D, CGF);
MEHandler.generateAllInfo(CombinedInfo);
MEHandler.generateAllInfo(CombinedInfo, OMPBuilder);

CGOpenMPRuntime::TargetDataInfo Info;
// Fill up the arrays and create the arguments.
Expand Down
7 changes: 6 additions & 1 deletion flang/include/flang/Lower/OpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConvertOp;
namespace Fortran {
namespace parser {
struct OpenMPConstruct;
struct OpenMPBlockConstruct;
struct OpenMPDeclarativeConstruct;
struct OmpEndLoopDirective;
struct OmpClauseList;
Expand All @@ -51,7 +52,6 @@ struct Variable;
// Generate the OpenMP terminator for Operation at Location.
void genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *,
mlir::Location);

void genOpenMPConstruct(AbstractConverter &, semantics::SemanticsContext &,
pft::Evaluation &, const parser::OpenMPConstruct &);
void genOpenMPDeclarativeConstruct(AbstractConverter &, pft::Evaluation &,
Expand All @@ -61,6 +61,11 @@ void genThreadprivateOp(AbstractConverter &, const pft::Variable &);
void genDeclareTargetIntGlobal(AbstractConverter &, const pft::Variable &);
void genOpenMPReduction(AbstractConverter &,
const Fortran::parser::OmpClauseList &clauseList);
void genImplicitMapsForTarget(
Fortran::lower::AbstractConverter &converter,
Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::pft::Evaluation &eval,
const Fortran::parser::OpenMPBlockConstruct &ompBlock);

mlir::Operation *findReductionChain(mlir::Value, mlir::Value * = nullptr);
fir::ConvertOp getConvertFromReductionOp(mlir::Operation *, mlir::Value);
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ bool CodeGenAction::beginSourceFileAction() {
}

pm.enableVerifier(/*verifyPasses=*/true);

pm.addPass(std::make_unique<Fortran::lower::VerifierPass>());

if (mlir::failed(pm.run(*mlirModule))) {
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
genOpenMPReduction(*this, blockClauses);
}

if (ompBlock) {
genImplicitMapsForTarget(*this, bridge.getSemanticsContext(), getEval(),
*ompBlock);
}

localSymbols.popScope();
builder->restoreInsertionPoint(insertPt);

Expand Down
1 change: 1 addition & 0 deletions flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
if (fir::GlobalOp global = builder.getNamedGlobal(globalName))
return global;

// Always define linkonce data since it may be optimized out from the module
// that actually owns the variable if it does not refers to it.
if (linkage == builder.createLinkOnceODRLinkage() ||
Expand Down
Loading

0 comments on commit ddb01b1

Please sign in to comment.