| %# -*- mode: sil -*- |
| // RUN: rm -rf %t |
| // RUN: mkdir %t |
| // RUN: %gyb %s > %t/arc-sequence-opts-loops.sil |
| // RUN: %target-sil-opt -enable-sil-verify-all -arc-sequence-opts %t/arc-sequence-opts-loops.sil -enable-loop-arc=0 | FileCheck %t/arc-sequence-opts-loops.sil |
| |
| %# Ignore the following admonition; it applies to the resulting .sil |
| %# test file only. |
| // DO NOT MODIFY THIS TEST FILE. IT IS AUTOMATICALLY GENERATED BY GYB. |
| |
| sil_stage canonical |
| |
| import Builtin |
| |
| // Utilities |
| |
| sil @user : $@convention(thin) (Builtin.NativeObject) -> () |
| |
| // Loop form 1 consists of CFG of the following form: |
| // |
| // BB0 -> BB1 |
| // BB1 -> BB1 |
| // BB1 -> BB2 |
| // |
| // Thus it is a simple loop without any interior basic blocks. |
| // |
| // We generate test retain release pairs at |
| % for i in range(16): |
| |
| // CHECK-LABEL: sil @loop_form_1_${i} : $@convention(thin) (Builtin.NativeObject) -> () { |
| sil @loop_form_1_${i} : $@convention(thin) (Builtin.NativeObject) -> () { |
| // CHECK: bb0 |
| bb0(%0 : $Builtin.NativeObject): |
| % if i & 1: |
| // CHECK-NEXT: strong_retain |
| strong_retain %0 : $Builtin.NativeObject |
| % end |
| // CHECK-NEXT: br bb |
| br bb1 |
| |
| // CHECK: bb1: |
| bb1: |
| % if (i & 2) and not (i & 4): |
| // CHECK-NEXT: strong_retain |
| % end |
| % if i & 2: |
| strong_retain %0 : $Builtin.NativeObject |
| % end |
| % if not (i & 2) and (i & 4): |
| // CHECK-NEXT: strong_release |
| % end |
| % if i & 4: |
| strong_release %0 : $Builtin.NativeObject |
| % end |
| // CHECK-NEXT: cond_br |
| cond_br undef, bb1, bb2 |
| |
| // CHECK: bb2: |
| bb2: |
| % if i & 8: |
| // CHECK-NEXT: strong_release |
| strong_release %0 : $Builtin.NativeObject |
| % end |
| %%1 = tuple () |
| return %1 : $() |
| } |
| % end |
| |
| // Loop form 2 consists of CFGs of the following form: |
| // |
| // BB0 -> BB1 |
| // BB1 -> BB2 |
| // BB2 -> BB1 |
| // BB2 -> BB3 |
| // |
| // I.e. a loop with a body of 2 and the jump into the loop not at the |
| // latch. |
| |
| % for i in range(3): |
| % for j in range(4): |
| |
| sil @loop_form_2_${i}_${j} : $@convention(thin) (Builtin.NativeObject) -> () { |
| // CHECK: bb0({{.*}}): |
| bb0(%0 : $Builtin.NativeObject): |
| % if i & 1: |
| // CHECK-NEXT: strong_retain |
| strong_retain %0 : $Builtin.NativeObject |
| % end |
| br bb1 |
| |
| // CHECK: bb1: |
| bb1: |
| % if j == 0: |
| // CHECK-NEXT: strong_retain |
| strong_retain %0 : $Builtin.NativeObject |
| % end |
| % if j == 1: |
| // CHECK-NEXT: strong_release |
| strong_release %0 : $Builtin.NativeObject |
| % end |
| br bb2 |
| |
| // CHECK: bb2: |
| bb2: |
| % if j == 2: |
| // CHECK-NEXT: strong_retain |
| strong_retain %0 : $Builtin.NativeObject |
| % end |
| % if j == 3: |
| // CHECK-NEXT: strong_release |
| strong_release %0 : $Builtin.NativeObject |
| % end |
| cond_br undef, bb1, bb3 |
| |
| // CHECK: bb3: |
| bb3: |
| % if i & 2: |
| // CHECK-NEXT: strong_release |
| strong_release %0 : $Builtin.NativeObject |
| % end |
| %%1 = tuple () |
| return %1 : $() |
| } |
| |
| % end |