Files
swift-mirror/include/swift/SILOptimizer/Utils/CanonicalizeInstruction.h
Josh Soref 730b16c569 Spelling siloptimizer
* access
* accessed
* accesses
* accessor
* acquiring
* across
* activated
* additive
* address
* addresses'
* aggregated
* analysis
* and
* appropriately
* archetype
* argument
* associated
* availability
* barriers
* because
* been
* beginning
* belongs
* beneficial
* blocks
* borrow
* builtin
* cannot
* canonical
* canonicalize
* clazz
* cleanup
* coalesceable
* coalesced
* comparisons
* completely
* component
* computed
* concrete
* conjunction
* conservatively
* constituent
* construct
* consuming
* containing
* covered
* creates
* critical
* dataflow
* declaration
* defined
* defining
* definition
* deinitialization
* deliberately
* dependencies
* dependent
* deserialized
* destroy
* deterministic
* deterministically
* devirtualizes
* diagnostic
* diagnostics
* differentiation
* disable
* discipline
* dominate
* dominates
* don't
* element
* eliminate
* eliminating
* elimination
* embedded
* encounter
* epilogue
* epsilon
* escape
* escaping
* essential
* evaluating
* evaluation
* evaluator
* executing
* existential
* existentials
* explicit
* expression
* extended
* extension
* extract
* for
* from
* function
* generic
* guarantee
* guaranteed
* happened
* heuristic
* however
* identifiable
* immediately
* implementation
* improper
* include
* infinite
* initialize
* initialized
* initializer
* inside
* instruction
* interference
* interferes
* interleaved
* internal
* intersection
* intractable
* intrinsic
* invalidates
* irreducible
* irrelevant
* language
* lifetime
* literal
* looks
* materialize
* meaning
* mergeable
* might
* mimics
* modification
* modifies
* multiple
* mutating
* necessarily
* necessary
* needsmultiplecopies
* nonetheless
* nothing
* occurred
* occurs
* optimization
* optimizing
* original
* outside
* overflow
* overlapping
* overridden
* owned
* ownership
* parallel
* parameter
* paths
* patterns
* pipeline
* plottable
* possible
* potentially
* practically
* preamble
* precede
* preceding
* predecessor
* preferable
* preparation
* probably
* projection
* properties
* property
* protocol
* reabstraction
* reachable
* recognized
* recursive
* recursively
* redundant
* reentrancy
* referenced
* registry
* reinitialization
* reload
* represent
* requires
* response
* responsible
* retrieving
* returned
* returning
* returns
* rewriting
* rewritten
* sample
* scenarios
* scope
* should
* sideeffects
* similar
* simplify
* simplifycfg
* somewhat
* spaghetti
* specialization
* specializations
* specialized
* specially
* statistically
* substitute
* substitution
* succeeds
* successful
* successfully
* successor
* superfluous
* surprisingly
* suspension
* swift
* targeted
* that
* that our
* the
* therefore
* this
* those
* threshold
* through
* transform
* transformation
* truncated
* ultimate
* unchecked
* uninitialized
* unlikely
* unmanaged
* unoptimized key
* updataflow
* usefulness
* utilities
* villain
* whenever
* writes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-10-03 18:31:33 -04:00

116 lines
4.5 KiB
C++

//===-- CanonicalizeInstruction.h - canonical SIL peepholes -----*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// SSA-peephole transformations that yield a more canonical SIL representation.
///
/// Unlike simplifyInstruction, these transformations may effect any
/// instruction, not only single-values, and may arbitrarily generate new SIL
/// instructions.
///
/// Unlike SILCombine, these peepholes must work on 'raw' SIL form and should be
/// limited to those necessary to aid in diagnostics and other mandatory
/// pipeline passes. Optimization may only be done to the extent that it
/// neither interferes with diagnostics nor increases compile time.
///
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEINSTRUCTION_H
#define SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEINSTRUCTION_H
#include "swift/SIL/BasicBlockUtils.h"
#include "swift/SIL/SILBasicBlock.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
#include "llvm/Support/Debug.h"
namespace swift {
/// Abstract base class. Implements all canonicalization transforms. Extended by
/// passes to be notified of each SIL modification.
struct CanonicalizeInstruction {
// May be overridden by passes.
static constexpr const char *defaultDebugType = "sil-canonicalize";
const char *debugType = defaultDebugType;
DeadEndBlocks &deadEndBlocks;
InstModCallbacks callbacks;
bool preserveDebugInfo;
CanonicalizeInstruction(const char *passDebugType,
DeadEndBlocks &deadEndBlocks)
: deadEndBlocks(deadEndBlocks),
callbacks() {
preserveDebugInfo = getFunction()->getEffectiveOptimizationMode()
<= OptimizationMode::NoOptimization;
#ifndef NDEBUG
if (llvm::DebugFlag && !llvm::isCurrentDebugType(debugType))
debugType = passDebugType;
#endif
callbacks = InstModCallbacks()
.onDelete([&](SILInstruction *toDelete) {
killInstruction(toDelete);
})
.onCreateNewInst([&](SILInstruction *newInst) {
notifyNewInstruction(newInst);
})
.onSetUseValue([&](Operand *use, SILValue newValue) {
use->set(newValue);
notifyHasNewUsers(newValue);
});
}
virtual ~CanonicalizeInstruction();
const SILFunction *getFunction() const { return deadEndBlocks.getFunction(); }
// TODO: callbacks should come from the current InstructionDeleter.
InstModCallbacks &getCallbacks() { return callbacks; }
/// Rewrite this instruction, based on its operands and uses, into a more
/// canonical representation.
///
/// Return an iterator to the next instruction or to the end of the block.
/// The returned iterator will follow any newly added or to-be-deleted
/// instructions, regardless of whether the pass immediately deletes the
/// instructions or simply records them for later deletion.
///
/// To (re)visit new instructions, override notifyNewInstruction().
///
/// To determine if any transformation at all occurred, override
/// notifyNewInstruction(), killInstruction(), and notifyNewUsers().
///
/// Warning: If the \p inst argument is killed and the client immediately
/// erases \p inst, then it may be an invalid pointer upon return.
SILBasicBlock::iterator canonicalize(SILInstruction *inst);
/// Record a newly generated instruction.
virtual void notifyNewInstruction(SILInstruction *inst) = 0;
/// Kill an instruction that no longer has uses, or whose side effect is now
/// represented by a different instruction. The client can defer erasing the
/// instruction but must eventually erase all killed instructions to restore
/// valid SIL.
///
/// This callback should not mutate any other instructions. It may only delete
/// the given argument. It will be called separately for each end-of-scope and
/// debug use before being called on the instruction they use.
virtual void killInstruction(SILInstruction *inst) = 0;
/// Record a SIL value that has acquired new users.
virtual void notifyHasNewUsers(SILValue value) = 0;
};
} // end namespace swift
#endif // SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEINSTRUCTION_H