[flang-commits] [flang] 7c20576 - [flang][cuda] fix parsing of cuda_kernel (#89613)

via flang-commits flang-commits at lists.llvm.org
Mon Apr 22 10:17:03 PDT 2024


Author: Iman Hosseini
Date: 2024-04-22T10:16:59-07:00
New Revision: 7c20576cc37ab6b078782caf7575dab4ef87b37c

URL: https://github.com/llvm/llvm-project/commit/7c20576cc37ab6b078782caf7575dab4ef87b37c
DIFF: https://github.com/llvm/llvm-project/commit/7c20576cc37ab6b078782caf7575dab4ef87b37c.diff

LOG: [flang][cuda] fix parsing of cuda_kernel (#89613)

Fix parsing of cuda_kernel: it missed a mlir::succeeded check and it was
not setting up the `types` and causing mismatch between values and types
of the grid/block (CUFKernelValues). @clementval

---------

Co-authored-by: Iman Hosseini <imanh at nvidia.com>
Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval at gmail.com>

Added: 
    

Modified: 
    flang/lib/Optimizer/Dialect/FIROps.cpp
    flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index cc08f29a98f022..24af94f9b90a1d 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -3907,7 +3907,7 @@ mlir::ParseResult parseCUFKernelValues(
   if (mlir::succeeded(parser.parseOptionalStar()))
     return mlir::success();
 
-  if (parser.parseOptionalLParen()) {
+  if (mlir::succeeded(parser.parseOptionalLParen())) {
     if (mlir::failed(parser.parseCommaSeparatedList(
             mlir::AsmParser::Delimiter::None, [&]() {
               if (parser.parseOperand(values.emplace_back()))
@@ -3915,11 +3915,17 @@ mlir::ParseResult parseCUFKernelValues(
               return mlir::success();
             })))
       return mlir::failure();
+    auto builder = parser.getBuilder();
+    for (size_t i = 0; i < values.size(); i++) {
+      types.emplace_back(builder.getI32Type());
+    }
     if (parser.parseRParen())
       return mlir::failure();
   } else {
     if (parser.parseOperand(values.emplace_back()))
       return mlir::failure();
+    auto builder = parser.getBuilder();
+    types.emplace_back(builder.getI32Type());
     return mlir::success();
   }
   return mlir::success();

diff  --git a/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf b/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
index 6179e609db383c..9b728cd19eb552 100644
--- a/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
+++ b/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
@@ -1,4 +1,5 @@
 ! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+! RUN: bbc -emit-hlfir -fcuda %s -o - | fir-opt | FileCheck %s
 
 ! Test lowering of CUDA kernel loop directive.
 


        


More information about the flang-commits mailing list