File tree Expand file tree Collapse file tree 5 files changed +26
-1
lines changed
SwiftCompilerSources/Sources/Optimizer/Utilities
include/swift/SILOptimizer
lib/SILOptimizer/PassManager Expand file tree Collapse file tree 5 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -50,4 +50,14 @@ struct SSAUpdater<Context: MutatingContext> {
50
50
context. notifyInstructionsChanged ( )
51
51
return context. _bridged. SSAUpdater_getValueInMiddleOfBlock ( block. bridged) . value
52
52
}
53
+
54
+ var insertedPhis : [ Phi ] {
55
+ var phis = [ Phi] ( )
56
+ let numPhis = context. _bridged. SSAUpdater_getNumInsertedPhis ( )
57
+ phis. reserveCapacity ( numPhis)
58
+ for idx in 0 ..< numPhis {
59
+ phis. append ( Phi ( context. _bridged. SSAUpdater_getInsertedPhi ( idx) . value) !)
60
+ }
61
+ return phis
62
+ }
53
63
}
Original file line number Diff line number Diff line change @@ -371,6 +371,8 @@ struct BridgedPassContext {
371
371
BRIDGED_INLINE void SSAUpdater_addAvailableValue (BridgedBasicBlock block, BridgedValue value) const ;
372
372
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedValue SSAUpdater_getValueAtEndOfBlock (BridgedBasicBlock block) const ;
373
373
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedValue SSAUpdater_getValueInMiddleOfBlock (BridgedBasicBlock block) const ;
374
+ BRIDGED_INLINE SwiftInt SSAUpdater_getNumInsertedPhis () const ;
375
+ SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedValue SSAUpdater_getInsertedPhi (SwiftInt idx) const ;
374
376
375
377
// Options
376
378
Original file line number Diff line number Diff line change @@ -555,6 +555,14 @@ BridgedValue BridgedPassContext::SSAUpdater_getValueInMiddleOfBlock(BridgedBasic
555
555
invocation->getSSAUpdater ()->getValueInMiddleOfBlock (block.unbridged ())};
556
556
}
557
557
558
+ SwiftInt BridgedPassContext::SSAUpdater_getNumInsertedPhis () const {
559
+ return (SwiftInt)invocation->getInsertedPhisBySSAUpdater ().size ();
560
+ }
561
+
562
+ BridgedValue BridgedPassContext::SSAUpdater_getInsertedPhi (SwiftInt idx) const {
563
+ return {invocation->getInsertedPhisBySSAUpdater ()[idx]};
564
+ }
565
+
558
566
bool BridgedPassContext::enableStackProtection () const {
559
567
swift::SILModule *mod = invocation->getPassManager ()->getModule ();
560
568
return mod->getOptions ().EnableStackProtection ;
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ class SwiftPassInvocation {
75
75
SILModule::SlabList allocatedSlabs;
76
76
77
77
SILSSAUpdater *ssaUpdater = nullptr ;
78
+ SmallVector<SILPhiArgument *, 4 > insertedPhisBySSAUpdater;
78
79
79
80
SwiftPassInvocation *nestedSwiftPassInvocation = nullptr ;
80
81
@@ -178,8 +179,9 @@ class SwiftPassInvocation {
178
179
179
180
void initializeSSAUpdater (SILFunction *fn, SILType type,
180
181
ValueOwnershipKind ownership) {
182
+ insertedPhisBySSAUpdater.clear ();
181
183
if (!ssaUpdater)
182
- ssaUpdater = new SILSSAUpdater;
184
+ ssaUpdater = new SILSSAUpdater (&insertedPhisBySSAUpdater) ;
183
185
ssaUpdater->initialize (fn, type, ownership);
184
186
}
185
187
@@ -188,6 +190,8 @@ class SwiftPassInvocation {
188
190
return ssaUpdater;
189
191
}
190
192
193
+ ArrayRef<SILPhiArgument *> getInsertedPhisBySSAUpdater () { return insertedPhisBySSAUpdater; }
194
+
191
195
SwiftPassInvocation *initializeNestedSwiftPassInvocation (SILFunction *newFunction) {
192
196
assert (!nestedSwiftPassInvocation && " Nested Swift pass invocation already initialized" );
193
197
nestedSwiftPassInvocation = new SwiftPassInvocation (passManager, transform, newFunction);
Original file line number Diff line number Diff line change @@ -1562,6 +1562,7 @@ irgen::IRGenModule *SwiftPassInvocation::getIRGenModule() {
1562
1562
}
1563
1563
1564
1564
void SwiftPassInvocation::endPass () {
1565
+ insertedPhisBySSAUpdater.clear ();
1565
1566
assert (allocatedSlabs.empty () && " StackList is leaking slabs" );
1566
1567
assert (numBlockSetsAllocated == 0 && " Not all BasicBlockSets deallocated" );
1567
1568
assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
You can’t perform that action at this time.
0 commit comments