Skip to content
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
13 changes: 13 additions & 0 deletions SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,16 @@ struct OperandSet : IntrusiveSet {
context.freeOperandSet(bridged)
}
}

extension IntrusiveSet {
mutating func insert(contentsOf source: some Sequence<Element>) {
for element in source {
_ = insert(element)
}
}

init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
self.init(context)
insert(contentsOf: source)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ private extension BranchInst {
let parentBB = parentBlock

for (argIdx, op) in operands.enumerated() {
targetBB.arguments[argIdx].uses.replaceAll(with: op.value, context)
let arg = targetBB.arguments[argIdx]
if let phi = Phi(arg),
let bfi = phi.borrowedFrom
{
bfi.uses.replaceAll(with: op.value, context)
context.erase(instruction: bfi)
} else {
arg.uses.replaceAll(with: op.value, context)
}
}
targetBB.eraseAllArguments(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ extension SwitchEnumInst : OnoneSimplifyable {
precondition(enumInst.payload == nil || !parentFunction.hasOwnership,
"missing payload argument in switch_enum case block")
builder.createBranch(to: caseBlock)
context.erase(instruction: self)
case 1:
builder.createBranch(to: caseBlock, arguments: [enumInst.payload!])
context.erase(instruction: self)
updateBorrowedFrom(for: [Phi(caseBlock.arguments[0])!], context)
default:
fatalError("case block of switch_enum cannot have more than 1 argument")
}
context.erase(instruction: self)

if canEraseEnumInst {
context.erase(instructionIncludingDebugUses: enumInst)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private func registerSwiftPasses() {
registerPass(rangeDumper, { rangeDumper.run($0) })
registerPass(runUnitTests, { runUnitTests.run($0) })
registerPass(testInstructionIteration, { testInstructionIteration.run($0) })
registerPass(updateBorrowedFromPass, { updateBorrowedFromPass.run($0) })
}

private func registerSwiftAnalyses() {
Expand All @@ -126,4 +127,5 @@ private func registerSwiftAnalyses() {

private func registerUtilities() {
registerVerifier()
registerBorrowedFromUpdater()
}
Loading