File: scf.mlir

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,998,492 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 (47 lines) | stat: -rw-r--r-- 1,697 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
// RUN: mlir-opt -convert-to-spirv="run-signature-conversion=false" %s | FileCheck %s

// CHECK-LABEL: @if_yield
// CHECK: %[[VAR:.*]] = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK:       spirv.mlir.selection {
// CHECK-NEXT:    spirv.BranchConditional {{%.*}}, [[TRUE:\^.*]], [[FALSE:\^.*]]
// CHECK-NEXT:  [[TRUE]]:
// CHECK:         %[[C0TRUE:.*]] = spirv.Constant 0.000000e+00 : f32
// CHECK:         %[[RETTRUE:.*]] = spirv.Constant 0.000000e+00 : f32
// CHECK-DAG:     spirv.Store "Function" %[[VAR]], %[[RETTRUE]] : f32
// CHECK:         spirv.Branch ^[[MERGE:.*]]
// CHECK-NEXT:  [[FALSE]]:
// CHECK:         %[[C0FALSE:.*]] = spirv.Constant 1.000000e+00 : f32
// CHECK:         %[[RETFALSE:.*]] = spirv.Constant 2.71828175 : f32
// CHECK-DAG:     spirv.Store "Function" %[[VAR]], %[[RETFALSE]] : f32
// CHECK:         spirv.Branch ^[[MERGE]]
// CHECK-NEXT:  ^[[MERGE]]:
// CHECK:         spirv.mlir.merge
// CHECK-NEXT:  }
// CHECK-DAG:   %[[OUT:.*]] = spirv.Load "Function" %[[VAR]] : f32
// CHECK:       spirv.ReturnValue %[[OUT]] : f32
func.func @if_yield(%arg0: i1) -> f32 {
  %0 = scf.if %arg0 -> f32 {
    %c0 = arith.constant 0.0 : f32
    %res = math.sqrt %c0 : f32
    scf.yield %res : f32
  } else {
    %c0 = arith.constant 1.0 : f32
    %res = math.exp %c0 : f32
    scf.yield %res : f32
  }
  return %0 : f32
}

// CHECK-LABEL: @while
func.func @while(%arg0: i32, %arg1: i32) -> i32 {
  %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
  }
  return %0 : i32
}