Skip to content

Commit 1d22288

Browse files
committed
[NFC] SIL: Subpass runs can take values.
Allow continueWithNextSubpassRun to take a SILValue.
1 parent 8ace8b9 commit 1d22288

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,9 @@ class SILPassManager {
444444

445445
void executePassPipelinePlan(const SILPassPipelinePlan &Plan);
446446

447-
bool continueWithNextSubpassRun(SILInstruction *forInst, SILFunction *function,
448-
SILTransform *trans);
447+
using Transformee = llvm::PointerUnion<SILValue, SILInstruction *>;
448+
bool continueWithNextSubpassRun(std::optional<Transformee> forTransformee,
449+
SILFunction *function, SILTransform *trans);
449450

450451
static bool isPassDisabled(StringRef passName);
451452
static bool isInstructionPassDisabled(StringRef instName);

include/swift/SILOptimizer/PassManager/Transforms.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ namespace swift {
133133
return PM->continueWithNextSubpassRun(forInst, F, this);
134134
}
135135

136+
bool continueWithNextSubpassRun(SILValue forValue) {
137+
return PM->continueWithNextSubpassRun(forValue, F, this);
138+
}
139+
136140
void invalidateAnalysis(SILAnalysis::InvalidationKind K) {
137141
PM->invalidateAnalysis(F, K);
138142
}

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,16 +488,35 @@ bool SILPassManager::continueTransforming() {
488488
return NumPassesRun < maxNumPassesToRun;
489489
}
490490

491-
bool SILPassManager::continueWithNextSubpassRun(SILInstruction *forInst,
492-
SILFunction *function,
493-
SILTransform *trans) {
491+
bool SILPassManager::continueWithNextSubpassRun(
492+
std::optional<Transformee> origTransformee, SILFunction *function,
493+
SILTransform *trans) {
494+
// Rewrite .some(nullptr) as .none.
495+
std::optional<llvm::PointerUnion<SILValue, SILInstruction *>> forTransformee;
496+
if (origTransformee) {
497+
auto forValue = dyn_cast<SILValue>(*origTransformee);
498+
if (forValue) {
499+
forTransformee = forValue;
500+
} else if (auto *forInst = cast<SILInstruction *>(*origTransformee)) {
501+
forTransformee = forInst;
502+
}
503+
}
504+
494505
unsigned subPass = numSubpassesRun++;
495506

496-
if (forInst && isFunctionSelectedForPrinting(function) &&
497-
SILPrintEverySubpass) {
507+
if (isFunctionSelectedForPrinting(function) && SILPrintEverySubpass) {
498508
dumpPassInfo("*** SIL function before ", trans, function);
499-
if (forInst) {
500-
llvm::dbgs() << " *** sub-pass " << subPass << " for " << *forInst;
509+
llvm::dbgs() << " *** sub-pass " << subPass << " for ";
510+
if (forTransformee) {
511+
auto forValue = dyn_cast<SILValue>(*forTransformee);
512+
if (forValue) {
513+
llvm::dbgs() << forValue;
514+
} else {
515+
auto *forInst = cast<SILInstruction *>(*forTransformee);
516+
llvm::dbgs() << *forInst;
517+
}
518+
} else {
519+
llvm::dbgs() << "???\n";
501520
}
502521
function->dump(getOptions().EmitVerboseSIL);
503522
}
@@ -509,8 +528,16 @@ bool SILPassManager::continueWithNextSubpassRun(SILInstruction *forInst,
509528

510529
if (subPass == maxNumSubpassesToRun - 1 && SILPrintLast) {
511530
dumpPassInfo("*** SIL function before ", trans, function);
512-
if (forInst) {
513-
llvm::dbgs() << " *** sub-pass " << subPass << " for " << *forInst;
531+
if (forTransformee) {
532+
auto forValue = dyn_cast<SILValue>(*forTransformee);
533+
if (forValue) {
534+
llvm::dbgs() << forValue;
535+
} else {
536+
auto *forInst = cast<SILInstruction *>(*forTransformee);
537+
llvm::dbgs() << *forInst;
538+
}
539+
} else {
540+
llvm::dbgs() << "???\n";
514541
}
515542
function->dump(getOptions().EmitVerboseSIL);
516543
}

0 commit comments

Comments
 (0)