[Mlir-commits] [mlir] [MLIR][NVVM] Add `NVVM_UnaryOp` Base Class (NFC) (PR #194378)

Guray Ozen llvmlistbot at llvm.org
Mon Apr 27 06:55:09 PDT 2026


https://github.com/grypp created https://github.com/llvm/llvm-project/pull/194378

Add `NVVM_UnaryOp` tablegen class to unify implementation

>From b533c1b7bd7bb3df27e049cb9faa5181166dbb2b Mon Sep 17 00:00:00 2001
From: Guray Ozen <gozen at nvidia.com>
Date: Mon, 27 Apr 2026 15:54:28 +0200
Subject: [PATCH] [MLIR][NVVM] Add `NVVM_UnaryOp` Base Class (NFC)

Add `NVVM_UnaryOp` tablegen class to unify implementation
---
 mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td | 32 +++++++++------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index 7f1f9774abf52..75128836b3eb7 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -302,6 +302,17 @@ class NVVM_SingleResultIntrinsicOp<string mnemonic, list<Trait> traits = [], str
   }];
 }
 
+// Base class for unary NVVM operations.
+class NVVM_UnaryOp<string mnemonic, list<Trait> traits = []> :
+    NVVM_SingleResultIntrinsicOp<mnemonic,
+        traits # [Pure, SameOperandsAndResultType]> {
+  let arguments = (ins F32:$src,
+                       DefaultValuedAttr<BoolAttr, "false">:$ftz);
+  let results = (outs F32:$res);
+  let assemblyFormat = "$src attr-dict `:` type($src)";
+}
+
+
 //===----------------------------------------------------------------------===//
 // NVVM special register op definitions
 //===----------------------------------------------------------------------===//
@@ -531,45 +542,30 @@ def NVVM_SinOp : NVVM_SingleResultIntrinsicOp<"sin",
   let summary = "Sine (fast approximation)";
   let description = [{
     Computes a fast approximation of the sine of the input value (in radians).
-    The `ftz` attribute, when set, flushes subnormal inputs and results to 
+    The `ftz` attribute, when set, flushes subnormal inputs and results to
     sign-preserving zero.
 
     For more information, see PTX ISA:
     [sin](https://docs.nvidia.com/cuda/parallel-thread-execution/#floating-point-instructions-sin)
   }];
-  let arguments = (ins F32:$src,
-                       DefaultValuedAttr<BoolAttr, "false">:$ftz);
-  let results = (outs F32:$res);
-  let assemblyFormat = "$src attr-dict `:` type($src)";
 }
 
-
-def NVVM_CosOp : NVVM_SingleResultIntrinsicOp<"cos",
-    [Pure, SameOperandsAndResultType]> {
+def NVVM_CosOp : NVVM_UnaryOp<"cos"> {
   let summary = "Cosine (fast approximation)";
   let description = [{
     Computes a fast approximation of the cosine of the input value (in
     radians). The `ftz` attribute, when set, flushes subnormal inputs
     and results to sign-preserving zero.
   }];
-  let arguments = (ins F32:$src,
-                       DefaultValuedAttr<BoolAttr, "false">:$ftz);
-  let results = (outs F32:$res);
-  let assemblyFormat = "$src attr-dict `:` type($src)";
 }
 
-def NVVM_Ex2Op : NVVM_SingleResultIntrinsicOp<"ex2",
-    [Pure, SameOperandsAndResultType]> {
+def NVVM_Ex2Op : NVVM_UnaryOp<"ex2"> {
   let summary = "Base-2 exponential (fast approximation)";
   let description = [{
     Computes a fast approximation of 2 raised to the power of the input
     value. The `ftz` attribute, when set, flushes subnormal inputs and
     results to sign-preserving zero.
   }];
-  let arguments = (ins F32:$src,
-                       DefaultValuedAttr<BoolAttr, "false">:$ftz);
-  let results = (outs F32:$res);
-  let assemblyFormat = "$src attr-dict `:` type($src)";
 }
 
 //===----------------------------------------------------------------------===//



More information about the Mlir-commits mailing list