Skip to content

Commit df81283

Browse files
committed
SILCombine: make it possible to add a Swift simplification to an existing SILCombine visit function.
So far a `SILCombineSimplifiable` could only replace a SILCombine visit implementation. With the `SWIFT_SILCOMBINE_PASS_WITH_LEGACY` (to be used in Passes.def) it's possible to keep an existing C++ implementation and on top of that add a Swift Simplification pass.
1 parent de841fd commit df81283

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
#define SWIFT_SILCOMBINE_PASS(Inst)
7979
#endif
8080

81+
#ifndef SWIFT_SILCOMBINE_PASS_WITH_LEGACY
82+
#define SWIFT_SILCOMBINE_PASS_WITH_LEGACY(Inst)
83+
#endif
84+
8185
/// PASS_RANGE(RANGE_ID, START, END)
8286
/// Pass IDs between PassKind::START and PassKind::END, inclusive,
8387
/// fall within the set known as
@@ -540,5 +544,6 @@ SWIFT_SILCOMBINE_PASS(UncheckedEnumDataInst)
540544
#undef SWIFT_MODULE_PASS
541545
#undef SWIFT_FUNCTION_PASS
542546
#undef SWIFT_SILCOMBINE_PASS
547+
#undef SWIFT_SILCOMBINE_PASS_WITH_LEGACY
543548
#undef PASS
544549
#undef PASS_RANGE

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,7 @@ void SILCombine_registerInstructionPass(BridgedStringRef instClassName,
610610
passesRegistered = true;
611611
}
612612

613-
#define SWIFT_SILCOMBINE_PASS(INST) \
614-
SILInstruction *SILCombiner::visit##INST(INST *inst) { \
613+
#define _RUN_SWIFT_SIMPLIFICATON(INST) \
615614
static BridgedInstructionPassRunFn runFunction = nullptr; \
616615
static bool passDisabled = false; \
617616
if (!runFunction) { \
@@ -633,12 +632,28 @@ SILInstruction *SILCombiner::visit##INST(INST *inst) { \
633632
} \
634633
runSwiftInstructionPass(inst, runFunction); \
635634
return nullptr; \
635+
636+
#define SWIFT_SILCOMBINE_PASS(INST) \
637+
SILInstruction *SILCombiner::visit##INST(INST *inst) { \
638+
_RUN_SWIFT_SIMPLIFICATON(INST) \
639+
} \
640+
641+
#define SWIFT_SILCOMBINE_PASS_WITH_LEGACY(INST) \
642+
SILInstruction *SILCombiner::visit##INST(INST *inst) { \
643+
if (auto *result = legacyVisit##INST(inst)) \
644+
return result; \
645+
if (!inst->isDeleted()) { \
646+
_RUN_SWIFT_SIMPLIFICATON(INST) \
647+
} \
648+
return nullptr; \
636649
} \
637650

638651
#define PASS(ID, TAG, DESCRIPTION)
639652

640653
#include "swift/SILOptimizer/PassManager/Passes.def"
641654

655+
#undef _RUN_SWIFT_SIMPLIFICATON
656+
642657
//===----------------------------------------------------------------------===//
643658
// Entry Points
644659
//===----------------------------------------------------------------------===//

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ class SILCombiner :
310310
#define SWIFT_FUNCTION_PASS(ID, TAG, DESCRIPTION)
311311
#define SWIFT_SILCOMBINE_PASS(INST) \
312312
SILInstruction *visit##INST(INST *);
313+
#define SWIFT_SILCOMBINE_PASS_WITH_LEGACY(INST) \
314+
SILInstruction *visit##INST(INST *); \
315+
SILInstruction *legacyVisit##INST(INST *);
313316
#include "swift/SILOptimizer/PassManager/Passes.def"
314317

315318
/// Instruction visitor helpers.

0 commit comments

Comments
 (0)