-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Changes from 3 commits
2a89a65
dc3d1a8
176ae91
db2b8f2
d07eb5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) | ||||||||||||||||
|
@@ -4402,6 +4405,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder, | |||||||||||||||
.Case([&](omp::TargetEnterDataOp enterDataOp) -> LogicalResult { | ||||||||||||||||
if (failed(checkImplementationStatus(*enterDataOp))) | ||||||||||||||||
return failure(); | ||||||||||||||||
if (!isOffloadEntry) | ||||||||||||||||
return success(); | ||||||||||||||||
|
||||||||||||||||
if (auto ifVar = enterDataOp.getIfExpr()) | ||||||||||||||||
ifCond = moduleTranslation.lookupValue(ifVar); | ||||||||||||||||
|
@@ -4422,6 +4427,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder, | |||||||||||||||
.Case([&](omp::TargetExitDataOp exitDataOp) -> LogicalResult { | ||||||||||||||||
if (failed(checkImplementationStatus(*exitDataOp))) | ||||||||||||||||
return failure(); | ||||||||||||||||
if (!isOffloadEntry) | ||||||||||||||||
return success(); | ||||||||||||||||
|
||||||||||||||||
if (auto ifVar = exitDataOp.getIfExpr()) | ||||||||||||||||
ifCond = moduleTranslation.lookupValue(ifVar); | ||||||||||||||||
|
@@ -4442,6 +4449,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder, | |||||||||||||||
.Case([&](omp::TargetUpdateOp updateDataOp) -> LogicalResult { | ||||||||||||||||
if (failed(checkImplementationStatus(*updateDataOp))) | ||||||||||||||||
return failure(); | ||||||||||||||||
if (!isOffloadEntry) | ||||||||||||||||
return success(); | ||||||||||||||||
|
||||||||||||||||
if (auto ifVar = updateDataOp.getIfExpr()) | ||||||||||||||||
ifCond = moduleTranslation.lookupValue(ifVar); | ||||||||||||||||
|
@@ -4467,6 +4476,10 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder, | |||||||||||||||
|
||||||||||||||||
if (failed(result)) | ||||||||||||||||
return failure(); | ||||||||||||||||
if (!isOffloadEntry) { | ||||||||||||||||
// Pretend we have IF(false) if we're not doing offload. | ||||||||||||||||
ifCond = builder.getFalse(); | ||||||||||||||||
} | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just reduce the changes to this? At the moment, the If overhead is still a concern for you, I think the other suggestion I made would achieve that while keeping this logic contained and make things easier to follow.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy; | ||||||||||||||||
MapInfoData mapData; | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think it would be more readable if we checked this condition and exited early before this
TypeSwitch
, rather than checking on each case and then later after it was executed.Also, shouldn't we still process the body of
omp.target_data
? That code still should run on the host, AFAIU.