Skip to content

Commit 2a89a65

Browse files
committed
[flang][OpenMP] Ignore target-data operations with no offload targets
When no offload targets are specified flang will ignore "target" constructs, but not "target data" constructs. This patch makes the behavior consistent across all offload-related operations. While ignoring "target" may produce semantically incorrect code, it may still be a useful debugging tool.
1 parent 9fed480 commit 2a89a65

File tree

5 files changed

+240
-183
lines changed

5 files changed

+240
-183
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s
2+
3+
!Make sure that there are no calls to the mapper.
4+
5+
!CHECK-NOT: call{{.*}}__tgt_target_data_begin_mapper
6+
!CHECK-NOT: call{{.*}}__tgt_target_data_end_mapper
7+
8+
program test
9+
10+
call f(1, 2)
11+
12+
contains
13+
14+
subroutine f(x, y)
15+
integer :: x, y
16+
!$omp target data map(tofrom: x, y)
17+
x = x + y
18+
!$omp end target data
19+
end subroutine
20+
end

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,6 +4378,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
43784378
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
43794379
llvm::OpenMPIRBuilder::TargetDataInfo info(/*RequiresDevicePointerInfo=*/true,
43804380
/*SeparateBeginEndCalls=*/true);
4381+
bool isTargetDevice = ompBuilder->Config.isTargetDevice();
4382+
bool isOffloadEntry =
4383+
isTargetDevice || !ompBuilder->Config.TargetTriples.empty();
43814384

43824385
LogicalResult result =
43834386
llvm::TypeSwitch<Operation *, LogicalResult>(op)
@@ -4402,6 +4405,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
44024405
.Case([&](omp::TargetEnterDataOp enterDataOp) -> LogicalResult {
44034406
if (failed(checkImplementationStatus(*enterDataOp)))
44044407
return failure();
4408+
if (!isOffloadEntry)
4409+
return success();
44054410

44064411
if (auto ifVar = enterDataOp.getIfExpr())
44074412
ifCond = moduleTranslation.lookupValue(ifVar);
@@ -4422,6 +4427,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
44224427
.Case([&](omp::TargetExitDataOp exitDataOp) -> LogicalResult {
44234428
if (failed(checkImplementationStatus(*exitDataOp)))
44244429
return failure();
4430+
if (!isOffloadEntry)
4431+
return success();
44254432

44264433
if (auto ifVar = exitDataOp.getIfExpr())
44274434
ifCond = moduleTranslation.lookupValue(ifVar);
@@ -4442,6 +4449,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
44424449
.Case([&](omp::TargetUpdateOp updateDataOp) -> LogicalResult {
44434450
if (failed(checkImplementationStatus(*updateDataOp)))
44444451
return failure();
4452+
if (!isOffloadEntry)
4453+
return success();
44454454

44464455
if (auto ifVar = updateDataOp.getIfExpr())
44474456
ifCond = moduleTranslation.lookupValue(ifVar);
@@ -4467,6 +4476,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
44674476

44684477
if (failed(result))
44694478
return failure();
4479+
if (!isOffloadEntry)
4480+
return success();
44704481

44714482
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
44724483
MapInfoData mapData;

0 commit comments

Comments
 (0)