Skip to content

Commit e871ae4

Browse files
authored
Merge pull request #71176 from eeckstein/borrowed-from-instruction
SIL: add the borrowed-from instruction
2 parents b6d6bd0 + e14c1d1 commit e871ae4

File tree

129 files changed

+1477
-837
lines changed

Some content is hidden

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

129 files changed

+1477
-837
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ struct OperandSet : IntrusiveSet {
228228
context.freeOperandSet(bridged)
229229
}
230230
}
231+
232+
extension IntrusiveSet {
233+
mutating func insert(contentsOf source: some Sequence<Element>) {
234+
for element in source {
235+
_ = insert(element)
236+
}
237+
}
238+
239+
init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
240+
self.init(context)
241+
insert(contentsOf: source)
242+
}
243+
}

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)