[clang] 5491576 - [CIR] Introduce IntTypeInterface to allow uniform integer types handling (#146660)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 2 07:29:06 PDT 2025


Author: Henrich Lauko
Date: 2025-07-02T16:29:03+02:00
New Revision: 5491576a16230a770a507115af2c90f600a5d447

URL: https://github.com/llvm/llvm-project/commit/5491576a16230a770a507115af2c90f600a5d447
DIFF: https://github.com/llvm/llvm-project/commit/5491576a16230a770a507115af2c90f600a5d447.diff

LOG: [CIR] Introduce IntTypeInterface to allow uniform integer types handling (#146660)

This will in future allow to use builtin integer types within cir operations

This mirrors incubat changes from https://github.com/llvm/clangir/pull/1724

Added: 
    

Modified: 
    clang/include/clang/CIR/Dialect/IR/CIRTypes.td
    clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index bfe42562abad7..898c26d22f6d1 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -35,7 +35,8 @@ class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
 
 def CIR_IntType : CIR_Type<"Int", "int", [
     DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
-    DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
+    DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
+    DeclareTypeInterfaceMethods<CIR_IntTypeInterface>,
 ]> {
   let summary = "Integer type with arbitrary precision up to a fixed limit";
   let description = [{

diff  --git a/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td b/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
index 1b1acf749e773..cf6c8571ddcd9 100644
--- a/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
+++ b/clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
@@ -15,6 +15,48 @@
 
 include "mlir/IR/OpBase.td"
 
+def CIR_IntTypeInterface : TypeInterface<"IntTypeInterface"> {
+  let description = [{
+    Contains helper functions to query properties about an integer type.
+  }];
+  let cppNamespace = "::cir";
+  let methods = [
+    InterfaceMethod<[{
+        Returns true if this is a signed integer type.
+      }],
+      /*retTy=*/"bool",
+      /*methodName=*/"isSigned",
+      /*args=*/(ins),
+      /*methodBody=*/"",
+      /*defaultImplementation=*/[{
+        return $_type.isSigned();
+      }]
+    >,
+    InterfaceMethod<[{
+        Returns true if this is an unsigned integer type.
+      }],
+      /*retTy=*/"bool",
+      /*methodName=*/"isUnsigned",
+      /*args=*/(ins),
+      /*methodBody=*/"",
+      /*defaultImplementation=*/[{
+        return $_type.isUnsigned();
+      }]
+    >,
+    InterfaceMethod<[{
+        Returns the bit width of this integer type.
+      }],
+      /*retTy=*/"unsigned",
+      /*methodName=*/"getWidth",
+      /*args=*/(ins),
+      /*methodBody=*/"",
+      /*defaultImplementation=*/[{
+        return $_type.getWidth();
+      }]
+    >
+  ];
+}
+
 def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
   let description = [{
     Contains helper functions to query properties about a floating-point type.


        


More information about the cfe-commits mailing list