Skip to content

SIL Optimizer: remove legacy C++ passes #61644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 6 additions & 29 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@
#define SWIFT_FUNCTION_PASS(Id, Tag, Description) PASS(Id, Tag, Description)
#endif

/// SWIFT_FUNCTION_PASS_WITH_LEGACY(Id, Tag, Description)
/// Like SWIFT_FUNCTION_PASS, but a C++ legacy pass is used if the Swift pass
/// is not registered.
/// The C++ legacy creation function must be named 'createLegacy<Id>'
///
#ifndef SWIFT_FUNCTION_PASS_WITH_LEGACY
#define SWIFT_FUNCTION_PASS_WITH_LEGACY(Id, Tag, Description) \
SWIFT_FUNCTION_PASS(Id, Tag, Description)
#endif

/// SWIFT_INSTRUCTION_PASS(Inst, Tag)
/// Similar to SWIFT_FUNCTION_PASS, but defines an instruction pass which is
/// implemented in swift and is run by the SILCombiner.
Expand All @@ -88,17 +78,6 @@
#define SWIFT_INSTRUCTION_PASS(Inst, Tag)
#endif

/// SWIFT_INSTRUCTION_PASS_WITH_LEGACY(Inst, Tag)
/// Like SWIFT_INSTRUCTION_PASS, but the a C++ legacy SILCombine visit
/// function is used if the swift pass is not registered.
/// The C++ legacy visit function must be named
/// 'SILCombiner::legacyVisit<Inst>'.
///
#ifndef SWIFT_INSTRUCTION_PASS_WITH_LEGACY
#define SWIFT_INSTRUCTION_PASS_WITH_LEGACY(Inst, Tag) \
SWIFT_INSTRUCTION_PASS(Inst, Tag)
#endif

