File: one-shot-bufferize.mlir

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (72 lines) | stat: -rw-r--r-- 3,289 bytes parent folder | download | duplicates (7)
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>
}