================
@@ -2701,7 +2701,42 @@ static void
 genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
        semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
        const parser::OpenMPDeclareMapperConstruct &declareMapperConstruct) {
-  TODO(converter.getCurrentLocation(), "OpenMPDeclareMapperConstruct");
+  fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+  lower::StatementContext stmtCtx;
+  const auto &spec =
+      std::get<parser::OmpDeclareMapperSpecifier>(declareMapperConstruct.t);
+  const auto &mapperName{std::get<std::optional<parser::Name>>(spec.t)};
+  const auto &varType{std::get<parser::TypeSpec>(spec.t)};
+  const auto &varName{std::get<parser::Name>(spec.t)};
+  assert(varType.declTypeSpec->category() ==
+             semantics::DeclTypeSpec::Category::TypeDerived &&
+         "Expected derived type");
+
+  std::string mapperNameStr;
+  if (mapperName.has_value())
+    mapperNameStr = mapperName->ToString();
+  else
+    mapperNameStr =
+        "default_" + varType.declTypeSpec->derivedTypeSpec().name().ToString();
+
+  mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
+  firOpBuilder.setInsertionPointToStart(converter.getModuleOp().getBody());
+  auto mlirType = converter.genType(varType.declTypeSpec->derivedTypeSpec());
+  auto varVal = firOpBuilder.createTemporaryAlloc(
+      converter.getCurrentLocation(), mlirType, varName.ToString());
----------------
kiranchandramohan wrote:

Isn't `declare mapper` providing a specification which is to be used for 
mapping in the associated regions? The variable in the `declare mapper` has its 
scope inside the construct since it is only used for specifying how to map. 
Similar to what @tblah is saying, you could do something like the following.

Assuming %x is the variable that is being mapped by the rules of the declare 
mapper:
```
omp.declare_mapper @default_my_type {
^bb0(%[[VAR:.*]]: [[TYPE]]):
  %v1 = omp.bounds
  %v2 = omp.map.info var_ptr(%[[VAR:.*]])
  omp.yield %v2
}

%x_map = omp.map.info var_ptr(%x) decl_map(@default_my_type)
omp.target_enter_data   map_entries(%x_map)
```

or 

```
omp.declare_mapper @default_my_type {
^bb0(%[[VAR:.*]]: [[TYPE]]):
  %v1 = omp.bounds
  %v2 = omp.map.info var_ptr(%[[VAR:.*]])
  omp.yield %v2
}
omp.target_enter_data   map_entries(%x : @default_my_type)
```

The alternative would be to not have a `declare mapper` construct and apply the 
declare mapper during lowering itself. But this would be early lowering and we 
wont be able to share code with Clang as well.

https://github.com/llvm/llvm-project/pull/117046
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to