Skip to content

Commit a6cef03

Browse files
committed
[mlir] Remove the type keyword from type alias definitions
This was carry over from LLVM IR where the alias definition can be ambiguous, but MLIR type aliases have no such problems. Having the `type` keyword is superfluous and doesn't add anything. This commit drops it, which also nicely aligns with the syntax for attribute aliases (which doesn't have a keyword). Differential Revision: https://reviews.llvm.org/D125501
1 parent c8457eb commit a6cef03

36 files changed

+137
-150
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,7 @@ def fir_GenTypeDescOp : fir_OneResultOp<"gentypedesc", [NoSideEffect]> {
25762576
is `!fir.tdesc<T>`.
25772577

25782578
```mlir
2579-
!T = type !fir.type<T{...}>
2579+
!T = !fir.type<T{...}>
25802580
%t = fir.gentypedesc !T // returns value of !fir.tdesc<!T>
25812581
```
25822582
}];

flang/test/Fir/affine-promotion.fir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// RUN: fir-opt --split-input-file --promote-to-affine --affine-loop-invariant-code-motion --cse %s | FileCheck %s
44

5-
!arr_d1 = type !fir.ref<!fir.array<?xf32>>
5+
!arr_d1 = !fir.ref<!fir.array<?xf32>>
66
#arr_len = affine_map<()[j1,k1] -> (k1 - j1 + 1)>
77

