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
}

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ private extension AccessBase {
462462
case .box, .global:
463463
return .no
464464
case .class(let rea):
465-
return .objectIfStackPromoted(rea.operand)
465+
return .objectIfStackPromoted(rea.instance)
466466
case .tail(let rta):
467-
return .objectIfStackPromoted(rta.operand)
467+
return .objectIfStackPromoted(rta.instance)
468468
case .argument(let arg):
469469
return .decidedInCaller(arg)
470470
case .yield, .pointer:
@@ -493,7 +493,7 @@ private extension Instruction {
493493

494494
// The result of an `address_to_pointer` may be used in any unsafe way, e.g.
495495
// passed to a C function.
496-
baseAddr = atp.operand
496+
baseAddr = atp.address
497497
case let ia as IndexAddrInst:
498498
if !ia.needsStackProtection {
499499
return nil

SwiftCompilerSources/Sources/Optimizer/TestPasses/AccessDumper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let accessDumper = FunctionPass(name: "dump-access", {
2929
case let st as StoreInst:
3030
printAccessInfo(address: st.destination)
3131
case let load as LoadInst:
32-
printAccessInfo(address: load.operand)
32+
printAccessInfo(address: load.address)
3333
case let apply as ApplyInst:
3434
guard let callee = apply.referencedFunction else {
3535
break

SwiftCompilerSources/Sources/Optimizer/TestPasses/EscapeInfoDumper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ let addressEscapeInfoDumper = FunctionPass(name: "dump-addr-escape-info", {
8080
for inst in function.instructions {
8181
switch inst {
8282
case let fli as FixLifetimeInst:
83-
valuesToCheck.append(fli.operand)
83+
valuesToCheck.append(fli.operand.value)
8484
case is FullApplySite:
8585
applies.append(inst)
8686
default:

SwiftCompilerSources/Sources/Optimizer/Utilities/AccessUtils.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
103103
case .stack(let asi): return "stack - \(asi)"
104104
case .global(let gl): return "global - @\(gl.name)"
105105
case .class(let rea): return "class - \(rea)"
106-
case .tail(let rta): return "tail - \(rta.operand)"
106+
case .tail(let rta): return "tail - \(rta.instance)"
107107
case .argument(let arg): return "argument - \(arg)"
108108
case .yield(let ba): return "yield - \(ba)"
109109
case .pointer(let p): return "pointer - \(p)"
@@ -123,9 +123,9 @@ enum AccessBase : CustomStringConvertible, Hashable {
123123
/// The reference value if this is an access to a referenced objecct (class, box, tail).
124124
var reference: Value? {
125125
switch self {
126-
case .box(let pbi): return pbi.operand
127-
case .class(let rea): return rea.operand
128-
case .tail(let rta): return rta.operand
126+
case .box(let pbi): return pbi.box
127+
case .class(let rea): return rea.instance
128+
case .tail(let rta): return rta.instance
129129
case .stack, .global, .argument, .yield, .pointer, .unidentified:
130130
return nil
131131
}
@@ -143,9 +143,9 @@ enum AccessBase : CustomStringConvertible, Hashable {
143143
/// True, if the address is immediately produced by an allocation in its function.
144144
var isLocal: Bool {
145145
switch self {
146-
case .box(let pbi): return pbi.operand is AllocBoxInst
147-
case .class(let rea): return rea.operand is AllocRefInstBase
148-
case .tail(let rta): return rta.operand is AllocRefInstBase
146+
case .box(let pbi): return pbi.box is AllocBoxInst
147+
case .class(let rea): return rea.instance is AllocRefInstBase
148+
case .tail(let rta): return rta.instance is AllocRefInstBase
149149
case .stack: return true
150150
case .global, .argument, .yield, .pointer, .unidentified:
151151
return false
@@ -193,16 +193,16 @@ enum AccessBase : CustomStringConvertible, Hashable {
193193
// First handle all pairs of the same kind (except `yield` and `pointer`).
194194
case (.box(let pb), .box(let otherPb)):
195195
return pb.fieldIndex != otherPb.fieldIndex ||
196-
isDifferentAllocation(pb.operand, otherPb.operand)
196+
isDifferentAllocation(pb.box, otherPb.box)
197197
case (.stack(let asi), .stack(let otherAsi)):
198198
return asi != otherAsi
199199
case (.global(let global), .global(let otherGlobal)):
200200
return global != otherGlobal
201201
case (.class(let rea), .class(let otherRea)):
202202
return rea.fieldIndex != otherRea.fieldIndex ||
203-
isDifferentAllocation(rea.operand, otherRea.operand)
203+
isDifferentAllocation(rea.instance, otherRea.instance)
204204
case (.tail(let rta), .tail(let otherRta)):
205-
return isDifferentAllocation(rta.operand, otherRta.operand)
205+
return isDifferentAllocation(rta.instance, otherRta.instance)
206206
case (.argument(let arg), .argument(let otherArg)):
207207
return (arg.convention.isExclusiveIndirect || otherArg.convention.isExclusiveIndirect) && arg != otherArg
208208

@@ -279,14 +279,14 @@ extension PointerToAddressInst {
279279

280280
mutating func rootDef(value: Value, path: SmallProjectionPath) -> WalkResult {
281281
if let atp = value as? AddressToPointerInst {
282-
if let res = result, atp.operand != res {
282+
if let res = result, atp.address != res {
283283
return .abortWalk
284284
}
285285

286-
if addrType != atp.operand.type { return .abortWalk }
286+
if addrType != atp.address.type { return .abortWalk }
287287
if !path.isEmpty { return .abortWalk }
288288

289-
self.result = atp.operand
289+
self.result = atp.address
290290
return .continueWalk
291291
}
292292
return .abortWalk
@@ -305,7 +305,7 @@ extension PointerToAddressInst {
305305
}
306306

307307
var walker = Walker(addrType: type)
308-
if walker.walkUp(value: operand, path: SmallProjectionPath()) == .abortWalk {
308+
if walker.walkUp(value: pointer, path: SmallProjectionPath()) == .abortWalk {
309309
return nil
310310
}
311311
return walker.result
@@ -473,11 +473,11 @@ extension ValueUseDefWalker where Path == SmallProjectionPath {
473473
let path = accessPath.projectionPath
474474
switch accessPath.base {
475475
case .box(let pbi):
476-
return walkUp(value: pbi.operand, path: path.push(.classField, index: pbi.fieldIndex)) != .abortWalk
476+
return walkUp(value: pbi.box, path: path.push(.classField, index: pbi.fieldIndex)) != .abortWalk
477477
case .class(let rea):
478-
return walkUp(value: rea.operand, path: path.push(.classField, index: rea.fieldIndex)) != .abortWalk
478+
return walkUp(value: rea.instance, path: path.push(.classField, index: rea.fieldIndex)) != .abortWalk
479479
case .tail(let rta):
480-
return walkUp(value: rta.operand, path: path.push(.tailElements, index: 0)) != .abortWalk
480+
return walkUp(value: rta.instance, path: path.push(.tailElements, index: 0)) != .abortWalk
481481
case .stack, .global, .argument, .yield, .pointer, .unidentified:
482482
return false
483483
}

0 commit comments

Comments
 (0)