[Flang][OpenMP] Handle SECTION construct from within SECTIONS (#77759)
[llvm-project.git] / mlir / utils / tree-sitter-mlir / test / corpus / affine.txt
blobadb47cd9701717f347c82e303793461c8a7f39e9
1 ================================================================================
2 affine_map with indexing and sum
3 ================================================================================
4 #inline_map_minmax_loop2 = affine_map<()[s0] -> (100, s0 + 1)>
5 #map0 = affine_map<(i) -> ()>
6 #bound_map1 = affine_map<(i, j)[s] -> (i + j + s)>
7 --------------------------------------------------------------------------------
9 (toplevel
10   (attribute_alias_def
11     (attribute_value
12       (builtin_attribute
13         (affine_map
14           (bare_id)
15           (integer_literal)
16           (bare_id)
17           (integer_literal)))))
18   (attribute_alias_def
19     (attribute_value
20       (builtin_attribute
21         (affine_map
22           (bare_id)))))
23   (attribute_alias_def
24     (attribute_value
25       (builtin_attribute
26         (affine_map
27           (bare_id)
28           (bare_id)
29           (bare_id)
30           (bare_id)
31           (bare_id)
32           (bare_id))))))
34 ================================================================================
35 affine_set expression
36 ================================================================================
37 #set0 = affine_set<(i)[N, M] : (i >= 0, -i + N >= 0, N - 5 == 0, -i + M + 1 >= 0)>
38 --------------------------------------------------------------------------------
40 (toplevel
41   (attribute_alias_def
42     (attribute_value
43       (builtin_attribute
44         (affine_set
45           (bare_id)
46           (bare_id)
47           (bare_id)
48           (bare_id)
49           (integer_literal)
50           (bare_id)
51           (bare_id)
52           (integer_literal)
53           (bare_id)
54           (integer_literal)
55           (integer_literal)
56           (bare_id)
57           (bare_id)
58           (integer_literal)
59           (integer_literal))))))
61 ================================================================================
62 affine.min and affine.max with non-trivial affine maps
63 ================================================================================
64 func.func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) {
65   %0 = affine.min affine_map<(d0)[s0] -> (1000, d0 + 512, s0)> (%arg0)[%arg1]
66   %1 = affine.min affine_map<(d0, d1)[s0] -> (d0 - d1, s0 + 512)> (%arg0, %arg1)[%arg2]
67   %2 = affine.min affine_map<()[s0, s1] -> (s0 - s1, 11)> ()[%arg1, %arg2]
68   %3 = affine.min affine_map<()[] -> (77, 78, 79)> ()[]
69   return
72 func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {
73   %0 = affine.max affine_map<(d0)[s0] -> (1000, d0 + 512, s0)> (%arg0)[%arg1]
74   %1 = affine.max affine_map<(d0, d1)[s0] -> (d0 - d1, s0 + 512)> (%arg0, %arg1)[%arg2]
75   %2 = affine.max affine_map<()[s0, s1] -> (s0 - s1, 11)> ()[%arg1, %arg2]
76   %3 = affine.max affine_map<()[] -> (77, 78, 79)> ()[]
77   return
79 --------------------------------------------------------------------------------
81 (toplevel
82   (operation
83     (custom_operation
84       (func_dialect
85         (symbol_ref_id)
86         (func_arg_list
87           (value_use)
88           (type
89             (builtin_type
90               (index_type)))
91           (value_use)
92           (type
93             (builtin_type
94               (index_type)))
95           (value_use)
96           (type
97             (builtin_type
98               (index_type))))
99         (region
100           (entry_block
101             (operation
102               (op_result
103                 (value_use))
104               (custom_operation
105                 (affine_dialect
106                   (attribute
107                     (builtin_attribute
108                       (affine_map
109                         (bare_id)
110                         (bare_id)
111                         (integer_literal)
112                         (bare_id)
113                         (integer_literal)
114                         (bare_id))))
115                   (value_use)
116                   (value_use))))
117             (operation
118               (op_result
119                 (value_use))
120               (custom_operation
121                 (affine_dialect
122                   (attribute
123                     (builtin_attribute
124                       (affine_map
125                         (bare_id)
126                         (bare_id)
127                         (bare_id)
128                         (bare_id)
129                         (bare_id)
130                         (bare_id)
131                         (integer_literal))))
132                   (value_use)
133                   (value_use)
134                   (value_use))))
135             (operation
136               (op_result
137                 (value_use))
138               (custom_operation
139                 (affine_dialect
140                   (attribute
141                     (builtin_attribute
142                       (affine_map
143                         (bare_id)
144                         (bare_id)
145                         (bare_id)
146                         (bare_id)
147                         (integer_literal))))
148                   (value_use)
149                   (value_use))))
150             (operation
151               (op_result
152                 (value_use))
153               (custom_operation
154                 (affine_dialect
155                   (attribute
156                     (builtin_attribute
157                       (affine_map
158                         (integer_literal)
159                         (integer_literal)
160                         (integer_literal)))))))
161             (operation
162               (custom_operation
163                 (func_dialect))))))))
164   (operation
165     (custom_operation
166       (func_dialect
167         (symbol_ref_id)
168         (func_arg_list
169           (value_use)
170           (type
171             (builtin_type
172               (index_type)))
173           (value_use)
174           (type
175             (builtin_type
176               (index_type)))
177           (value_use)
178           (type
179             (builtin_type
180               (index_type))))
181         (region
182           (entry_block
183             (operation
184               (op_result
185                 (value_use))
186               (custom_operation
187                 (affine_dialect
188                   (attribute
189                     (builtin_attribute
190                       (affine_map
191                         (bare_id)
192                         (bare_id)
193                         (integer_literal)
194                         (bare_id)
195                         (integer_literal)
196                         (bare_id))))
197                   (value_use)
198                   (value_use))))
199             (operation
200               (op_result
201                 (value_use))
202               (custom_operation
203                 (affine_dialect
204                   (attribute
205                     (builtin_attribute
206                       (affine_map
207                         (bare_id)
208                         (bare_id)
209                         (bare_id)
210                         (bare_id)
211                         (bare_id)
212                         (bare_id)
213                         (integer_literal))))
214                   (value_use)
215                   (value_use)
216                   (value_use))))
217             (operation
218               (op_result
219                 (value_use))
220               (custom_operation
221                 (affine_dialect
222                   (attribute
223                     (builtin_attribute
224                       (affine_map
225                         (bare_id)
226                         (bare_id)
227                         (bare_id)
228                         (bare_id)
229                         (integer_literal))))
230                   (value_use)
231                   (value_use))))
232             (operation
233               (op_result
234                 (value_use))
235               (custom_operation
236                 (affine_dialect
237                   (attribute
238                     (builtin_attribute
239                       (affine_map
240                         (integer_literal)
241                         (integer_literal)
242                         (integer_literal)))))))
243             (operation
244               (custom_operation
245                 (func_dialect)))))))))
247 ================================================================================
248 affine.dma_start and affine.dma_wait with complicated affine expressions
249 ================================================================================
250 func.func @test4(%arg0 : index, %arg1 : index) {
251   %0 = memref.alloc() : memref<100x100xf32>
252   %1 = memref.alloc() : memref<100x100xf32, 2>
253   %2 = memref.alloc() : memref<1xi32>
254   %c64 = arith.constant 64 : index
255   affine.for %i0 = 0 to 10 {
256     affine.for %i1 = 0 to 10 {
257       affine.dma_start %0[(%i0 + symbol(%arg0)) floordiv 3, %i1],
258                        %1[%i0, (%i1 + symbol(%arg1)) mod 9 + 7],
259                        %2[%i0 + %i1 + 11], %c64
260         : memref<100x100xf32>, memref<100x100xf32, 2>, memref<1xi32>
261       affine.dma_wait %2[%i0 + %i1 + 11], %c64 : memref<1xi32>
262     }
263   }
264   return
266 --------------------------------------------------------------------------------
268 (toplevel
269   (operation
270     (custom_operation
271       (func_dialect
272         (symbol_ref_id)
273         (func_arg_list
274           (value_use)
275           (type
276             (builtin_type
277               (index_type)))
278           (value_use)
279           (type
280             (builtin_type
281               (index_type))))
282         (region
283           (entry_block
284             (operation
285               (op_result
286                 (value_use))
287               (custom_operation
288                 (memref_dialect
289                   (type
290                     (builtin_type
291                       (memref_type
292                         (dim_list
293                           (float_type))))))))
294             (operation
295               (op_result
296                 (value_use))
297               (custom_operation
298                 (memref_dialect
299                   (type
300                     (builtin_type
301                       (memref_type
302                         (dim_list
303                           (float_type))
304                         (attribute_value
305                           (integer_literal))))))))
306             (operation
307               (op_result
308                 (value_use))
309               (custom_operation
310                 (memref_dialect
311                   (type
312                     (builtin_type
313                       (memref_type
314                         (dim_list
315                           (integer_type))))))))
316             (operation
317               (op_result
318                 (value_use))
319               (custom_operation
320                 (arith_dialect
321                   (integer_literal)
322                   (type
323                     (builtin_type
324                       (index_type))))))
325             (operation
326               (custom_operation
327                 (affine_dialect
328                   (value_use)
329                   (integer_literal)
330                   (integer_literal)
331                   (region
332                     (entry_block
333                       (operation
334                         (custom_operation
335                           (affine_dialect
336                             (value_use)
337                             (integer_literal)
338                             (integer_literal)
339                             (region
340                               (entry_block
341                                 (operation
342                                   (custom_operation
343                                     (affine_dialect
344                                       (value_use)
345                                       (value_use)
346                                       (value_use)
347                                       (integer_literal)
348                                       (value_use)
349                                       (value_use)
350                                       (value_use)
351                                       (value_use)
352                                       (value_use)
353                                       (integer_literal)
354                                       (integer_literal)
355                                       (value_use)
356                                       (value_use)
357                                       (value_use)
358                                       (integer_literal)
359                                       (value_use)
360                                       (type
361                                         (builtin_type
362                                           (memref_type
363                                             (dim_list
364                                               (float_type)))))
365                                       (type
366                                         (builtin_type
367                                           (memref_type
368                                             (dim_list
369                                               (float_type))
370                                             (attribute_value
371                                               (integer_literal)))))
372                                       (type
373                                         (builtin_type
374                                           (memref_type
375                                             (dim_list
376                                               (integer_type))))))))
377                                 (operation
378                                   (custom_operation
379                                     (affine_dialect
380                                       (value_use)
381                                       (value_use)
382                                       (value_use)
383                                       (integer_literal)
384                                       (value_use)
385                                       (type
386                                         (builtin_type
387                                           (memref_type
388                                             (dim_list
389                                               (integer_type))))))))))))))))))
390             (operation
391               (custom_operation
392                 (func_dialect)))))))))
394 ================================================================================
395 affine_map with complex affine expression
396 ================================================================================
397 func.func @semiaffine_mod(%arg0: index, %arg1: index) -> index {
398   %a = affine.apply affine_map<(d0)[s0] ->((-((d0 floordiv s0) * s0) + s0 * s0) mod s0)> (%arg0)[%arg1]
399   return %a : index
402 func.func @semiaffine_floordiv(%arg0: index, %arg1: index) -> index {
403   %a = affine.apply affine_map<(d0)[s0] ->((-((d0 floordiv s0) * s0) + ((2 * s0) mod (3 * s0))) floordiv s0)> (%arg0)[%arg1]
404   return %a : index
406 --------------------------------------------------------------------------------
408 (toplevel
409   (operation
410     (custom_operation
411       (func_dialect
412         (symbol_ref_id)
413         (func_arg_list
414           (value_use)
415           (type
416             (builtin_type
417               (index_type)))
418           (value_use)
419           (type
420             (builtin_type
421               (index_type))))
422         (func_return
423           (type_list_attr_parens
424             (type
425               (builtin_type
426                 (index_type)))))
427         (region
428           (entry_block
429             (operation
430               (op_result
431                 (value_use))
432               (custom_operation
433                 (affine_dialect
434                   (attribute
435                     (builtin_attribute
436                       (affine_map
437                         (bare_id)
438                         (bare_id)
439                         (bare_id)
440                         (bare_id)
441                         (bare_id)
442                         (bare_id)
443                         (bare_id)
444                         (bare_id))))
445                   (value_use)
446                   (value_use))))
447             (operation
448               (custom_operation
449                 (func_dialect
450                   (value_use)
451                   (type
452                     (builtin_type
453                       (index_type)))))))))))
454   (operation
455     (custom_operation
456       (func_dialect
457         (symbol_ref_id)
458         (func_arg_list
459           (value_use)
460           (type
461             (builtin_type
462               (index_type)))
463           (value_use)
464           (type
465             (builtin_type
466               (index_type))))
467         (func_return
468           (type_list_attr_parens
469             (type
470               (builtin_type
471                 (index_type)))))
472         (region
473           (entry_block
474             (operation
475               (op_result
476                 (value_use))
477               (custom_operation
478                 (affine_dialect
479                   (attribute
480                     (builtin_attribute
481                       (affine_map
482                         (bare_id)
483                         (bare_id)
484                         (bare_id)
485                         (bare_id)
486                         (bare_id)
487                         (integer_literal)
488                         (bare_id)
489                         (integer_literal)
490                         (bare_id)
491                         (bare_id))))
492                   (value_use)
493                   (value_use))))
494             (operation
495               (custom_operation
496                 (func_dialect
497                   (value_use)
498                   (type
499                     (builtin_type
500                       (index_type))))))))))))