Skip to content

Commit 801a30a

Browse files
[CodeGen][MIR] Support parsing of scalable vectors in MIR (#70893)
This patch builds on the support for vectors by adding ability to parse scalable vectors in MIR and updates error messages to reflect that ability.
1 parent 65dc96c commit 801a30a

19 files changed

+317
-9
lines changed

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,24 +1946,41 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
19461946

19471947
// Now we're looking for a vector.
19481948
if (Token.isNot(MIToken::less))
1949-
return error(Loc,
1950-
"expected sN, pA, <M x sN>, or <M x pA> for GlobalISel type");
1949+
return error(Loc, "expected sN, pA, <M x sN>, <M x pA>, <vscale x M x sN>, "
1950+
"or <vscale x M x pA> for GlobalISel type");
19511951
lex();
19521952

1953-
if (Token.isNot(MIToken::IntegerLiteral))
1953+
bool HasVScale =
1954+
Token.is(MIToken::Identifier) && Token.stringValue() == "vscale";
1955+
if (HasVScale) {
1956+
lex();
1957+
if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
1958+
return error("expected <vscale x M x sN> or <vscale x M x pA>");
1959+
lex();
1960+
}
1961+
1962+
auto GetError = [this, &HasVScale, Loc]() {
1963+
if (HasVScale)
1964+
return error(
1965+
Loc, "expected <vscale x M x sN> or <vscale M x pA> for vector type");
19541966
return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1967+
};
1968+
1969+
if (Token.isNot(MIToken::IntegerLiteral))
1970+
return GetError();
19551971
uint64_t NumElements = Token.integerValue().getZExtValue();
19561972
if (!verifyVectorElementCount(NumElements))
19571973
return error("invalid number of vector elements");
19581974

19591975
lex();
19601976

19611977
if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
1962-
return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1978+
return GetError();
19631979
lex();
19641980

19651981
if (Token.range().front() != 's' && Token.range().front() != 'p')
1966-
return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1982+
return GetError();
1983+
19671984
StringRef SizeStr = Token.range().drop_front();
19681985
if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
19691986
return error("expected integers after 's'/'p' type character");
@@ -1981,14 +1998,15 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
19811998

19821999
Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
19832000
} else
1984-
return error(Loc, "expected <M x sN> or <M x pA> for vector type");
2001+
return GetError();
19852002
lex();
19862003

19872004
if (Token.isNot(MIToken::greater))
1988-
return error(Loc, "expected <M x sN> or <M x pA> for vector type");
2005+
return GetError();
2006+
19892007
lex();
19902008

1991-
Ty = LLT::fixed_vector(NumElements, Ty);
2009+
Ty = LLT::vector(ElementCount::get(NumElements, HasVScale), Ty);
19922010
return false;
19932011
}
19942012

llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid1.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ name: test_low_level_type_does_not_start_with_s_p_lt
55
body: |
66
bb.0:
77
liveins: $x0
8-
; CHECK: [[@LINE+1]]:10: expected sN, pA, <M x sN>, or <M x pA> for GlobalISel type
8+
; CHECK: [[@LINE+1]]:10: expected sN, pA, <M x sN>, <M x pA>, <vscale x M x sN>, or <vscale x M x pA> for GlobalISel type
99
%0:_(i64) = COPY $x0
1010
...
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscale0
4+
body: |
5+
bb.0:
6+
%0:_(<vscale) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale x M x pA>
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscale1
4+
body: |
5+
bb.0:
6+
%0:_(<vscale notanx) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale x M x pA>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMxp
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x p) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected integers after 's'/'p' type character
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMxs32
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x s32) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMxp0
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x p0) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMxs32X
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x s32 X) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMxp0
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x p0 X) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscale0
5+
body: |
6+
bb.0:
7+
%0:_(notatype) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected sN, pA, <M x sN>, <M x pA>, <vscale x M x sN>, or <vscale x M x pA> for GlobalISel type
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscalex0
4+
body: |
5+
bb.0:
6+
%0:_(<vscale x) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscalex0
4+
body: |
5+
bb.0:
6+
%0:_(<vscale x) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscalex1
4+
body: |
5+
bb.0:
6+
%0:_(<vscale x notanint) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscalexM
4+
body: |
5+
bb.0:
6+
%0:_(<vscale x 4) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMx0
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
11+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscalexMx1
4+
body: |
5+
bb.0:
6+
%0:_(<vscale x 4 x notansorp) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected <vscale x M x sN> or <vscale M x pA> for vector type
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: err_after_vscalexMxs
5+
body: |
6+
bb.0:
7+
%0:_(<vscale x 4 x s) = IMPLICIT_DEF
8+
...
9+
10+
# CHECK: expected integers after 's'/'p' type character
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: not llc -run-pass none -o - %s 2>&1 | FileCheck %s
2+
---
3+
name: err_after_vscalexMxpX
4+
body: |
5+
bb.0:
6+
%0:_(<vscale x 4 x pX) = IMPLICIT_DEF
7+
...
8+
9+
# CHECK: expected integers after 's'/'p' type character
10+
11+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# RUN: llc -run-pass=none -o - %s | FileCheck %s
2+
3+
---
4+
name: test_nxv1s8
5+
body: |
6+
bb.0:
7+
; CHECK-LABEL: name: test_nxv1s8
8+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s8>) = IMPLICIT_DEF
9+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s8>) = COPY [[DEF]](<vscale x 1 x s8>)
10+
%0:_(<vscale x 1 x s8>) = IMPLICIT_DEF
11+
%1:_(<vscale x 1 x s8>) = COPY %0
12+
...
13+
14+
---
15+
name: test_nxv1s16
16+
body: |
17+
bb.0:
18+
; CHECK-LABEL: name: test_nxv1s16
19+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s16>) = IMPLICIT_DEF
20+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s16>) = COPY [[DEF]](<vscale x 1 x s16>)
21+
%0:_(<vscale x 1 x s16>) = IMPLICIT_DEF
22+
%1:_(<vscale x 1 x s16>) = COPY %0
23+
...
24+
25+
---
26+
name: test_nxv1s32
27+
body: |
28+
bb.0:
29+
; CHECK-LABEL: name: test_nxv1s32
30+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s32>) = IMPLICIT_DEF
31+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s32>) = COPY [[DEF]](<vscale x 1 x s32>)
32+
%0:_(<vscale x 1 x s32>) = IMPLICIT_DEF
33+
%1:_(<vscale x 1 x s32>) = COPY %0
34+
...
35+
36+
---
37+
name: test_nxv1s64
38+
body: |
39+
bb.0:
40+
; CHECK-LABEL: name: test_nxv1s64
41+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s64>) = IMPLICIT_DEF
42+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s64>) = COPY [[DEF]](<vscale x 1 x s64>)
43+
%0:_(<vscale x 1 x s64>) = IMPLICIT_DEF
44+
%1:_(<vscale x 1 x s64>) = COPY %0
45+
...
46+
47+
---
48+
name: test_nxv4s8
49+
body: |
50+
bb.0:
51+
; CHECK-LABEL: name: test_nxv4s8
52+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s8>) = IMPLICIT_DEF
53+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s8>) = COPY [[DEF]](<vscale x 4 x s8>)
54+
%0:_(<vscale x 4 x s8>) = IMPLICIT_DEF
55+
%1:_(<vscale x 4 x s8>) = COPY %0
56+
...
57+
58+
---
59+
name: test_nxv4s16
60+
body: |
61+
bb.0:
62+
; CHECK-LABEL: name: test_nxv4s16
63+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s16>) = IMPLICIT_DEF
64+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s16>) = COPY [[DEF]](<vscale x 4 x s16>)
65+
%0:_(<vscale x 4 x s16>) = IMPLICIT_DEF
66+
%1:_(<vscale x 4 x s16>) = COPY %0
67+
...
68+
69+
---
70+
name: test_nxv4s32
71+
body: |
72+
bb.0:
73+
; CHECK-LABEL: name: test_nxv4s32
74+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s32>) = IMPLICIT_DEF
75+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s32>) = COPY [[DEF]](<vscale x 4 x s32>)
76+
%0:_(<vscale x 4 x s32>) = IMPLICIT_DEF
77+
%1:_(<vscale x 4 x s32>) = COPY %0
78+
...
79+
80+
---
81+
name: test_nxv4s64
82+
body: |
83+
bb.0:
84+
; CHECK-LABEL: name: test_nxv4s64
85+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s64>) = IMPLICIT_DEF
86+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s64>) = COPY [[DEF]](<vscale x 4 x s64>)
87+
%0:_(<vscale x 4 x s64>) = IMPLICIT_DEF
88+
%1:_(<vscale x 4 x s64>) = COPY %0
89+
...
90+
91+
---
92+
name: test_nxv1p0
93+
body: |
94+
bb.0:
95+
; CHECK-LABEL: name: test_nxv1p0
96+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x p0>) = IMPLICIT_DEF
97+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x p0>) = COPY [[DEF]](<vscale x 1 x p0>)
98+
%0:_(<vscale x 1 x p0>) = IMPLICIT_DEF
99+
%1:_(<vscale x 1 x p0>) = COPY %0
100+
...
101+
102+
---
103+
name: test_nxv1sp1
104+
body: |
105+
bb.0:
106+
; CHECK-LABEL: name: test_nxv1sp1
107+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x p0>) = IMPLICIT_DEF
108+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x p0>) = COPY [[DEF]](<vscale x 1 x p0>)
109+
%0:_(<vscale x 1 x p0>) = IMPLICIT_DEF
110+
%1:_(<vscale x 1 x p0>) = COPY %0
111+
...
112+
113+
---
114+
name: test_nxv4p0
115+
body: |
116+
bb.0:
117+
; CHECK-LABEL: name: test_nxv4p0
118+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x p0>) = IMPLICIT_DEF
119+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x p0>) = COPY [[DEF]](<vscale x 4 x p0>)
120+
%0:_(<vscale x 4 x p0>) = IMPLICIT_DEF
121+
%1:_(<vscale x 4 x p0>) = COPY %0
122+
...
123+
124+
---
125+
name: test_nxv4p1
126+
body: |
127+
bb.0:
128+
; CHECK-LABEL: name: test_nxv4p1
129+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x p1>) = IMPLICIT_DEF
130+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x p1>) = COPY [[DEF]](<vscale x 4 x p1>)
131+
%0:_(<vscale x 4 x p1>) = IMPLICIT_DEF
132+
%1:_(<vscale x 4 x p1>) = COPY %0
133+
...

0 commit comments

Comments
 (0)