Skip to content

Commit 0a05124

Browse files
committed
Swift Optimizer: add simplification of debug_step
When compiling with optimizations, unconditionally remove `debug_step`
1 parent a8c9aae commit 0a05124

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ swift_compiler_sources(Optimizer
1313
SimplifyBuiltin.swift
1414
SimplifyCondBranch.swift
1515
SimplifyCondFail.swift
16+
SimplifyDebugStep.swift
1617
SimplifyGlobalValue.swift
1718
SimplifyStrongRetainRelease.swift
1819
SimplifyStructExtract.swift
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===--- SimplifyDebugStep.swift ------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SIL
14+
15+
extension DebugStepInst : Simplifyable {
16+
func simplify(_ context: SimplifyContext) {
17+
// When compiling with optimizations (note: it's not a OnoneSimplifyable transformation),
18+
// unconditionally remove debug_step instructions.
19+
context.erase(instruction: self)
20+
}
21+
}
22+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=debug_step | %FileCheck %s --check-prefix=CHECK-ONONE --check-prefix=CHECK
2+
// RUN: %target-sil-opt -enable-sil-verify-all %s -simplification -simplify-instruction=debug_step | %FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK
3+
4+
// REQUIRES: swift_in_compiler
5+
6+
import Swift
7+
import Builtin
8+
9+
// CHECK-LABEL: sil @testit
10+
// CHECK-O-NOT: debug_step
11+
// CHECK-ONONE: debug_step
12+
// CHECK: } // end sil function 'testit'
13+
sil @testit : $@convention(thin) () -> () {
14+
bb0:
15+
debug_step
16+
%r = tuple ()
17+
return %r : $()
18+
}
19+

0 commit comments

Comments
 (0)