summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaOpenMP.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm@meinersbur.de>2019-02-22 22:29:42 +0000
committerMichael Kruse <llvm@meinersbur.de>2019-02-22 22:29:42 +0000
commit01f670df8f3717a66a37169d1d3c93d724bd60cf (patch)
tree5cf69bd161d21d1f3f061671ccec2018e90435bd /clang/lib/Sema/SemaOpenMP.cpp
parent8fffa1dfa3bddf44b73a6f622eafa752347202f5 (diff)
downloadbcm5719-llvm-01f670df8f3717a66a37169d1d3c93d724bd60cf.tar.gz
bcm5719-llvm-01f670df8f3717a66a37169d1d3c93d724bd60cf.zip
[OpenMP 5.0] Parsing/sema support for to clause with mapper modifier.
This patch implements the parsing and sema support for OpenMP to clause with potential user-defined mappers attached. User defined mapper is a new feature in OpenMP 5.0. A to/from clause can have an explicit or implicit associated mapper, which instructs the compiler to generate and use customized mapping functions. An example is shown below: struct S { int len; int *d; }; #pragma omp declare mapper(id: struct S s) map(s, s.d[0:s.len]) struct S ss; #pragma omp target update to(mapper(id): ss) // use the mapper with name 'id' to map ss to device Contributed-by: <lildmh@gmail.com> Differential Revision: https://reviews.llvm.org/D58523 llvm-svn: 354698
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp74
1 files changed, 40 insertions, 34 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 04be5b56e36..5a6891d01ab 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -9802,7 +9802,8 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
DepLinMapLoc, ColonLoc, VarList, Locs);
break;
case OMPC_to:
- Res = ActOnOpenMPToClause(VarList, Locs);
+ Res = ActOnOpenMPToClause(VarList, ReductionOrMapperIdScopeSpec,
+ ReductionOrMapperId, Locs);
break;
case OMPC_from:
Res = ActOnOpenMPFromClause(VarList, Locs);
@@ -13140,17 +13141,23 @@ struct MappableVarListInfo {
static void checkMappableExpressionList(
Sema &SemaRef, DSAStackTy *DSAS, OpenMPClauseKind CKind,
MappableVarListInfo &MVLI, SourceLocation StartLoc,
+ CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo MapperId,
+ ArrayRef<Expr *> UnresolvedMappers,
OpenMPMapClauseKind MapType = OMPC_MAP_unknown,
- bool IsMapTypeImplicit = false, CXXScopeSpec *MapperIdScopeSpec = nullptr,
- const DeclarationNameInfo *MapperId = nullptr,
- ArrayRef<Expr *> UnresolvedMappers = llvm::None) {
+ bool IsMapTypeImplicit = false) {
// We only expect mappable expressions in 'to', 'from', and 'map' clauses.
assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) &&
"Unexpected clause kind with mappable expressions!");
- assert(
- ((CKind == OMPC_map && MapperIdScopeSpec && MapperId) ||
- (CKind != OMPC_map && !MapperIdScopeSpec && !MapperId)) &&
- "Map clauses and only map clauses have user-defined mapper identifiers.");
+
+ // If the identifier of user-defined mapper is not specified, it is "default".
+ // We do not change the actual name in this clause to distinguish whether a
+ // mapper is specified explicitly, i.e., it is not explicitly specified when
+ // MapperId.getName() is empty.
+ if (!MapperId.getName() || MapperId.getName().isEmpty()) {
+ auto &DeclNames = SemaRef.getASTContext().DeclarationNames;
+ MapperId.setName(DeclNames.getIdentifier(
+ &SemaRef.getASTContext().Idents.get("default")));
+ }
// Iterators to find the current unresolved mapper expression.
auto UMIt = UnresolvedMappers.begin(), UMEnd = UnresolvedMappers.end();
@@ -13183,16 +13190,14 @@ static void checkMappableExpressionList(
if (VE->isValueDependent() || VE->isTypeDependent() ||
VE->isInstantiationDependent() ||
VE->containsUnexpandedParameterPack()) {
- if (CKind == OMPC_map) {
+ if (CKind != OMPC_from) {
// Try to find the associated user-defined mapper.
ExprResult ER = buildUserDefinedMapperRef(
- SemaRef, DSAS->getCurScope(), *MapperIdScopeSpec, *MapperId,
+ SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId,
VE->getType().getCanonicalType(), UnresolvedMapper);
if (ER.isInvalid())
continue;
MVLI.UDMapperList.push_back(ER.get());
- } else {
- MVLI.UDMapperList.push_back(nullptr);
}
// We can only analyze this information once the missing information is
// resolved.
@@ -13225,16 +13230,14 @@ static void checkMappableExpressionList(
if (const auto *TE = dyn_cast<CXXThisExpr>(BE)) {
// Add store "this" pointer to class in DSAStackTy for future checking
DSAS->addMappedClassesQualTypes(TE->getType());
- if (CKind == OMPC_map) {
+ if (CKind != OMPC_from) {
// Try to find the associated user-defined mapper.
ExprResult ER = buildUserDefinedMapperRef(
- SemaRef, DSAS->getCurScope(), *MapperIdScopeSpec, *MapperId,
+ SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId,
VE->getType().getCanonicalType(), UnresolvedMapper);
if (ER.isInvalid())
continue;
MVLI.UDMapperList.push_back(ER.get());
- } else {
- MVLI.UDMapperList.push_back(nullptr);
}
// Skip restriction checking for variable or field declarations
MVLI.ProcessedVarList.push_back(RE);
@@ -13352,16 +13355,16 @@ static void checkMappableExpressionList(
continue;
}
}
+ }
- // Try to find the associated user-defined mapper.
+ // Try to find the associated user-defined mapper.
+ if (CKind != OMPC_from) {
ExprResult ER = buildUserDefinedMapperRef(
- SemaRef, DSAS->getCurScope(), *MapperIdScopeSpec, *MapperId,
+ SemaRef, DSAS->getCurScope(), MapperIdScopeSpec, MapperId,
Type.getCanonicalType(), UnresolvedMapper);
if (ER.isInvalid())
continue;
MVLI.UDMapperList.push_back(ER.get());
- } else {
- MVLI.UDMapperList.push_back(nullptr);
}
// Save the current expression.
@@ -13410,17 +13413,10 @@ OMPClause *Sema::ActOnOpenMPMapClause(
++Count;
}
- // If the identifier of user-defined mapper is not specified, it is "default".
- if (!MapperId.getName() || MapperId.getName().isEmpty()) {
- auto &DeclNames = getASTContext().DeclarationNames;
- MapperId.setName(
- DeclNames.getIdentifier(&getASTContext().Idents.get("default")));
- }
-
MappableVarListInfo MVLI(VarList);
checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, Locs.StartLoc,
- MapType, IsMapTypeImplicit, &MapperIdScopeSpec,
- &MapperId, UnresolvedMappers);
+ MapperIdScopeSpec, MapperId, UnresolvedMappers,
+ MapType, IsMapTypeImplicit);
// We need to produce a map clause even if we don't have variables so that
// other diagnostics related with non-existing map clauses are accurate.
@@ -14169,20 +14165,30 @@ void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
}
OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList,
- const OMPVarListLocTy &Locs) {
+ CXXScopeSpec &MapperIdScopeSpec,
+ DeclarationNameInfo &MapperId,
+ const OMPVarListLocTy &Locs,
+ ArrayRef<Expr *> UnresolvedMappers) {
MappableVarListInfo MVLI(VarList);
- checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, Locs.StartLoc);
+ checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, Locs.StartLoc,
+ MapperIdScopeSpec, MapperId, UnresolvedMappers);
if (MVLI.ProcessedVarList.empty())
return nullptr;
- return OMPToClause::Create(Context, Locs, MVLI.ProcessedVarList,
- MVLI.VarBaseDeclarations, MVLI.VarComponents);
+ return OMPToClause::Create(
+ Context, Locs, MVLI.ProcessedVarList, MVLI.VarBaseDeclarations,
+ MVLI.VarComponents, MVLI.UDMapperList,
+ MapperIdScopeSpec.getWithLocInContext(Context), MapperId);
}
OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList,
const OMPVarListLocTy &Locs) {
MappableVarListInfo MVLI(VarList);
- checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, Locs.StartLoc);
+ CXXScopeSpec MapperIdScopeSpec;
+ DeclarationNameInfo MapperId;
+ ArrayRef<Expr *> UnresolvedMappers;
+ checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, Locs.StartLoc,
+ MapperIdScopeSpec, MapperId, UnresolvedMappers);
if (MVLI.ProcessedVarList.empty())
return nullptr;
OpenPOWER on IntegriCloud