/// PASS_RANGE(RANGE_ID, START, END)
/// Pass IDs between PassKind::START and PassKind::END, inclusive,
/// fall within the set known as
Expand Down Expand Up @@ -142,7 +121,7 @@ PASS(ArrayCountPropagation, "array-count-propagation",
"Array Count Propagation")
PASS(ArrayElementPropagation, "array-element-propagation",
"Array Element Propagation")
SWIFT_FUNCTION_PASS_WITH_LEGACY(AssumeSingleThreaded, "sil-assume-single-threaded",
SWIFT_FUNCTION_PASS(AssumeSingleThreaded, "sil-assume-single-threaded",
"Assume Single-Threaded Environment")
PASS(BasicInstructionPropertyDumper, "basic-instruction-property-dump",
"Print SIL Instruction MemBehavior and ReleaseBehavior Information")
Expand Down Expand Up @@ -326,7 +305,7 @@ PASS(MemBehaviorDumper, "mem-behavior-dump",
"Print SIL Instruction MemBehavior from Alias Analysis over all Pairs")
PASS(LSLocationPrinter, "lslocation-dump",
"Print Load-Store Location Results Covering all Accesses")
SWIFT_FUNCTION_PASS_WITH_LEGACY(MergeCondFails, "merge-cond_fails",
SWIFT_FUNCTION_PASS(MergeCondFails, "merge-cond_fails",
"Merge SIL cond_fail to Eliminate Redundant Overflow Checks")
PASS(MoveCondFailToPreds, "move-cond-fail-to-preds",
"Move SIL cond_fail by Hoisting Checks")
Expand Down Expand Up @@ -367,7 +346,7 @@ PASS(RedundantPhiElimination, "redundant-phi-elimination",
"Redundant Phi Block Argument Elimination")
PASS(PhiExpansion, "phi-expansion",
"Replace Phi arguments by their only used field")
SWIFT_FUNCTION_PASS_WITH_LEGACY(ReleaseDevirtualizer, "release-devirtualizer",
SWIFT_FUNCTION_PASS(ReleaseDevirtualizer, "release-devirtualizer",
"SIL release Devirtualization")
PASS(RetainSinking, "retain-sinking",
"SIL retain Sinking")
Expand Down Expand Up @@ -489,15 +468,13 @@ PASS(PruneVTables, "prune-vtables",
PASS_RANGE(AllPasses, AADumper, PruneVTables)

SWIFT_INSTRUCTION_PASS(BeginCOWMutationInst, "simplify-begin_cow_mutation")
SWIFT_INSTRUCTION_PASS_WITH_LEGACY(GlobalValueInst, "simplify-global_value")
SWIFT_INSTRUCTION_PASS_WITH_LEGACY(StrongRetainInst, "simplify-strong_retain")
SWIFT_INSTRUCTION_PASS_WITH_LEGACY(StrongReleaseInst, "simplify-strong_release")
SWIFT_INSTRUCTION_PASS(GlobalValueInst, "simplify-global_value")
SWIFT_INSTRUCTION_PASS(StrongRetainInst, "simplify-strong_retain")
SWIFT_INSTRUCTION_PASS(StrongReleaseInst, "simplify-strong_release")

#undef IRGEN_PASS
#undef SWIFT_MODULE_PASS
#undef SWIFT_FUNCTION_PASS
#undef SWIFT_FUNCTION_PASS_WITH_LEGACY
#undef SWIFT_INSTRUCTION_PASS
#undef SWIFT_INSTRUCTION_PASS_WITH_LEGACY
#undef PASS
#undef PASS_RANGE
3 changes: 0 additions & 3 deletions include/swift/SILOptimizer/PassManager/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ namespace swift {

#define PASS(ID, TAG, NAME) \
SILTransform *create##ID();
#define SWIFT_FUNCTION_PASS_WITH_LEGACY(ID, TAG, NAME) \
PASS(ID, TAG, NAME) \
SILTransform *createLegacy##ID();
#define IRGEN_PASS(ID, TAG, NAME)
#include "Passes.def"

Expand Down
8 changes: 0 additions & 8 deletions lib/SILOptimizer/PassManager/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,6 @@ SILTransform *swift::create##ID() { return new ID##Pass(); } \
SWIFT_FUNCTION_PASS_COMMON(ID, TAG) \
SILTransform *swift::create##ID() { return new ID##Pass(); } \

#define SWIFT_FUNCTION_PASS_WITH_LEGACY(ID, TAG, DESCRIPTION) \
SWIFT_FUNCTION_PASS_COMMON(ID, TAG) \
SILTransform *swift::create##ID() { \
if (passesRegistered) \
return new ID##Pass(); \
return createLegacy##ID(); \
} \

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

#undef SWIFT_FUNCTION_PASS_COMMON
3 changes: 0 additions & 3 deletions lib/SILOptimizer/SILCombiner/SILCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,6 @@ SILInstruction *SILCombiner::visit##INST(INST *inst) { \
#define SWIFT_INSTRUCTION_PASS(INST, TAG) \
SWIFT_INSTRUCTION_PASS_COMMON(INST, TAG, { return nullptr; })

#define SWIFT_INSTRUCTION_PASS_WITH_LEGACY(INST, TAG) \
SWIFT_INSTRUCTION_PASS_COMMON(INST, TAG, { return legacyVisit##INST(inst); })

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

#undef SWIFT_INSTRUCTION_PASS_COMMON
Expand Down
4 changes: 0 additions & 4 deletions lib/SILOptimizer/SILCombiner/SILCombiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ class SILCombiner :
SILInstruction *optimizeStringObject(BuiltinInst *BI);
SILInstruction *visitBuiltinInst(BuiltinInst *BI);
SILInstruction *visitCondFailInst(CondFailInst *CFI);
SILInstruction *legacyVisitStrongRetainInst(StrongRetainInst *SRI);
SILInstruction *visitCopyValueInst(CopyValueInst *cvi);
SILInstruction *visitDestroyValueInst(DestroyValueInst *dvi);
SILInstruction *visitRefToRawPointerInst(RefToRawPointerInst *RRPI);
Expand Down Expand Up @@ -270,7 +269,6 @@ class SILCombiner :
SILInstruction *visitRawPointerToRefInst(RawPointerToRefInst *RPTR);
SILInstruction *
visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *TEDAI);
SILInstruction *legacyVisitStrongReleaseInst(StrongReleaseInst *SRI);
SILInstruction *visitCondBranchInst(CondBranchInst *CBI);
SILInstruction *
visitUncheckedTrivialBitCastInst(UncheckedTrivialBitCastInst *UTBCI);
Expand Down Expand Up @@ -298,8 +296,6 @@ class SILCombiner :
visitConvertEscapeToNoEscapeInst(ConvertEscapeToNoEscapeInst *Cvt);
SILInstruction *
visitDifferentiableFunctionExtractInst(DifferentiableFunctionExtractInst *DFEI);

SILInstruction *legacyVisitGlobalValueInst(GlobalValueInst *globalValue);

#define PASS(ID, TAG, DESCRIPTION)
#define SWIFT_FUNCTION_PASS(ID, TAG, DESCRIPTION)
Expand Down
99 changes: 0 additions & 99 deletions lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,60 +1250,6 @@ SILInstruction *SILCombiner::visitDestroyValueInst(DestroyValueInst *dvi) {
return nullptr;
}

SILInstruction *SILCombiner::legacyVisitStrongRetainInst(StrongRetainInst *SRI) {
assert(!SRI->getFunction()->hasOwnership());

// Retain of ThinToThickFunction is a no-op.
SILValue funcOper = SRI->getOperand();
if (auto *CFI = dyn_cast<ConvertFunctionInst>(funcOper))
funcOper = CFI->getOperand();

if (isa<ThinToThickFunctionInst>(funcOper))
return eraseInstFromFunction(*SRI);

if (isa<ObjCExistentialMetatypeToObjectInst>(SRI->getOperand()) ||
isa<ObjCMetatypeToObjectInst>(SRI->getOperand()))
return eraseInstFromFunction(*SRI);

// Retain and Release of tagged strings is a no-op.
// The builtin code pattern to find tagged strings is:
// builtin "stringObjectOr_Int64" (or to tag the string)
// value_to_bridge_object (cast the UInt to bridge object)
if (isa<ValueToBridgeObjectInst>(SRI->getOperand())) {
return eraseInstFromFunction(*SRI);
}

// Sometimes in the stdlib due to hand offs, we will see code like:
//
// strong_release %0
// strong_retain %0
//
// with the matching strong_retain to the strong_release in a predecessor
// basic block and the matching strong_release for the strong_retain in a
// successor basic block.
//
// Due to the matching pairs being in different basic blocks, the ARC
// Optimizer (which is currently local to one basic block does not handle
// it). But that does not mean that we cannot eliminate this pair with a
// peephole.

// If we are not the first instruction in this basic block...
if (SRI != &*SRI->getParent()->begin()) {
auto Pred = std::prev(SRI->getIterator());

// ...and the predecessor instruction is a strong_release on the same value
// as our strong_retain...
if (auto *Release = dyn_cast<StrongReleaseInst>(&*Pred))
// Remove them...
if (Release->getOperand() == SRI->getOperand()) {
eraseInstFromFunction(*Release);
return eraseInstFromFunction(*SRI);
}
}

return nullptr;
}

/// Create a value from stores to an address.
///
/// If there are only stores to \p addr, return the stored value. Also, if there
Expand Down Expand Up @@ -1858,37 +1804,6 @@ SILInstruction *SILCombiner::visitUncheckedTakeEnumDataAddrInst(
return eraseInstFromFunction(*tedai);
}

SILInstruction *SILCombiner::legacyVisitStrongReleaseInst(StrongReleaseInst *SRI) {
assert(!SRI->getFunction()->hasOwnership());

// Release of ThinToThickFunction is a no-op.
if (isa<ThinToThickFunctionInst>(SRI->getOperand()))
return eraseInstFromFunction(*SRI);

if (isa<ObjCExistentialMetatypeToObjectInst>(SRI->getOperand()) ||
isa<ObjCMetatypeToObjectInst>(SRI->getOperand()))
return eraseInstFromFunction(*SRI);

// Retain and Release of tagged strings is a no-op.
// The builtin code pattern to find tagged strings is:
// builtin "stringObjectOr_Int64" (or to tag the string)
// value_to_bridge_object (cast the UInt to bridge object)
if (isa<ValueToBridgeObjectInst>(SRI->getOperand())) {
return eraseInstFromFunction(*SRI);
}

// Release of a classbound existential converted from a class is just a
// release of the class, squish the conversion.
if (auto ier = dyn_cast<InitExistentialRefInst>(SRI->getOperand()))
if (ier->hasOneUse()) {
SRI->setOperand(ier->getOperand());
eraseInstFromFunction(*ier);
return SRI;
}

return nullptr;
}

SILInstruction *SILCombiner::visitCondBranchInst(CondBranchInst *CBI) {
// NOTE: All of the following optimizations do invalidates branches by
// replacing the branches, but do not modify the underlying CFG properties
Expand Down Expand Up @@ -2411,20 +2326,6 @@ static bool checkGlobalValueUsers(SILValue val,
return true;
}

SILInstruction *
SILCombiner::legacyVisitGlobalValueInst(GlobalValueInst *globalValue) {
// Delete all reference count instructions on a global_value if the only other
// users are projections (ref_element_addr and ref_tail_addr).
SmallVector<SILInstruction *, 8> toDelete;
if (!checkGlobalValueUsers(globalValue, toDelete))
return nullptr;
for (SILInstruction *inst : toDelete) {
eraseInstFromFunction(*inst);
}
return nullptr;

}

// Simplify `differentiable_function_extract` of `differentiable_function`.
//
// Before:
Expand Down
57 changes: 0 additions & 57 deletions lib/SILOptimizer/Transforms/AssumeSingleThreaded.cpp

This file was deleted.

3 changes: 0 additions & 3 deletions lib/SILOptimizer/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ target_sources(swiftSILOptimizer PRIVATE
AllocBoxToStack.cpp
ArrayCountPropagation.cpp
ArrayElementValuePropagation.cpp
AssumeSingleThreaded.cpp
COWOpts.cpp
CSE.cpp
ConditionForwarding.cpp
Expand All @@ -21,7 +20,6 @@ target_sources(swiftSILOptimizer PRIVATE
DifferentiabilityWitnessDevirtualizer.cpp
EagerSpecializer.cpp
GenericSpecializer.cpp
MergeCondFail.cpp
Outliner.cpp
ObjectOutliner.cpp
AssemblyVisionRemarkGenerator.cpp
Expand All @@ -31,7 +29,6 @@ target_sources(swiftSILOptimizer PRIVATE
PruneVTables.cpp
RedundantLoadElimination.cpp
RedundantOverflowCheckRemoval.cpp
ReleaseDevirtualizer.cpp
SILCodeMotion.cpp
SILLowerAggregateInstrs.cpp
SILMem2Reg.cpp
Expand Down
Loading