Skip to content

[flang][OpenMP] Skip runtime mapping with no offload targets #144534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions flang/test/Lower/ignore-target-data.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefix=NORT
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefix=LLVM

!Make sure that there are no calls to the mapper.
!NORT-NOT: call{{.*}}__tgt_target_data_begin_mapper
!NORT-NOT: call{{.*}}__tgt_target_data_end_mapper

!Make sure we generate the body
!LLVM: define internal void @_QFPf(ptr %[[A0:[0-9]+]], ptr %[[A1:[0-9]+]]) {
!LLVM: %[[V0:[0-9]+]] = load i32, ptr %[[A0]], align 4
!LLVM: %[[V1:[0-9]+]] = load i32, ptr %[[A1]], align 4
!LLVM: %[[V2:[0-9]+]] = add i32 %[[V0]], %[[V1]]
!LLVM: store i32 %[[V2]], ptr %[[A0]], align 4
!LLVM: ret void
!LLVM: }


program test

call f(1, 2)

contains

subroutine f(x, y)
integer :: x, y
!$omp target data map(tofrom: x, y)
x = x + y
!$omp end target data
end subroutine
end
Original file line number Diff line number Diff line change
Expand Up @@ -4378,6 +4378,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
llvm::OpenMPIRBuilder::TargetDataInfo info(/*RequiresDevicePointerInfo=*/true,
/*SeparateBeginEndCalls=*/true);
bool isTargetDevice = ompBuilder->Config.isTargetDevice();
bool isOffloadEntry =
isTargetDevice || !ompBuilder->Config.TargetTriples.empty();

LogicalResult result =
llvm::TypeSwitch<Operation *, LogicalResult>(op)
Expand Down Expand Up @@ -4467,6 +4470,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,

if (failed(result))
return failure();
// Pretend we have IF(false) if we're not doing offload.
if (!isOffloadEntry)
ifCond = builder.getFalse();

using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
MapInfoData mapData;
Expand Down
Loading
Loading