Skip to content

Commit efcd90a

Browse files
committed
Swift SIL: rename ownership enums and properties in LoadInst and StoreInst
`ownership` is a bad name in `LoadInst`, because it hides `Value.ownership`. Therefore rename it to `loadOwnership`. Do the same for ownership in StoreInst to be consistent.
1 parent 06d7403 commit efcd90a

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private struct CollectedEffects {
113113

114114
case let store as StoreInst:
115115
addEffects(.write, to: store.destination)
116-
if store.destinationOwnership == .assign {
116+
if store.storeOwnership == .assign {
117117
addDestroyEffects(ofAddress: store.destination)
118118
}
119119

@@ -454,7 +454,7 @@ private struct ArgumentEscapingWalker : ValueDefUseWalker, AddressDefUseWalker {
454454
case let load as LoadInst:
455455
if !address.value.hasTrivialType &&
456456
// In non-ossa SIL we don't know if a load is taking.
457-
(!function.hasOwnership || load.ownership == .take) {
457+
(!function.hasOwnership || load.loadOwnership == .take) {
458458
foundTakingLoad = true
459459
}
460460
return .continueWalk

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DeadStoreElimination.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,22 @@ private extension StoreInst {
154154
for idx in 0..<type.getNominalFields(in: parentFunction).count {
155155
let srcField = builder.createStructExtract(struct: source, fieldIndex: idx)
156156
let destFieldAddr = builder.createStructElementAddr(structAddress: destination, fieldIndex: idx)
157-
builder.createStore(source: srcField, destination: destFieldAddr, ownership: destinationOwnership)
157+
builder.createStore(source: srcField, destination: destFieldAddr, ownership: storeOwnership)
158158
}
159159
context.erase(instruction: self)
160160
} else if type.isTuple {
161161
let builder = Builder(after: self, context)
162162
for idx in 0..<type.tupleElements.count {
163163
let srcField = builder.createTupleExtract(tuple: source, elementIndex: idx)
164164
let destFieldAddr = builder.createTupleElementAddr(tupleAddress: destination, elementIndex: idx)
165-
builder.createStore(source: srcField, destination: destFieldAddr, ownership: destinationOwnership)
165+
builder.createStore(source: srcField, destination: destFieldAddr, ownership: storeOwnership)
166166
}
167167
context.erase(instruction: self)
168168
}
169169
}
170170

171171
var hasValidOwnershipForDeadStoreElimination: Bool {
172-
switch destinationOwnership {
172+
switch storeOwnership {
173173
case .unqualified, .trivial:
174174
return true
175175
case .initialize, .assign:

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyInitEnumDataAddr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension InitEnumDataAddrInst : OnoneSimplifyable {
4343

4444
let builder = Builder(before: store, context)
4545
let enumInst = builder.createEnum(caseIndex: self.caseIndex, payload: store.source, enumType: self.enum.type.objectType)
46-
let storeOwnership = StoreInst.Ownership(for: self.enum.type, in: parentFunction, initialize: true)
46+
let storeOwnership = StoreInst.StoreOwnership(for: self.enum.type, in: parentFunction, initialize: true)
4747
builder.createStore(source: enumInst, destination: self.enum, ownership: storeOwnership)
4848
context.erase(instruction: store)
4949
context.erase(instruction: inject)

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyLoad.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension LoadInst : OnoneSimplifyable, SILCombineSimplifyable {
4545

4646
operand.set(to: uac.fromAddress, context)
4747
let builder = Builder(before: self, context)
48-
let newLoad = builder.createLoad(fromAddress: uac.fromAddress, ownership: ownership)
48+
let newLoad = builder.createLoad(fromAddress: uac.fromAddress, ownership: loadOwnership)
4949
let cast = builder.createUpcast(from: newLoad, to: type)
5050
uses.replaceAll(with: cast, context)
5151
context.erase(instruction: self)
@@ -184,7 +184,7 @@ extension LoadInst : OnoneSimplifyable, SILCombineSimplifyable {
184184

185185
/// Removes the `load [copy]` if the loaded value is just destroyed.
186186
private func removeIfDead(_ context: SimplifyContext) {
187-
if ownership == .copy,
187+
if loadOwnership == .copy,
188188
loadedValueIsDead(context) {
189189
for use in uses {
190190
context.erase(instruction: use.instruction)

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
435435
case is StoreInst, is StoreWeakInst, is StoreUnownedInst:
436436
let store = instruction as! StoringInstruction
437437
assert(operand == store.destinationOperand)
438-
if let si = store as? StoreInst, si.destinationOwnership == .assign {
438+
if let si = store as? StoreInst, si.storeOwnership == .assign {
439439
if handleDestroy(of: operand.value, path: path.with(knownType: nil)) == .abortWalk {
440440
return .abortWalk
441441
}

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public struct Builder {
113113
return notifyNew(cast.getAs(UpcastInst.self))
114114
}
115115

116-
public func createLoad(fromAddress: Value, ownership: LoadInst.Ownership) -> LoadInst {
116+
public func createLoad(fromAddress: Value, ownership: LoadInst.LoadOwnership) -> LoadInst {
117117
let load = bridged.createLoad(fromAddress.bridged, ownership.rawValue)
118118
return notifyNew(load.getAs(LoadInst.self))
119119
}
@@ -274,7 +274,7 @@ public struct Builder {
274274
}
275275

276276
@discardableResult
277-
public func createStore(source: Value, destination: Value, ownership: StoreInst.Ownership) -> StoreInst {
277+
public func createStore(source: Value, destination: Value, ownership: StoreInst.StoreOwnership) -> StoreInst {
278278
let store = bridged.createStore(source.bridged, destination.bridged, ownership.rawValue)
279279
return notifyNew(store.getAs(StoreInst.self))
280280
}

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ extension StoringInstruction {
228228

229229
final public class StoreInst : Instruction, StoringInstruction {
230230
// must match with enum class StoreOwnershipQualifier
231-
public enum Ownership: Int {
231+
public enum StoreOwnership: Int {
232232
case unqualified = 0, initialize = 1, assign = 2, trivial = 3
233233

234234
public init(for type: Type, in function: Function, initialize: Bool) {
@@ -243,8 +243,8 @@ final public class StoreInst : Instruction, StoringInstruction {
243243
}
244244
}
245245
}
246-
public var destinationOwnership: Ownership {
247-
Ownership(rawValue: bridged.StoreInst_getStoreOwnership())!
246+
public var storeOwnership: StoreOwnership {
247+
StoreOwnership(rawValue: bridged.StoreInst_getStoreOwnership())!
248248
}
249249
}
250250

@@ -387,11 +387,11 @@ final public class LoadInst : SingleValueInstruction, UnaryInstruction {
387387
public var address: Value { operand.value }
388388

389389
// must match with enum class LoadOwnershipQualifier
390-
public enum Ownership: Int {
390+
public enum LoadOwnership: Int {
391391
case unqualified = 0, take = 1, copy = 2, trivial = 3
392392
}
393-
public var ownership: Ownership {
394-
Ownership(rawValue: bridged.LoadInst_getLoadOwnership())!
393+
public var loadOwnership: LoadOwnership {
394+
LoadOwnership(rawValue: bridged.LoadInst_getLoadOwnership())!
395395
}
396396
}
397397

0 commit comments

Comments
 (0)