[flang-commits] [flang] fix parsing of cuda_kernel (PR #89613)

Iman Hosseini via flang-commits flang-commits at lists.llvm.org
Mon Apr 22 07:57:32 PDT 2024


https://github.com/ImanHosseini created https://github.com/llvm/llvm-project/pull/89613

None

>From 77d00892e40e7e19503eeb7051871f1b4254b5d8 Mon Sep 17 00:00:00 2001
From: Iman Hosseini <imanh at nvidia.com>
Date: Mon, 22 Apr 2024 07:56:23 -0700
Subject: [PATCH] fix parsing of cuda_kernel

---
 flang/lib/Optimizer/Dialect/FIROps.cpp               | 11 +++++++++--
 flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index cc08f29a98f022..83ee243d351c02 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -3904,10 +3904,11 @@ mlir::ParseResult parseCUFKernelValues(
     mlir::OpAsmParser &parser,
     llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &values,
     llvm::SmallVectorImpl<mlir::Type> &types) {
-  if (mlir::succeeded(parser.parseOptionalStar()))
+  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 +3916,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.getType<mlir::IntegerType>(32));
+    }
     if (parser.parseRParen())
       return mlir::failure();
   } else {
     if (parser.parseOperand(values.emplace_back()))
       return mlir::failure();
+    auto builder = parser.getBuilder();
+    types.emplace_back(builder.getType<mlir::IntegerType>(32));
     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