Skip to content

Commit 349f8d6

Browse files
authored
[flang][OpenMP] Skip runtime mapping with no offload targets (#144534)
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 c8c4bd1 commit 349f8d6

File tree

5 files changed

+245
-183
lines changed

5 files changed

+245
-183
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefix=NORT
2+
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefix=LLVM
3+
4+
!Make sure that there are no calls to the mapper.
5+
!NORT-NOT: call{{.*}}__tgt_target_data_begin_mapper
6+
!NORT-NOT: call{{.*}}__tgt_target_data_end_mapper
7+
8+
!Make sure we generate the body
9+
!LLVM: define internal void @_QFPf(ptr %[[A0:[0-9]+]], ptr %[[A1:[0-9]+]]) {
10+
!LLVM: %[[V0:[0-9]+]] = load i32, ptr %[[A0]], align 4
11+
!LLVM: %[[V1:[0-9]+]] = load i32, ptr %[[A1]], align 4
12+
!LLVM: %[[V2:[0-9]+]] = add i32 %[[V0]], %[[V1]]
13+
!LLVM: store i32 %[[V2]], ptr %[[A0]], align 4
14+
!LLVM: ret void
15+
!LLVM: }
16+
17+
18+
program test
19+
20+
call f(1, 2)
21+
22+
contains
23+
24+
subroutine f(x, y)
25+
integer :: x, y
26+
!$omp target data map(tofrom: x, y)
27+
x = x + y
28+
!$omp end target data
29+
end subroutine
30+
end

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

Lines changed: 6 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)
@@ -4467,6 +4470,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
44674470

44684471
if (failed(result))
44694472
return failure();
4473+
// Pretend we have IF(false) if we're not doing offload.
4474+
if (!isOffloadEntry)
4475+
ifCond = builder.getFalse();
44704476

44714477
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
44724478
MapInfoData mapData;

0 commit comments

Comments
 (0)