Skip to content

SwiftCompilerSources: move the Context and MutatingContext protocols from the Optimizer to the SIL module #83367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SIL

extension FunctionPassContext {
var aliasAnalysis: AliasAnalysis {
let bridgedAA = _bridged.getAliasAnalysis()
let bridgedAA = bridgedPassContext.getAliasAnalysis()
return AliasAnalysis(bridged: bridgedAA, context: self)
}
}
Expand Down Expand Up @@ -113,15 +113,15 @@ struct AliasAnalysis {
bridgedAliasAnalysis.mutableCachePointer.assumingMemoryBound(to: Cache.self).deinitialize(count: 1)
},
// getMemEffectsFn
{ (bridgedCtxt: BridgedPassContext,
{ (bridgedCtxt: BridgedContext,
bridgedAliasAnalysis: BridgedAliasAnalysis,
bridgedAddr: BridgedValue,
bridgedInst: BridgedInstruction) -> BridgedMemoryBehavior in
let aa = AliasAnalysis(bridged: bridgedAliasAnalysis, context: FunctionPassContext(_bridged: bridgedCtxt))
return aa.getMemoryEffect(of: bridgedInst.instruction, on: bridgedAddr.value).bridged
},
// isObjReleasedFn
{ (bridgedCtxt: BridgedPassContext,
{ (bridgedCtxt: BridgedContext,
bridgedAliasAnalysis: BridgedAliasAnalysis,
bridgedObj: BridgedValue,
bridgedInst: BridgedInstruction) -> Bool in
Expand All @@ -142,7 +142,7 @@ struct AliasAnalysis {
},

// isAddrVisibleFromObj
{ (bridgedCtxt: BridgedPassContext,
{ (bridgedCtxt: BridgedContext,
bridgedAliasAnalysis: BridgedAliasAnalysis,
bridgedAddr: BridgedValue,
bridgedObj: BridgedValue) -> Bool in
Expand All @@ -159,7 +159,7 @@ struct AliasAnalysis {
},

// mayAliasFn
{ (bridgedCtxt: BridgedPassContext,
{ (bridgedCtxt: BridgedContext,
bridgedAliasAnalysis: BridgedAliasAnalysis,
bridgedLhs: BridgedValue,
bridgedRhs: BridgedValue) -> Bool in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

swift_compiler_sources(Optimizer
BasicBlockRange.swift
DeadEndBlocks.swift
FunctionUses.swift
InstructionRange.swift
ReachableBlocks.swift
Set.swift
Stack.swift
Worklist.swift)
ReachableBlocks.swift)
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private func tryConvertBoxesToStack(in function: Function, _ context: FunctionPa
hoistMarkUnresolvedInsts(stackAddress: stack, checkKind: .consumableAndAssignable, context)
}
if !promotableBoxes.isEmpty {
function.fixStackNesting(context)
context.fixStackNesting(in: function)
}

return functionsToSpecialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ let autodiffClosureSpecialization = FunctionPass(name: "autodiff-closure-special
}

if context.needFixStackNesting {
function.fixStackNesting(context)
context.fixStackNesting(in: function)
}

remainingSpecializationRounds -= 1
Expand Down Expand Up @@ -836,7 +836,7 @@ private extension SpecializationCloner {
}

if (self.context.needFixStackNesting) {
self.cloned.fixStackNesting(self.context)
self.context.fixStackNesting(in: self.cloned)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let computeEscapeEffects = FunctionPass(name: "compute-escape-effects") {
return
}

context.modifyEffects(in: function) { (effects: inout FunctionEffects) in
function.modifyEffects(context) { (effects: inout FunctionEffects) in
effects.escapeEffects.arguments = newEffects
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let computeSideEffects = FunctionPass(name: "compute-side-effects") {
}

// Finally replace the function's side effects.
context.modifyEffects(in: function) { (effects: inout FunctionEffects) in
function.modifyEffects(context) { (effects: inout FunctionEffects) in
let globalEffects = function.isProgramTerminationPoint ?
collectedEffects.globalEffects.forProgramTerminationPoints
: collectedEffects.globalEffects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func runSimplification(on function: Function, _ context: FunctionPassContext,
} while !worklist.isEmpty

if context.needFixStackNesting {
function.fixStackNesting(context)
context.fixStackNesting(in: function)
}

return changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let stackPromotion = FunctionPass(name: "stack-promotion") {
}
if needFixStackNesting {
// Make sure that all stack allocating instructions are nested correctly.
function.fixStackNesting(context)
context.fixStackNesting(in: function)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension BuiltinInst : OnoneSimplifiable, SILCombineSimplifiable {
case .Xor:
simplifyNegation(context)
default:
if let literal = constantFold(context) {
if let literal = context.constantFold(builtin: self) {
uses.replaceAll(with: literal, context)
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ private extension BuiltinInst {
if constantFoldStringNullPointerCheck(isEqual: isEqual, context) {
return
}
if let literal = constantFold(context) {
if let literal = context.constantFold(builtin: self) {
uses.replaceAll(with: literal, context)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private struct StackProtectionOptimization {
process(instruction: inst, in: function, mustFixStackNesting: &mustFixStackNesting, context)
}
if mustFixStackNesting {
function.fixStackNesting(context)
context.fixStackNesting(in: function)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

swift_compiler_sources(Optimizer
Context.swift
ContextCommon.swift
FunctionPassContext.swift
ModulePassContext.swift
Options.swift
Passes.swift
PassRegistration.swift)

PassRegistration.swift
SimplifyContext.swift)
Loading