Files
swift-mirror/SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/CMakeLists.txt
Erik Eckstein 181b2f1f6d Optimizer: eliminate struct_extracts of an owned struct where the struct_extracts are inside a borrow scope
This is done by splitting the `begin_borrow` of the whole struct into individual borrows of the fields (for trivial fields no borrow is needed).
And then sinking the `struct` to it's consuming use(s).

```
  %3 = struct $S(%nonTrivialField, %trivialField)  // owned
  ...
  %4 = begin_borrow %3
  %5 = struct_extract %4, #S.nonTrivialField
  %6 = struct_extract %4, #S.trivialField
  use %5, %6
  end_borrow %4
  ...
  end_of_lifetime %3
```
->
```
  ...
  %5 = begin_borrow %nonTrivialField
  use %5, %trivialField
  end_borrow %5
  ...
  %3 = struct $S(%nonTrivialField, %trivialField)
  end_of_lifetime %3
```

This optimization is important for Array code where the Array buffer is constantly wrapped into structs and then extracted again to access the buffer.
2025-10-08 17:48:37 +02:00

50 lines
1.5 KiB
CMake

# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
swift_compiler_sources(Optimizer
SimplifyAllocRefDynamic.swift
SimplifyAllocStack.swift
SimplifyApply.swift
SimplifyBeginAndLoadBorrow.swift
SimplifyBeginCOWMutation.swift
SimplifyBranch.swift
SimplifyBuiltin.swift
SimplifyCheckedCast.swift
SimplifyClassifyBridgeObject.swift
SimplifyCondBranch.swift
SimplifyCondFail.swift
SimplifyConvertEscapeToNoEscape.swift
SimplifyCopyBlock.swift
SimplifyCopyValue.swift
SimplifyDebugStep.swift
SimplifyDestroyValue.swift
SimplifyDestructure.swift
SimplifyEndCOWMutationAddr.swift
SimplifyExplicitCopy.swift
SimplifyFixLifetime.swift
SimplifyGlobalValue.swift
SimplifyInitEnumDataAddr.swift
SimplifyKeyPath.swift
SimplifyLoad.swift
SimplifyMarkDependence.swift
SimplifyMisc.swift
SimplifyPartialApply.swift
SimplifyPointerToAddress.swift
SimplifyRefCasts.swift
SimplifyRetainReleaseValue.swift
SimplifyStrongRetainRelease.swift
SimplifyStruct.swift
SimplifyStructExtract.swift
SimplifySwitchEnum.swift
SimplifyTuple.swift
SimplifyTupleExtract.swift
SimplifyUncheckedAddrCast.swift
SimplifyUncheckedEnumData.swift
SimplifyValueToBridgeObject.swift
SimplifyWitnessMethod.swift)