File: control_flow.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 (70 lines) | stat: -rw-r--r-- 2,125 bytes parent folder | download | duplicates (5)
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
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP

// simple(10, true)  -> 20
// simple(10, false) -> 30
func.func @simple(i64, i1) -> i64 {
^bb0(%a: i64, %cond: i1):
  cf.cond_br %cond, ^bb1, ^bb2
^bb1:
  cf.br ^bb3(%a: i64)
^bb2:
  %b = emitc.call "add"(%a, %a) : (i64, i64) -> i64
  cf.br ^bb3(%b: i64)
^bb3(%c: i64):
  cf.br ^bb4(%c, %a : i64, i64)
^bb4(%d : i64, %e : i64):
  %0 = emitc.call "add"(%d, %e) : (i64, i64) -> i64
  return %0 : i64
}
  // CPP-DECLTOP: int64_t simple(int64_t [[A:[^ ]*]], bool [[COND:[^ ]*]]) {
    // CPP-DECLTOP-NEXT: int64_t [[B:[^ ]*]];
    // CPP-DECLTOP-NEXT: int64_t [[V0:[^ ]*]];
    // CPP-DECLTOP-NEXT: int64_t [[C:[^ ]*]];
    // CPP-DECLTOP-NEXT: int64_t [[D:[^ ]*]];
    // CPP-DECLTOP-NEXT: int64_t [[E:[^ ]*]];
    // CPP-DECLTOP-NEXT: if ([[COND]]) {
    // CPP-DECLTOP-NEXT: goto [[BB1:[^ ]*]];
    // CPP-DECLTOP-NEXT: } else {
    // CPP-DECLTOP-NEXT: goto [[BB2:[^ ]*]];
    // CPP-DECLTOP-NEXT: }
    // CPP-DECLTOP-NEXT: [[BB1]]:
    // CPP-DECLTOP-NEXT: [[C]] = [[A]];
    // CPP-DECLTOP-NEXT: goto [[BB3:[^ ]*]];
    // CPP-DECLTOP-NEXT: [[BB2]]:
    // CPP-DECLTOP-NEXT: [[B]] = add([[A]], [[A]]);
    // CPP-DECLTOP-NEXT: [[C]] = [[B]];
    // CPP-DECLTOP-NEXT: goto [[BB3]];
    // CPP-DECLTOP-NEXT: [[BB3]]:
    // CPP-DECLTOP-NEXT: [[D]] = [[C]];
    // CPP-DECLTOP-NEXT: [[E]] = [[A]];
    // CPP-DECLTOP-NEXT: goto [[BB4:[^ ]*]];
    // CPP-DECLTOP-NEXT: [[BB4]]:
    // CPP-DECLTOP-NEXT: [[V0]] = add([[D]], [[E]]);
    // CPP-DECLTOP-NEXT: return [[V0]];


func.func @block_labels0() {
^bb1:
    cf.br ^bb2
^bb2:
    return
}
// CPP-DECLTOP: void block_labels0() {
  // CPP-DECLTOP-NEXT: goto label2;
  // CPP-DECLTOP-NEXT: label2:
  // CPP-DECLTOP-NEXT: return;
  // CPP-DECLTOP-NEXT: }


// Repeat the same function to make sure the names of the block labels get reset.
func.func @block_labels1() {
^bb1:
    cf.br ^bb2
^bb2:
    return
}
// CPP-DECLTOP: void block_labels1() {
  // CPP-DECLTOP-NEXT: goto label2;
  // CPP-DECLTOP-NEXT: label2:
  // CPP-DECLTOP-NEXT: return;
  // CPP-DECLTOP-NEXT: }