Skip to content

Commit ed54253

Browse files
committed
SIL Optimizer: remove legacy C++ passes
They were used as a backup during the transition to Swift passes. Now they are not needed anymore.
1 parent 5b6c814 commit ed54253

28 files changed

+31
-500
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@
6565
#define SWIFT_FUNCTION_PASS(Id, Tag, Description) PASS(Id, Tag, Description)
6666
#endif
6767

68-
/// SWIFT_FUNCTION_PASS_WITH_LEGACY(Id, Tag, Description)
69-
/// Like SWIFT_FUNCTION_PASS, but a C++ legacy pass is used if the Swift pass
70-
/// is not registered.
71-
/// The C++ legacy creation function must be named 'createLegacy<Id>'
72-
///
73-
#ifndef SWIFT_FUNCTION_PASS_WITH_LEGACY
74-
#define SWIFT_FUNCTION_PASS_WITH_LEGACY(Id, Tag, Description) \
75-
SWIFT_FUNCTION_PASS(Id, Tag, Description)
76-
#endif
77-
7868
/// SWIFT_INSTRUCTION_PASS(Inst, Tag)
7969
/// Similar to SWIFT_FUNCTION_PASS, but defines an instruction pass which is
8070
/// implemented in swift and is run by the SILCombiner.
@@ -88,17 +78,6 @@
8878
#define SWIFT_INSTRUCTION_PASS(Inst, Tag)
8979
#endif
9080

