File: cold_block_info.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; 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 (223 lines) | stat: -rw-r--r-- 5,640 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -module-name main -emit-sil -o %t/output.sil %s -O \
// RUN:   -enable-noreturn-prediction \
// RUN:   -enable-throws-prediction \
// RUN:   -Xllvm --debug-only=cold-block-info 2> %t/debug.txt

// RUN: %FileCheck %s --input-file=%t/debug.txt \
// RUN:               --implicit-check-not 'converged after {{[3-9]}} iters'

// REQUIRES: asserts

public enum MyError: Error { case err; case number(Int) }

@inline(never)
func dump(_ s: String) { print(s) }

@inline(never)
func random() -> Int { return Int.random(in: 0..<1024) }

@inline(never)
func listenForConnections() -> Never {
  while true {
    dump("listening!")
  }
}

// CHECK-LABEL: --> Final for $s4main14createLauncheryyF
// CHECK: {
// CHECK-NEXT: $s4main14createLauncheryyF::bb0 -> cold
// CHECK-NEXT: STATISTICS: warm 0 | cold 1
// CHECK-NEXT: }
public func createLauncher() {
  dump("getting ready!")
  listenForConnections()
}

// CHECK-LABEL: --> Final for $s4main6goBoomyS2iSgF
// CHECK: {
// CHECK-NEXT: $s4main6goBoomyS2iSgF::bb1 -> cold
// CHECK-NEXT: STATISTICS: warm 0 | cold 1
// CHECK-NEXT: }
public func goBoom(_ i: Int?) -> Int {
  return i!
}


// CHECK-LABEL: --> Stopping early in $s4main19goBoom_preconditionyySbF
public func goBoom_precondition(_ b: Bool) {
  // NOTE: cond_fail instructions from preconditions aren't terminators,
  // so there's nothing cold in this function!
  precondition(b)

  var x = random()
  precondition(x >= 0)

  if (x > 100) {
    x = 0
  }

  for i in 0..<x {
    precondition(i <= 100)
    dump(i)
  }
}

// CHECK-LABEL: --> Final for $s4main17goBoom_fatalErroryySiF
// CHECK: {
// CHECK-DAG: $s4main17goBoom_fatalErroryySiF::bb1 -> cold
// CHECK-DAG: $s4main17goBoom_fatalErroryySiF::bb0 -> cold
// CHECK-DAG: $s4main17goBoom_fatalErroryySiF::bb3 -> cold
// CHECK-DAG: $s4main17goBoom_fatalErroryySiF::bb2 -> cold
// CHECK-NEXT: STATISTICS: warm 0
// CHECK: }
public func goBoom_fatalError(_ i: Int) {
  for i in 0..<i {
    dump("do something")
  }
  fatalError("kablam")
}


// CHECK-LABEL: --> Final for $s4main13sirThrowsALotyS2iKF
// CHECK: {
// CHECK-DAG: $s4main13sirThrowsALotyS2iKF::bb3 -> cold
// CHECK-DAG: $s4main13sirThrowsALotyS2iKF::bb2 -> cold
// CHECK-DAG: $s4main13sirThrowsALotyS2iKF::bb4 -> cold
// CHECK-DAG: $s4main13sirThrowsALotyS2iKF::bb5 -> cold
// CHECK-NEXT: STATISTICS: warm 0
// CHECK: }
@inline(never)
public func sirThrowsALot(_ i: Int) throws -> Int {
  dump("entry")
  switch i {
    case 0:
      dump("case 0")
      return random()
    case 1:
      dump("case 1")
      throw MyError.err
    default:
      dump("case n")
      throw MyError.number(i)
  }
}

// CHECK-LABEL: --> Final for $s4main22catchTheseThrowsSimpleyS2iF
// CHECK: {
// CHECK-DAG: $s4main22catchTheseThrowsSimpleyS2iF::bb1 -> warm
// CHECK-DAG: $s4main22catchTheseThrowsSimpleyS2iF::bb2 -> cold
// CHECK: }
public func catchTheseThrowsSimple(_ i: Int) -> Int {
  if let ans = try? sirThrowsALot(i) {
    return ans
  } else {
    dump("did throw!")
    return random()
  }
}

// Make sure there's at least 3 cold blocks and no warm ones.
// Inlining and multiple runs of the analysis, and especially platform
// differences, can yield different numbers of blocks being analyzed!

// CHECK-LABEL: --> Final for $s4main012pleasePleaseC0yySiKF
// CHECK-COUNT-3: -> cold
// CHECK: STATISTICS: warm 0
// CHECK: }
public func pleasePleasePlease(_ i: Int) throws {
  if i > random() {
    fatalError("oof")
  } else {
    throw MyError.number(i)
  }
}


// CHECK-LABEL: --> Final for $s4main21nestedTreesOfThrowingyySi_S3itAA7MyErrorOYKF
// CHECK-NOT: bb0
// CHECK: }
public func nestedTreesOfThrowing(_ i: Int, _ j: Int, _ k: Int, _ l: Int) throws(MyError) {
  switch i {
  case 0:
    switch j {
    case 0:
      switch k {
        case 0:
        switch l {
          case 0: throw MyError.number(0)
          case 1: throw MyError.number(1)
          default: return  // <-- the one non-throwing case that prevents bb0 from being cold!
        }
        case 1:
        switch l {
          case 0: throw MyError.number(1)
          case 1: throw MyError.number(2)
          default: throw MyError.err
        }
        default:
          throw MyError.err
      }
    case 1:
      switch k {
        case 0:
        switch l {
          case 0: throw MyError.number(1)
          case 1: throw MyError.number(2)
          default: throw MyError.err
        }
        case 1:
        switch l {
          case 0: throw MyError.number(2)
          case 1: throw MyError.number(3)
          default: throw MyError.err
        }
        default:
          throw MyError.err
      }
    default:
      throw MyError.err
    }
  case 1:
    switch j {
    case 0:
      switch k {
        case 0:
        switch l {
          case 0: throw MyError.number(1)
          case 1: throw MyError.number(2)
          default: throw MyError.err
        }
        case 1:
        switch l {
          case 0: throw MyError.number(2)
          case 1: throw MyError.number(3)
          default: throw MyError.err
        }
        default:
          throw MyError.err
      }
    case 1:
      switch k {
        case 0:
        switch l {
          case 0: throw MyError.number(2)
          case 1: throw MyError.number(3)
          default: throw MyError.err
        }
        case 1:
        switch l {
          case 0: throw MyError.number(3)
          case 1: throw MyError.number(4)
          default: throw MyError.err
        }
        default:
          throw MyError.err
      }
    default:
      throw MyError.err
    }
  default:
    throw MyError.err
  }
}