Skip to content

Commit f35e193

Browse files
committed
Revert "[flang][cuda] Use fir.cuda_deallocate for automatic deallocation (#89450)"
This reverts commit 2a632d3. This has some implication on OpenACC postDeallocate action
1 parent c60aa43 commit f35e193

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

flang/include/flang/Lower/Allocatable.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ void genDeallocateStmt(AbstractConverter &converter,
5555

5656
void genDeallocateBox(AbstractConverter &converter,
5757
const fir::MutableBoxValue &box, mlir::Location loc,
58-
const Fortran::semantics::Symbol *sym = nullptr,
5958
mlir::Value declaredTypeDesc = {});
6059

6160
/// Deallocate an allocatable if it is allocated at the end of its lifetime.
6261
void genDeallocateIfAllocated(AbstractConverter &converter,
6362
const fir::MutableBoxValue &box,
64-
mlir::Location loc,
65-
const Fortran::semantics::Symbol *sym = nullptr);
63+
mlir::Location loc);
6664

6765
/// Create a MutableBoxValue for an allocatable or pointer entity.
6866
/// If the variables is a local variable that is not a dummy, it will be

flang/lib/Lower/Allocatable.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -859,20 +859,18 @@ genDeallocate(fir::FirOpBuilder &builder,
859859
void Fortran::lower::genDeallocateBox(
860860
Fortran::lower::AbstractConverter &converter,
861861
const fir::MutableBoxValue &box, mlir::Location loc,
862-
const Fortran::semantics::Symbol *sym, mlir::Value declaredTypeDesc) {
862+
mlir::Value declaredTypeDesc) {
863863
const Fortran::lower::SomeExpr *statExpr = nullptr;
864864
const Fortran::lower::SomeExpr *errMsgExpr = nullptr;
865865
ErrorManager errorManager;
866866
errorManager.init(converter, loc, statExpr, errMsgExpr);
867867
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
868-
genDeallocate(builder, converter, loc, box, errorManager, declaredTypeDesc,
869-
sym);
868+
genDeallocate(builder, converter, loc, box, errorManager, declaredTypeDesc);
870869
}
871870

872871
void Fortran::lower::genDeallocateIfAllocated(
873872
Fortran::lower::AbstractConverter &converter,
874-
const fir::MutableBoxValue &box, mlir::Location loc,
875-
const Fortran::semantics::Symbol *sym) {
873+
const fir::MutableBoxValue &box, mlir::Location loc) {
876874
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
877875
mlir::Value isAllocated =
878876
fir::factory::genIsAllocatedOrAssociatedTest(builder, loc, box);
@@ -882,9 +880,9 @@ void Fortran::lower::genDeallocateIfAllocated(
882880
eleType.isa<fir::RecordType>() && box.isPolymorphic()) {
883881
mlir::Value declaredTypeDesc = builder.create<fir::TypeDescOp>(
884882
loc, mlir::TypeAttr::get(eleType));
885-
genDeallocateBox(converter, box, loc, sym, declaredTypeDesc);
883+
genDeallocateBox(converter, box, loc, declaredTypeDesc);
886884
} else {
887-
genDeallocateBox(converter, box, loc, sym);
885+
genDeallocateBox(converter, box, loc);
888886
}
889887
})
890888
.end();

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,13 @@ static void instantiateLocal(Fortran::lower::AbstractConverter &converter,
916916
break;
917917
case VariableCleanUp::Deallocate:
918918
auto *converterPtr = &converter;
919-
auto *sym = &var.getSymbol();
920-
converter.getFctCtx().attachCleanup([converterPtr, loc, exv, sym]() {
919+
converter.getFctCtx().attachCleanup([converterPtr, loc, exv]() {
921920
const fir::MutableBoxValue *mutableBox =
922921
exv.getBoxOf<fir::MutableBoxValue>();
923922
assert(mutableBox &&
924923
"trying to deallocate entity not lowered as allocatable");
925924
Fortran::lower::genDeallocateIfAllocated(*converterPtr, *mutableBox,
926-
loc, sym);
925+
loc);
927926
});
928927
}
929928
}

flang/test/Lower/CUDA/cuda-allocatable.cuf

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ end subroutine
1717

1818
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
1919

