@@ -1449,6 +1449,30 @@ void SwiftPassInvocation::freeNodeSet(NodeSet *set) {
14491449 }
14501450}
14511451
1452+ OperandSet *SwiftPassInvocation::allocOperandSet () {
1453+ require (numOperandSetsAllocated < OperandSetCapacity,
1454+ " too many OperandSets allocated" );
1455+
1456+ auto *storage = (OperandSet *)operandSetStorage + numOperandSetsAllocated;
1457+ OperandSet *set = new (storage) OperandSet (function);
1458+ aliveOperandSets[numOperandSetsAllocated] = true ;
1459+ ++numOperandSetsAllocated;
1460+ return set;
1461+ }
1462+
1463+ void SwiftPassInvocation::freeOperandSet (OperandSet *set) {
1464+ int idx = set - (OperandSet *)operandSetStorage;
1465+ assert (idx >= 0 && idx < numOperandSetsAllocated);
1466+ assert (aliveOperandSets[idx] && " double free of OperandSet" );
1467+ aliveOperandSets[idx] = false ;
1468+
1469+ while (numOperandSetsAllocated > 0 && !aliveOperandSets[numOperandSetsAllocated - 1 ]) {
1470+ auto *set = (OperandSet *)operandSetStorage + numOperandSetsAllocated - 1 ;
1471+ set->~OperandSet ();
1472+ --numOperandSetsAllocated;
1473+ }
1474+ }
1475+
14521476void SwiftPassInvocation::startModulePassRun (SILModuleTransform *transform) {
14531477 assert (!this ->function && !this ->transform && " a pass is already running" );
14541478 this ->function = nullptr ;
@@ -1493,6 +1517,7 @@ void SwiftPassInvocation::endPass() {
14931517 assert (allocatedSlabs.empty () && " StackList is leaking slabs" );
14941518 assert (numBlockSetsAllocated == 0 && " Not all BasicBlockSets deallocated" );
14951519 assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
1520+ assert (numOperandSetsAllocated == 0 && " Not all OperandSets deallocated" );
14961521 assert (numClonersAllocated == 0 && " Not all cloners deallocated" );
14971522 assert (!needFixStackNesting && " Stack nesting not fixed" );
14981523 if (ssaUpdater) {
@@ -1517,6 +1542,7 @@ void SwiftPassInvocation::endTransformFunction() {
15171542 function = nullptr ;
15181543 assert (numBlockSetsAllocated == 0 && " Not all BasicBlockSets deallocated" );
15191544 assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
1545+ assert (numOperandSetsAllocated == 0 && " Not all OperandSets deallocated" );
15201546}
15211547
15221548void SwiftPassInvocation::beginVerifyFunction (SILFunction *function) {
@@ -1535,6 +1561,7 @@ void SwiftPassInvocation::endVerifyFunction() {
15351561 " verifyication must not change the SIL of a function" );
15361562 assert (numBlockSetsAllocated == 0 && " Not all BasicBlockSets deallocated" );
15371563 assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
1564+ assert (numOperandSetsAllocated == 0 && " Not all OperandSets deallocated" );
15381565 function = nullptr ;
15391566 }
15401567}
0 commit comments