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

Akash Banerjee via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 28 13:26:45 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());
----------------
TIFitis wrote:

I have made the required changes to both PRs to update the representation for the DeclMapperOp.

Some changes I've incorporated are:

Inside DeclMapperOp's region I've introduce a new `DeclMapperInfoOp` to which I've attached the `MapClause`. Not having any `MapClause` explicitly associated seemed weird to me, also walking through the region collecting all the `MapInfoOps` for processing in various places in the code base seemed like a bad design to me.

Also, instead of using the block arg, I've created a `temporary alloca` inside the region. This is to save the hassle of binding the block_arg to the symbol, binding the `alloca` is much more straightforward.

We can drop the entire `DeclMapperOp` including the region once it reaches `OpenMPTOLLVMIRTranslation`.

Let me what are your thoughts on this approach :)

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


More information about the llvm-branch-commits mailing list