diff --git a/flang/include/flang/Lower/OpenMP.h b/flang/include/flang/Lower/OpenMP.h index 6e150ef4e8e82..581c93f76d627 100644 --- a/flang/include/flang/Lower/OpenMP.h +++ b/flang/include/flang/Lower/OpenMP.h @@ -57,6 +57,7 @@ struct Variable; struct OMPDeferredDeclareTargetInfo { mlir::omp::DeclareTargetCaptureClause declareTargetCaptureClause; mlir::omp::DeclareTargetDeviceType declareTargetDeviceType; + bool automap = false; const Fortran::semantics::Symbol &sym; }; diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index b98ad3cf7b76a..6548b501f29d1 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -1179,12 +1179,13 @@ bool ClauseProcessor::processLinear(mlir::omp::LinearClauseOps &result) const { } bool ClauseProcessor::processLink( - llvm::SmallVectorImpl &result) const { + llvm::SmallVectorImpl &result) const { return findRepeatableClause( [&](const omp::clause::Link &clause, const parser::CharBlock &) { // Case: declare target link(var1, var2)... gatherFuncAndVarSyms( - clause.v, mlir::omp::DeclareTargetCaptureClause::link, result); + clause.v, mlir::omp::DeclareTargetCaptureClause::link, result, + /*automap=*/false); }); } @@ -1507,26 +1508,28 @@ bool ClauseProcessor::processTaskReduction( } bool ClauseProcessor::processTo( - llvm::SmallVectorImpl &result) const { + llvm::SmallVectorImpl &result) const { return findRepeatableClause( [&](const omp::clause::To &clause, const parser::CharBlock &) { // Case: declare target to(func, var1, var2)... gatherFuncAndVarSyms(std::get(clause.t), - mlir::omp::DeclareTargetCaptureClause::to, result); + mlir::omp::DeclareTargetCaptureClause::to, result, + /*automap=*/false); }); } bool ClauseProcessor::processEnter( - llvm::SmallVectorImpl &result) const { + llvm::SmallVectorImpl &result) const { return findRepeatableClause( [&](const omp::clause::Enter &clause, const parser::CharBlock &source) { mlir::Location currentLocation = converter.genLocation(source); - if (std::get>(clause.t)) - TODO(currentLocation, "Declare target enter AUTOMAP modifier"); + bool automap = + std::get>(clause.t) + .has_value(); // Case: declare target enter(func, var1, var2)... gatherFuncAndVarSyms(std::get(clause.t), mlir::omp::DeclareTargetCaptureClause::enter, - result); + result, automap); }); } diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h index f8a1f7983b79b..7f894afc1ab37 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.h +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h @@ -118,7 +118,7 @@ class ClauseProcessor { bool processDepend(lower::SymMap &symMap, lower::StatementContext &stmtCtx, mlir::omp::DependClauseOps &result) const; bool - processEnter(llvm::SmallVectorImpl &result) const; + processEnter(llvm::SmallVectorImpl &result) const; bool processIf(omp::clause::If::DirectiveNameModifier directiveName, mlir::omp::IfClauseOps &result) const; bool processInReduction( @@ -129,7 +129,7 @@ class ClauseProcessor { llvm::SmallVectorImpl &isDeviceSyms) const; bool processLinear(mlir::omp::LinearClauseOps &result) const; bool - processLink(llvm::SmallVectorImpl &result) const; + processLink(llvm::SmallVectorImpl &result) const; // This method is used to process a map clause. // The optional parameter mapSyms is used to store the original Fortran symbol @@ -150,7 +150,7 @@ class ClauseProcessor { bool processTaskReduction( mlir::Location currentLocation, mlir::omp::TaskReductionClauseOps &result, llvm::SmallVectorImpl &outReductionSyms) const; - bool processTo(llvm::SmallVectorImpl &result) const; + bool processTo(llvm::SmallVectorImpl &result) const; bool processUseDeviceAddr( lower::StatementContext &stmtCtx, mlir::omp::UseDeviceAddrClauseOps &result, diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index d1efd8e8d2ca7..a9c7919eff0d0 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -764,14 +764,14 @@ static void getDeclareTargetInfo( lower::pft::Evaluation &eval, const parser::OpenMPDeclareTargetConstruct &declareTargetConstruct, mlir::omp::DeclareTargetOperands &clauseOps, - llvm::SmallVectorImpl &symbolAndClause) { + llvm::SmallVectorImpl &symbolAndClause) { const auto &spec = std::get(declareTargetConstruct.t); if (const auto *objectList{parser::Unwrap(spec.u)}) { ObjectList objects{makeObjects(*objectList, semaCtx)}; // Case: declare target(func, var1, var2) gatherFuncAndVarSyms(objects, mlir::omp::DeclareTargetCaptureClause::to, - symbolAndClause); + symbolAndClause, /*automap=*/false); } else if (const auto *clauseList{ parser::Unwrap(spec.u)}) { List clauses = makeClauses(*clauseList, semaCtx); @@ -804,21 +804,20 @@ static void collectDeferredDeclareTargets( llvm::SmallVectorImpl &deferredDeclareTarget) { mlir::omp::DeclareTargetOperands clauseOps; - llvm::SmallVector symbolAndClause; + llvm::SmallVector symbolAndClause; getDeclareTargetInfo(converter, semaCtx, eval, declareTargetConstruct, clauseOps, symbolAndClause); // Return the device type only if at least one of the targets for the // directive is a function or subroutine mlir::ModuleOp mod = converter.getFirOpBuilder().getModule(); - for (const DeclareTargetCapturePair &symClause : symbolAndClause) { - mlir::Operation *op = mod.lookupSymbol( - converter.mangleName(std::get(symClause))); + for (const DeclareTargetCaptureInfo &symClause : symbolAndClause) { + mlir::Operation *op = + mod.lookupSymbol(converter.mangleName(symClause.symbol)); if (!op) { - deferredDeclareTarget.push_back({std::get<0>(symClause), - clauseOps.deviceType, - std::get<1>(symClause)}); + deferredDeclareTarget.push_back({symClause.clause, clauseOps.deviceType, + symClause.automap, symClause.symbol}); } } } @@ -829,16 +828,16 @@ getDeclareTargetFunctionDevice( lower::pft::Evaluation &eval, const parser::OpenMPDeclareTargetConstruct &declareTargetConstruct) { mlir::omp::DeclareTargetOperands clauseOps; - llvm::SmallVector symbolAndClause; + llvm::SmallVector symbolAndClause; getDeclareTargetInfo(converter, semaCtx, eval, declareTargetConstruct, clauseOps, symbolAndClause); // Return the device type only if at least one of the targets for the // directive is a function or subroutine mlir::ModuleOp mod = converter.getFirOpBuilder().getModule(); - for (const DeclareTargetCapturePair &symClause : symbolAndClause) { - mlir::Operation *op = mod.lookupSymbol( - converter.mangleName(std::get(symClause))); + for (const DeclareTargetCaptureInfo &symClause : symbolAndClause) { + mlir::Operation *op = + mod.lookupSymbol(converter.mangleName(symClause.symbol)); if (mlir::isa_and_nonnull(op)) return clauseOps.deviceType; @@ -1055,7 +1054,7 @@ getImplicitMapTypeAndKind(fir::FirOpBuilder &firOpBuilder, static void markDeclareTarget(mlir::Operation *op, lower::AbstractConverter &converter, mlir::omp::DeclareTargetCaptureClause captureClause, - mlir::omp::DeclareTargetDeviceType deviceType) { + mlir::omp::DeclareTargetDeviceType deviceType, bool automap) { // TODO: Add support for program local variables with declare target applied auto declareTargetOp = llvm::dyn_cast(op); if (!declareTargetOp) @@ -1070,11 +1069,11 @@ markDeclareTarget(mlir::Operation *op, lower::AbstractConverter &converter, if (declareTargetOp.isDeclareTarget()) { if (declareTargetOp.getDeclareTargetDeviceType() != deviceType) declareTargetOp.setDeclareTarget(mlir::omp::DeclareTargetDeviceType::any, - captureClause); + captureClause, automap); return; } - declareTargetOp.setDeclareTarget(deviceType, captureClause); + declareTargetOp.setDeclareTarget(deviceType, captureClause, automap); } //===----------------------------------------------------------------------===// @@ -3540,14 +3539,14 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, const parser::OpenMPDeclareTargetConstruct &declareTargetConstruct) { mlir::omp::DeclareTargetOperands clauseOps; - llvm::SmallVector symbolAndClause; + llvm::SmallVector symbolAndClause; mlir::ModuleOp mod = converter.getFirOpBuilder().getModule(); getDeclareTargetInfo(converter, semaCtx, eval, declareTargetConstruct, clauseOps, symbolAndClause); - for (const DeclareTargetCapturePair &symClause : symbolAndClause) { - mlir::Operation *op = mod.lookupSymbol( - converter.mangleName(std::get(symClause))); + for (const DeclareTargetCaptureInfo &symClause : symbolAndClause) { + mlir::Operation *op = + mod.lookupSymbol(converter.mangleName(symClause.symbol)); // Some symbols are deferred until later in the module, these are handled // upon finalization of the module for OpenMP inside of Bridge, so we simply @@ -3555,10 +3554,8 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, if (!op) continue; - markDeclareTarget( - op, converter, - std::get(symClause), - clauseOps.deviceType); + markDeclareTarget(op, converter, symClause.clause, clauseOps.deviceType, + symClause.automap); } } @@ -4141,7 +4138,7 @@ bool Fortran::lower::markOpenMPDeferredDeclareTargetFunctions( deviceCodeFound = true; markDeclareTarget(op, converter, declTar.declareTargetCaptureClause, - devType); + devType, declTar.automap); } return deviceCodeFound; diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index 13fda978c5369..77b1e39083aa6 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -102,9 +102,10 @@ getIterationVariableSymbol(const lower::pft::Evaluation &eval) { void gatherFuncAndVarSyms( const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause, - llvm::SmallVectorImpl &symbolAndClause) { + llvm::SmallVectorImpl &symbolAndClause, + bool automap) { for (const Object &object : objects) - symbolAndClause.emplace_back(clause, *object.sym()); + symbolAndClause.emplace_back(clause, *object.sym(), automap); } mlir::omp::MapInfoOp diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index 11641ba5e8606..60f44a7f0610c 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -42,8 +42,15 @@ class AbstractConverter; namespace omp { -using DeclareTargetCapturePair = - std::pair; +struct DeclareTargetCaptureInfo { + mlir::omp::DeclareTargetCaptureClause clause; + bool automap = false; + const semantics::Symbol &symbol; + + DeclareTargetCaptureInfo(mlir::omp::DeclareTargetCaptureClause c, + const semantics::Symbol &s, bool a = false) + : clause(c), automap(a), symbol(s) {} +}; // A small helper structure for keeping track of a component members MapInfoOp // and index data when lowering OpenMP map clauses. Keeps track of the @@ -150,7 +157,8 @@ getIterationVariableSymbol(const lower::pft::Evaluation &eval); void gatherFuncAndVarSyms( const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause, - llvm::SmallVectorImpl &symbolAndClause); + llvm::SmallVectorImpl &symbolAndClause, + bool automap = false); int64_t getCollapseValue(const List &clauses); diff --git a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp b/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp index ae5c0ecc5b7f6..3031bb5da6919 100644 --- a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp +++ b/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp @@ -95,8 +95,9 @@ class FunctionFilteringPass return WalkResult::skip(); } if (declareTargetOp) - declareTargetOp.setDeclareTarget(declareType, - omp::DeclareTargetCaptureClause::to); + declareTargetOp.setDeclareTarget( + declareType, omp::DeclareTargetCaptureClause::to, + declareTargetOp.getDeclareTargetAutomap()); } return WalkResult::advance(); }); diff --git a/flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp b/flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp index a7ffd5fda82b7..0b0e6bd9ecf34 100644 --- a/flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp +++ b/flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp @@ -33,7 +33,7 @@ class MarkDeclareTargetPass void markNestedFuncs(mlir::omp::DeclareTargetDeviceType parentDevTy, mlir::omp::DeclareTargetCaptureClause parentCapClause, - mlir::Operation *currOp, + bool parentAutomap, mlir::Operation *currOp, llvm::SmallPtrSet visited) { if (visited.contains(currOp)) return; @@ -57,13 +57,16 @@ class MarkDeclareTargetPass currentDt != mlir::omp::DeclareTargetDeviceType::any) { current.setDeclareTarget( mlir::omp::DeclareTargetDeviceType::any, - current.getDeclareTargetCaptureClause()); + current.getDeclareTargetCaptureClause(), + current.getDeclareTargetAutomap()); } } else { - current.setDeclareTarget(parentDevTy, parentCapClause); + current.setDeclareTarget(parentDevTy, parentCapClause, + parentAutomap); } - markNestedFuncs(parentDevTy, parentCapClause, currFOp, visited); + markNestedFuncs(parentDevTy, parentCapClause, parentAutomap, + currFOp, visited); } } } @@ -81,7 +84,8 @@ class MarkDeclareTargetPass llvm::SmallPtrSet visited; markNestedFuncs(declareTargetOp.getDeclareTargetDeviceType(), declareTargetOp.getDeclareTargetCaptureClause(), - functionOp, visited); + declareTargetOp.getDeclareTargetAutomap(), functionOp, + visited); } } @@ -92,9 +96,10 @@ class MarkDeclareTargetPass // the contents of the device clause getOperation()->walk([&](mlir::omp::TargetOp tarOp) { llvm::SmallPtrSet visited; - markNestedFuncs(mlir::omp::DeclareTargetDeviceType::nohost, - mlir::omp::DeclareTargetCaptureClause::to, tarOp, - visited); + markNestedFuncs( + /*parentDevTy=*/mlir::omp::DeclareTargetDeviceType::nohost, + /*parentCapClause=*/mlir::omp::DeclareTargetCaptureClause::to, + /*parentAutomap=*/false, tarOp, visited); }); } }; diff --git a/flang/test/Lower/OpenMP/common-block-map.f90 b/flang/test/Lower/OpenMP/common-block-map.f90 index 06df0d2d9fb18..743438593a3d5 100644 --- a/flang/test/Lower/OpenMP/common-block-map.f90 +++ b/flang/test/Lower/OpenMP/common-block-map.f90 @@ -1,7 +1,7 @@ !RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s !CHECK: fir.global common @var_common_(dense<0> : vector<8xi8>) {{.*}} : !fir.array<8xi8> -!CHECK: fir.global common @var_common_link_(dense<0> : vector<8xi8>) {{{.*}} omp.declare_target = #omp.declaretarget} : !fir.array<8xi8> +!CHECK: fir.global common @var_common_link_(dense<0> : vector<8xi8>) {{{.*}} omp.declare_target = #omp.declaretarget} : !fir.array<8xi8> !CHECK-LABEL: func.func @_QPmap_full_block !CHECK: %[[CB_ADDR:.*]] = fir.address_of(@var_common_) : !fir.ref> diff --git a/flang/test/Lower/OpenMP/declare-target-data.f90 b/flang/test/Lower/OpenMP/declare-target-data.f90 index 154853a0fa20c..474944d7c0bb0 100644 --- a/flang/test/Lower/OpenMP/declare-target-data.f90 +++ b/flang/test/Lower/OpenMP/declare-target-data.f90 @@ -1,86 +1,90 @@ -!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 %s -o - | FileCheck %s +!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 %s -o - | FileCheck %s !RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -fopenmp-is-target-device %s -o - | FileCheck %s module test_0 implicit none -!CHECK-DAG: fir.global @_QMtest_0Edata_int {omp.declare_target = #omp.declaretarget} : i32 +!CHECK-DAG: fir.global @_QMtest_0Edata_int {omp.declare_target = #omp.declaretarget} : i32 INTEGER :: data_int = 10 !$omp declare target link(data_int) -!CHECK-DAG: fir.global @_QMtest_0Earray_1d({{.*}}) {omp.declare_target = #omp.declaretarget} : !fir.array<3xi32> +!CHECK-DAG: fir.global @_QMtest_0Earray_1d({{.*}}) {omp.declare_target = #omp.declaretarget} : !fir.array<3xi32> INTEGER :: array_1d(3) = (/1,2,3/) !$omp declare target link(array_1d) -!CHECK-DAG: fir.global @_QMtest_0Earray_2d({{.*}}) {omp.declare_target = #omp.declaretarget} : !fir.array<2x2xi32> +!CHECK-DAG: fir.global @_QMtest_0Earray_2d({{.*}}) {omp.declare_target = #omp.declaretarget} : !fir.array<2x2xi32> INTEGER :: array_2d(2,2) = reshape((/1,2,3,4/), (/2,2/)) !$omp declare target link(array_2d) -!CHECK-DAG: fir.global @_QMtest_0Ept1 {omp.declare_target = #omp.declaretarget} : !fir.box> +!CHECK-DAG: fir.global @_QMtest_0Ept1 {omp.declare_target = #omp.declaretarget} : !fir.box> INTEGER, POINTER :: pt1 !$omp declare target link(pt1) -!CHECK-DAG: fir.global @_QMtest_0Ept2_tar {omp.declare_target = #omp.declaretarget} target : i32 -INTEGER, TARGET :: pt2_tar = 5 +!CHECK-DAG: fir.global @_QMtest_0Ept2_tar {omp.declare_target = #omp.declaretarget} target : i32 +INTEGER, TARGET :: pt2_tar = 5 !$omp declare target link(pt2_tar) -!CHECK-DAG: fir.global @_QMtest_0Ept2 {omp.declare_target = #omp.declaretarget} : !fir.box> +!CHECK-DAG: fir.global @_QMtest_0Ept2 {omp.declare_target = #omp.declaretarget} : !fir.box> INTEGER, POINTER :: pt2 => pt2_tar !$omp declare target link(pt2) -!CHECK-DAG: fir.global @_QMtest_0Edata_int_to {omp.declare_target = #omp.declaretarget} : i32 +!CHECK-DAG: fir.global @_QMtest_0Edata_int_to {omp.declare_target = #omp.declaretarget} : i32 INTEGER :: data_int_to = 5 !$omp declare target to(data_int_to) -!CHECK-DAG: fir.global @_QMtest_0Edata_int_enter {omp.declare_target = #omp.declaretarget} : i32 +!CHECK-DAG: fir.global @_QMtest_0Edata_int_enter {omp.declare_target = #omp.declaretarget} : i32 INTEGER :: data_int_enter = 5 !$omp declare target enter(data_int_enter) -!CHECK-DAG: fir.global @_QMtest_0Edata_int_clauseless {omp.declare_target = #omp.declaretarget} : i32 +!CHECK-DAG: fir.global @_QMtest_0Edata_int_clauseless {omp.declare_target = #omp.declaretarget} : i32 INTEGER :: data_int_clauseless = 1 !$omp declare target(data_int_clauseless) -!CHECK-DAG: fir.global @_QMtest_0Edata_extended_to_1 {omp.declare_target = #omp.declaretarget} : f32 -!CHECK-DAG: fir.global @_QMtest_0Edata_extended_to_2 {omp.declare_target = #omp.declaretarget} : f32 +!CHECK-DAG: fir.global @_QMtest_0Edata_extended_to_1 {omp.declare_target = #omp.declaretarget} : f32 +!CHECK-DAG: fir.global @_QMtest_0Edata_extended_to_2 {omp.declare_target = #omp.declaretarget} : f32 REAL :: data_extended_to_1 = 2 REAL :: data_extended_to_2 = 3 !$omp declare target to(data_extended_to_1, data_extended_to_2) -!CHECK-DAG: fir.global @_QMtest_0Edata_extended_enter_1 {omp.declare_target = #omp.declaretarget} : f32 -!CHECK-DAG: fir.global @_QMtest_0Edata_extended_enter_2 {omp.declare_target = #omp.declaretarget} : f32 +!CHECK-DAG: fir.global @_QMtest_0Edata_extended_enter_1 {omp.declare_target = #omp.declaretarget} : f32 +!CHECK-DAG: fir.global @_QMtest_0Edata_extended_enter_2 {omp.declare_target = #omp.declaretarget} : f32 REAL :: data_extended_enter_1 = 2 REAL :: data_extended_enter_2 = 3 !$omp declare target enter(data_extended_enter_1, data_extended_enter_2) -!CHECK-DAG: fir.global @_QMtest_0Edata_extended_link_1 {omp.declare_target = #omp.declaretarget} : f32 -!CHECK-DAG: fir.global @_QMtest_0Edata_extended_link_2 {omp.declare_target = #omp.declaretarget} : f32 +!CHECK-DAG: fir.global @_QMtest_0Edata_extended_link_1 {omp.declare_target = #omp.declaretarget} : f32 +!CHECK-DAG: fir.global @_QMtest_0Edata_extended_link_2 {omp.declare_target = #omp.declaretarget} : f32 REAL :: data_extended_link_1 = 2 REAL :: data_extended_link_2 = 3 !$omp declare target link(data_extended_link_1, data_extended_link_2) +!CHECK-DAG: fir.global @_QMtest_0Eautomap_data {omp.declare_target = #omp.declaretarget} target : !fir.box> +INTEGER, ALLOCATABLE, TARGET :: automap_data +!$omp declare target enter(automap : automap_data) + contains end module test_0 PROGRAM commons - !CHECK-DAG: fir.global @numbers_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { + !CHECK-DAG: fir.global @numbers_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { REAL :: one = 1 REAL :: two = 2 COMMON /numbers/ one, two !$omp declare target(/numbers/) - - !CHECK-DAG: fir.global @numbers_link_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { + + !CHECK-DAG: fir.global @numbers_link_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { REAL :: one_link = 1 REAL :: two_link = 2 COMMON /numbers_link/ one_link, two_link !$omp declare target link(/numbers_link/) - !CHECK-DAG: fir.global @numbers_to_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { + !CHECK-DAG: fir.global @numbers_to_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { REAL :: one_to = 1 REAL :: two_to = 2 COMMON /numbers_to/ one_to, two_to !$omp declare target to(/numbers_to/) - !CHECK-DAG: fir.global @numbers_enter_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { + !CHECK-DAG: fir.global @numbers_enter_ {alignment = 4 : i64, omp.declare_target = #omp.declaretarget} : tuple { REAL :: one_enter = 1 REAL :: two_enter = 2 COMMON /numbers_enter/ one_enter, two_enter diff --git a/flang/test/Lower/OpenMP/declare-target-deferred-marking.f90 b/flang/test/Lower/OpenMP/declare-target-deferred-marking.f90 index 079d43e309028..528563aba6962 100644 --- a/flang/test/Lower/OpenMP/declare-target-deferred-marking.f90 +++ b/flang/test/Lower/OpenMP/declare-target-deferred-marking.f90 @@ -51,10 +51,10 @@ end subroutine unused_unemitted_interface end program main !HOST-LABEL: func.func {{.*}} @host_interface() -!HOST-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} +!HOST-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} !ALL-LABEL: func.func {{.*}} @called_from_target_interface(!fir.ref, !fir.ref) -!ALL-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} +!ALL-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} !ALL-LABEL: func.func {{.*}} @any_interface() -!ALL-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} +!ALL-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} !ALL-LABEL: func.func {{.*}} @device_interface() -!ALL-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} +!ALL-SAME: {{.*}}, omp.declare_target = #omp.declaretarget{{.*}} diff --git a/flang/test/Lower/OpenMP/declare-target-func-and-subr.f90 b/flang/test/Lower/OpenMP/declare-target-func-and-subr.f90 index 1c43f1d09eddb..4abf750cf735a 100644 --- a/flang/test/Lower/OpenMP/declare-target-func-and-subr.f90 +++ b/flang/test/Lower/OpenMP/declare-target-func-and-subr.f90 @@ -6,7 +6,7 @@ ! zero clause declare target ! DEVICE-LABEL: func.func @_QPfunc_t_device() -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_T_DEVICE() RESULT(I) !$omp declare target to(FUNC_T_DEVICE) device_type(nohost) INTEGER :: I @@ -14,7 +14,7 @@ FUNCTION FUNC_T_DEVICE() RESULT(I) END FUNCTION FUNC_T_DEVICE ! DEVICE-LABEL: func.func @_QPfunc_enter_device() -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_ENTER_DEVICE() RESULT(I) !$omp declare target enter(FUNC_ENTER_DEVICE) device_type(nohost) INTEGER :: I @@ -22,7 +22,7 @@ FUNCTION FUNC_ENTER_DEVICE() RESULT(I) END FUNCTION FUNC_ENTER_DEVICE ! HOST-LABEL: func.func @_QPfunc_t_host() -! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_T_HOST() RESULT(I) !$omp declare target to(FUNC_T_HOST) device_type(host) INTEGER :: I @@ -30,7 +30,7 @@ FUNCTION FUNC_T_HOST() RESULT(I) END FUNCTION FUNC_T_HOST ! HOST-LABEL: func.func @_QPfunc_enter_host() -! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_ENTER_HOST() RESULT(I) !$omp declare target enter(FUNC_ENTER_HOST) device_type(host) INTEGER :: I @@ -38,7 +38,7 @@ FUNCTION FUNC_ENTER_HOST() RESULT(I) END FUNCTION FUNC_ENTER_HOST ! ALL-LABEL: func.func @_QPfunc_t_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_T_ANY() RESULT(I) !$omp declare target to(FUNC_T_ANY) device_type(any) INTEGER :: I @@ -46,7 +46,7 @@ FUNCTION FUNC_T_ANY() RESULT(I) END FUNCTION FUNC_T_ANY ! ALL-LABEL: func.func @_QPfunc_enter_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_ENTER_ANY() RESULT(I) !$omp declare target enter(FUNC_ENTER_ANY) device_type(any) INTEGER :: I @@ -54,7 +54,7 @@ FUNCTION FUNC_ENTER_ANY() RESULT(I) END FUNCTION FUNC_ENTER_ANY ! ALL-LABEL: func.func @_QPfunc_default_t_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_DEFAULT_T_ANY() RESULT(I) !$omp declare target to(FUNC_DEFAULT_T_ANY) INTEGER :: I @@ -62,7 +62,7 @@ FUNCTION FUNC_DEFAULT_T_ANY() RESULT(I) END FUNCTION FUNC_DEFAULT_T_ANY ! ALL-LABEL: func.func @_QPfunc_default_enter_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_DEFAULT_ENTER_ANY() RESULT(I) !$omp declare target enter(FUNC_DEFAULT_ENTER_ANY) INTEGER :: I @@ -70,7 +70,7 @@ FUNCTION FUNC_DEFAULT_ENTER_ANY() RESULT(I) END FUNCTION FUNC_DEFAULT_ENTER_ANY ! ALL-LABEL: func.func @_QPfunc_default_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_DEFAULT_ANY() RESULT(I) !$omp declare target INTEGER :: I @@ -78,7 +78,7 @@ FUNCTION FUNC_DEFAULT_ANY() RESULT(I) END FUNCTION FUNC_DEFAULT_ANY ! ALL-LABEL: func.func @_QPfunc_default_extendedlist() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_DEFAULT_EXTENDEDLIST() RESULT(I) !$omp declare target(FUNC_DEFAULT_EXTENDEDLIST) INTEGER :: I @@ -86,7 +86,7 @@ FUNCTION FUNC_DEFAULT_EXTENDEDLIST() RESULT(I) END FUNCTION FUNC_DEFAULT_EXTENDEDLIST ! ALL-LABEL: func.func @_QPfunc_name_as_result() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} FUNCTION FUNC_NAME_AS_RESULT() !$omp declare target(FUNC_NAME_AS_RESULT) FUNC_NAME_AS_RESULT = 1.0 @@ -99,61 +99,61 @@ END FUNCTION FUNC_NAME_AS_RESULT ! zero clause declare target ! DEVICE-LABEL: func.func @_QPsubr_t_device() -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_T_DEVICE() !$omp declare target to(SUBR_T_DEVICE) device_type(nohost) END ! DEVICE-LABEL: func.func @_QPsubr_enter_device() -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_ENTER_DEVICE() !$omp declare target enter(SUBR_ENTER_DEVICE) device_type(nohost) END ! HOST-LABEL: func.func @_QPsubr_t_host() -! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_T_HOST() !$omp declare target to(SUBR_T_HOST) device_type(host) END ! HOST-LABEL: func.func @_QPsubr_enter_host() -! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! HOST-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_ENTER_HOST() !$omp declare target enter(SUBR_ENTER_HOST) device_type(host) END ! ALL-LABEL: func.func @_QPsubr_t_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_T_ANY() !$omp declare target to(SUBR_T_ANY) device_type(any) END ! ALL-LABEL: func.func @_QPsubr_enter_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_ENTER_ANY() !$omp declare target enter(SUBR_ENTER_ANY) device_type(any) END ! ALL-LABEL: func.func @_QPsubr_default_t_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_DEFAULT_T_ANY() !$omp declare target to(SUBR_DEFAULT_T_ANY) END ! ALL-LABEL: func.func @_QPsubr_default_enter_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_DEFAULT_ENTER_ANY() !$omp declare target enter(SUBR_DEFAULT_ENTER_ANY) END ! ALL-LABEL: func.func @_QPsubr_default_any() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_DEFAULT_ANY() !$omp declare target END ! ALL-LABEL: func.func @_QPsubr_default_extendedlist() -! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! ALL-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} SUBROUTINE SUBR_DEFAULT_EXTENDEDLIST() !$omp declare target(SUBR_DEFAULT_EXTENDEDLIST) END @@ -161,7 +161,7 @@ SUBROUTINE SUBR_DEFAULT_EXTENDEDLIST() !! ----- ! DEVICE-LABEL: func.func @_QPrecursive_declare_target -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} RECURSIVE FUNCTION RECURSIVE_DECLARE_TARGET(INCREMENT) RESULT(K) !$omp declare target to(RECURSIVE_DECLARE_TARGET) device_type(nohost) INTEGER :: INCREMENT, K @@ -173,7 +173,7 @@ RECURSIVE FUNCTION RECURSIVE_DECLARE_TARGET(INCREMENT) RESULT(K) END FUNCTION RECURSIVE_DECLARE_TARGET ! DEVICE-LABEL: func.func @_QPrecursive_declare_target_enter -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}} RECURSIVE FUNCTION RECURSIVE_DECLARE_TARGET_ENTER(INCREMENT) RESULT(K) !$omp declare target enter(RECURSIVE_DECLARE_TARGET_ENTER) device_type(nohost) INTEGER :: INCREMENT, K diff --git a/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap-enter.f90 b/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap-enter.f90 index 941f1eecbaf56..e8709f23c5413 100644 --- a/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap-enter.f90 +++ b/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap-enter.f90 @@ -4,7 +4,7 @@ !RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=52 -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE ! CHECK-LABEL: func.func @_QPimplicitly_captured_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_twice() result(k) integer :: i i = 10 @@ -12,7 +12,7 @@ function implicitly_captured_twice() result(k) end function implicitly_captured_twice ! CHECK-LABEL: func.func @_QPtarget_function_twice_host -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_twice_host() result(i) !$omp declare target enter(target_function_twice_host) device_type(host) integer :: i @@ -20,7 +20,7 @@ function target_function_twice_host() result(i) end function target_function_twice_host ! DEVICE-LABEL: func.func @_QPtarget_function_twice_device -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_twice_device() result(i) !$omp declare target enter(target_function_twice_device) device_type(nohost) integer :: i @@ -30,7 +30,7 @@ end function target_function_twice_device !! ----- ! DEVICE-LABEL: func.func @_QPimplicitly_captured_nest -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest() result(k) integer :: i i = 10 @@ -44,7 +44,7 @@ function implicitly_captured_one() result(k) end function implicitly_captured_one ! DEVICE-LABEL: func.func @_QPimplicitly_captured_two -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two() result(k) integer :: i i = 10 @@ -52,7 +52,7 @@ function implicitly_captured_two() result(k) end function implicitly_captured_two ! DEVICE-LABEL: func.func @_QPtarget_function_test -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test() result(j) !$omp declare target enter(target_function_test) device_type(nohost) integer :: i, j @@ -63,7 +63,7 @@ end function target_function_test !! ----- ! CHECK-LABEL: func.func @_QPimplicitly_captured_nest_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest_twice() result(k) integer :: i i = 10 @@ -71,13 +71,13 @@ function implicitly_captured_nest_twice() result(k) end function implicitly_captured_nest_twice ! CHECK-LABEL: func.func @_QPimplicitly_captured_one_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_one_twice() result(k) k = implicitly_captured_nest_twice() end function implicitly_captured_one_twice ! CHECK-LABEL: func.func @_QPimplicitly_captured_two_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two_twice() result(k) integer :: i i = 10 @@ -85,7 +85,7 @@ function implicitly_captured_two_twice() result(k) end function implicitly_captured_two_twice ! DEVICE-LABEL: func.func @_QPtarget_function_test_device -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test_device() result(j) !$omp declare target enter(target_function_test_device) device_type(nohost) integer :: i, j @@ -94,7 +94,7 @@ function target_function_test_device() result(j) end function target_function_test_device ! CHECK-LABEL: func.func @_QPtarget_function_test_host -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test_host() result(j) !$omp declare target enter(target_function_test_host) device_type(host) integer :: i, j @@ -105,7 +105,7 @@ end function target_function_test_host !! ----- ! DEVICE-LABEL: func.func @_QPimplicitly_captured_with_dev_type_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} recursive function implicitly_captured_with_dev_type_recursive(increment) result(k) !$omp declare target enter(implicitly_captured_with_dev_type_recursive) device_type(host) integer :: increment, k @@ -117,7 +117,7 @@ recursive function implicitly_captured_with_dev_type_recursive(increment) result end function implicitly_captured_with_dev_type_recursive ! DEVICE-LABEL: func.func @_QPtarget_function_with_dev_type_recurse -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_with_dev_type_recurse() result(i) !$omp declare target enter(target_function_with_dev_type_recurse) device_type(nohost) integer :: i @@ -129,28 +129,28 @@ end function target_function_with_dev_type_recurse module test_module contains ! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_nest_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest_twice() result(i) integer :: i i = 10 end function implicitly_captured_nest_twice ! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_one_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_one_twice() result(k) !$omp declare target enter(implicitly_captured_one_twice) device_type(host) k = implicitly_captured_nest_twice() end function implicitly_captured_one_twice ! DEVICE-LABEL: func.func @_QMtest_modulePimplicitly_captured_two_twice -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two_twice() result(y) integer :: y y = 5 end function implicitly_captured_two_twice ! DEVICE-LABEL: func.func @_QMtest_modulePtarget_function_test_device -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test_device() result(j) !$omp declare target enter(target_function_test_device) device_type(nohost) integer :: i, j @@ -174,7 +174,7 @@ recursive subroutine implicitly_captured_recursive(increment) end program ! DEVICE-LABEL: func.func @_QPimplicitly_captured_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} recursive subroutine implicitly_captured_recursive(increment) integer :: increment if (increment == 10) then @@ -185,7 +185,7 @@ recursive subroutine implicitly_captured_recursive(increment) end subroutine ! DEVICE-LABEL: func.func @_QPcaller_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} subroutine caller_recursive !$omp declare target enter(caller_recursive) device_type(nohost) call implicitly_captured_recursive(0) diff --git a/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap.f90 b/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap.f90 index 8140fcc5f4813..be1e5a0d31f4b 100644 --- a/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap.f90 +++ b/flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap.f90 @@ -4,7 +4,7 @@ !RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=50 -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE ! CHECK-LABEL: func.func @_QPimplicitly_captured -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured(toggle) result(k) integer :: i, j, k logical :: toggle @@ -19,7 +19,7 @@ end function implicitly_captured ! CHECK-LABEL: func.func @_QPtarget_function -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function(toggle) result(i) !$omp declare target integer :: i @@ -30,7 +30,7 @@ end function target_function !! ----- ! CHECK-LABEL: func.func @_QPimplicitly_captured_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_twice() result(k) integer :: i i = 10 @@ -38,7 +38,7 @@ function implicitly_captured_twice() result(k) end function implicitly_captured_twice ! CHECK-LABEL: func.func @_QPtarget_function_twice_host -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_twice_host() result(i) !$omp declare target to(target_function_twice_host) device_type(host) integer :: i @@ -46,7 +46,7 @@ function target_function_twice_host() result(i) end function target_function_twice_host ! DEVICE-LABEL: func.func @_QPtarget_function_twice_device -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_twice_device() result(i) !$omp declare target to(target_function_twice_device) device_type(nohost) integer :: i @@ -56,7 +56,7 @@ end function target_function_twice_device !! ----- ! DEVICE-LABEL: func.func @_QPimplicitly_captured_nest -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest() result(k) integer :: i i = 10 @@ -70,7 +70,7 @@ function implicitly_captured_one() result(k) end function implicitly_captured_one ! DEVICE-LABEL: func.func @_QPimplicitly_captured_two -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two() result(k) integer :: i i = 10 @@ -78,7 +78,7 @@ function implicitly_captured_two() result(k) end function implicitly_captured_two ! DEVICE-LABEL: func.func @_QPtarget_function_test -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test() result(j) !$omp declare target to(target_function_test) device_type(nohost) integer :: i, j @@ -89,7 +89,7 @@ end function target_function_test !! ----- ! CHECK-LABEL: func.func @_QPimplicitly_captured_nest_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest_twice() result(k) integer :: i i = 10 @@ -97,13 +97,13 @@ function implicitly_captured_nest_twice() result(k) end function implicitly_captured_nest_twice ! CHECK-LABEL: func.func @_QPimplicitly_captured_one_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_one_twice() result(k) k = implicitly_captured_nest_twice() end function implicitly_captured_one_twice ! CHECK-LABEL: func.func @_QPimplicitly_captured_two_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two_twice() result(k) integer :: i i = 10 @@ -111,7 +111,7 @@ function implicitly_captured_two_twice() result(k) end function implicitly_captured_two_twice ! DEVICE-LABEL: func.func @_QPtarget_function_test_device -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test_device() result(j) !$omp declare target to(target_function_test_device) device_type(nohost) integer :: i, j @@ -120,7 +120,7 @@ function target_function_test_device() result(j) end function target_function_test_device ! CHECK-LABEL: func.func @_QPtarget_function_test_host -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test_host() result(j) !$omp declare target to(target_function_test_host) device_type(host) integer :: i, j @@ -131,7 +131,7 @@ end function target_function_test_host !! ----- ! DEVICE-LABEL: func.func @_QPimplicitly_captured_with_dev_type_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} recursive function implicitly_captured_with_dev_type_recursive(increment) result(k) !$omp declare target to(implicitly_captured_with_dev_type_recursive) device_type(host) integer :: increment, k @@ -143,7 +143,7 @@ recursive function implicitly_captured_with_dev_type_recursive(increment) result end function implicitly_captured_with_dev_type_recursive ! DEVICE-LABEL: func.func @_QPtarget_function_with_dev_type_recurse -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_with_dev_type_recurse() result(i) !$omp declare target to(target_function_with_dev_type_recurse) device_type(nohost) integer :: i @@ -155,28 +155,28 @@ end function target_function_with_dev_type_recurse module test_module contains ! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_nest_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest_twice() result(i) integer :: i i = 10 end function implicitly_captured_nest_twice ! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_one_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_one_twice() result(k) !$omp declare target to(implicitly_captured_one_twice) device_type(host) k = implicitly_captured_nest_twice() end function implicitly_captured_one_twice ! DEVICE-LABEL: func.func @_QMtest_modulePimplicitly_captured_two_twice -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two_twice() result(y) integer :: y y = 5 end function implicitly_captured_two_twice ! DEVICE-LABEL: func.func @_QMtest_modulePtarget_function_test_device -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function target_function_test_device() result(j) !$omp declare target to(target_function_test_device) device_type(nohost) integer :: i, j @@ -200,7 +200,7 @@ recursive subroutine implicitly_captured_recursive(increment) end program ! DEVICE-LABEL: func.func @_QPimplicitly_captured_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} recursive subroutine implicitly_captured_recursive(increment) integer :: increment if (increment == 10) then @@ -211,7 +211,7 @@ recursive subroutine implicitly_captured_recursive(increment) end subroutine ! DEVICE-LABEL: func.func @_QPcaller_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} subroutine caller_recursive !$omp declare target to(caller_recursive) device_type(nohost) call implicitly_captured_recursive(0) diff --git a/flang/test/Lower/OpenMP/declare-target-implicit-tarop-cap.f90 b/flang/test/Lower/OpenMP/declare-target-implicit-tarop-cap.f90 index eca527ffffcec..c1c1ea37fe471 100644 --- a/flang/test/Lower/OpenMP/declare-target-implicit-tarop-cap.f90 +++ b/flang/test/Lower/OpenMP/declare-target-implicit-tarop-cap.f90 @@ -4,7 +4,7 @@ !RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=52 -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE ! DEVICE-LABEL: func.func @_QPimplicit_capture -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicit_capture() result(i) implicit none integer :: i @@ -21,35 +21,35 @@ subroutine subr_target() !! ----- ! CHECK-LABEL: func.func @_QPimplicitly_captured_nest_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest_twice() result(i) integer :: i i = 10 end function implicitly_captured_nest_twice ! CHECK-LABEL: func.func @_QPimplicitly_captured_one_twice -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_one_twice() result(k) !$omp declare target to(implicitly_captured_one_twice) device_type(host) k = implicitly_captured_nest_twice() end function implicitly_captured_one_twice ! CHECK-LABEL: func.func @_QPimplicitly_captured_nest_twice_enter -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_nest_twice_enter() result(i) integer :: i i = 10 end function implicitly_captured_nest_twice_enter ! CHECK-LABEL: func.func @_QPimplicitly_captured_one_twice_enter -! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_one_twice_enter() result(k) !$omp declare target enter(implicitly_captured_one_twice_enter) device_type(host) k = implicitly_captured_nest_twice_enter() end function implicitly_captured_one_twice_enter ! DEVICE-LABEL: func.func @_QPimplicitly_captured_two_twice -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} function implicitly_captured_two_twice() result(y) integer :: y y = 5 @@ -67,7 +67,7 @@ end function target_function_test_device !! ----- ! DEVICE-LABEL: func.func @_QPimplicitly_captured_recursive -! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} +! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget{{.*}}} recursive function implicitly_captured_recursive(increment) result(k) integer :: increment, k if (increment == 10) then diff --git a/flang/test/Lower/OpenMP/declare-target-unnamed-main.f90 b/flang/test/Lower/OpenMP/declare-target-unnamed-main.f90 index b7d6d2fa232ad..f54f7ed14d1d5 100644 --- a/flang/test/Lower/OpenMP/declare-target-unnamed-main.f90 +++ b/flang/test/Lower/OpenMP/declare-target-unnamed-main.f90 @@ -7,7 +7,7 @@ ! appropriately mark the function as declare target, even when ! unused within the target region. -!CHECK: func.func @_QPfoo(%{{.*}}: !fir.ref{{.*}}) -> f32 attributes {{{.*}}omp.declare_target = #omp.declaretarget{{.*}}} +!CHECK: func.func @_QPfoo(%{{.*}}: !fir.ref{{.*}}) -> f32 attributes {{{.*}}omp.declare_target = #omp.declaretarget{{.*}}} interface real function foo (x) diff --git a/flang/test/Lower/OpenMP/function-filtering-2.f90 b/flang/test/Lower/OpenMP/function-filtering-2.f90 index a94cbfffca5bf..34d910c53d6ea 100644 --- a/flang/test/Lower/OpenMP/function-filtering-2.f90 +++ b/flang/test/Lower/OpenMP/function-filtering-2.f90 @@ -5,13 +5,13 @@ ! RUN: bbc -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s ! RUN: %if amdgpu-registered-target %{ bbc -target amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s %} -! MLIR: func.func @{{.*}}implicit_invocation() attributes {omp.declare_target = #omp.declaretarget} +! MLIR: func.func @{{.*}}implicit_invocation() attributes {omp.declare_target = #omp.declaretarget} ! MLIR: return ! LLVM: define {{.*}} @{{.*}}implicit_invocation{{.*}}( subroutine implicit_invocation() end subroutine implicit_invocation -! MLIR: func.func @{{.*}}declaretarget() attributes {omp.declare_target = #omp.declaretarget} +! MLIR: func.func @{{.*}}declaretarget() attributes {omp.declare_target = #omp.declaretarget} ! MLIR: return ! LLVM: define {{.*}} @{{.*}}declaretarget{{.*}}( subroutine declaretarget() @@ -19,7 +19,7 @@ subroutine declaretarget() call implicit_invocation() end subroutine declaretarget -! MLIR: func.func @{{.*}}declaretarget_enter() attributes {omp.declare_target = #omp.declaretarget} +! MLIR: func.func @{{.*}}declaretarget_enter() attributes {omp.declare_target = #omp.declaretarget} ! MLIR: return ! LLVM: define {{.*}} @{{.*}}declaretarget_enter{{.*}}( subroutine declaretarget_enter() @@ -27,7 +27,7 @@ subroutine declaretarget_enter() call implicit_invocation() end subroutine declaretarget_enter -! MLIR: func.func @{{.*}}no_declaretarget() attributes {omp.declare_target = #omp.declaretarget} +! MLIR: func.func @{{.*}}no_declaretarget() attributes {omp.declare_target = #omp.declaretarget} ! MLIR: return ! LLVM: define {{.*}} @{{.*}}no_declaretarget{{.*}}( subroutine no_declaretarget() diff --git a/flang/test/Lower/OpenMP/omp-declare-target-program-var.f90 b/flang/test/Lower/OpenMP/omp-declare-target-program-var.f90 index d18f42ae3ceb0..dc23a8190cb8d 100644 --- a/flang/test/Lower/OpenMP/omp-declare-target-program-var.f90 +++ b/flang/test/Lower/OpenMP/omp-declare-target-program-var.f90 @@ -5,7 +5,7 @@ PROGRAM main ! HOST-DAG: %[[I_REF:.*]] = fir.alloca f32 {bindc_name = "i", uniq_name = "_QFEi"} ! HOST-DAG: %[[I_DECL:.*]]:2 = hlfir.declare %[[I_REF]] {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) REAL :: I - ! ALL-DAG: fir.global internal @_QFEi {omp.declare_target = #omp.declaretarget} : f32 { + ! ALL-DAG: fir.global internal @_QFEi {omp.declare_target = #omp.declaretarget} : f32 { ! ALL-DAG: %[[UNDEF:.*]] = fir.zero_bits f32 ! ALL-DAG: fir.has_value %[[UNDEF]] : f32 ! ALL-DAG: } diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td index 72ce4c6a21cb3..c9e6764e7d634 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td @@ -42,10 +42,10 @@ def AtomicControlAttr : OpenMP_Attr<"AtomicControl", "atomic_control"> { //===----------------------------------------------------------------------===// def DeclareTargetAttr : OpenMP_Attr<"DeclareTarget", "declaretarget"> { - let parameters = (ins - OptionalParameter<"DeclareTargetDeviceTypeAttr">:$device_type, - OptionalParameter<"DeclareTargetCaptureClauseAttr">:$capture_clause - ); + let parameters = + (ins OptionalParameter<"DeclareTargetDeviceTypeAttr">:$device_type, + OptionalParameter<"DeclareTargetCaptureClauseAttr">:$capture_clause, + OptionalParameter<"BoolAttr">:$automap); let assemblyFormat = "`<` struct(params) `>`"; } diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td index 0dc385b08a823..d471e6c0ed70b 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -329,14 +329,16 @@ def DeclareTargetInterface : OpInterface<"DeclareTargetInterface"> { /*retTy=*/"void", /*methodName=*/"setDeclareTarget", (ins "mlir::omp::DeclareTargetDeviceType":$deviceType, - "mlir::omp::DeclareTargetCaptureClause":$captureClause), [{}], [{ + "mlir::omp::DeclareTargetCaptureClause":$captureClause, + "bool":$automap), [{}], [{ $_op->setAttr("omp.declare_target", mlir::omp::DeclareTargetAttr::get( $_op->getContext(), mlir::omp::DeclareTargetDeviceTypeAttr::get( $_op->getContext(), deviceType), mlir::omp::DeclareTargetCaptureClauseAttr::get( - $_op->getContext(), captureClause))); + $_op->getContext(), captureClause), + mlir::BoolAttr::get($_op->getContext(), automap))); }]>, InterfaceMethod< /*description=*/[{ @@ -374,6 +376,19 @@ def DeclareTargetInterface : OpInterface<"DeclareTargetInterface"> { if (auto dAttr = llvm::dyn_cast_or_null(dTar)) return dAttr.getCaptureClause().getValue(); return {}; + }]>, + InterfaceMethod< + /*description=*/[{ + Return true if the DeclareTarget attribute has the AUTOMAP modifier. + }], + /*retTy=*/"bool", + /*methodName=*/"getDeclareTargetAutomap", + (ins), [{}], [{ + if (mlir::Attribute dTar = $_op->getAttr("omp.declare_target")) + if (auto dAttr = llvm::dyn_cast_or_null(dTar)) + if (auto autoVal = dAttr.getAutomap()) + return autoVal.getValue(); + return false; }]> ]; }