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

Iman Hosseini via flang-commits flang-commits at lists.llvm.org
Mon Apr 22 09:29:09 PDT 2024


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

>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 1/4] 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.
 

>From 31cbddb68ba48d53e03a358de11e742503282b45 Mon Sep 17 00:00:00 2001
From: Iman Hosseini <hosseini.iman at yahoo.com>
Date: Mon, 22 Apr 2024 17:05:53 +0100
Subject: [PATCH 2/4] Update flang/lib/Optimizer/Dialect/FIROps.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval at gmail.com>
---
 flang/lib/Optimizer/Dialect/FIROps.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 83ee243d351c02..ba8423eb8707f2 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -3918,7 +3918,7 @@ mlir::ParseResult parseCUFKernelValues(
       return mlir::failure();
     auto builder = parser.getBuilder();
     for (size_t i = 0; i < values.size(); i++) {
-      types.emplace_back(builder.getType<mlir::IntegerType>(32));
+      types.emplace_back(builder.getI32Type());
     }
     if (parser.parseRParen())
       return mlir::failure();

>From 9dc5be327ef4d30b9e505b3334aa1a7d0161d9e6 Mon Sep 17 00:00:00 2001
From: Iman Hosseini <hosseini.iman at yahoo.com>
Date: Mon, 22 Apr 2024 17:06:15 +0100
Subject: [PATCH 3/4] Update flang/lib/Optimizer/Dialect/FIROps.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval at gmail.com>
---
 flang/lib/Optimizer/Dialect/FIROps.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index ba8423eb8707f2..4388ad0896b7ac 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -3926,7 +3926,7 @@ mlir::ParseResult parseCUFKernelValues(
     if (parser.parseOperand(values.emplace_back()))
       return mlir::failure();
     auto builder = parser.getBuilder();
-    types.emplace_back(builder.getType<mlir::IntegerType>(32));
+    types.emplace_back(builder.getI32Type());
     return mlir::success();
   }
   return mlir::success();

>From 749d4c2f0c8d0a30b7d6fff058fc45af1479811f Mon Sep 17 00:00:00 2001
From: Iman Hosseini <hosseini.iman at yahoo.com>
Date: Mon, 22 Apr 2024 17:29:00 +0100
Subject: [PATCH 4/4] Update FIROps.cpp

---
 flang/lib/Optimizer/Dialect/FIROps.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 4388ad0896b7ac..24af94f9b90a1d 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -3904,9 +3904,8 @@ 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 (mlir::succeeded(parser.parseOptionalLParen())) {
     if (mlir::failed(parser.parseCommaSeparatedList(



More information about the flang-commits mailing list