[Mlir-commits] [mlir] [mlir][IR] Add `ValueSemantics` trait to integer, float, ... types (PR #135183)

Matthias Springer llvmlistbot at llvm.org
Thu Apr 10 07:06:41 PDT 2025


https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/135183

None

>From f0279157c733ac96bdd894ebc69a31831692ce48 Mon Sep 17 00:00:00 2001
From: Matthias Springer <mspringer at nvidia.com>
Date: Thu, 10 Apr 2025 16:05:57 +0200
Subject: [PATCH] [mlir][IR] Add `ValueSemantics` trait to integer, float, ...
 types

---
 mlir/include/mlir/IR/BuiltinTypes.td | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td
index 771de01fc8d5d..56f026b414898 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.td
+++ b/mlir/include/mlir/IR/BuiltinTypes.td
@@ -36,6 +36,19 @@ class Builtin_Type<string name, string typeMnemonic, list<Trait> traits = [],
 //===----------------------------------------------------------------------===//
 
 /// Type trait indicating that the type has value semantics.
+///
+/// Reading (from) an SSA value with a value-semantics type always gives the
+/// same value.
+///
+/// Examples:
+/// * An integer SSA value semantically always carries the same integer value.
+/// * Reading (extracting) from a tensor always yields a semantically
+///   equivalent SSA value. (But the extracted value itself does not
+///   necessarily have value semantics.)
+///
+/// Counter examples:
+/// * Loading from a memref may yield different values, depending on the state
+///   of the memory.
 def ValueSemantics : NativeTypeTrait<"ValueSemantics"> {
   let cppNamespace = "::mlir";
 }
@@ -44,7 +57,7 @@ def ValueSemantics : NativeTypeTrait<"ValueSemantics"> {
 // ComplexType
 //===----------------------------------------------------------------------===//
 
-def Builtin_Complex : Builtin_Type<"Complex", "complex"> {
+def Builtin_Complex : Builtin_Type<"Complex", "complex", [ValueSemantics]> {
   let summary = "Complex number with a parameterized element type";
   let description = [{
     Syntax:
@@ -84,7 +97,8 @@ class Builtin_FloatType<string name, string mnemonic,
     : Builtin_Type<name, mnemonic, /*traits=*/[
         DeclareTypeInterfaceMethods<
             FloatTypeInterface,
-            ["getFloatSemantics"] # declaredInterfaceMethods>]> {
+            ["getFloatSemantics"] # declaredInterfaceMethods>,
+        ValueSemantics]> {
 }
 
 // Float types that are cached in MLIRContext.
@@ -466,7 +480,7 @@ def Builtin_Function : Builtin_Type<"Function", "function"> {
 //===----------------------------------------------------------------------===//
 
 def Builtin_Index : Builtin_Type<"Index", "index",
-    [VectorElementTypeInterface]> {
+    [VectorElementTypeInterface, ValueSemantics]> {
   let summary = "Integer-like type with unknown platform-dependent bit width";
   let description = [{
     Syntax:
@@ -497,7 +511,7 @@ def Builtin_Index : Builtin_Type<"Index", "index",
 //===----------------------------------------------------------------------===//
 
 def Builtin_Integer : Builtin_Type<"Integer", "integer",
-    [VectorElementTypeInterface]> {
+    [VectorElementTypeInterface, ValueSemantics]> {
   let summary = "Integer type with arbitrary precision up to a fixed limit";
   let description = [{
     Syntax:
@@ -1075,7 +1089,7 @@ def Builtin_RankedTensor : Builtin_Type<"RankedTensor", "tensor", [
 // TupleType
 //===----------------------------------------------------------------------===//
 
-def Builtin_Tuple : Builtin_Type<"Tuple", "tuple"> {
+def Builtin_Tuple : Builtin_Type<"Tuple", "tuple", [ValueSemantics]> {
   let summary = "Fixed-sized collection of other types";
   let description = [{
     Syntax:



More information about the Mlir-commits mailing list