Skip to content

Commit 5d3339e

Browse files
committed
Swift SIL: support for sub-pass bisecting: add PassContext.continueWithNextSubpassRun
1 parent 904b0a7 commit 5d3339e

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/PassUtils.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ struct PassContext {
2222

2323
let _bridged: BridgedPassContext
2424

25+
func continueWithNextSubpassRun(for inst: Instruction? = nil) -> Bool {
26+
let bridgedInst = OptionalBridgedInstruction(obj: inst?.bridged.obj)
27+
return PassContext_continueWithNextSubpassRun(_bridged, bridgedInst) != 0
28+
}
29+
2530
var aliasAnalysis: AliasAnalysis {
2631
let bridgedAA = PassContext_getAliasAnalysis(_bridged)
2732
return AliasAnalysis(bridged: bridgedAA)

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ void Function_register(SwiftMetatype metatype,
173173
FunctionCopyEffectsFn copyEffectsFn,
174174
FunctionGetEffectFlagsFn hasEffectsFn);
175175

176+
SwiftInt PassContext_continueWithNextSubpassRun(BridgedPassContext passContext,
177+
OptionalBridgedInstruction inst);
176178
void PassContext_notifyChanges(BridgedPassContext passContext,
177179
enum ChangeNotificationKind changeKind);
178180
void PassContext_eraseInstruction(BridgedPassContext passContext,

include/swift/SIL/SILBridgingUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ template <class I = SILInstruction> I *castToInst(BridgedInstruction inst) {
5858
return cast<I>(static_cast<SILNode *>(inst.obj)->castToInstruction());
5959
}
6060

61+
template <class I = SILInstruction> I *castToInst(OptionalBridgedInstruction inst) {
62+
if (!inst.obj)
63+
return nullptr;
64+
return cast<I>(static_cast<SILNode *>(inst.obj)->castToInstruction());
65+
}
66+
6167
inline SILBasicBlock *castToBasicBlock(BridgedBasicBlock block) {
6268
return static_cast<SILBasicBlock *>(block.obj);
6369
}

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class SwiftPassInvocation {
5050
/// Backlink to the pass manager.
5151
SILPassManager *passManager;
5252

53+
/// The current transform.
54+
SILTransform *transform = nullptr;
55+
5356
/// The currently optimized function.
5457
SILFunction *function = nullptr;
5558

@@ -76,6 +79,8 @@ class SwiftPassInvocation {
7679
passManager(passManager) {}
7780

7881
SILPassManager *getPassManager() const { return passManager; }
82+
83+
SILTransform *getTransform() const { return transform; }
7984

8085
SILFunction *getFunction() const { return function; }
8186

@@ -94,7 +99,7 @@ class SwiftPassInvocation {
9499
void notifyChanges(SILAnalysis::InvalidationKind invalidationKind);
95100

96101
/// Called by the pass manager before the pass starts running.
97-
void startFunctionPassRun(SILFunction *function);
102+
void startFunctionPassRun(SILFunctionTransform *transform);
98103

99104
/// Called by the SILCombiner before the instruction pass starts running.
100105
void startInstructionPassRun(SILInstruction *inst);

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
530530
assert(changeNotifications == SILAnalysis::InvalidationKind::Nothing
531531
&& "change notifications not cleared");
532532

533-
swiftPassInvocation.startFunctionPassRun(F);
533+
swiftPassInvocation.startFunctionPassRun(SFT);
534534

535535
// Run it!
536536
SFT->run();
@@ -1209,9 +1209,10 @@ void SwiftPassInvocation::freeBlockSet(BasicBlockSet *set) {
12091209
}
12101210
}
12111211

1212-
void SwiftPassInvocation::startFunctionPassRun(SILFunction *function) {
1213-
assert(!this->function && "a pass is already running");
1214-
this->function = function;
1212+
void SwiftPassInvocation::startFunctionPassRun(SILFunctionTransform *transform) {
1213+
assert(!this->function && !this->transform && "a pass is already running");
1214+
this->function = transform->getFunction();
1215+
this->transform = transform;
12151216
}
12161217

12171218
void SwiftPassInvocation::startInstructionPassRun(SILInstruction *inst) {
@@ -1221,8 +1222,9 @@ void SwiftPassInvocation::startInstructionPassRun(SILInstruction *inst) {
12211222

12221223
void SwiftPassInvocation::finishedFunctionPassRun() {
12231224
endPassRunChecks();
1224-
assert(function && "not running a pass");
1225+
assert(function && transform && "not running a pass");
12251226
function = nullptr;
1227+
transform = nullptr;
12261228
}
12271229

12281230
void SwiftPassInvocation::finishedInstructionPassRun() {
@@ -1282,6 +1284,14 @@ BridgedSlab PassContext_freeSlab(BridgedPassContext passContext,
12821284
return toBridgedSlab(inv->freeSlab(castToSlab(slab)));
12831285
}
12841286

1287+
SwiftInt PassContext_continueWithNextSubpassRun(BridgedPassContext passContext,
1288+
OptionalBridgedInstruction inst) {
1289+
SwiftPassInvocation *inv = castToPassInvocation(passContext);
1290+
SILInstruction *i = castToInst(inst);
1291+
return inv->getPassManager()->continueWithNextSubpassRun(i,
1292+
inv->getFunction(), inv->getTransform()) ? 1: 0;
1293+
}
1294+
12851295
void PassContext_notifyChanges(BridgedPassContext passContext,
12861296
enum ChangeNotificationKind changeKind) {
12871297
SwiftPassInvocation *inv = castToPassInvocation(passContext);

0 commit comments

Comments
 (0)