File: one-shot-bufferize.mlir

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (72 lines) | stat: -rw-r--r-- 3,289 bytes parent folder | download | duplicates (6)
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
// RUN: mlir-opt -one-shot-bufferize="bufferize-function-boundaries" -split-input-file %s | FileCheck %s
// RUN: mlir-opt -one-shot-bufferize -split-input-file %s | FileCheck %s --check-prefix=CHECK-NO-FUNC

// CHECK-NO-FUNC-LABEL: func @br(
//  CHECK-NO-FUNC-SAME:     %[[t:.*]]: tensor<5xf32>)
//       CHECK-NO-FUNC:   %[[m:.*]] = bufferization.to_memref %[[t]] : memref<5xf32, strided<[?], offset: ?>>
//       CHECK-NO-FUNC:   %[[r:.*]] = scf.execute_region -> memref<5xf32, strided<[?], offset: ?>> {
//       CHECK-NO-FUNC:     cf.br ^[[block:.*]](%[[m]]
//       CHECK-NO-FUNC:   ^[[block]](%[[arg1:.*]]: memref<5xf32, strided<[?], offset: ?>>):
//       CHECK-NO-FUNC:     scf.yield %[[arg1]]
//       CHECK-NO-FUNC:   }
//       CHECK-NO-FUNC:   return
func.func @br(%t: tensor<5xf32>) {
  %0 = scf.execute_region -> tensor<5xf32> {
    cf.br ^bb1(%t : tensor<5xf32>)
  ^bb1(%arg1 : tensor<5xf32>):
    scf.yield %arg1 : tensor<5xf32>
  }
  return
}

// -----

// CHECK-NO-FUNC-LABEL: func @cond_br(
//  CHECK-NO-FUNC-SAME:     %[[t1:.*]]: tensor<5xf32>,
//       CHECK-NO-FUNC:   %[[m1:.*]] = bufferization.to_memref %[[t1]] : memref<5xf32, strided<[?], offset: ?>>
//       CHECK-NO-FUNC:   %[[alloc:.*]] = memref.alloc() {{.*}} : memref<5xf32>
//       CHECK-NO-FUNC:   %[[r:.*]] = scf.execute_region -> memref<5xf32, strided<[?], offset: ?>> {
//       CHECK-NO-FUNC:     cf.cond_br %{{.*}}, ^[[block1:.*]](%[[m1]] : {{.*}}), ^[[block2:.*]](%[[alloc]] : {{.*}})
//       CHECK-NO-FUNC:   ^[[block1]](%[[arg1:.*]]: memref<5xf32, strided<[?], offset: ?>>):
//       CHECK-NO-FUNC:     scf.yield %[[arg1]]
//       CHECK-NO-FUNC:   ^[[block2]](%[[arg2:.*]]: memref<5xf32>):
//       CHECK-NO-FUNC:     %[[cast:.*]] = memref.cast %[[arg2]] : memref<5xf32> to memref<5xf32, strided<[?], offset: ?>
//       CHECK-NO-FUNC:     cf.br ^[[block1]](%[[cast]] : {{.*}})
//       CHECK-NO-FUNC:   }
//       CHECK-NO-FUNC:   return
func.func @cond_br(%t1: tensor<5xf32>, %c: i1) {
  // Use an alloc for the second block instead of a function block argument.
  // A cast must be inserted because the two will have different layout maps.
  %t0 = bufferization.alloc_tensor() : tensor<5xf32>
  %0 = scf.execute_region -> tensor<5xf32> {
    cf.cond_br %c, ^bb1(%t1 : tensor<5xf32>), ^bb2(%t0 : tensor<5xf32>)
  ^bb1(%arg1 : tensor<5xf32>):
    scf.yield %arg1 : tensor<5xf32>
  ^bb2(%arg2 : tensor<5xf32>):
    cf.br ^bb1(%arg2 : tensor<5xf32>)
  }
  return
}

// -----

// CHECK-LABEL: func @looping_branches(
func.func @looping_branches() -> tensor<5xf32> {
// CHECK: %[[alloc:.*]] = memref.alloc
  %0 = bufferization.alloc_tensor() : tensor<5xf32>
// CHECK: cf.br {{.*}}(%[[alloc]]
  cf.br ^bb1(%0: tensor<5xf32>)
// CHECK: ^{{.*}}(%[[arg1:.*]]: memref<5xf32>):
^bb1(%arg1: tensor<5xf32>):
  %pos = "test.foo"() : () -> (index)
  %val = "test.bar"() : () -> (f32)
// CHECK: memref.store %{{.*}}, %[[arg1]]
  %inserted = tensor.insert %val into %arg1[%pos] : tensor<5xf32>
  %cond = "test.qux"() : () -> (i1)
// CHECK: cf.cond_br {{.*}}(%[[arg1]] {{.*}}(%[[arg1]]
  cf.cond_br %cond, ^bb1(%inserted: tensor<5xf32>), ^bb2(%inserted: tensor<5xf32>)
// CHECK: ^{{.*}}(%[[arg2:.*]]: memref<5xf32>):
^bb2(%arg2: tensor<5xf32>):
// CHECK: return %[[arg2]]
  func.return %arg2 : tensor<5xf32>
}