Files
Erik Eckstein 6714a72256 Optimizer: re-implement and improve the AllocBoxToStack pass
This pass replaces `alloc_box` with `alloc_stack` if the box is not escaping.
The original implementation had some limitations. It could not handle cases of local functions which are called multiple times or even recursively, e.g.

```
public func foo() -> Int {
  var i = 1

  func localFunction() { i += 1 }

  localFunction()
  localFunction()
  return i
}

```

The new implementation (done in Swift) fixes this problem with a new algorithm.
It's not only more powerful, but also simpler: the new pass has less than half lines of code than the old pass.

The pass is invoked in the mandatory pipeline and later in the optimizer pipeline.
The new implementation provides a module-pass for the mandatory pipeline (whereas the "regular" pass is a function pass).
This is required because the mandatory pass needs to remove originals of specialized closures, which cannot be done from a function-pass.
In the old implementation this was done with a hack by adding a semantic attribute and deleting the function later in the pipeline.

I still kept the sources of the old pass for being able to bootstrap the compiler without a host compiler.

rdar://142756547
2025-06-20 08:15:04 +02:00

40 lines
1.2 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
AllocBoxToStack.swift
AssumeSingleThreaded.swift
AsyncDemotion.swift
BooleanLiteralFolding.swift
CleanupDebugSteps.swift
ClosureSpecialization.swift
ComputeEscapeEffects.swift
ComputeSideEffects.swift
CopyToBorrowOptimization.swift
DeadStoreElimination.swift
DeinitDevirtualizer.swift
DestroyHoisting.swift
DiagnoseInfiniteRecursion.swift
InitializeStaticGlobals.swift
LetPropertyLowering.swift
LifetimeDependenceDiagnostics.swift
LifetimeDependenceInsertion.swift
LifetimeDependenceScopeFixup.swift
ObjectOutliner.swift
ObjCBridgingOptimization.swift
MergeCondFails.swift
NamedReturnValueOptimization.swift
RedundantLoadElimination.swift
ReleaseDevirtualizer.swift
SimplificationPasses.swift
StackPromotion.swift
StripObjectHeaders.swift
TempLValueElimination.swift
TempRValueElimination.swift
)