Skip to content

Commit 024c9f0

Browse files
Merge pull request #5317 from swiftwasm/main
[pull] swiftwasm from main
2 parents 9b4e20f + 83888d3 commit 024c9f0

File tree

141 files changed

+1789
-909
lines changed

Some content is hidden

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

141 files changed

+1789
-909
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeEscapeEffects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private struct IsExclusiveReturnEscapeVisitor : EscapeVisitorWithResult {
209209
var result = false
210210

211211
func isExclusiveEscape(returnInst: ReturnInst, _ context: FunctionPassContext) -> Bool {
212-
return returnInst.operand.at(returnPath).visit(using: self, context) ?? false
212+
return returnInst.returnedValue.at(returnPath).visit(using: self, context) ?? false
213213
}
214214

215215
mutating func visitUse(operand: Operand, path: EscapePath) -> UseResult {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private struct CollectedEffects {
9898
addDestroyEffects(ofValue: inst.operands[0].value)
9999

100100
case let da as DestroyAddrInst:
101-
addDestroyEffects(ofAddress: da.operand)
101+
addDestroyEffects(ofAddress: da.destroyedAddress)
102102

103103
case let copy as CopyAddrInst:
104104
addEffects(.read, to: copy.source)
@@ -146,7 +146,7 @@ private struct CollectedEffects {
146146
case let fl as FixLifetimeInst:
147147
// A fix_lifetime instruction acts like a read on the operand to prevent
148148
// releases moving above the fix_lifetime.
149-
addEffects(.read, to: fl.operand)
149+
addEffects(.read, to: fl.operand.value)
150150

151151
// Instructions which have effects defined in SILNodes.def, but those effects are
152152
// not relevant for our purpose.

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/MergeCondFails.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ let mergeCondFailsPass = FunctionPass(name: "merge-cond_fails", runMergeCondFail
1717
/// Return true if the operand of the cond_fail instruction looks like
1818
/// the overflow bit of an arithmetic instruction.
1919
private func hasOverflowConditionOperand(_ cfi: CondFailInst) -> Bool {
20-
if let tei = cfi.operand as? TupleExtractInst {
21-
return tei.operand is BuiltinInst
20+
if let tei = cfi.condition as? TupleExtractInst {
21+
return tei.operand.value is BuiltinInst
2222
}
2323
return false
2424
}
@@ -73,10 +73,10 @@ private func mergeCondFails(_ condFailToMerge: inout Stack<CondFailInst>,
7373
mergedCond = builder.createBuiltinBinaryFunction(name: "or",
7474
operandType: prevCond.type,
7575
resultType: prevCond.type,
76-
arguments: [prevCond, cfi.operand])
76+
arguments: [prevCond, cfi.condition])
7777
didMerge = true
7878
} else {
79-
mergedCond = cfi.operand
79+
mergedCond = cfi.condition
8080
}
8181
}
8282
if !didMerge {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ObjCBridgingOptimization.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ private func removeBridgingCodeInPredecessors(of block: BasicBlock, _ context: F
237237

238238
let en = branch.operands[0].value as! EnumInst
239239
context.erase(instruction: branch)
240-
let op = en.operand
240+
let payload = en.payload
241241
context.erase(instruction: en)
242-
if let bridgingCall = op {
242+
if let bridgingCall = payload {
243243
context.erase(instruction: bridgingCall as! ApplyInst)
244244
}
245245
}
@@ -249,7 +249,7 @@ private func lookThroughOwnershipInsts(_ value: Value) -> Value {
249249
// Looks like it's sufficient to support begin_borrow for now.
250250
// TODO: add copy_value if needed.
251251
if let bbi = value as? BeginBorrowInst {
252-
return bbi.operand
252+
return bbi.borrowedValue
253253
}
254254
return value
255255
}
@@ -286,10 +286,10 @@ private func isOptionalBridging(of value: Value, isBridging: (Value) -> ApplyIns
286286
singleEnumUse.instruction is BranchInst else {
287287
return nil
288288
}
289-
if let enumOp = enumInst.operand {
289+
if let payload = enumInst.payload {
290290
// The some-case
291291
if someSwitch != nil { return nil }
292-
guard let bridgingCall = isBridging(enumOp),
292+
guard let bridgingCall = isBridging(payload),
293293
bridgingCall.uses.isSingleUse else {
294294
return nil
295295
}
@@ -298,8 +298,8 @@ private func isOptionalBridging(of value: Value, isBridging: (Value) -> ApplyIns
298298
// If it's an ObjC -> Swift bridging call the argument is wrapped into an optional enum.
299299
if callArgument.type.isEnum {
300300
guard let sourceEnum = callArgument as? EnumInst,
301-
let sourceEnumOp = sourceEnum.operand,
302-
let (se, someCase) = isPayloadOfSwitchEnum(sourceEnumOp),
301+
let sourcePayload = sourceEnum.payload,
302+
let (se, someCase) = isPayloadOfSwitchEnum(sourcePayload),
303303
enumInst.caseIndex == someCase,
304304
sourceEnum.caseIndex == someCase,
305305
sourceEnum.type == se.enumOp.type else {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ReleaseDevirtualizer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private func tryDevirtualizeReleaseOfObject(
7878
// Check if the release instruction right before the `dealloc_stack_ref` really releases
7979
// the allocated object (and not something else).
8080
var finder = FindAllocationOfRelease(allocation: allocRefInstruction)
81-
if !finder.allocationIsRoot(of: release.operand) {
81+
if !finder.allocationIsRoot(of: release.operand.value) {
8282
return
8383
}
8484

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBeginCOWMutation.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension BeginCOWMutationInst : Simplifyable, SILCombineSimplifyable {
5656
private extension BeginCOWMutationInst {
5757

5858
func optimizeEmptySingleton(_ context: SimplifyContext) {
59-
if !isEmptyCOWSingleton(operand) {
59+
if !isEmptyCOWSingleton(instance) {
6060
return
6161
}
6262
if uniquenessResult.nonDebugUses.isEmpty {
@@ -73,14 +73,14 @@ private extension BeginCOWMutationInst {
7373
if !uniquenessResult.nonDebugUses.isEmpty {
7474
return false
7575
}
76-
let buffer = bufferResult
76+
let buffer = instanceResult
7777
if buffer.nonDebugUses.contains(where: { !($0.instruction is EndCOWMutationInst) }) {
7878
return false
7979
}
8080

8181
for use in buffer.nonDebugUses {
8282
let endCOW = use.instruction as! EndCOWMutationInst
83-
endCOW.uses.replaceAll(with: operand, context)
83+
endCOW.uses.replaceAll(with: instance, context)
8484
context.erase(instruction: endCOW)
8585
}
8686
context.erase(instructionIncludingDebugUses: self)
@@ -91,14 +91,14 @@ private extension BeginCOWMutationInst {
9191
if !uniquenessResult.nonDebugUses.isEmpty {
9292
return false
9393
}
94-
guard let endCOW = operand as? EndCOWMutationInst else {
94+
guard let endCOW = instance as? EndCOWMutationInst else {
9595
return false
9696
}
9797
if endCOW.nonDebugUses.contains(where: { $0.instruction != self }) {
9898
return false
9999
}
100100

101-
bufferResult.uses.replaceAll(with: endCOW.operand, context)
101+
instanceResult.uses.replaceAll(with: endCOW.instance, context)
102102
context.erase(instructionIncludingDebugUses: self)
103103
context.erase(instructionIncludingDebugUses: endCOW)
104104
return true
@@ -114,7 +114,7 @@ private func isEmptyCOWSingleton(_ value: Value) -> Bool {
114114
is RawPointerToRefInst,
115115
is AddressToPointerInst,
116116
is CopyValueInst:
117-
v = (v as! UnaryInstruction).operand
117+
v = (v as! UnaryInstruction).operand.value
118118
case let globalAddr as GlobalAddrInst:
119119
let name = globalAddr.global.name
120120
return name == "_swiftEmptyArrayStorage" ||

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ private func typesOfValuesAreEqual(_ lhs: Value, _ rhs: Value, in function: Func
7676
return nil
7777
}
7878

79-
let lhsTy = lhsExistential.operand.type.instanceTypeOfMetatype(in: function)
80-
let rhsTy = rhsExistential.operand.type.instanceTypeOfMetatype(in: function)
79+
let lhsTy = lhsExistential.metatype.type.instanceTypeOfMetatype(in: function)
80+
let rhsTy = rhsExistential.metatype.type.instanceTypeOfMetatype(in: function)
8181

8282
// Do we know the exact types? This is not the case e.g. if a type is passed as metatype
8383
// to the function.
84-
let typesAreExact = lhsExistential.operand is MetatypeInst &&
85-
rhsExistential.operand is MetatypeInst
84+
let typesAreExact = lhsExistential.metatype is MetatypeInst &&
85+
rhsExistential.metatype is MetatypeInst
8686

8787
switch (lhsTy.typeKind, rhsTy.typeKind) {
8888
case (_, .unknown), (.unknown, _):

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyStrongRetainRelease.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SIL
1414

1515
extension StrongRetainInst : Simplifyable, SILCombineSimplifyable {
1616
func simplify(_ context: SimplifyContext) {
17-
if isNotReferenceCounted(value: operand) {
17+
if isNotReferenceCounted(value: instance) {
1818
context.erase(instruction: self)
1919
return
2020
}
@@ -34,7 +34,7 @@ extension StrongRetainInst : Simplifyable, SILCombineSimplifyable {
3434
// peephole.
3535
if let prev = previous {
3636
if let release = prev as? StrongReleaseInst {
37-
if release.operand == operand {
37+
if release.instance == self.instance {
3838
context.erase(instruction: self)
3939
context.erase(instruction: release)
4040
return
@@ -46,7 +46,7 @@ extension StrongRetainInst : Simplifyable, SILCombineSimplifyable {
4646

4747
extension StrongReleaseInst : Simplifyable, SILCombineSimplifyable {
4848
func simplify(_ context: SimplifyContext) {
49-
let op = operand
49+
let op = instance
5050
if isNotReferenceCounted(value: op) {
5151
context.erase(instruction: self)
5252
return
@@ -56,7 +56,7 @@ extension StrongReleaseInst : Simplifyable, SILCombineSimplifyable {
5656
// release of the class, squish the conversion.
5757
if let ier = op as? InitExistentialRefInst {
5858
if ier.uses.isSingleUse {
59-
setOperand(at: 0, to: ier.operand, context)
59+
setOperand(at: 0, to: ier.instance, context)
6060
context.erase(instruction: ier)
6161
return
6262
}
@@ -69,11 +69,11 @@ extension StrongReleaseInst : Simplifyable, SILCombineSimplifyable {
6969
private func isNotReferenceCounted(value: Value) -> Bool {
7070
switch value {
7171
case let cfi as ConvertFunctionInst:
72-
return isNotReferenceCounted(value: cfi.operand)
72+
return isNotReferenceCounted(value: cfi.fromFunction)
7373
case let uci as UpcastInst:
74-
return isNotReferenceCounted(value: uci.operand)
74+
return isNotReferenceCounted(value: uci.fromInstance)
7575
case let urc as UncheckedRefCastInst:
76-
return isNotReferenceCounted(value: urc.operand)
76+
return isNotReferenceCounted(value: urc.fromInstance)
7777
case let gvi as GlobalValueInst:
7878
// Since Swift 5.1, statically allocated objects have "immortal" reference
7979
// counts. Therefore we can safely eliminate unbalanced retains and
@@ -90,8 +90,8 @@ private func isNotReferenceCounted(value: Value) -> Bool {
9090
// %0 = global_addr @_swiftEmptyArrayStorage
9191
// %1 = address_to_pointer %0
9292
// %2 = raw_pointer_to_ref %1
93-
if let atp = rptr.operand as? AddressToPointerInst {
94-
return atp.operand is GlobalAddrInst
93+
if let atp = rptr.pointer as? AddressToPointerInst {
94+
return atp.address is GlobalAddrInst
9595
}
9696
}
9797
return false

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyStructExtract.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SIL
1414

1515
extension StructExtractInst : OnoneSimplifyable {
1616
func simplify(_ context: SimplifyContext) {
17-
guard let structInst = operand as? StructInst else {
17+
guard let structInst = self.struct as? StructInst else {
1818
return
1919
}
2020
context.tryReplaceRedundantInstructionPair(first: structInst, second: self,

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyUncheckedEnumData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import SIL
1414

1515
extension UncheckedEnumDataInst : OnoneSimplifyable {
1616
func simplify(_ context: SimplifyContext) {
17-
guard let enumInst = operand as? EnumInst else {
17+
guard let enumInst = self.enum as? EnumInst else {
1818
return
1919
}
2020
if caseIndex != enumInst.caseIndex {
2121
return
2222
}
23-
context.tryReplaceRedundantInstructionPair(first: enumInst, second: self, with: enumInst.operand)
23+
context.tryReplaceRedundantInstructionPair(first: enumInst, second: self, with: enumInst.payload!)
2424
}
2525
}

0 commit comments

Comments
 (0)