File: while.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (72 lines) | stat: -rw-r--r-- 2,928 bytes parent folder | download | duplicates (4)
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 -allow-unregistered-dialect -convert-scf-to-spirv %s -o - | FileCheck %s

module attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.0, [Shader, Int64], [SPV_KHR_storage_buffer_storage_class]>, #spirv.resource_limits<>>
} {

// CHECK-LABEL: @while_loop1
func.func @while_loop1(%arg0: i32, %arg1: i32) -> i32 {
  // CHECK-SAME: (%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32)
  // CHECK: %[[INITVAR:.*]] = spirv.Constant 2 : i32
  // CHECK: %[[VAR1:.*]] = spirv.Variable : !spirv.ptr<i32, Function>
  // CHECK: spirv.mlir.loop {
  // CHECK:   spirv.Branch ^[[HEADER:.*]](%[[ARG1]] : i32)
  // CHECK: ^[[HEADER]](%[[INDVAR1:.*]]: i32):
  // CHECK:   %[[CMP:.*]] = spirv.SLessThan %[[INDVAR1]], %[[ARG2]] : i32
  // CHECK:   spirv.Store "Function" %[[VAR1]], %[[INDVAR1]] : i32
  // CHECK:   spirv.BranchConditional %[[CMP]], ^[[BODY:.*]](%[[INDVAR1]] : i32), ^[[MERGE:.*]]
  // CHECK: ^[[BODY]](%[[INDVAR2:.*]]: i32):
  // CHECK:   %[[UPDATED:.*]] = spirv.IMul %[[INDVAR2]], %[[INITVAR]] : i32
  // CHECK: spirv.Branch ^[[HEADER]](%[[UPDATED]] : i32)
  // CHECK: ^[[MERGE]]:
  // CHECK:   spirv.mlir.merge
  // CHECK: }
  %c2_i32 = arith.constant 2 : i32
  %0 = scf.while (%arg3 = %arg0) : (i32) -> (i32) {
    %1 = arith.cmpi slt, %arg3, %arg1 : i32
    scf.condition(%1) %arg3 : i32
  } do {
  ^bb0(%arg5: i32):
    %1 = arith.muli %arg5, %c2_i32 : i32
    scf.yield %1 : i32
  }
  // CHECK: %[[OUT:.*]] = spirv.Load "Function" %[[VAR1]] : i32
  // CHECK: spirv.ReturnValue %[[OUT]] : i32
  return %0 : i32
}

// -----

// CHECK-LABEL: @while_loop2
func.func @while_loop2(%arg0: f32) -> i64 {
  // CHECK-SAME: (%[[ARG:.*]]: f32)
  // CHECK: %[[VAR:.*]] = spirv.Variable : !spirv.ptr<i64, Function>
  // CHECK: spirv.mlir.loop {
  // CHECK:   spirv.Branch ^[[HEADER:.*]](%[[ARG]] : f32)
  // CHECK: ^[[HEADER]](%[[INDVAR1:.*]]: f32):
  // CHECK:   %[[SHARED:.*]] = "foo.shared_compute"(%[[INDVAR1]]) : (f32) -> i64
  // CHECK:   %[[CMP:.*]] = "foo.evaluate_condition"(%[[INDVAR1]], %[[SHARED]]) : (f32, i64) -> i1
  // CHECK:   spirv.Store "Function" %[[VAR]], %[[SHARED]] : i64
  // CHECK:   spirv.BranchConditional %[[CMP]], ^[[BODY:.*]](%[[SHARED]] : i64), ^[[MERGE:.*]]
  // CHECK: ^[[BODY]](%[[INDVAR2:.*]]: i64):
  // CHECK:   %[[UPDATED:.*]] = "foo.payload"(%[[INDVAR2]]) : (i64) -> f32
  // CHECK: spirv.Branch ^[[HEADER]](%[[UPDATED]] : f32)
  // CHECK: ^[[MERGE]]:
  // CHECK:   spirv.mlir.merge
  // CHECK: }
  %res = scf.while (%arg1 = %arg0) : (f32) -> i64 {
    %shared = "foo.shared_compute"(%arg1) : (f32) -> i64
    %condition = "foo.evaluate_condition"(%arg1, %shared) : (f32, i64) -> i1
    scf.condition(%condition) %shared : i64
  } do {
  ^bb0(%arg2: i64):
    %res = "foo.payload"(%arg2) : (i64) -> f32
    scf.yield %res : f32
  }
  // CHECK: %[[OUT:.*]] = spirv.Load "Function" %[[VAR]] : i64
  // CHECK: spirv.ReturnValue %[[OUT]] : i64
  return %res : i64
}

} // end module