Allow 'constant' op to work with affineint, add some accessors, rearrange
testsuite a bit.
PiperOrigin-RevId: 205852871
diff --git a/include/mlir/IR/Types.h b/include/mlir/IR/Types.h
index 654b558..c7b051b 100644
--- a/include/mlir/IR/Types.h
+++ b/include/mlir/IR/Types.h
@@ -64,9 +64,13 @@
/// Return the LLVMContext in which this type was uniqued.
MLIRContext *getContext() const { return context; }
- /// Print the current type.
- void print(raw_ostream &os) const;
- void dump() const;
+ // Convenience predicates. This is only for primitive types, derived types
+ // should use isa/dyn_cast.
+ bool isAffineInt() const { return getKind() == Kind::AffineInt; }
+ bool isBF16() const { return getKind() == Kind::BF16; }
+ bool isF16() const { return getKind() == Kind::F16; }
+ bool isF32() const { return getKind() == Kind::F32; }
+ bool isF64() const { return getKind() == Kind::F64; }
// Convenience factories.
static IntegerType *getInteger(unsigned width, MLIRContext *ctx);
@@ -76,6 +80,10 @@
static PrimitiveType *getF32(MLIRContext *ctx);
static PrimitiveType *getF64(MLIRContext *ctx);
+ /// Print the current type.
+ void print(raw_ostream &os) const;
+ void dump() const;
+
protected:
explicit Type(Kind kind, MLIRContext *context)
: context(context), kind(kind), subclassData(0) {
diff --git a/lib/IR/StandardOps.cpp b/lib/IR/StandardOps.cpp
index cb03db7..1307b2a 100644
--- a/lib/IR/StandardOps.cpp
+++ b/lib/IR/StandardOps.cpp
@@ -43,7 +43,7 @@
return "requires a 'value' attribute";
auto *type = this->getType();
- if (isa<IntegerType>(type)) {
+ if (isa<IntegerType>(type) || type->isAffineInt()) {
if (!isa<IntegerAttr>(value))
return "requires 'value' to be an integer for an integer result type";
return nullptr;
diff --git a/test/IR/parser-affine-map.mlir b/test/IR/affine-map.mlir
similarity index 100%
rename from test/IR/parser-affine-map.mlir
rename to test/IR/affine-map.mlir
diff --git a/test/IR/parser-core-ops.mlir b/test/IR/core-ops.mlir
similarity index 88%
rename from test/IR/parser-core-ops.mlir
rename to test/IR/core-ops.mlir
index 127e374..586e631 100644
--- a/test/IR/parser-core-ops.mlir
+++ b/test/IR/core-ops.mlir
@@ -28,7 +28,8 @@
// CHECK: dim xxx, 2 : sometype
%a = "dim"(%42){index: 2} : (tensor<4x4x?xf32>) -> affineint
- %f = "Const"(){value: 1} : () -> f32
+ %f = "FIXMEConst"(){value: 1} : () -> f32
+
// CHECK: addf xx, yy : sometype
"addf"(%f, %f) : (f32,f32) -> f32
@@ -40,9 +41,8 @@
// CHECK-LABEL: cfgfunc @affine_apply() {
cfgfunc @affine_apply() {
bb0:
- // TODO: Make constant work with affineint.
- %i = "const"() {value: 0} : () -> affineint
- %j = "const"() {value: 1} : () -> affineint
+ %i = "constant"() {value: 0} : () -> affineint
+ %j = "constant"() {value: 1} : () -> affineint
// CHECK: affine_apply map: (d0) -> ((d0 + 1))
%x = "affine_apply" (%i) { map: (d0) -> (d0 + 1) } :
diff --git a/test/IR/parser-affine-map-negative.mlir b/test/IR/invalid-affinemap.mlir
similarity index 100%
rename from test/IR/parser-affine-map-negative.mlir
rename to test/IR/invalid-affinemap.mlir
diff --git a/test/IR/invalid-ops.mlir b/test/IR/invalid-ops.mlir
index 1498ec8..42e92bb 100644
--- a/test/IR/invalid-ops.mlir
+++ b/test/IR/invalid-ops.mlir
@@ -37,8 +37,7 @@
cfgfunc @affine_apply_no_map() {
bb0:
- // TODO Make constant work with affineint.
- %i = "const"() {value: 0} : () -> affineint
+ %i = "constant"() {value: 0} : () -> affineint
%x = "affine_apply" (%i) { } : (affineint) -> (affineint) // expected-error {{'affine_apply' op requires an affine map.}}
return
}
diff --git a/test/IR/parser-errors.mlir b/test/IR/invalid.mlir
similarity index 100%
rename from test/IR/parser-errors.mlir
rename to test/IR/invalid.mlir
diff --git a/test/IR/parser.mlir b/test/IR/parser.mlir
index cd06fb5..d461e74 100644
--- a/test/IR/parser.mlir
+++ b/test/IR/parser.mlir
@@ -169,7 +169,7 @@
bb1: // CHECK: bb1:
// CHECK: %1 = "baz"(%2#1, %2#0, %0#1) : (f32, i11, i17) -> (i16, i8)
%1 = "baz"(%2#1, %2#0, %0#1) : (f32, i11, i17) -> (i16, i8)
-
+
// CHECK: return %1#0 : i16, %1#1 : i8
return %1#0, %1#1 : i16, i8