func.mlir
6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// RUN: mlir-opt -split-input-file -verify-diagnostics %s | mlir-opt | FileCheck %s
// RUN: mlir-opt -split-input-file -verify-diagnostics -mlir-print-op-generic %s | FileCheck %s --check-prefix=GENERIC
module {
// GENERIC: "llvm.func"
// GENERIC: sym_name = "foo"
// GENERIC-SAME: type = !llvm<"void ()">
// GENERIC-SAME: () -> ()
// CHECK: llvm.func @foo()
"llvm.func"() ({
}) {sym_name = "foo", type = !llvm<"void ()">} : () -> ()
// GENERIC: "llvm.func"
// GENERIC: sym_name = "bar"
// GENERIC-SAME: type = !llvm<"i64 (i64, i64)">
// GENERIC-SAME: () -> ()
// CHECK: llvm.func @bar(!llvm.i64, !llvm.i64) -> !llvm.i64
"llvm.func"() ({
}) {sym_name = "bar", type = !llvm<"i64 (i64, i64)">} : () -> ()
// GENERIC: "llvm.func"
// CHECK: llvm.func @baz(%{{.*}}: !llvm.i64) -> !llvm.i64
"llvm.func"() ({
// GENERIC: ^bb0
^bb0(%arg0: !llvm.i64):
// GENERIC: llvm.return
llvm.return %arg0 : !llvm.i64
// GENERIC: sym_name = "baz"
// GENERIC-SAME: type = !llvm<"i64 (i64)">
// GENERIC-SAME: () -> ()
}) {sym_name = "baz", type = !llvm<"i64 (i64)">} : () -> ()
// CHECK: llvm.func @qux(!llvm<"i64*"> {llvm.noalias = true}, !llvm.i64)
// CHECK: attributes {xxx = {yyy = 42 : i64}}
"llvm.func"() ({
}) {sym_name = "qux", type = !llvm<"void (i64*, i64)">,
arg0 = {llvm.noalias = true}, xxx = {yyy = 42}} : () -> ()
// CHECK: llvm.func @roundtrip1()
llvm.func @roundtrip1()
// CHECK: llvm.func @roundtrip2(!llvm.i64, !llvm.float) -> !llvm.double
llvm.func @roundtrip2(!llvm.i64, !llvm.float) -> !llvm.double
// CHECK: llvm.func @roundtrip3(!llvm.i32, !llvm.i1)
llvm.func @roundtrip3(%a: !llvm.i32, %b: !llvm.i1)
// CHECK: llvm.func @roundtrip4(%{{.*}}: !llvm.i32, %{{.*}}: !llvm.i1) {
llvm.func @roundtrip4(%a: !llvm.i32, %b: !llvm.i1) {
llvm.return
}
// CHECK: llvm.func @roundtrip5()
// CHECK: attributes {baz = 42 : i64, foo = "bar"}
llvm.func @roundtrip5() attributes {foo = "bar", baz = 42}
// CHECK: llvm.func @roundtrip6()
// CHECK: attributes {baz = 42 : i64, foo = "bar"}
llvm.func @roundtrip6() attributes {foo = "bar", baz = 42} {
llvm.return
}
// CHECK: llvm.func @roundtrip7() {
llvm.func @roundtrip7() attributes {} {
llvm.return
}
// CHECK: llvm.func @roundtrip8() -> !llvm.i32
llvm.func @roundtrip8() -> !llvm.i32 attributes {}
// CHECK: llvm.func @roundtrip9(!llvm<"i32*"> {llvm.noalias = true})
llvm.func @roundtrip9(!llvm<"i32*"> {llvm.noalias = true})
// CHECK: llvm.func @roundtrip10(!llvm<"i32*"> {llvm.noalias = true})
llvm.func @roundtrip10(%arg0: !llvm<"i32*"> {llvm.noalias = true})
// CHECK: llvm.func @roundtrip11(%{{.*}}: !llvm<"i32*"> {llvm.noalias = true}) {
llvm.func @roundtrip11(%arg0: !llvm<"i32*"> {llvm.noalias = true}) {
llvm.return
}
// CHECK: llvm.func @roundtrip12(%{{.*}}: !llvm<"i32*"> {llvm.noalias = true})
// CHECK: attributes {foo = 42 : i32}
llvm.func @roundtrip12(%arg0: !llvm<"i32*"> {llvm.noalias = true})
attributes {foo = 42 : i32} {
llvm.return
}
// CHECK: llvm.func @variadic(...)
llvm.func @variadic(...)
// CHECK: llvm.func @variadic_args(!llvm.i32, !llvm.i32, ...)
llvm.func @variadic_args(!llvm.i32, !llvm.i32, ...)
//
// Check that functions can have linkage attributes.
//
// CHECK: llvm.func internal
llvm.func internal @internal_func() {
llvm.return
}
// CHECK: llvm.func weak
llvm.func weak @weak_linkage() {
llvm.return
}
// Omit the `external` linkage, which is the default, in the custom format.
// Check that it is present in the generic format using its numeric value.
//
// CHECK: llvm.func @external_func
// GENERIC: linkage = 10
llvm.func external @external_func()
}
// -----
module {
// expected-error@+1 {{expects one region}}
"llvm.func"() {sym_name = "no_region", type = !llvm<"void ()">} : () -> ()
}
// -----
module {
// expected-error@+1 {{requires a type attribute 'type'}}
"llvm.func"() ({}) {sym_name = "missing_type"} : () -> ()
}
// -----
module {
// expected-error@+1 {{requires 'type' attribute of wrapped LLVM function type}}
"llvm.func"() ({}) {sym_name = "non_llvm_type", type = i64} : () -> ()
}
// -----
module {
// expected-error@+1 {{requires 'type' attribute of wrapped LLVM function type}}
"llvm.func"() ({}) {sym_name = "non_function_type", type = !llvm<"i64">} : () -> ()
}
// -----
module {
// expected-error@+1 {{entry block must have 0 arguments}}
"llvm.func"() ({
^bb0(%arg0: !llvm.i64):
llvm.return
}) {sym_name = "wrong_arg_number", type = !llvm<"void ()">} : () -> ()
}
// -----
module {
// expected-error@+1 {{entry block argument #0 is not of LLVM type}}
"llvm.func"() ({
^bb0(%arg0: i64):
llvm.return
}) {sym_name = "wrong_arg_number", type = !llvm<"void (i64)">} : () -> ()
}
// -----
module {
// expected-error@+1 {{entry block argument #0 does not match the function signature}}
"llvm.func"() ({
^bb0(%arg0: !llvm.i32):
llvm.return
}) {sym_name = "wrong_arg_number", type = !llvm<"void (i64)">} : () -> ()
}
// -----
module {
// expected-error@+1 {{failed to construct function type: expected LLVM type for function arguments}}
llvm.func @foo(i64)
}
// -----
module {
// expected-error@+1 {{failed to construct function type: expected LLVM type for function results}}
llvm.func @foo() -> i64
}
// -----
module {
// expected-error@+1 {{failed to construct function type: expected zero or one function result}}
llvm.func @foo() -> (!llvm.i64, !llvm.i64)
}
// -----
module {
// expected-error@+1 {{only external functions can be variadic}}
llvm.func @variadic_def(...) {
llvm.return
}
}
// -----
module {
// expected-error@+1 {{variadic arguments must be in the end of the argument list}}
llvm.func @variadic_inside(%arg0: !llvm.i32, ..., %arg1: !llvm.i32)
}
// -----
module {
// expected-error@+1 {{external functions must have 'external' or 'extern_weak' linkage}}
llvm.func internal @internal_external_func()
}
// -----
module {
// expected-error@+1 {{functions cannot have 'common' linkage}}
llvm.func common @common_linkage_func()
}