[llvm-branch-commits] [flang] [MLIR][OpenMP] Add Lowering support for OpenMP Declare Mapper directive (PR #117046)
Tom Eccles via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 25 07:17:51 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());
----------------
tblah wrote:
Unfortunately I am not very familiar with the target offload parts of OpenMP so I might have missunderstood something here.
OpenMP 5.2 (section 5.8.8) says
> The visibility and accessibility of this declaration are the same as those of a variable declared at the same location in the program.
Therefore I don't think it is right to be pushing this to the module scope in case there are conflicting mappers declared in different scopes in the same module.
If I understand correctly, the `declare mapper` directive declares `var`:
> The variable declared by var is available for use in all map clauses on the directive, and no part of the variable to be mapped is mapped by default.
So it should be treated as though this parse node is a variable declaration so `createTemporaryAlloc` would be appropriate if this is inside of a function, but if it is not, this should probably be a `fir.global` (like if you declared a module- or file-level variable).
https://github.com/llvm/llvm-project/pull/117046
More information about the llvm-branch-commits
mailing list