Skip to content

Commit c71c89f

Browse files
committed
[flang][openmp] fix OMPFunctionFiltering pass after llvm#87796
1 parent b4a0fd4 commit c71c89f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "flang/Optimizer/Dialect/FIRDialect.h"
15+
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
1516
#include "flang/Optimizer/Transforms/Passes.h"
1617

1718
#include "mlir/Dialect/Func/IR/FuncOps.h"
@@ -66,6 +67,12 @@ class OMPFunctionFilteringPass
6667
SymbolTable::UseRange funcUses = *funcOp.getSymbolUses(op);
6768
for (SymbolTable::SymbolUse use : funcUses) {
6869
Operation *callOp = use.getUser();
70+
if (mlir::isa<func::FuncOp>(callOp)) {
71+
// Do not delete internal procedures holding the symbol of their
72+
// Fortran host procedure as attribute.
73+
callOp->removeAttr(fir::getHostSymbolAttrName());
74+
continue;
75+
}
6976
// If the callOp has users then replace them with Undef values.
7077
if (!callOp->use_empty()) {
7178
SmallVector<Value> undefResults;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
! RUN: %flang_fc1 -fopenmp -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM-HOST %s
2+
! RUN: %flang_fc1 -fopenmp -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s
3+
! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM-DEVICE %s
4+
! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s
5+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s
6+
! RUN: bbc -fopenmp -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s
7+
8+
! Check that the correct LLVM IR functions are kept for the host and device
9+
! after running the whole set of translation and transformation passes from
10+
! Fortran.
11+
12+
! MLIR-HOST: func.func @{{.*}}host_parent_procedure(
13+
! MLIR-HOST: return
14+
! MLIR-DEVICE-NOT: func.func {{.*}}host_parent_procedure(
15+
16+
! LLVM-HOST: define {{.*}} @host_parent_procedure{{.*}}(
17+
! LLVM-DEVICE-NOT: {{.*}} @{{.*}}_host_parent_procedure{{.*}}(
18+
subroutine host_parent_procedure(x)
19+
integer, intent(out) :: x
20+
call target_internal_proc(x)
21+
contains
22+
! MLIR-ALL: func.func private @_QFhost_parent_procedurePtarget_internal_proc(
23+
24+
! LLVM-HOST: define {{.*}} @_QFhost_parent_procedurePtarget_internal_proc(
25+
! LLVM-HOST: define {{.*}} @__omp_offloading_{{.*}}QFhost_parent_procedurePtarget_internal_proc{{.*}}(
26+
27+
! FIXME: the last check above should also work on the host, but the offload function
28+
! is deleted because it is private and all its usages have been removed in the
29+
! device code. Maybe the private attribute should be removed on internal
30+
! functions while filtering?
31+
subroutine target_internal_proc(x)
32+
integer, intent(out) :: x
33+
!$omp target map(from:x)
34+
x = 10
35+
!$omp end target
36+
end subroutine
37+
end subroutine

0 commit comments

Comments
 (0)