88
func.func @loop_with_load_and_store(%a1: !arr_d1, %a2: !arr_d1, %a3: !arr_d1) {
@@ -75,7 +75,7 @@ func.func @loop_with_load_and_store(%a1: !arr_d1, %a2: !arr_d1, %a3: !arr_d1) {
7575

7676
// -----
7777

78-
!arr_d1 = type !fir.ref<!fir.array<?xf32>>
78+
!arr_d1 = !fir.ref<!fir.array<?xf32>>
7979
#arr_len = affine_map<()[j1,k1] -> (k1 - j1 + 1)>
8080

8181
func.func @loop_with_if(%a: !arr_d1, %v: f32) {

flang/test/Fir/array-value-copy-3.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// RUN: fir-opt --array-value-copy %s | FileCheck %s
77

88

9-
!t_with_alloc_comp = type !fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>
9+
!t_with_alloc_comp = !fir.type<t{i:!fir.box<!fir.heap<!fir.array<?xi32>>>}>
1010
func.func private @custom_assign(!fir.ref<!t_with_alloc_comp>, !fir.ref<!t_with_alloc_comp>)
1111
func.func @test_overlap_with_alloc_components(%arg0: !fir.ref<!fir.array<10x!t_with_alloc_comp>>) {
1212
%0 = fir.alloca !fir.box<!t_with_alloc_comp>

flang/test/Fir/ignore-missing-type-descriptor.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Missing derived type descriptor pointers are replaced by null pointers.
55
// RUN: tco --ignore-missing-type-desc -o - %s | FileCheck %s
66

7-
!some_freestyle_type = type !fir.type<some_not_mangled_type{j:i32}>
7+
!some_freestyle_type = !fir.type<some_not_mangled_type{j:i32}>
88

99
func.func private @bar(!fir.box<!some_freestyle_type>)
1010

flang/test/Fir/recursive-type.fir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
// RUN: fir-opt --fir-to-llvm-ir="target=i386-unknown-linux-gnu" %s | FileCheck %s
66
// RUN: fir-opt --fir-to-llvm-ir="target=powerpc64le-unknown-linux-gn" %s | FileCheck %s
77

8-
!t1 = type !fir.type<t1 {a1:!fir.ptr<!fir.type<t1>>}>
9-
!t2 = type !fir.type<t2 {b1:f32,b2:!fir.ptr<!fir.type<t2>>,b3:i32,b4:!fir.ptr<!fir.type<t2>>}>
10-
!t3 = type !fir.type<t3 {c1:!fir.ptr<!fir.type<t4>>}>
11-
!t4 = type !fir.type<t4 {d1:!fir.ptr<!fir.type<t3>>}>
8+
!t1 = !fir.type<t1 {a1:!fir.ptr<!fir.type<t1>>}>
9+
!t2 = !fir.type<t2 {b1:f32,b2:!fir.ptr<!fir.type<t2>>,b3:i32,b4:!fir.ptr<!fir.type<t2>>}>
10+
!t3 = !fir.type<t3 {c1:!fir.ptr<!fir.type<t4>>}>
11+
!t4 = !fir.type<t4 {d1:!fir.ptr<!fir.type<t3>>}>
1212

1313
// CHECK-LABEL: llvm.func @recursiveTypes
1414
// CHECK-SAME: %{{.*}}: !llvm.struct<"[[T1:.*]]", (ptr<struct<"[[T1]]">>)>

mlir/docs/LangRef.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ function-type ::= (type | type-list-parens) `->` (type | type-list-parens)
657657
### Type Aliases
658658

659659
```
660-
type-alias-def ::= '!' alias-name '=' 'type' type
660+
type-alias-def ::= '!' alias-name '=' type
661661
type-alias ::= '!' alias-name
662662
```
663663

@@ -669,7 +669,7 @@ names are reserved for [dialect types](#dialect-types).
669669
Example:
670670

671671
```mlir
672-
!avx_m128 = type vector<4 x f32>
672+
!avx_m128 = vector<4 x f32>
673673
674674
// Using the original type.
675675
"foo"(%x) : vector<4 x f32> -> ()

mlir/docs/TargetLLVMIR.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ func.func @foo(%arg0: memref<?xf32>) -> () {
367367
368368
// Gets converted to the following
369369
// (using type alias for brevity):
370-
!llvm.memref_1d = type !llvm.struct<(ptr<f32>, ptr<f32>, i64,
371-
array<1xi64>, array<1xi64>)>
370+
!llvm.memref_1d = !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<1xi64>, array<1xi64>)>
372371
373372
llvm.func @foo(%arg0: !llvm.ptr<f32>, // Allocated pointer.
374373
%arg1: !llvm.ptr<f32>, // Aligned pointer.
@@ -398,8 +397,7 @@ func.func @bar() {
398397
399398
// Gets converted to the following
400399
// (using type alias for brevity):
401-
!llvm.memref_1d = type !llvm.struct<(ptr<f32>, ptr<f32>, i64,
402-
array<1xi64>, array<1xi64>)>
400+
!llvm.memref_1d = !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<1xi64>, array<1xi64>)>
403401
404402
llvm.func @bar() {
405403
%0 = "get"() : () -> !llvm.memref_1d
@@ -619,8 +617,7 @@ func.func @qux(%arg0: memref<?x?xf32>)
619617
620618
// Gets converted into the following
621619
// (using type alias for brevity):
622-
!llvm.memref_2d = type !llvm.struct<(ptr<f32>, ptr<f32>, i64,
623-
array<2xi64>, array<2xi64>)>
620+
!llvm.memref_2d = !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2xi64>, array<2xi64>)>
624621
625622
// Function with unpacked arguments.
626623
llvm.func @qux(%arg0: !llvm.ptr<f32>, %arg1: !llvm.ptr<f32>,
@@ -665,10 +662,8 @@ func.func @foo(%arg0: memref<?x?xf32>) {
665662
666663
// Gets converted into the following
667664
// (using type alias for brevity):
668-
!llvm.memref_2d = type !llvm.struct<(ptr<f32>, ptr<f32>, i64,
669-
array<2xi64>, array<2xi64>)>
670-
!llvm.memref_2d_ptr = type !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64,
671-
array<2xi64>, array<2xi64>)>>
665+
!llvm.memref_2d = !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2xi64>, array<2xi64>)>
666+
!llvm.memref_2d_ptr = !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<2xi64>, array<2xi64>)>>
672667
673668
// Function with unpacked arguments.
674669
llvm.func @foo(%arg0: !llvm.ptr<f32>, %arg1: !llvm.ptr<f32>,
@@ -704,10 +699,8 @@ func.func @foo(%arg0: memref<?x?xf32>) -> memref<?x?xf32> {
704699
705700
// Gets converted into the following
706701
// (using type alias for brevity):
707-
!llvm.memref_2d = type !llvm.struct<(ptr<f32>, ptr<f32>, i64,
708-
array<2xi64>, array<2xi64>)>
709-
!llvm.memref_2d_ptr = type !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64,
710-
array<2xi64>, array<2xi64>)>>
702+
!llvm.memref_2d = !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2xi64>, array<2xi64>)>
703+
!llvm.memref_2d_ptr = !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<2xi64>, array<2xi64>)>>
711704
712705
// Function with unpacked arguments.
713706
llvm.func @foo(%arg0: !llvm.ptr<f32>, %arg1: !llvm.ptr<f32>, %arg2: i64,

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ void AliasState::printAliases(raw_ostream &os, NewLineCounter &newLine,
822822
}
823823
for (const auto &it : llvm::make_filter_range(typeToAlias, filterFn)) {
824824
it.second.print(os << '!');
825-
os << " = type " << it.first << newLine;
825+
os << " = " << it.first << newLine;
826826
}
827827
}
828828

mlir/lib/Parser/Parser.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ ParseResult TopLevelOperationParser::parseAttributeAliasDef() {
21052105

21062106
/// Parse a type alias declaration.
21072107
///
2108-
/// type-alias-def ::= '!' alias-name `=` 'type' type
2108+
/// type-alias-def ::= '!' alias-name `=` type
21092109
///
21102110
ParseResult TopLevelOperationParser::parseTypeAliasDef() {
21112111
assert(getToken().is(Token::exclamation_identifier));
@@ -2119,12 +2119,10 @@ ParseResult TopLevelOperationParser::parseTypeAliasDef() {
21192119
if (aliasName.contains('.'))
21202120
return emitError("type names with a '.' are reserved for "
21212121
"dialect-defined names");
2122-
21232122
consumeToken(Token::exclamation_identifier);
21242123

2125-
// Parse the '=' and 'type'.
2126-
if (parseToken(Token::equal, "expected '=' in type alias definition") ||
2127-
parseToken(Token::kw_type, "expected 'type' in type alias definition"))
2124+
// Parse the '='.
2125+
if (parseToken(Token::equal, "expected '=' in type alias definition"))
21282126
return failure();
21292127

21302128
// Parse the type.

mlir/test/Conversion/FuncToLLVM/func-memref.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func.func @check_scalar_func_call(%in : f32) {
101101

102102
// -----
103103

104-
!base_type = type memref<64xi32, 201>
104+
!base_type = memref<64xi32, 201>
105105

106106
// CHECK-LABEL: func @loop_carried
107107
// BAREPTR-LABEL: func @loop_carried

mlir/test/Dialect/LLVMIR/types.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ func.func @ptr_elem_interface(%arg0: !llvm.ptr<!test.smpla>) {
197197
// DialectAsmPrinter to have a mechanism for querying the presence and
198198
// usability of an alias outside of its `printType` method.
199199

200-
!baz = type i64
201-
!qux = type !llvm.struct<(!baz)>
200+
!baz = i64
201+
!qux = !llvm.struct<(!baz)>
202202

203-
!rec = type !llvm.struct<"a", (ptr<struct<"a">>)>
203+
!rec = !llvm.struct<"a", (ptr<struct<"a">>)>
204204

205205
// CHECK: aliases
206206
llvm.func @aliases() {

mlir/test/Dialect/Linalg/standard.mlir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ func.func @dot(%arg0: memref<?xf32, offset: ?, strides: [1]>,
3737
library_call = "external_outerproduct_matmul"
3838
}
3939

40-
!vector_type_A = type vector<4xf32>
41-
!vector_type_B = type vector<4xf32>
42-
!vector_type_C = type vector<4x4xf32>
40+
!vector_type_A = vector<4xf32>
41+
!vector_type_B = vector<4xf32>
42+
!vector_type_C = vector<4x4xf32>
4343

44-
!matrix_type_A = type memref<?x?x!vector_type_A>
45-
!matrix_type_B = type memref<?x?x!vector_type_B>
46-
!matrix_type_C = type memref<?x?x!vector_type_C>
44+
!matrix_type_A = memref<?x?x!vector_type_A>
45+
!matrix_type_B = memref<?x?x!vector_type_B>
46+
!matrix_type_C = memref<?x?x!vector_type_C>
4747

4848
func.func @matmul_vec_impl(%A: !matrix_type_A, %B: !matrix_type_B, %C: !matrix_type_C) {
4949
linalg.generic #matmul_trait

mlir/test/Dialect/Quant/parse-any-invalid.mlir

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,59 @@
33
// -----
44
// Unrecognized token: missing storage type maximum
55
// expected-error@+1 {{expected ':'}}
6-
!qalias = type !quant.any<i8<16>:f32>
6+
!qalias = !quant.any<i8<16>:f32>
77

88
// -----
99
// Unrecognized token: missing closing angle bracket
1010
// expected-error@+1 {{expected '>'}}
11-
!qalias = type !quant<"any<i8<-4:3:f32>">
11+
!qalias = !quant<"any<i8<-4:3:f32>">
1212

1313
// -----
1414
// Unrecognized token: missing type colon
1515
// expected-error@+1 {{expected '>'}}
16-
!qalias = type !quant.any<i8<-4:3>f32>
16+
!qalias = !quant.any<i8<-4:3>f32>
1717

1818
// -----
1919
// Unrecognized storage type: illegal prefix
2020
// expected-error@+1 {{illegal storage type prefix}}
21-
!qalias = type !quant.any<int8<-4:3>:f32>
21+
!qalias = !quant.any<int8<-4:3>:f32>
2222

2323
// -----
2424
// Unrecognized storage type: no width
2525
// expected-error@+1 {{illegal storage type prefix}}
26-
!qalias = type !quant.any<i<-4:3>:f32>
26+
!qalias = !quant.any<i<-4:3>:f32>
2727

2828
// -----
2929
// Unrecognized storage type: storage size > 32
3030
// expected-error@+1 {{illegal storage type size: 33}}
31-
!qalias = type !quant.any<i33:f32>
31+
!qalias = !quant.any<i33:f32>
3232

3333
// -----
3434
// Unrecognized storage type: storage size < 0
3535
// expected-error@+1 {{illegal storage type size: 1024}}
36-
!qalias = type !quant.any<i1024<-4:3>:f32>
36+
!qalias = !quant.any<i1024<-4:3>:f32>
3737

3838
// -----
3939
// Unrecognized storage type: storage size
4040
// expected-error@+1 {{invalid integer width}}
41-
!qalias = type !quant.any<i0123123123123123<-4:3>:f32>
41+
!qalias = !quant.any<i0123123123123123<-4:3>:f32>
4242

4343
// -----
4444
// Illegal storage min/max: max - min < 0
4545
// expected-error@+1 {{illegal storage min and storage max: (2:1)}}
46-
!qalias = type !quant.any<i8<2:1>:f32>
46+
!qalias = !quant.any<i8<2:1>:f32>
4747

4848
// -----
4949
// Illegal storage min/max: max - min == 0
5050
// expected-error@+1 {{illegal storage min and storage max: (1:1)}}
51-
!qalias = type !quant.any<i8<1:1>:f32>
51+
!qalias = !quant.any<i8<1:1>:f32>
5252

5353
// -----
5454
// Illegal storage min/max: max > defaultMax
5555
// expected-error@+1 {{illegal storage type maximum: 9}}
56-
!qalias = type !quant.any<i4<-1:9>:f32>
56+
!qalias = !quant.any<i4<-1:9>:f32>
5757

5858
// -----
5959
// Illegal storage min/max: min < defaultMin
6060
// expected-error@+1 {{illegal storage type minimum: -9}}
61-
!qalias = type !quant.any<i4<-9:1>:f32>
61+
!qalias = !quant.any<i4<-9:1>:f32>

mlir/test/Dialect/Quant/parse-any.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// -----
44
// CHECK-LABEL: parseFullySpecified
55
// CHECK: !quant.any<i8<-8:7>:f32>
6-
!qalias = type !quant.any<i8<-8:7>:f32>
6+
!qalias = !quant.any<i8<-8:7>:f32>
77
func.func @parseFullySpecified() -> !qalias {
88
%0 = "foo"() : () -> !qalias
99
return %0 : !qalias
@@ -12,7 +12,7 @@ func.func @parseFullySpecified() -> !qalias {
1212
// -----
1313
// CHECK-LABEL: parseNoExpressedType
1414
// CHECK: !quant.any<i8<-8:7>>
15-
!qalias = type !quant.any<i8<-8:7>>
15+
!qalias = !quant.any<i8<-8:7>>
1616
func.func @parseNoExpressedType() -> !qalias {
1717
%0 = "foo"() : () -> !qalias
1818
return %0 : !qalias
@@ -21,7 +21,7 @@ func.func @parseNoExpressedType() -> !qalias {
2121
// -----
2222
// CHECK-LABEL: parseOnlyStorageType
2323
// CHECK: !quant.any<i8>
24-
!qalias = type !quant.any<i8>
24+
!qalias = !quant.any<i8>
2525
func.func @parseOnlyStorageType() -> !qalias {
2626
%0 = "foo"() : () -> !qalias
2727
return %0 : !qalias

mlir/test/Dialect/Quant/parse-calibrated-invalid.mlir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
// Unrecognized token: missing calibrated type maximum
55
// expected-error@+2 {{calibrated values must be present}}
66
// expected-error@+1 {{expected ':'}}
7-
!qalias = type !quant.calibrated<f32<-0.998>>
7+
!qalias = !quant.calibrated<f32<-0.998>>
88

99
// -----
1010
// Unrecognized token: missing closing angle bracket
1111
// expected-error@+1 {{expected '>'}}
12-
!qalias = type !quant<"calibrated<f32<-0.998:1.232>">
12+
!qalias = !quant<"calibrated<f32<-0.998:1.232>">
1313

1414
// -----
1515
// Unrecognized expressed type: integer type
1616
// expected-error@+2 {{invalid kind of type specified}}
1717
// expected-error@+1 {{expecting float expressed type}}
18-
!qalias = type !quant.calibrated<i8<-4:3>>
18+
!qalias = !quant.calibrated<i8<-4:3>>
1919

2020
// -----
2121
// Illegal storage min/max: max - min < 0
2222
// expected-error@+1 {{illegal min and max: (1.000000e+00:-1.000000e+00)}}
23-
!qalias = type !quant.calibrated<f32<1.0:-1.0>>
23+
!qalias = !quant.calibrated<f32<1.0:-1.0>>
2424

2525
// -----
2626
// Illegal storage min/max: max - min == 0
2727
// expected-error@+1 {{illegal min and max: (1.000000e+00:1.000000e+00)}}
28-
!qalias = type !quant.calibrated<f32<1.0:1.0>>
28+
!qalias = !quant.calibrated<f32<1.0:1.0>>

mlir/test/Dialect/Quant/parse-calibrated.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// -----
44
// CHECK-LABEL: parseCalibrated
55
// CHECK: !quant.calibrated<f32<-0.998:1.232100e+00>
6-
!qalias = type !quant.calibrated<f32<-0.998:1.2321>>
6+
!qalias = !quant.calibrated<f32<-0.998:1.2321>>
77
func.func @parseCalibrated() -> !qalias {
88
%0 = "foo"() : () -> !qalias
99
return %0 : !qalias

0 commit comments

Comments
 (0)