Parse ML function arguments, return statement operands, and for statement loop header.
Loop bounds and presumed to be constants for now and are stored in ForStmt as affine constant expressions. ML function arguments, return statement operands and loop variable name are dropped for now.
PiperOrigin-RevId: 205256208
diff --git a/test/IR/parser-errors.mlir b/test/IR/parser-errors.mlir
index 4f67c8e..49fd2da 100644
--- a/test/IR/parser-errors.mlir
+++ b/test/IR/parser-errors.mlir
@@ -130,12 +130,24 @@
// -----
+mlfunc @malformed_for() {
+ for %i = 1 too 10 { // expected-error {{expected 'to' between bounds}}
+ }
+}
+
+// -----
+
mlfunc @incomplete_for() {
- for
+ for %i = 1 to 10 step 2
} // expected-error {{expected '{' before statement list}}
// -----
+mlfunc @nonconstant_step(%1 : i32) {
+ for %2 = 1 to 5 step %1 { // expected-error {{expected non-negative integer for now}}
+
+// -----
+
mlfunc @non_statement() {
asd // expected-error {{expected operation name in quotes}}
}
@@ -160,7 +172,6 @@
return
}
-
// -----
cfgfunc @redef() {
@@ -168,4 +179,16 @@
%x = "dim"(){index: 0} : ()->i32
%x = "dim"(){index: 0} : ()->i32 // expected-error {{redefinition of SSA value %x}}
return
-}
\ No newline at end of file
+}
+
+mlfunc @missing_rbrace() {
+ return %a
+mlfunc @d {return} // expected-error {{expected ',' or '}'}}
+
+// -----
+
+mlfunc @malformed_type(%a : intt) { // expected-error {{expected type}}
+}
+
+// -----
+
diff --git a/test/IR/parser.mlir b/test/IR/parser.mlir
index 3a7986c..9b384b4 100644
--- a/test/IR/parser.mlir
+++ b/test/IR/parser.mlir
@@ -96,22 +96,32 @@
return // CHECK: return
} // CHECK: }
+// CHECK-LABEL: mlfunc @mlfunc_with_args(f16) {
+mlfunc @mlfunc_with_args(%a : f16) {
+ return %a // CHECK: return
+}
+
// CHECK-LABEL: cfgfunc @cfgfunc_with_ops() {
cfgfunc @cfgfunc_with_ops() {
bb0:
%t = "getTensor"() : () -> tensor<4x4x?xf32>
+
// CHECK: dim xxx, 2 : sometype
%a = "dim"(%t){index: 2} : (tensor<4x4x?xf32>) -> affineint
// CHECK: addf xx, yy : sometype
"addf"() : () -> ()
+
+ // CHECK: return
return
}
// CHECK-LABEL: mlfunc @loops() {
mlfunc @loops() {
- for { // CHECK: for {
- for { // CHECK: for {
+ // CHECK: for x = 1 to 100 step 2 {
+ for %i = 1 to 100 step 2 {
+ // CHECK: for x = 1 to 200 {
+ for %j = 1 to 200 {
} // CHECK: }
} // CHECK: }
return // CHECK: return
@@ -119,14 +129,14 @@
// CHECK-LABEL: mlfunc @ifstmt() {
mlfunc @ifstmt() {
- for { // CHECK for {
- if () { // CHECK if () {
- } else if () { // CHECK } else if () {
- } else { // CHECK } else {
- } // CHECK }
- } // CHECK }
- return // CHECK return
-} // CHECK }
+ for %i = 1 to 10 { // CHECK for x = 1 to 10 {
+ if () { // CHECK if () {
+ } else if () { // CHECK } else if () {
+ } else { // CHECK } else {
+ } // CHECK }
+ } // CHECK }
+ return // CHECK return
+} // CHECK }
// CHECK-LABEL: cfgfunc @attributes() {
cfgfunc @attributes() {