Files
swift-mirror/include/swift/SILOptimizer/Utils/KeyPathProjector.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

91 lines
3.1 KiB
C++

//===-- KeyPathProjector.h - Project a static key path ----------*- 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Utility class to project a statically known key path
/// expression to a direct property access sequence.
///
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SILOPTIMIZER_UTILS_KEYPATHPROJECTOR_H
#define SWIFT_SILOPTIMIZER_UTILS_KEYPATHPROJECTOR_H
#include "swift/SIL/SILBuilder.h"
#include <memory>
namespace swift {
class KeyPathInst;
/// Projects a statically known key path expression to
/// a direct property access.
class KeyPathProjector {
public:
/// The type of a key path access.
enum class AccessType {
/// A get-only access (i.e. swift_getAtKeyPath).
Get,
/// A set-only access (i.e. swift_setAtWritableKeyPath).
Set,
/// A modification (i.e. swift_modifyAtWritableKeyPath).
Modify
};
/// Creates a key path projector for a key path.
///
/// Returns nullptr if \p keyPath is not a keypath instruction or if there is
/// any other reason why the optimization cannot be done.
///
/// \param keyPath The key path to project. Must be the result of either
/// a keypath instruction or an upcast of a key path instruction.
/// \param root The address of the object the key path is applied to.
/// \param loc The location of the key path application.
/// \param builder The SILBuilder to use.
static std::unique_ptr<KeyPathProjector>
create(SILValue keyPath, SILValue root, SILLocation loc, SILBuilder &builder);
/// Extract the literal KeyPathInst underlying a value, or return null if there is none.
static KeyPathInst *
getLiteralKeyPath(SILValue keyPath);
/// Projects the key path to an address. Sets up the projection,
/// invokes the callback, then tears down the projection.
/// \param accessType The access type of the projected address.
/// \param callback A callback to invoke with the projected address.
/// The projected address is only valid from within \p callback.
/// If accessType is Get or Modify, the projected addres is an
/// initialized address type. If accessType is set, the projected
/// address points to uninitialized memory.
virtual void project(AccessType accessType,
std::function<void(SILValue addr)> callback) = 0;
virtual ~KeyPathProjector() {};
/// Whether this projection returns a struct.
virtual bool isStruct() = 0;
protected:
KeyPathProjector(SILLocation loc, SILBuilder &builder)
: loc(loc), builder(builder) {}
/// The location of the key path application.
SILLocation loc;
/// The SILBuilder to use.
SILBuilder &builder;
};
} // end namespace swift
#endif /* KeyPathProjector_h */