File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
SwiftCompilerSources/Sources/Optimizer/DataStructures Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,44 @@ struct SpecificInstructionSet<InstType: Instruction> : IntrusiveSet {
177
177
}
178
178
}
179
179
180
+ /// An `InstructionSet` which also provides a `count` property.
181
+ struct SpecificInstructionSetWithCount < InstType: Instruction > : IntrusiveSet {
182
+ private( set) var count = 0
183
+ private var underlyingSet : SpecificInstructionSet < InstType >
184
+
185
+ init ( _ context: some Context ) {
186
+ self . underlyingSet = SpecificInstructionSet ( context)
187
+ }
188
+
189
+ func contains( _ inst: InstType ) -> Bool { underlyingSet. contains ( inst) }
190
+
191
+ var isEmpty : Bool { count == 0 }
192
+
193
+ /// Returns true if `inst` was not contained in the set before inserting.
194
+ @discardableResult
195
+ mutating func insert( _ inst: InstType ) -> Bool {
196
+ if underlyingSet. insert ( inst) {
197
+ count += 1
198
+ return true
199
+ }
200
+ return false
201
+ }
202
+
203
+ mutating func erase( _ inst: InstType ) {
204
+ if underlyingSet. contains ( inst) {
205
+ count -= 1
206
+ assert ( count >= 0 )
207
+ }
208
+ underlyingSet. erase ( inst)
209
+ }
210
+
211
+ var description : String { underlyingSet. description }
212
+
213
+ mutating func deinitialize( ) { underlyingSet. deinitialize ( ) }
214
+ }
215
+
180
216
typealias InstructionSet = SpecificInstructionSet < Instruction >
217
+ typealias InstructionSetWithCount = SpecificInstructionSetWithCount < Instruction >
181
218
182
219
/// A set of operands.
183
220
///
You can’t perform that action at this time.
0 commit comments