[clang] [llvm] [OpenMP]Generate implicit default mapper for mapping array section. (PR #101101)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 14:50:21 PDT 2024


================
@@ -20796,6 +20796,150 @@ struct MappableVarListInfo {
 };
 } // namespace
 
+static std::pair<DeclRefExpr *, VarDecl *>
+buildImplicitMap(Sema &S, QualType BaseType, DSAStackTy *Stack,
+                 SmallVectorImpl<OMPClause *> &Maps) {
+
+  const RecordDecl *RD = BaseType->getAsRecordDecl();
+  // AST context is RD's ParentASTContext().
+  ASTContext &Ctx = RD->getParentASTContext();
+  // DeclContext is RD's DeclContext.
+  DeclContext *DCT = const_cast<DeclContext *>(RD->getDeclContext());
+  SourceRange Range = RD->getSourceRange();
+  DeclarationNameInfo ImplicitName;
+  // Dummy variable _s for Mapper.
+  ImplicitName.setName(
+      Ctx.DeclarationNames.getIdentifier(&Ctx.Idents.get("_s")));
+  DeclarationName VN = ImplicitName.getName();
+  TypeSourceInfo *TInfo =
+      Ctx.getTrivialTypeSourceInfo(BaseType, Range.getEnd());
+  VarDecl *VD =
+      VarDecl::Create(Ctx, DCT, Range.getEnd(), Range.getEnd(),
+                      VN.getAsIdentifierInfo(), BaseType, TInfo, SC_None);
+  DeclRefExpr *MapperVarRef =
+      buildDeclRefExpr(S, VD, BaseType, SourceLocation());
+
+  // Create implicit map clause for mapper.
+  SmallVector<Expr *, 4> SExprs;
+  for (auto *FD : RD->fields()) {
+    Expr *BE = S.BuildMemberExpr(
+        MapperVarRef, /*IsArrow=*/false, Range.getBegin(),
+        NestedNameSpecifierLoc(), Range.getBegin(), FD,
+        DeclAccessPair::make(FD, FD->getAccess()),
+        /*HadMultipleCandidates=*/false,
+        DeclarationNameInfo(FD->getDeclName(), FD->getSourceRange().getBegin()),
+        FD->getType(), VK_LValue, OK_Ordinary);
+    SExprs.push_back(BE);
+  }
+  CXXScopeSpec MapperIdScopeSpec;
+  DeclarationNameInfo MapperId;
+  OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
+
+  OMPClause *MapClasue = S.OpenMP().ActOnOpenMPMapClause(
+      nullptr, OMPC_MAP_MODIFIER_unknown, SourceLocation(), MapperIdScopeSpec,
+      MapperId, DKind == OMPD_target_enter_data ? OMPC_MAP_to : OMPC_MAP_tofrom,
+      /*IsMapTypeImplicit=*/true, SourceLocation(), SourceLocation(), SExprs,
+      OMPVarListLocTy());
+  Maps.push_back(MapClasue);
+  return {MapperVarRef, VD};
+}
+
+static ExprResult buildImplicitMapper(Sema &S, QualType BaseType,
+                                      DSAStackTy *Stack) {
+
+  // Build impilicit map for mapper
+  SmallVector<OMPClause *, 4> Maps;
+  VarDecl *VD;
+  DeclRefExpr *MapperVarRef;
+  std::tie(MapperVarRef, VD) = buildImplicitMap(S, BaseType, Stack, Maps);
----------------
alexey-bataev wrote:

```suggestion
  auto [MapperVarRef, VD] = buildImplicitMap(S, BaseType, Stack, Maps);
```

https://github.com/llvm/llvm-project/pull/101101


More information about the cfe-commits mailing list