Skip to content

Commit 9ddaf33

Browse files
committed
SIL, Optimizer: update and handle borrowed-from instructions
Compute, update and handle borrowed-from instruction in various utilities and passes. Also, used borrowed-from to simplify `gatherBorrowIntroducers` and `gatherEnclosingValues`. Replace those utilities by `Value.getBorrowIntroducers` and `Value.getEnclosingValues`, which return a lazily computed Sequence of borrowed/enclosing values.
1 parent 6bb6ca3 commit 9ddaf33

File tree

98 files changed

+1153
-821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1153
-821
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBranch.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ private extension BranchInst {
4949
let parentBB = parentBlock
5050

5151
for (argIdx, op) in operands.enumerated() {
52-
targetBB.arguments[argIdx].uses.replaceAll(with: op.value, context)
52+
let arg = targetBB.arguments[argIdx]
53+
if let phi = Phi(arg),
54+
let bfi = phi.borrowedFrom
55+
{
56+
bfi.uses.replaceAll(with: op.value, context)
57+
context.erase(instruction: bfi)
58+
} else {
59+
arg.uses.replaceAll(with: op.value, context)
60+
}
5361
}
5462
targetBB.eraseAllArguments(context)
5563

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifySwitchEnum.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ extension SwitchEnumInst : OnoneSimplifyable {
4848
precondition(enumInst.payload == nil || !parentFunction.hasOwnership,
4949
"missing payload argument in switch_enum case block")
5050
builder.createBranch(to: caseBlock)
51+
context.erase(instruction: self)
5152
case 1:
5253
builder.createBranch(to: caseBlock, arguments: [enumInst.payload!])
54+
context.erase(instruction: self)
55+
updateBorrowedFrom(for: [Phi(caseBlock.arguments[0])!], context)
5356
default:
5457
fatalError("case block of switch_enum cannot have more than 1 argument")
5558
}
56-
context.erase(instruction: self)
5759

5860
if canEraseEnumInst {
5961
context.erase(instructionIncludingDebugUses: enumInst)

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private func registerSwiftPasses() {
117117
registerPass(rangeDumper, { rangeDumper.run($0) })
118118
registerPass(runUnitTests, { runUnitTests.run($0) })
119119
registerPass(testInstructionIteration, { testInstructionIteration.run($0) })
120+
registerPass(updateBorrowedFromPass, { updateBorrowedFromPass.run($0) })
120121
}
121122

122123
private func registerSwiftAnalyses() {
@@ -126,4 +127,5 @@ private func registerSwiftAnalyses() {
126127

127128
private func registerUtilities() {
128129
registerVerifier()
130+
registerBorrowedFromUpdater()
129131
}

0 commit comments

Comments
 (0)