20-
! CHECK: %[[BOX_LOAD:.*]] = fir.load %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
21-
! CHECK: %[[ADDR:.*]] = fir.box_addr %[[BOX_LOAD]] : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
22-
! CHECK: %[[ADDR_I64:.*]] = fir.convert %[[ADDR]] : (!fir.heap<!fir.array<?xf32>>) -> i64
23-
! CHECK: %[[C0:.*]] = arith.constant 0 : i64
24-
! CHECK: %[[NE_C0:.*]] = arith.cmpi ne, %[[ADDR_I64]], %[[C0]] : i64
25-
! CHECK: fir.if %[[NE_C0]] {
26-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
27-
! CHECK: }
28-
2920
subroutine sub2()
3021
real, allocatable, managed :: a(:)
3122
integer :: istat
@@ -46,10 +37,6 @@ end subroutine
4637
! CHECK: %[[STAT:.*]] = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<managed>, hasStat} -> i32
4738
! CHECK: fir.store %[[STAT]] to %[[ISTAT_DECL]]#1 : !fir.ref<i32>
4839

49-
! CHECK: fir.if %{{.*}} {
50-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<managed>} -> i32
51-
! CHECK: }
52-
5340
subroutine sub3()
5441
integer, allocatable, pinned :: a(:,:)
5542
logical :: plog
@@ -63,9 +50,6 @@ end subroutine
6350
! CHECK: %[[PLOG_DECL:.*]]:2 = hlfir.declare %5 {uniq_name = "_QFsub3Eplog"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
6451
! CHECK-2: fir.call @_FortranAAllocatableSetBounds
6552
! CHECK: %{{.*}} = fir.cuda_allocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> pinned(%[[PLOG_DECL]]#1 : !fir.ref<!fir.logical<4>>) {cuda_attr = #fir.cuda<pinned>} -> i32
66-
! CHECK: fir.if %{{.*}} {
67-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> {cuda_attr = #fir.cuda<pinned>} -> i32
68-
! CHECK: }
6953

7054
subroutine sub4()
7155
real, allocatable, device :: a(:)
@@ -81,9 +65,6 @@ end subroutine
8165
! CHECK: fir.call @_FortranAAllocatableSetBounds
8266
! CHECK: %[[STREAM:.*]] = fir.load %[[ISTREAM_DECL]]#0 : !fir.ref<i32>
8367
! CHECK: %{{.*}} = fir.cuda_allocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> stream(%[[STREAM]] : i32) {cuda_attr = #fir.cuda<device>} -> i32
84-
! CHECK: fir.if %{{.*}} {
85-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
86-
! CHECK: }
8768

8869
subroutine sub5()
8970
real, allocatable, device :: a(:)
@@ -99,11 +80,6 @@ end subroutine
9980
! CHECK: %[[LOAD_B:.*]] = fir.load %[[BOX_B_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
10081
! CHECK: fir.call @_FortranAAllocatableSetBounds
10182
! CHECK: %{{.*}} = fir.cuda_allocate %[[BOX_A_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> source(%[[LOAD_B]] : !fir.box<!fir.heap<!fir.array<?xf32>>>) {cuda_attr = #fir.cuda<device>} -> i32
102-
! CHECK: fir.if
103-
! CHECK: fir.freemem
104-
! CHECK: fir.if %{{.*}} {
105-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_A_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
106-
! CHECK: }
10783

10884
subroutine sub6()
10985
real, allocatable, device :: a(:)
@@ -119,9 +95,6 @@ end subroutine
11995
! CHECK: %[[LOAD_B:.*]] = fir.load %[[BOX_B_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
12096
! CHECK: fir.call @_FortranAAllocatableApplyMold
12197
! CHECK: %{{.*}} = fir.cuda_allocate %[[BOX_A_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
122-
! CHECK: fir.if %{{.*}} {
123-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_A_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
124-
! CHECK: }
12598

12699
subroutine sub7()
127100
real, allocatable, device :: a(:)
@@ -147,6 +120,3 @@ end subroutine
147120
! CHECK: %[[ERR_BOX:.*]] = fir.embox %[[ERR_DECL]]#1 : (!fir.ref<!fir.char<1,50>>) -> !fir.box<!fir.char<1,50>>
148121
! CHECK: %[[STAT:.*]] = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> errmsg(%15 : !fir.box<!fir.char<1,50>>) {cuda_attr = #fir.cuda<device>, hasStat} -> i32
149122
! CHECK: fir.store %[[STAT]] to %[[ISTAT_DECL]]#1 : !fir.ref<i32>
150-
! CHECK: fir.if %{{.*}} {
151-
! CHECK: %{{.*}} = fir.cuda_deallocate %[[BOX_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {cuda_attr = #fir.cuda<device>} -> i32
152-
! CHECK: }

0 commit comments

Comments
 (0)