[flang-commits] [flang] 09cdfd6 - [flang][cuda] Avoid hlfir.declare verifier error when creating temps (#89984)

via flang-commits flang-commits at lists.llvm.org
Thu Apr 25 08:50:56 PDT 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-04-25T08:50:52-07:00
New Revision: 09cdfd68a6cce69cd4c935b8c38ad391cea265ae

URL: https://github.com/llvm/llvm-project/commit/09cdfd68a6cce69cd4c935b8c38ad391cea265ae
DIFF: https://github.com/llvm/llvm-project/commit/09cdfd68a6cce69cd4c935b8c38ad391cea265ae.diff

LOG: [flang][cuda] Avoid hlfir.declare verifier error when creating temps (#89984)

When creating temporaries for implicit transfer, the newly create
hlfir.declare operation was missing some information like the shape and
the verifier was throwing an error. Fix it by making sure we have an
ExtendedValue when calling addSymbol to register the temp.

```
error: loc("cuda-data-transfer.cuf":67:22): 'hlfir.declare' op of array entity
with a raw address base must have a shape operand that is a shape or shapeshift
```

Thanks @jeanPerier for the advice!

FYI @ImanHosseini

Added: 
    

Modified: 
    flang/lib/Lower/Bridge.cpp
    flang/test/Lower/CUDA/cuda-data-transfer.cuf

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index ecad5eb665e01a..f66607dfa22f1b 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -3794,7 +3794,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
           auto needCleanup = fir::getIntIfConstant(cleanup);
           if (needCleanup && *needCleanup)
             temps.push_back(temp);
-          addSymbol(sym, temp, /*forced=*/true);
+          addSymbol(sym,
+                    hlfir::translateToExtendedValue(loc, builder, temp).first,
+                    /*forced=*/true);
           builder.create<fir::CUDADataTransferOp>(loc, addr, temp,
                                                   transferKindAttr);
           ++nbDeviceResidentObject;

diff  --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
index 025d8147e5392d..70483685d20019 100644
--- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
@@ -98,7 +98,7 @@ end
 
 ! CHECK: %[[TEMP:.*]] = fir.allocmem !fir.array<10xi32> {bindc_name = ".tmp", uniq_name = ""}
 ! CHECK: %[[DECL_TEMP:.*]]:2 = hlfir.declare %[[TEMP]](%{{.*}}) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<10xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<10xi32>>, !fir.heap<!fir.array<10xi32>>)
-! CHECK: %[[ADEV_TEMP:.*]]:2 = hlfir.declare %21#0 {cuda_attr = #fir.cuda<device>, uniq_name = "_QFsub2Eadev"} : (!fir.heap<!fir.array<10xi32>>) -> (!fir.heap<!fir.array<10xi32>>, !fir.heap<!fir.array<10xi32>>)
+! CHECK: %[[ADEV_TEMP:.*]]:2 = hlfir.declare %[[DECL_TEMP]]#1(%{{.*}}) {cuda_attr = #fir.cuda<device>, uniq_name = "_QFsub2Eadev"} : (!fir.heap<!fir.array<10xi32>>, !fir.shape<1>) -> (!fir.heap<!fir.array<10xi32>>, !fir.heap<!fir.array<10xi32>>)
 ! CHECK: fir.cuda_data_transfer %[[ADEV]]#1 to %[[DECL_TEMP]]#0 {transfer_kind = #fir.cuda_transfer<device_host>} : !fir.ref<!fir.array<10xi32>>, !fir.heap<!fir.array<10xi32>>
 ! CHECK: %[[ELEMENTAL:.*]] = hlfir.elemental %{{.*}} unordered : (!fir.shape<1>) -> !hlfir.expr<10xi32>
 ! CHECK: hlfir.assign %[[ELEMENTAL]] to %[[BHOST]]#0 : !hlfir.expr<10xi32>, !fir.ref<!fir.array<10xi32>>


        


More information about the flang-commits mailing list