diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -181,6 +181,8 @@ if (ci.getInvocation().getFrontendOpts().features.IsEnabled( Fortran::common::LanguageFeature::OpenMP)) { + mlir::ModuleOp::attachInterface( + *mlirModule->getContext()); mlir::omp::OpenMPDialect::setIsDevice( *mlirModule, ci.getInvocation().getLangOpts().OpenMPIsDevice); } diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp --- a/flang/tools/bbc/bbc.cpp +++ b/flang/tools/bbc/bbc.cpp @@ -243,6 +243,8 @@ kindMap, loweringOptions, {}); burnside.lower(parseTree, semanticsContext); mlir::ModuleOp mlirModule = burnside.getModule(); + mlir::ModuleOp::attachInterface( + *mlirModule.getContext()); if (enableOpenMP) mlir::omp::OpenMPDialect::setIsDevice(mlirModule, enableOpenMPDevice); std::error_code ec; diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -47,4 +47,30 @@ ]; } +def DeviceModuleInterface : OpInterface<"DeviceModuleInterface"> { + let description = [{ + Operations that represent a device module should have this interface. + }]; + + let cppNamespace = "::mlir::omp"; + + let methods = [ + InterfaceMethod< + "Get target CPU", "std::string", + "getTargetCPU", (ins), [{}], [{ + if (::mlir::Attribute targetCpu = $_op->getAttr("omp.target_cpu")) + if (targetCpu.isa<::mlir::StringAttr>()) + return targetCpu.dyn_cast<::mlir::StringAttr>().getValue().str(); + return llvm::Twine{""}.str(); + }]>, + InterfaceMethod< + "Set target CPU", "std::string", + "setTargetCPU", (ins "llvm::StringRef":$cpu), [{}], [{ + $_op->setAttr(mlir::StringAttr::get($_op->getContext(), + llvm::Twine{"omp.target_cpu"}), + mlir::StringAttr::get($_op->getContext(), cpu)); + }]>, + ]; +} + #endif // OpenMP_OPS_INTERFACES