Skip to content

Commit 657abcc

Browse files
committed
Swift Optimizer: add SpecificInstructionSet and SpecificInstructionWorklist
To be used for specific instruction types
1 parent c261cb5 commit 657abcc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct ValueSet : IntrusiveSet {
135135
/// This type should be a move-only type, but unfortunately we don't have move-only
136136
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
137137
/// destruct this data structure, e.g. in a `defer {}` block.
138-
struct InstructionSet : IntrusiveSet {
138+
struct SpecificInstructionSet<InstType: Instruction> : IntrusiveSet {
139139

140140
private let context: BridgedPassContext
141141
private let bridged: BridgedNodeSet
@@ -145,25 +145,25 @@ struct InstructionSet : IntrusiveSet {
145145
self.bridged = self.context.allocNodeSet()
146146
}
147147

148-
func contains(_ inst: Instruction) -> Bool {
148+
func contains(_ inst: InstType) -> Bool {
149149
bridged.containsInstruction(inst.bridged)
150150
}
151151

152152
/// Returns true if `inst` was not contained in the set before inserting.
153153
@discardableResult
154-
mutating func insert(_ inst: Instruction) -> Bool {
154+
mutating func insert(_ inst: InstType) -> Bool {
155155
bridged.insertInstruction(inst.bridged)
156156
}
157157

158-
mutating func erase(_ inst: Instruction) {
158+
mutating func erase(_ inst: InstType) {
159159
bridged.eraseInstruction(inst.bridged)
160160
}
161161

162162
var description: String {
163163
let function = bridged.getFunction().function
164164
var d = "{\n"
165-
for inst in function.instructions {
166-
if contains(inst) {
165+
for i in function.instructions {
166+
if let inst = i as? InstType, contains(inst) {
167167
d += inst.description + "\n"
168168
}
169169
}
@@ -177,6 +177,8 @@ struct InstructionSet : IntrusiveSet {
177177
}
178178
}
179179

180+
typealias InstructionSet = SpecificInstructionSet<Instruction>
181+
180182
/// A set of operands.
181183
///
182184
/// This is an extremely efficient implementation which does not need memory

SwiftCompilerSources/Sources/Optimizer/DataStructures/Worklist.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct Worklist<Set: IntrusiveSet> : CustomStringConvertible, NoReflectionChildr
7474

7575
typealias BasicBlockWorklist = Worklist<BasicBlockSet>
7676
typealias InstructionWorklist = Worklist<InstructionSet>
77+
typealias SpecificInstructionWorklist<InstType: Instruction> = Worklist<SpecificInstructionSet<InstType>>
7778
typealias ValueWorklist = Worklist<ValueSet>
7879
typealias OperandWorklist = Worklist<OperandSet>
7980

0 commit comments

Comments
 (0)