Skip to content

Optimizer: fix spelling of the Simplifiable protocol #79316

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
Feb 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import SIL
//===--------------------------------------------------------------------===//

/// Instructions which can be simplified at all optimization levels
protocol Simplifyable : Instruction {
protocol Simplifiable : Instruction {
func simplify(_ context: SimplifyContext)
}

/// Instructions which can be simplified at -Onone
protocol OnoneSimplifyable : Simplifyable {
protocol OnoneSimplifiable : Simplifiable {
}

/// Instructions which can only be simplified at the end of the -Onone pipeline
protocol LateOnoneSimplifyable : Instruction {
protocol LateOnoneSimplifiable : Instruction {
func simplifyLate(_ context: SimplifyContext)
}

Expand All @@ -38,7 +38,7 @@ let ononeSimplificationPass = FunctionPass(name: "onone-simplification") {
(function: Function, context: FunctionPassContext) in

runSimplification(on: function, context, preserveDebugInfo: true) {
if let i = $0 as? OnoneSimplifyable {
if let i = $0 as? OnoneSimplifiable {
i.simplify($1)
}
}
Expand All @@ -48,7 +48,7 @@ let simplificationPass = FunctionPass(name: "simplification") {
(function: Function, context: FunctionPassContext) in

runSimplification(on: function, context, preserveDebugInfo: false) {
if let i = $0 as? Simplifyable {
if let i = $0 as? Simplifiable {
i.simplify($1)
}
}
Expand All @@ -58,9 +58,9 @@ let lateOnoneSimplificationPass = FunctionPass(name: "late-onone-simplification"
(function: Function, context: FunctionPassContext) in

runSimplification(on: function, context, preserveDebugInfo: true) {
if let i = $0 as? LateOnoneSimplifyable {
if let i = $0 as? LateOnoneSimplifiable {
i.simplifyLate($1)
} else if let i = $0 as? OnoneSimplifyable {
} else if let i = $0 as? OnoneSimplifiable {
i.simplify($1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension AllocRefDynamicInst : OnoneSimplifyable {
extension AllocRefDynamicInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
/// Optimize alloc_ref_dynamic of a known type to alloc_ref:
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension ApplyInst : OnoneSimplifyable {
extension ApplyInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
if tryTransformThickToThinCallee(of: self, context) {
return
Expand All @@ -25,13 +25,13 @@ extension ApplyInst : OnoneSimplifyable {
}
}

extension TryApplyInst : OnoneSimplifyable {
extension TryApplyInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
_ = context.tryDevirtualize(apply: self, isMandatory: false)
}
}

extension BeginApplyInst : OnoneSimplifyable {
extension BeginApplyInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
_ = context.tryDevirtualize(apply: self, isMandatory: false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension BeginBorrowInst : OnoneSimplifyable, SILCombineSimplifyable {
extension BeginBorrowInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
if borrowedValue.ownership == .owned,
// We need to keep lexical lifetimes in place.
Expand All @@ -27,7 +27,7 @@ extension BeginBorrowInst : OnoneSimplifyable, SILCombineSimplifyable {
}
}

extension LoadBorrowInst : Simplifyable, SILCombineSimplifyable {
extension LoadBorrowInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
if uses.ignoreDebugUses.ignoreUsers(ofType: EndBorrowInst.self).isEmpty {
context.erase(instructionIncludingAllUsers: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension BeginCOWMutationInst : Simplifyable, SILCombineSimplifyable {
extension BeginCOWMutationInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {

/// The buffer of an empty Array/Set/Dictionary singleton is known to be not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension BranchInst : OnoneSimplifyable {
extension BranchInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
tryMergeWithTargetBlock(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension BuiltinInst : OnoneSimplifyable {
extension BuiltinInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
switch id {
case .IsConcrete:
Expand Down Expand Up @@ -62,7 +62,7 @@ extension BuiltinInst : OnoneSimplifyable {
}
}

extension BuiltinInst : LateOnoneSimplifyable {
extension BuiltinInst : LateOnoneSimplifiable {
func simplifyLate(_ context: SimplifyContext) {
if id == .IsConcrete {
// At the end of the pipeline we can be sure that the isConcrete's type doesn't get "more" concrete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension CheckedCastAddrBranchInst : OnoneSimplifyable {
extension CheckedCastAddrBranchInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
guard let castWillSucceed = self.dynamicCastResult else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import AST
import SIL

extension ClassifyBridgeObjectInst : OnoneSimplifyable, SILCombineSimplifyable {
extension ClassifyBridgeObjectInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
// Constant fold `classify_bridge_object` to `(false, false)` if the operand is known
// to be a swift class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension CondBranchInst : OnoneSimplifyable {
extension CondBranchInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
tryConstantFold(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension CondFailInst : OnoneSimplifyable {
extension CondFailInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {

/// Eliminates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension ConvertEscapeToNoEscapeInst : OnoneSimplifyable {
extension ConvertEscapeToNoEscapeInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
tryCombineWithThinToThickOperand(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension CopyValueInst : OnoneSimplifyable, SILCombineSimplifyable {
extension CopyValueInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
if fromValue.ownership == .none {
uses.replaceAll(with: fromValue, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import SIL

extension DebugStepInst : Simplifyable {
extension DebugStepInst : Simplifiable {
func simplify(_ context: SimplifyContext) {
// When compiling with optimizations (note: it's not a OnoneSimplifyable transformation),
// When compiling with optimizations (note: it's not a OnoneSimplifiable transformation),
// unconditionally remove debug_step instructions.
context.erase(instruction: self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension DestroyValueInst : OnoneSimplifyable, SILCombineSimplifyable {
extension DestroyValueInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
if destroyedValue.ownership == .none {
context.erase(instruction: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension DestructureTupleInst : OnoneSimplifyable, SILCombineSimplifyable {
extension DestructureTupleInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {

// If the tuple is trivial, replace
Expand Down Expand Up @@ -56,7 +56,7 @@ extension DestructureTupleInst : OnoneSimplifyable, SILCombineSimplifyable {
}
}

extension DestructureStructInst : OnoneSimplifyable, SILCombineSimplifyable {
extension DestructureStructInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {

// If the struct is trivial, replace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import SIL
/// operand).
/// The benefit of this transformation is that it enables other optimizations, like mem2reg.
///
extension FixLifetimeInst : Simplifyable, SILCombineSimplifyable {
extension FixLifetimeInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
let opValue = operand.value
guard opValue is AllocStackInst || opValue is StoreBorrowInst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SIL
// Note that `simplifyStrongRetainPass` and `simplifyStrongReleasePass` can
// even remove "unbalanced" retains/releases of a `global_value`, but this
// requires a minimum deployment target.
extension GlobalValueInst : Simplifyable, SILCombineSimplifyable {
extension GlobalValueInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
var users = Stack<Instruction>(context)
defer { users.deinitialize() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension InitEnumDataAddrInst : OnoneSimplifyable {
extension InitEnumDataAddrInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {

// Optimize the sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension KeyPathInst : OnoneSimplifyable {
extension KeyPathInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
if allUsesRemovable(instruction: self) {
if parentFunction.hasOwnership {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension LoadInst : OnoneSimplifyable, SILCombineSimplifyable {
extension LoadInst : OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
if optimizeLoadOfAddrUpcast(context) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension TypeValueInst: OnoneSimplifyable, SILCombineSimplifyable {
extension TypeValueInst: OnoneSimplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
// If our parameter is not known statically, then bail.
guard paramType.isInteger else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension PartialApplyInst : OnoneSimplifyable {
extension PartialApplyInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
let optimizedApplyOfPartialApply = context.tryOptimizeApplyOfPartialApply(closure: self)
if optimizedApplyOfPartialApply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension PointerToAddressInst : OnoneSimplifyable, SILCombineSimplifyable {
extension PointerToAddressInst : OnoneSimplifiable, SILCombineSimplifiable {

func simplify(_ context: SimplifyContext) {
if removeAddressToPointerToAddressPair(of: self, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

import SIL

// Note: this simplifications are not SILCombineSimplifyable, because SILCombine has
// Note: this simplifications are not SILCombineSimplifiable, because SILCombine has
// its own simplifications for those cast instructions which are not ported to Swift, yet.

extension CheckedCastBranchInst : OnoneSimplifyable {
extension CheckedCastBranchInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
// Has only an effect if the source is an (existential) reference.
simplifySourceOperandOfRefCast(context)
}
}

extension UncheckedRefCastInst : OnoneSimplifyable {
extension UncheckedRefCastInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
simplifySourceOperandOfRefCast(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension RetainValueInst : Simplifyable, SILCombineSimplifyable {
extension RetainValueInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {

// Remove pairs of
Expand Down Expand Up @@ -59,7 +59,7 @@ extension RetainValueInst : Simplifyable, SILCombineSimplifyable {
}
}

extension ReleaseValueInst : Simplifyable, SILCombineSimplifyable {
extension ReleaseValueInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {

// Replace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension StrongRetainInst : Simplifyable, SILCombineSimplifyable {
extension StrongRetainInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
if isNotReferenceCounted(value: instance) {
context.erase(instruction: self)
Expand Down Expand Up @@ -44,7 +44,7 @@ extension StrongRetainInst : Simplifyable, SILCombineSimplifyable {
}
}

extension StrongReleaseInst : Simplifyable, SILCombineSimplifyable {
extension StrongReleaseInst : Simplifiable, SILCombineSimplifiable {
func simplify(_ context: SimplifyContext) {
let op = instance
if isNotReferenceCounted(value: op) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension StructExtractInst : OnoneSimplifyable {
extension StructExtractInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
guard let structInst = self.struct as? StructInst else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import SIL
//
// Other case blocks of the switch_enum become dead.
//
extension SwitchEnumInst : OnoneSimplifyable {
extension SwitchEnumInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {
guard let enumInst = enumOp as? EnumInst,
let caseBlock = getUniqueSuccessor(forCaseIndex: enumInst.caseIndex) else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension TupleInst : OnoneSimplifyable {
extension TupleInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {

// Eliminate the redundant instruction pair
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SIL

extension TupleExtractInst : OnoneSimplifyable {
extension TupleExtractInst : OnoneSimplifiable {
func simplify(_ context: SimplifyContext) {

// Replace tuple_extract(tuple(x)) -> x
Expand Down
Loading