[Mlir-commits] [mlir] [MLIR][NVVM] Add `NVVM_UnaryOp` Base Class (NFC) (PR #194378)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Apr 27 06:58:45 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: Guray Ozen (grypp)
<details>
<summary>Changes</summary>
Add `NVVM_UnaryOp` tablegen class to unify implementation
---
Full diff: https://github.com/llvm/llvm-project/pull/194378.diff
1 Files Affected:
- (modified) mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td (+14-18)
``````````diff
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)";
}
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/194378
More information about the Mlir-commits
mailing list