[all-commits] [llvm/llvm-project] ff7fca: [flang][cuda] Support memory cleanup at a return s...
khaki3 via All-commits
all-commits at lists.llvm.org
Fri Nov 15 08:45:05 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: ff7fca7fa8646d73f884ab8a351e4178499c4d05
https://github.com/llvm/llvm-project/commit/ff7fca7fa8646d73f884ab8a351e4178499c4d05
Author: khaki3 <47756807+khaki3 at users.noreply.github.com>
Date: 2024-11-15 (Fri, 15 Nov 2024)
Changed paths:
M flang/include/flang/Lower/StatementContext.h
M flang/lib/Lower/Bridge.cpp
A flang/test/Lower/CUDA/cuda-return01.cuf
A flang/test/Lower/CUDA/cuda-return02.cuf
Log Message:
-----------
[flang][cuda] Support memory cleanup at a return statement (#116304)
We generate `cuf.free` and `func.return` twice if a return statement
exists at the end of program.
```f90
program test
integer, device :: a(10)
return
end
```
```
% flang -x cuda test.cuf -mmlir --mlir-print-ir-after-all
error: loc("/path/to/test.cuf":3:3): 'func.return' op must be the last operation in the parent block
// -----// IR Dump After Fortran::lower::VerifierPass Failed () //----- //
```
Dumped IR:
```mlir
"func.func"() <{function_type = () -> (), sym_name = "_QQmain"}> ({
...
"cuf.free"(%5#1) <{data_attr = #cuf.cuda<device>}> : (!fir.ref<!fir.array<10xi32>>) -> ()
"func.return"() : () -> ()
"cuf.free"(%5#1) <{data_attr = #cuf.cuda<device>}> : (!fir.ref<!fir.array<10xi32>>) -> ()
"func.return"() : () -> ()
}
...
```
The routine `genExitRoutine` in `Bridge.cpp` is guarded by
`blockIsUnterminated()` to make sure that `func.return` is generated
only at the end of a block. However, we redundantly run
`bridge.fctCtx().finalizeAndKeep()` before `genExitRoutine` in this
case, resulting in two pairs of `cuf.free` and `func.return`. This PR
fixes `Bridge.cpp` by using `blockIsUnterminated()` to guard
`finalizeAndKeep` as well.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list