[flang-commits] [flang] [flang][cuda] Fix fir.cuda_kernel_launch assembly with no args (PR #85987)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Wed Mar 20 11:56:31 PDT 2024


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/85987

When the kernel launch has no arguments, the generated parser was expecting at least a type to be present. Make the last part of the assemble format optional.
Add a run line to round-trip the output through fir-opt so we make sure the IR can be parsed and printed correctly. 

>From 3affce1ae54a1ebad25bd8acdf8867f27a65b6d4 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 20 Mar 2024 11:52:57 -0700
Subject: [PATCH] [flang][cuda] Fix fir.cuda_kernel_launch syntax so it can be
 parsed when no args

---
 flang/include/flang/Optimizer/Dialect/FIROps.td | 2 +-
 flang/test/Lower/CUDA/cuda-kernel-calls.cuf     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 8a7e36e42457f5..b991ec76fdd956 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2466,7 +2466,7 @@ def fir_CUDAKernelLaunch : fir_Op<"cuda_kernel_launch", [CallOpInterface,
   let assemblyFormat = [{
     $callee `<` `<` `<` $grid_x `,` $grid_y `,` $grid_z `,`$block_x `,`
         $block_y `,` $block_z ( `,` $bytes^ ( `,` $stream^ )? )? `>` `>` `>`
-        `` `(` $args `)` `:` `(` type($args) `)` attr-dict
+        `` `(` $args `)` ( `:` `(` type($args)^ `)` )? attr-dict
   }];
 
   let extraClassDeclaration = [{
diff --git a/flang/test/Lower/CUDA/cuda-kernel-calls.cuf b/flang/test/Lower/CUDA/cuda-kernel-calls.cuf
index f4327b3261751f..7e28fbb2231a2d 100644
--- a/flang/test/Lower/CUDA/cuda-kernel-calls.cuf
+++ b/flang/test/Lower/CUDA/cuda-kernel-calls.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 procedure calls.
 



More information about the flang-commits mailing list