91-
/// SWIFT_INSTRUCTION_PASS_WITH_LEGACY(Inst, Tag)
92-
/// Like SWIFT_INSTRUCTION_PASS, but the a C++ legacy SILCombine visit
93-
/// function is used if the swift pass is not registered.
94-
/// The C++ legacy visit function must be named
95-
/// 'SILCombiner::legacyVisit<Inst>'.
96-
///
97-
#ifndef SWIFT_INSTRUCTION_PASS_WITH_LEGACY
98-
#define SWIFT_INSTRUCTION_PASS_WITH_LEGACY(Inst, Tag) \
99-
SWIFT_INSTRUCTION_PASS(Inst, Tag)
100-
#endif
101-
10281
/// PASS_RANGE(RANGE_ID, START, END)
10382
/// Pass IDs between PassKind::START and PassKind::END, inclusive,
10483
/// fall within the set known as
@@ -142,7 +121,7 @@ PASS(ArrayCountPropagation, "array-count-propagation",
142121
"Array Count Propagation")
143122
PASS(ArrayElementPropagation, "array-element-propagation",
144123
"Array Element Propagation")
145-
SWIFT_FUNCTION_PASS_WITH_LEGACY(AssumeSingleThreaded, "sil-assume-single-threaded",
124+
SWIFT_FUNCTION_PASS(AssumeSingleThreaded, "sil-assume-single-threaded",
146125
"Assume Single-Threaded Environment")
147126
PASS(BasicInstructionPropertyDumper, "basic-instruction-property-dump",
148127
"Print SIL Instruction MemBehavior and ReleaseBehavior Information")
@@ -326,7 +305,7 @@ PASS(MemBehaviorDumper, "mem-behavior-dump",
326305
"Print SIL Instruction MemBehavior from Alias Analysis over all Pairs")
327306
PASS(LSLocationPrinter, "lslocation-dump",
328307
"Print Load-Store Location Results Covering all Accesses")
329-
SWIFT_FUNCTION_PASS_WITH_LEGACY(MergeCondFails, "merge-cond_fails",
308+
SWIFT_FUNCTION_PASS(MergeCondFails, "merge-cond_fails",
330309
"Merge SIL cond_fail to Eliminate Redundant Overflow Checks")
331310
PASS(MoveCondFailToPreds, "move-cond-fail-to-preds",
332311
"Move SIL cond_fail by Hoisting Checks")
@@ -367,7 +346,7 @@ PASS(RedundantPhiElimination, "redundant-phi-elimination",
367346
"Redundant Phi Block Argument Elimination")
368347
PASS(PhiExpansion, "phi-expansion",
369348
"Replace Phi arguments by their only used field")
370-
SWIFT_FUNCTION_PASS_WITH_LEGACY(ReleaseDevirtualizer, "release-devirtualizer",
349+
SWIFT_FUNCTION_PASS(ReleaseDevirtualizer, "release-devirtualizer",
371350
"SIL release Devirtualization")
372351
PASS(RetainSinking, "retain-sinking",
373352
"SIL retain Sinking")
@@ -489,15 +468,13 @@ PASS(PruneVTables, "prune-vtables",
489468
PASS_RANGE(AllPasses, AADumper, PruneVTables)
490469

491470
SWIFT_INSTRUCTION_PASS(BeginCOWMutationInst, "simplify-begin_cow_mutation")
492-
SWIFT_INSTRUCTION_PASS_WITH_LEGACY(GlobalValueInst, "simplify-global_value")
493-
SWIFT_INSTRUCTION_PASS_WITH_LEGACY(StrongRetainInst, "simplify-strong_retain")
494-
SWIFT_INSTRUCTION_PASS_WITH_LEGACY(StrongReleaseInst, "simplify-strong_release")
471+
SWIFT_INSTRUCTION_PASS(GlobalValueInst, "simplify-global_value")
472+
SWIFT_INSTRUCTION_PASS(StrongRetainInst, "simplify-strong_retain")
473+
SWIFT_INSTRUCTION_PASS(StrongReleaseInst, "simplify-strong_release")
495474

496475
#undef IRGEN_PASS
497476
#undef SWIFT_MODULE_PASS
498477
#undef SWIFT_FUNCTION_PASS
499-
#undef SWIFT_FUNCTION_PASS_WITH_LEGACY
500478
#undef SWIFT_INSTRUCTION_PASS
501-
#undef SWIFT_INSTRUCTION_PASS_WITH_LEGACY
502479
#undef PASS
503480
#undef PASS_RANGE

include/swift/SILOptimizer/PassManager/Passes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ namespace swift {
7676

7777
#define PASS(ID, TAG, NAME) \
7878
SILTransform *create##ID();
79-
#define SWIFT_FUNCTION_PASS_WITH_LEGACY(ID, TAG, NAME) \
80-
PASS(ID, TAG, NAME) \
81-
SILTransform *createLegacy##ID();
8279
#define IRGEN_PASS(ID, TAG, NAME)
8380
#include "Passes.def"
8481

lib/SILOptimizer/PassManager/Passes.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,6 @@ SILTransform *swift::create##ID() { return new ID##Pass(); } \
304304
SWIFT_FUNCTION_PASS_COMMON(ID, TAG) \
305305
SILTransform *swift::create##ID() { return new ID##Pass(); } \
306306

307-
#define SWIFT_FUNCTION_PASS_WITH_LEGACY(ID, TAG, DESCRIPTION) \
308-
SWIFT_FUNCTION_PASS_COMMON(ID, TAG) \
309-
SILTransform *swift::create##ID() { \
310-
if (passesRegistered) \
311-
return new ID##Pass(); \
312-
return createLegacy##ID(); \
313-
} \
314-
315307
#include "swift/SILOptimizer/PassManager/Passes.def"
316308

317309
#undef SWIFT_FUNCTION_PASS_COMMON

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,6 @@ SILInstruction *SILCombiner::visit##INST(INST *inst) { \
574574
#define SWIFT_INSTRUCTION_PASS(INST, TAG) \
575575
SWIFT_INSTRUCTION_PASS_COMMON(INST, TAG, { return nullptr; })
576576

577-
#define SWIFT_INSTRUCTION_PASS_WITH_LEGACY(INST, TAG) \
578-
SWIFT_INSTRUCTION_PASS_COMMON(INST, TAG, { return legacyVisit##INST(inst); })
579-
580577
#include "swift/SILOptimizer/PassManager/Passes.def"
581578

582579
#undef SWIFT_INSTRUCTION_PASS_COMMON

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ class SILCombiner :
240240
SILInstruction *optimizeStringObject(BuiltinInst *BI);
241241
SILInstruction *visitBuiltinInst(BuiltinInst *BI);
242242
SILInstruction *visitCondFailInst(CondFailInst *CFI);
243-
SILInstruction *legacyVisitStrongRetainInst(StrongRetainInst *SRI);
244243
SILInstruction *visitCopyValueInst(CopyValueInst *cvi);
245244
SILInstruction *visitDestroyValueInst(DestroyValueInst *dvi);
246245
SILInstruction *visitRefToRawPointerInst(RefToRawPointerInst *RRPI);
@@ -270,7 +269,6 @@ class SILCombiner :
270269
SILInstruction *visitRawPointerToRefInst(RawPointerToRefInst *RPTR);
271270
SILInstruction *
272271
visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *TEDAI);
273-
SILInstruction *legacyVisitStrongReleaseInst(StrongReleaseInst *SRI);
274272
SILInstruction *visitCondBranchInst(CondBranchInst *CBI);
275273
SILInstruction *
276274
visitUncheckedTrivialBitCastInst(UncheckedTrivialBitCastInst *UTBCI);
@@ -298,8 +296,6 @@ class SILCombiner :
298296
visitConvertEscapeToNoEscapeInst(ConvertEscapeToNoEscapeInst *Cvt);
299297
SILInstruction *
300298
visitDifferentiableFunctionExtractInst(DifferentiableFunctionExtractInst *DFEI);
301-
302-
SILInstruction *legacyVisitGlobalValueInst(GlobalValueInst *globalValue);
303299

304300
#define PASS(ID, TAG, DESCRIPTION)
305301
#define SWIFT_FUNCTION_PASS(ID, TAG, DESCRIPTION)

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,60 +1250,6 @@ SILInstruction *SILCombiner::visitDestroyValueInst(DestroyValueInst *dvi) {
12501250
return nullptr;
12511251
}
12521252

1253-
SILInstruction *SILCombiner::legacyVisitStrongRetainInst(StrongRetainInst *SRI) {
1254-
assert(!SRI->getFunction()->hasOwnership());
1255-
1256-
// Retain of ThinToThickFunction is a no-op.
1257-
SILValue funcOper = SRI->getOperand();
1258-
if (auto *CFI = dyn_cast<ConvertFunctionInst>(funcOper))
1259-
funcOper = CFI->getOperand();
1260-
1261-
if (isa<ThinToThickFunctionInst>(funcOper))
1262-
return eraseInstFromFunction(*SRI);
1263-
1264-
if (isa<ObjCExistentialMetatypeToObjectInst>(SRI->getOperand()) ||
1265-
isa<ObjCMetatypeToObjectInst>(SRI->getOperand()))
1266-
return eraseInstFromFunction(*SRI);
1267-
1268-
// Retain and Release of tagged strings is a no-op.
1269-
// The builtin code pattern to find tagged strings is:
1270-
// builtin "stringObjectOr_Int64" (or to tag the string)
1271-
// value_to_bridge_object (cast the UInt to bridge object)
1272-
if (isa<ValueToBridgeObjectInst>(SRI->getOperand())) {
1273-
return eraseInstFromFunction(*SRI);
1274-
}
1275-
1276-
// Sometimes in the stdlib due to hand offs, we will see code like:
1277-
//
1278-
// strong_release %0
1279-
// strong_retain %0
1280-
//
1281-
// with the matching strong_retain to the strong_release in a predecessor
1282-
// basic block and the matching strong_release for the strong_retain in a
1283-
// successor basic block.
1284-
//
1285-
// Due to the matching pairs being in different basic blocks, the ARC
1286-
// Optimizer (which is currently local to one basic block does not handle
1287-
// it). But that does not mean that we cannot eliminate this pair with a
1288-
// peephole.
1289-
1290-
// If we are not the first instruction in this basic block...
1291-
if (SRI != &*SRI->getParent()->begin()) {
1292-
auto Pred = std::prev(SRI->getIterator());
1293-
1294-
// ...and the predecessor instruction is a strong_release on the same value
1295-
// as our strong_retain...
1296-
if (auto *Release = dyn_cast<StrongReleaseInst>(&*Pred))
1297-
// Remove them...
1298-
if (Release->getOperand() == SRI->getOperand()) {
1299-
eraseInstFromFunction(*Release);
1300-
return eraseInstFromFunction(*SRI);
1301-
}
1302-
}
1303-
1304-
return nullptr;
1305-
}
1306-
13071253
/// Create a value from stores to an address.
13081254
///
13091255
/// If there are only stores to \p addr, return the stored value. Also, if there
@@ -1858,37 +1804,6 @@ SILInstruction *SILCombiner::visitUncheckedTakeEnumDataAddrInst(
18581804
return eraseInstFromFunction(*tedai);
18591805
}
18601806

1861-
SILInstruction *SILCombiner::legacyVisitStrongReleaseInst(StrongReleaseInst *SRI) {
1862-
assert(!SRI->getFunction()->hasOwnership());
1863-
1864-
// Release of ThinToThickFunction is a no-op.
1865-
if (isa<ThinToThickFunctionInst>(SRI->getOperand()))
1866-
return eraseInstFromFunction(*SRI);
1867-
1868-
if (isa<ObjCExistentialMetatypeToObjectInst>(SRI->getOperand()) ||
1869-
isa<ObjCMetatypeToObjectInst>(SRI->getOperand()))
1870-
return eraseInstFromFunction(*SRI);
1871-
1872-
// Retain and Release of tagged strings is a no-op.
1873-
// The builtin code pattern to find tagged strings is:
1874-
// builtin "stringObjectOr_Int64" (or to tag the string)
1875-
// value_to_bridge_object (cast the UInt to bridge object)
1876-
if (isa<ValueToBridgeObjectInst>(SRI->getOperand())) {
1877-
return eraseInstFromFunction(*SRI);
1878-
}
1879-
1880-
// Release of a classbound existential converted from a class is just a
1881-
// release of the class, squish the conversion.
1882-
if (auto ier = dyn_cast<InitExistentialRefInst>(SRI->getOperand()))
1883-
if (ier->hasOneUse()) {
1884-
SRI->setOperand(ier->getOperand());
1885-
eraseInstFromFunction(*ier);
1886-
return SRI;
1887-
}
1888-
1889-
return nullptr;
1890-
}
1891-
18921807
SILInstruction *SILCombiner::visitCondBranchInst(CondBranchInst *CBI) {
18931808
// NOTE: All of the following optimizations do invalidates branches by
18941809
// replacing the branches, but do not modify the underlying CFG properties
@@ -2411,20 +2326,6 @@ static bool checkGlobalValueUsers(SILValue val,
24112326
return true;
24122327
}
24132328

2414-
SILInstruction *
2415-
SILCombiner::legacyVisitGlobalValueInst(GlobalValueInst *globalValue) {
2416-
// Delete all reference count instructions on a global_value if the only other
2417-
// users are projections (ref_element_addr and ref_tail_addr).
2418-
SmallVector<SILInstruction *, 8> toDelete;
2419-
if (!checkGlobalValueUsers(globalValue, toDelete))
2420-
return nullptr;
2421-
for (SILInstruction *inst : toDelete) {
2422-
eraseInstFromFunction(*inst);
2423-
}
2424-
return nullptr;
2425-
2426-
}
2427-
24282329
// Simplify `differentiable_function_extract` of `differentiable_function`.
24292330
//
24302331
// Before:

lib/SILOptimizer/Transforms/AssumeSingleThreaded.cpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/SILOptimizer/Transforms/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ target_sources(swiftSILOptimizer PRIVATE
77
AllocBoxToStack.cpp
88
ArrayCountPropagation.cpp
99
ArrayElementValuePropagation.cpp
10-
AssumeSingleThreaded.cpp
1110
COWOpts.cpp
1211
CSE.cpp
1312
ConditionForwarding.cpp
@@ -21,7 +20,6 @@ target_sources(swiftSILOptimizer PRIVATE
2120
DifferentiabilityWitnessDevirtualizer.cpp
2221
EagerSpecializer.cpp
2322
GenericSpecializer.cpp
24-
MergeCondFail.cpp
2523
Outliner.cpp
2624
ObjectOutliner.cpp
2725
AssemblyVisionRemarkGenerator.cpp
@@ -31,7 +29,6 @@ target_sources(swiftSILOptimizer PRIVATE
3129
PruneVTables.cpp
3230
RedundantLoadElimination.cpp
3331
RedundantOverflowCheckRemoval.cpp
34-
ReleaseDevirtualizer.cpp
3532
SILCodeMotion.cpp
3633
SILLowerAggregateInstrs.cpp
3734
SILMem2Reg.cpp

0 commit comments

Comments
 (0)