Skip to content

Commit de14247

Browse files
authored
Merge pull request #84949 from eeckstein/operand-apis
SIL: streamline Operand Sequence APIs
2 parents a375fa1 + 610539a commit de14247

File tree

14 files changed

+34
-47
lines changed

14 files changed

+34
-47
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocBoxToStack.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private func createAllocStack(for allocBox: AllocBoxInst, flags: Flags, _ contex
363363
isLexical: flags.isLexical,
364364
isFromVarDecl: flags.isFromVarDecl)
365365
let stackLocation: Value
366-
if let mu = allocBox.uses.getSingleUser(ofType: MarkUninitializedInst.self) {
366+
if let mu = allocBox.uses.singleUser(ofType: MarkUninitializedInst.self) {
367367
stackLocation = builder.createMarkUninitialized(value: asi, kind: mu.kind)
368368
} else {
369369
stackLocation = asi
@@ -484,7 +484,7 @@ private func hoistMarkUnresolvedInsts(stackAddress: Value,
484484
builder = Builder(atBeginOf: stackAddress.parentBlock, context)
485485
}
486486
let mu = builder.createMarkUnresolvedNonCopyableValue(value: stackAddress, checkKind: checkKind, isStrict: false)
487-
stackAddress.uses.ignore(user: mu).ignoreDebugUses.ignoreUses(ofType: DeallocStackInst.self)
487+
stackAddress.uses.ignore(user: mu).ignoreDebugUses.ignore(usersOfType: DeallocStackInst.self)
488488
.replaceAll(with: mu, context)
489489
}
490490

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ConstantCapturePropagation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private func rewritePartialApply(_ partialApply: PartialApplyInst, withSpecializ
233233
// leave the key path itself out of the dependency chain, and introduce dependencies on those
234234
// operands instead, so that the key path object itself can be made dead.
235235
for md in newClosure.uses.users(ofType: MarkDependenceInst.self) {
236-
if md.base.uses.getSingleUser(ofType: PartialApplyInst.self) == partialApply {
236+
if md.base.uses.singleUser(ofType: PartialApplyInst.self) == partialApply {
237237
md.replace(with: newClosure, context)
238238
}
239239
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DestroyHoisting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let destroyHoisting = FunctionPass(name: "destroy-hoisting") {
8383
private func optimize(value: Value, _ context: FunctionPassContext) {
8484
guard value.ownership == .owned,
8585
// Avoid all the analysis effort if there are no destroys to hoist.
86-
!value.uses.filterUses(ofType: DestroyValueInst.self).isEmpty
86+
!value.uses.filter(usersOfType: DestroyValueInst.self).isEmpty
8787
else {
8888
return
8989
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/InitializeStaticGlobals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ private struct InitValueBuilder: AddressDefUseWalker {
478478
case .PrepareInitialization:
479479
return .continueWalk
480480
case .AddressOfRawLayout:
481-
if let addr2Ptr = bi.uses.getSingleUser(ofType: PointerToAddressInst.self) {
481+
if let addr2Ptr = bi.uses.singleUser(ofType: PointerToAddressInst.self) {
482482
return walkDownUses(ofAddress: addr2Ptr, path: path)
483483
}
484484
return .abortWalk

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/TempRValueElimination.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private func tryEliminate(copy: CopyLikeInstruction, keepDebugInfo: Bool, _ cont
8383
removeDestroys(of: allocStack, context)
8484
}
8585

86-
allocStack.uses.ignoreUses(ofType: DeallocStackInst.self).replaceAll(with: copy.sourceAddress, context)
86+
allocStack.uses.ignore(usersOfType: DeallocStackInst.self).replaceAll(with: copy.sourceAddress, context)
8787

8888
if keepDebugInfo {
8989
Builder(before: copy, context).createDebugStep()
@@ -247,7 +247,7 @@ private extension AllocStackInst {
247247
var liferange = InstructionRange(begin: self, context)
248248
defer { liferange.deinitialize() }
249249

250-
liferange.insert(contentsOf: uses.ignoreUses(ofType: DeallocStackInst.self).lazy.map { $0.instruction })
250+
liferange.insert(contentsOf: uses.ignore(usersOfType: DeallocStackInst.self).lazy.map { $0.instruction })
251251

252252
for use in uses {
253253
switch use.instruction {

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyAllocStack.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private extension AllocStackInst {
207207
iea.replace(with: newAlloc, context)
208208
}
209209
case let oea as OpenExistentialAddrInst:
210-
assert(oea.uses.ignoreUses(ofType: DestroyAddrInst.self).isEmpty)
210+
assert(oea.uses.ignore(usersOfType: DestroyAddrInst.self).isEmpty)
211211
oea.replace(with: newAlloc, context)
212212
case let cab as CheckedCastAddrBranchInst:
213213
let builder = Builder(before: cab, context)
@@ -247,7 +247,7 @@ private extension AllocStackInst {
247247
is DebugValueInst:
248248
break
249249
case let oea as OpenExistentialAddrInst:
250-
if !oea.uses.ignoreUses(ofType: DestroyAddrInst.self).isEmpty {
250+
if !oea.uses.ignore(usersOfType: DestroyAddrInst.self).isEmpty {
251251
return nil
252252
}
253253
case let iea as InitExistentialAddrInst:

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBeginAndLoadBorrow.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension BeginBorrowInst : OnoneSimplifiable, SILCombineSimplifiable {
2929

3030
extension LoadBorrowInst : Simplifiable, SILCombineSimplifiable {
3131
func simplify(_ context: SimplifyContext) {
32-
if uses.ignoreDebugUses.ignoreUses(ofType: EndBorrowInst.self).isEmpty {
32+
if uses.ignoreDebugUses.ignore(usersOfType: EndBorrowInst.self).isEmpty {
3333
context.erase(instructionIncludingAllUsers: self)
3434
return
3535
}
@@ -52,7 +52,7 @@ extension LoadBorrowInst : Simplifiable, SILCombineSimplifiable {
5252

5353
private func tryCombineWithCopy(_ context: SimplifyContext) {
5454
let forwardedValue = lookThroughSingleForwardingUses()
55-
guard let singleUser = forwardedValue.uses.ignoreUses(ofType: EndBorrowInst.self).singleUse?.instruction,
55+
guard let singleUser = forwardedValue.uses.ignore(usersOfType: EndBorrowInst.self).singleUse?.instruction,
5656
let copy = singleUser as? CopyValueInst,
5757
copy.parentBlock == self.parentBlock else {
5858
return
@@ -81,13 +81,13 @@ private func tryReplaceBorrowWithOwnedOperand(beginBorrow: BeginBorrowInst, _ co
8181
private func removeBorrowOfThinFunction(beginBorrow: BeginBorrowInst, _ context: SimplifyContext) {
8282
guard let thin2thickFn = beginBorrow.borrowedValue as? ThinToThickFunctionInst,
8383
// For simplicity don't go into the trouble of removing reborrow phi arguments.
84-
beginBorrow.uses.filterUses(ofType: BranchInst.self).isEmpty else
84+
beginBorrow.uses.filter(usersOfType: BranchInst.self).isEmpty else
8585
{
8686
return
8787
}
8888
// `thin_to_thick_function` has "none" ownership and is compatible with guaranteed values.
8989
// Therefore the `begin_borrow` is not needed.
90-
beginBorrow.uses.ignoreUses(ofType: EndBorrowInst.self).replaceAll(with: thin2thickFn, context)
90+
beginBorrow.uses.ignore(usersOfType: EndBorrowInst.self).replaceAll(with: thin2thickFn, context)
9191
context.erase(instructionIncludingAllUsers: beginBorrow)
9292
}
9393

@@ -110,7 +110,7 @@ private func tryReplaceCopy(
110110
withCopiedOperandOf beginBorrow: BeginBorrowInst,
111111
_ context: SimplifyContext
112112
) -> Bool {
113-
guard let singleUser = forwardedValue.uses.ignoreUses(ofType: EndBorrowInst.self).singleUse?.instruction,
113+
guard let singleUser = forwardedValue.uses.ignore(usersOfType: EndBorrowInst.self).singleUse?.instruction,
114114
let copy = singleUser as? CopyValueInst,
115115
copy.parentBlock == beginBorrow.parentBlock else {
116116
return false
@@ -153,7 +153,7 @@ private extension Value {
153153
/// ```
154154
/// Returns self if this value has no uses which are ForwardingInstructions.
155155
func lookThroughSingleForwardingUses() -> Value {
156-
if let singleUse = uses.ignoreUses(ofType: EndBorrowInst.self).singleUse,
156+
if let singleUse = uses.ignore(usersOfType: EndBorrowInst.self).singleUse,
157157
let fwdInst = singleUse.instruction as? (SingleValueInstruction & ForwardingInstruction),
158158
fwdInst.canConvertToOwned,
159159
fwdInst.isSingleForwardedOperand(singleUse),
@@ -165,17 +165,17 @@ private extension Value {
165165
}
166166

167167
var allUsesCanBeConvertedToOwned: Bool {
168-
let relevantUses = uses.ignoreUses(ofType: EndBorrowInst.self)
168+
let relevantUses = uses.ignore(usersOfType: EndBorrowInst.self)
169169
return relevantUses.allSatisfy { $0.canAccept(ownership: .owned) }
170170
}
171171

172172
func isDestroyed(after nonDestroyUser: Instruction) -> Bool {
173-
return uses.getSingleUser(notOfType: DestroyValueInst.self) == nonDestroyUser &&
173+
return uses.singleUser(notOfType: DestroyValueInst.self) == nonDestroyUser &&
174174
nonDestroyUser.dominates(destroysOf: self)
175175
}
176176

177177
func replaceAllDestroys(with replacement: Value, _ context: SimplifyContext) {
178-
uses.filterUses(ofType: DestroyValueInst.self).replaceAll(with: replacement, context)
178+
uses.filter(usersOfType: DestroyValueInst.self).replaceAll(with: replacement, context)
179179
}
180180
}
181181

@@ -187,7 +187,7 @@ private extension Instruction {
187187
// The value and instruction are in the same block. All uses are dominated by both.
188188
return true
189189
}
190-
let destroys = value.uses.filterUses(ofType: DestroyValueInst.self)
190+
let destroys = value.uses.filter(usersOfType: DestroyValueInst.self)
191191
return destroys.allSatisfy({ $0.instruction.parentBlock == parentBlock})
192192
}
193193
}

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ private extension Value {
406406
// var p = Point(x: 10, y: 20)
407407
// let o = UnsafePointer(&p)
408408
// Therefore ignore the `end_access` use of a `begin_access`.
409-
let relevantUses = singleUseValue.uses.ignoreDebugUses.ignoreUses(ofType: EndAccessInst.self)
409+
let relevantUses = singleUseValue.uses.ignoreDebugUses.ignore(usersOfType: EndAccessInst.self)
410410

411411
guard let use = relevantUses.singleUse else {
412412
return nil

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private struct StackProtectionOptimization {
361361
let builder = Builder(after: beginAccess, location: beginAccess.location.asAutoGenerated, context)
362362
let temporary = builder.createAllocStack(beginAccess.type)
363363

364-
beginAccess.uses.ignoreUses(ofType: EndAccessInst.self).replaceAll(with: temporary, context)
364+
beginAccess.uses.ignore(usersOfType: EndAccessInst.self).replaceAll(with: temporary, context)
365365

366366
for endAccess in beginAccess.endInstructions {
367367
let endBuilder = Builder(before: endAccess, location: endAccess.location.asAutoGenerated, context)

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ extension Instruction {
432432
case .USubOver:
433433
// Handle StringObjectOr(tuple_extract(usub_with_overflow(x, offset)), bits)
434434
// This pattern appears in UTF8 String literal construction.
435-
if let tei = bi.uses.getSingleUser(ofType: TupleExtractInst.self),
435+
if let tei = bi.uses.singleUser(ofType: TupleExtractInst.self),
436436
tei.isResultOfOffsetSubtract {
437437
return true
438438
}
@@ -446,7 +446,7 @@ extension Instruction {
446446
// Handle StringObjectOr(tuple_extract(usub_with_overflow(x, offset)), bits)
447447
// This pattern appears in UTF8 String literal construction.
448448
if tei.isResultOfOffsetSubtract,
449-
let bi = tei.uses.getSingleUser(ofType: BuiltinInst.self),
449+
let bi = tei.uses.singleUser(ofType: BuiltinInst.self),
450450
bi.id == .StringObjectOr {
451451
return true
452452
}

0 commit comments

Comments
 (0)