[llvm-branch-commits] [flang] [MLIR][OpenMP] Add Lowering support for OpenMP Declare Mapper directive (PR #117046)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 27 08:35:05 PST 2024


================
@@ -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());
----------------
agozillon wrote:

> ```
> 1. If a DECLARE MAPPER directive is not specified for a type DT, a predefined mapper exists for type DT as if the type DT had appeared in the directive as follows:
> 
> !$OMP DECLARE MAPPER (DT :: var) MAP (TOFROM: var)
> 2. If a variable is not a scalar then it is treated as if it had appeared in a map clause with a map-type of tofrom. Which is effectively equivalent to the following and extending declare mapper for non-derived types:
> !$OMP DECLARE MAPPER (T :: var) MAP (TOFROM: var)
> ```

I think the keyword here is likely "as if", so as long as the effects are as described it's reasonable would be my reading, and if we really wanted to be exact about the wording we'd generate/embed our own equivalent pragmas to the above for all default mappings, and then lower them, so not just at the MLIR level. However, saying that I am not against defining a default declare mapper for all cases once it's in place,  it might tidy things up a bit, but it may also be more complicated/trouble than it's worth, in either case I am fine with the approach of defining default declare mappers if we'd like to go down that route :-) 

I'd also love it if whatever implementation we landed on was compatible with the OpenACC implementations documentation/approach to mapping descriptors via runtime calls, as I'd like to move towards that eventually when I have some time to dig into it and see if it's viable for us. I imagine it will be, I just don't know a ton about the region'd approach so hope it wouldn't be prohibitive of this.


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


More information about the llvm-branch-commits mailing list