Skip to content

Commit 6428a7b

Browse files
committed
Optimizer: move protocol CopyLikeInstruction from TempRValueElimination to OptUtils, so that other passes can use it as well
1 parent b4010e6 commit 6428a7b

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/TempRValueElimination.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,6 @@ private func removeTempRValues(in function: Function, keepDebugInfo: Bool, _ con
6666
}
6767
}
6868

69-
private protocol CopyLikeInstruction: Instruction {
70-
var sourceAddress: Value { get }
71-
var destinationAddress: Value { get }
72-
var isTakeOfSource: Bool { get }
73-
var isInitializationOfDestination: Bool { get }
74-
var loadingInstruction: Instruction { get }
75-
}
76-
77-
extension CopyAddrInst: CopyLikeInstruction {
78-
var sourceAddress: Value { source }
79-
var destinationAddress: Value { destination }
80-
var loadingInstruction: Instruction { self }
81-
}
82-
83-
// A `store` which has a `load` as source operand. This is basically the same as a `copy_addr`.
84-
extension StoreInst: CopyLikeInstruction {
85-
var sourceAddress: Value { load.address }
86-
var destinationAddress: Value { destination }
87-
var isTakeOfSource: Bool { load.loadOwnership == .take }
88-
var isInitializationOfDestination: Bool { storeOwnership != .assign }
89-
var loadingInstruction: Instruction { load }
90-
private var load: LoadInst { source as! LoadInst }
91-
}
92-
9369
private func tryEliminate(copy: CopyLikeInstruction, keepDebugInfo: Bool, _ context: FunctionPassContext) {
9470

9571
guard let (allocStack, lastUseOfAllocStack) =

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,3 +974,30 @@ extension Type {
974974
return context._bridged.shouldExpand(self.bridged)
975975
}
976976
}
977+
978+
/// Used by TempLValueElimination and TempRValueElimination to make the optimization work by both,
979+
/// `copy_addr` and `load`-`store`-pairs.
980+
protocol CopyLikeInstruction: Instruction {
981+
var sourceAddress: Value { get }
982+
var destinationAddress: Value { get }
983+
var isTakeOfSource: Bool { get }
984+
var isInitializationOfDestination: Bool { get }
985+
var loadingInstruction: Instruction { get }
986+
}
987+
988+
extension CopyAddrInst: CopyLikeInstruction {
989+
var sourceAddress: Value { source }
990+
var destinationAddress: Value { destination }
991+
var loadingInstruction: Instruction { self }
992+
}
993+
994+
// A `store` which has a `load` as source operand. This is basically the same as a `copy_addr`.
995+
extension StoreInst: CopyLikeInstruction {
996+
var sourceAddress: Value { load.address }
997+
var destinationAddress: Value { destination }
998+
var isTakeOfSource: Bool { load.loadOwnership == .take }
999+
var isInitializationOfDestination: Bool { storeOwnership != .assign }
1000+
var loadingInstruction: Instruction { load }
1001+
private var load: LoadInst { source as! LoadInst }
1002+
}
1003+

0 commit comments

Comments
 (0)