[PATCH] D76136: [MLIR] Add support for explicitly signed / unsigned integer constants

Andi Drebes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 13 08:33:59 PDT 2020


andidr created this revision.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.
andidr added reviewers: antiagainst, rriddle, ftynse, nicolasvasilache.

Currently, only signless integers are allowed as constants. This patch additionally allows for explicitly signed and explicitly unsigned integer constants.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76136

Files:
  mlir/lib/Dialect/StandardOps/IR/Ops.cpp
  mlir/test/IR/parser.mlir


Index: mlir/test/IR/parser.mlir
===================================================================
--- mlir/test/IR/parser.mlir
+++ mlir/test/IR/parser.mlir
@@ -492,12 +492,17 @@
 
 // Test pretty printing of constant names.
 // CHECK-LABEL: func @constants
-func @constants() -> (i32, i23, i23, i1, i1) {
+func @constants() -> (i32, i23, ui32, ui23, i23, i1, i1) {
   // CHECK: %{{.*}} = constant 42 : i32
   %x = constant 42 : i32
   // CHECK: %{{.*}} = constant 17 : i23
   %y = constant 17 : i23
 
+  // CHECK: %{{.*}} = constant 42 : ui32
+  %ux = constant 42 : ui32
+  // CHECK: %{{.*}} = constant 17 : ui23
+  %uy = constant 17 : ui23
+
   // This is a redundant definition of 17, the asmprinter gives it a unique name
   // CHECK: %{{.*}} = constant 17 : i23
   %z = constant 17 : i23
@@ -513,7 +518,7 @@
   %h = constant 0xf32 : i32
 
   // CHECK: return %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}
-  return %x, %y, %z, %t, %f : i32, i23, i23, i1, i1
+  return %x, %y, %ux, %uy, %z, %t, %f : i32, i23, ui32, ui23, i23, i1, i1
 }
 
 // CHECK-LABEL: func @typeattr
Index: mlir/lib/Dialect/StandardOps/IR/Ops.cpp
===================================================================
--- mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -878,7 +878,7 @@
     // Otherwise, build a complex name with the value and type.
     SmallString<32> specialNameBuffer;
     llvm::raw_svector_ostream specialName(specialNameBuffer);
-    specialName << 'c' << intCst.getInt();
+    specialName << 'c' << intCst.getValue();
     if (intTy)
       specialName << '_' << type;
     setNameFn(getResult(), specialName.str());
@@ -917,7 +917,7 @@
 /// ConstantIntOp only matches values whose result type is an IntegerType.
 bool ConstantIntOp::classof(Operation *op) {
   return ConstantOp::classof(op) &&
-         op->getResult(0).getType().isSignlessInteger();
+    (op->getResult(0).getType().isa<IntegerType>());
 }
 
 void ConstantIntOp::build(Builder *builder, OperationState &result,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76136.250214.patch
Type: text/x-patch
Size: 2019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200313/10e505ff/attachment.bin>


More information about the llvm-commits mailing list