mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Enable KeyPath/AnyKeyPath/PartialKeyPath/WritableKeyPath in Embedded Swift, but for compile-time use only: - Add keypath optimizations into the mandatory optimizations pipeline - Allow keypath optimizations to look through begin_borrow, to make them work even in OSSA. - If a use of a KeyPath doesn't optimize away, diagnose in PerformanceDiagnostics - Make UnsafePointer.pointer(to:) transparent to allow the keypath optimization to happen in the callers of UnsafePointer.pointer(to:).
36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
//===--- SimplifyKeyPath.swift --------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import SIL
|
|
|
|
extension KeyPathInst : OnoneSimplifyable {
|
|
func simplify(_ context: SimplifyContext) {
|
|
if allUsesRemovable(instruction: self) {
|
|
context.erase(instructionIncludingAllUsers: self)
|
|
}
|
|
}
|
|
}
|
|
|
|
fileprivate func allUsesRemovable(instruction: Instruction) -> Bool {
|
|
for result in instruction.results {
|
|
for use in result.uses {
|
|
if !(use.instruction is UpcastInst || use.instruction is DestroyValueInst || use.instruction is BeginBorrowInst || use.instruction is EndBorrowInst) {
|
|
return false
|
|
}
|
|
if !allUsesRemovable(instruction: use.instruction) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|