Skip to content

Commit 1a6ad0c

Browse files
committed
Optimizer: add var insertedPhis in SSAUpdater
1 parent 4c1dbd7 commit 1a6ad0c

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/SSAUpdater.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ struct SSAUpdater<Context: MutatingContext> {
5050
context.notifyInstructionsChanged()
5151
return context._bridged.SSAUpdater_getValueInMiddleOfBlock(block.bridged).value
5252
}
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+
}
5363
}

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ struct BridgedPassContext {
371371
BRIDGED_INLINE void SSAUpdater_addAvailableValue(BridgedBasicBlock block, BridgedValue value) const;
372372
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedValue SSAUpdater_getValueAtEndOfBlock(BridgedBasicBlock block) const;
373373
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;
374376

375377
// Options
376378

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ BridgedValue BridgedPassContext::SSAUpdater_getValueInMiddleOfBlock(BridgedBasic
555555
invocation->getSSAUpdater()->getValueInMiddleOfBlock(block.unbridged())};
556556
}
557557

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+
558566
bool BridgedPassContext::enableStackProtection() const {
559567
swift::SILModule *mod = invocation->getPassManager()->getModule();
560568
return mod->getOptions().EnableStackProtection;

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class SwiftPassInvocation {
7575
SILModule::SlabList allocatedSlabs;
7676

7777
SILSSAUpdater *ssaUpdater = nullptr;
78+
SmallVector<SILPhiArgument *, 4> insertedPhisBySSAUpdater;
7879

7980
SwiftPassInvocation *nestedSwiftPassInvocation = nullptr;
8081

@@ -178,8 +179,9 @@ class SwiftPassInvocation {
178179

179180
void initializeSSAUpdater(SILFunction *fn, SILType type,
180181
ValueOwnershipKind ownership) {
182+
insertedPhisBySSAUpdater.clear();
181183
if (!ssaUpdater)
182-
ssaUpdater = new SILSSAUpdater;
184+
ssaUpdater = new SILSSAUpdater(&insertedPhisBySSAUpdater);
183185
ssaUpdater->initialize(fn, type, ownership);
184186
}
185187

@@ -188,6 +190,8 @@ class SwiftPassInvocation {
188190
return ssaUpdater;
189191
}
190192

193+
ArrayRef<SILPhiArgument *> getInsertedPhisBySSAUpdater() { return insertedPhisBySSAUpdater; }
194+
191195
SwiftPassInvocation *initializeNestedSwiftPassInvocation(SILFunction *newFunction) {
192196
assert(!nestedSwiftPassInvocation && "Nested Swift pass invocation already initialized");
193197
nestedSwiftPassInvocation = new SwiftPassInvocation(passManager, transform, newFunction);

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ irgen::IRGenModule *SwiftPassInvocation::getIRGenModule() {
15621562
}
15631563

15641564
void SwiftPassInvocation::endPass() {
1565+
insertedPhisBySSAUpdater.clear();
15651566
assert(allocatedSlabs.empty() && "StackList is leaking slabs");
15661567
assert(numBlockSetsAllocated == 0 && "Not all BasicBlockSets deallocated");
15671568
assert(numNodeSetsAllocated == 0 && "Not all NodeSets deallocated");

0 commit comments

Comments
 (0)