Commit Graph

197 Commits

Author SHA1 Message Date
Nate Chandler
e357fb45c5 [OpaqueValues] Handle Builtin.copy.
Specify the operand ownership of the Builtin differently depending on
whether lowered addresses are used.  Handle rewriting the value version
of the builtin as the address version of the builtin in AddressLowering.
2022-11-02 13:48:47 -07:00
Nate Chandler
24c4c617d2 [AddressLowering] Rewrite partial_apply uses.
Use the CallArgRewriter to rewrite uses by partial_apply insts just as
uses by apply insts, etc., are rewritten.
2022-11-01 13:02:32 -07:00
Nate Chandler
5d1c99c0d6 [AddressLowering] CallArgRewriter takes ApplySite.
Rather than being able to handle only to FullApplySites, it now handles
PartialApplyInsts as well.
2022-11-01 13:02:32 -07:00
nate-chandler
b7793511a1 Merge pull request #61747 from nate-chandler/opaque-values/1/20221014
[AddressLowering] Storage root inherits lexical.
2022-10-27 16:35:15 -07:00
Nate Chandler
c766956440 [AddressLowering] Storage root inherits lexical.
When a `begin_borrow [lexical]` is lowered, the lifetime that it
describes can't be shortened (or eliminated) when lowering.  In some
cases, though, there will not be an alloc_stack corresponding directly
to the value being borrowed.

In these cases, mark the whole aggregate lexical.
2022-10-27 11:33:51 -07:00
Nate Chandler
ed623d7b64 [NFC] Shortened SIL [init] flag.
Instead of writing out [initalization] for some instructions, use [init]
everywhere.
2022-10-27 10:38:54 -07:00
Nate Chandler
a995c56d79 [Gardening] Removed unused variable. 2022-10-26 11:01:30 -07:00
Nate Chandler
5ce0148c2a [Gardening] Tweaked comment. 2022-10-26 07:57:55 -07:00
Andrew Trick
ca503b54b7 Redesign PrunedLiveness APIs, introducing live ranges
First restore the basic PrunedLiveness abstraction to its original
intention. Move code outside of the basic abstraction that polutes the
abstraction and is fundamentally wrong from the perspective of the
liveness abstraction.

Most clients need to reason about live ranges, including the def
points, not just liveness based on use points. Add a PrunedLiveRange
layer of types that understand where the live range is
defined. Knowing where the live range is defined (the kill set) helps
reliably check that arbitrary points are within the boundary. This
way, the client doesn't need to be manage this on its own. We can also
support holes in the live range for non-SSA liveness. This makes it
safe and correct for the way liveness is now being used. This layer
safety handles:

- multiple defs
- instructions that are both uses and defs
- dead values
- unreachable code
- self-loops

So it's no longer the client's responsibility to check these things!

Add SSAPrunedLiveness and MultiDefPrunedLiveness to safely handle each
situation.

Split code that I can't figure out into
DiagnosticPrunedLiveness. Hopefully it will be deleted soon.
2022-10-04 13:27:44 -07:00
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
Meghana Gupta
05452dad86 Fix store_borrow generation in AddressLowering 2022-08-16 15:08:22 -07:00
Michael Gottesman
1e6187c4f4 [sil] Update all usages of old API SILValue::getOwnershipKind() in favor of new ValueBase::getOwnershipKind().
Andy some time ago already created the new API but didn't go through and update
the old occurences. I did that in this PR and then deprecated the old API. The
tree is clean, so I could just remove it, but I decided to be nicer to
downstream people by deprecating it first.
2022-07-26 11:46:23 -07:00
Meghana Gupta
7cf67e7eb4 Fix computation of dominance frontier (#59278) 2022-06-07 10:52:29 -07:00
Meghana Gupta
fb0be6ad97 Run AddressLowering after DI and RawSILInstLowering 2022-05-31 20:49:29 -07:00
Meghana Gupta
25186fffbd Use AddressMaterialization::materializeAddress instead of directly using storageAddres 2022-05-31 20:49:29 -07:00
Meghana Gupta
f0e52dbc56 AddressLowering: Handle opaque use in ValueMetatypeInst 2022-05-31 20:49:28 -07:00
Meghana Gupta
8a1ce59601 AddressLowering: Don't generate an end_borrow for store_borrow
store_borrow returns the address to be borrowed and not a token
Don't generate an end_borrow until this is fixed first
2022-05-31 20:49:21 -07:00
Meghana Gupta
dcce7fcf63 AddressLowering: Handle coroutines (#58821) 2022-05-13 19:53:29 -07:00
Meghana Gupta
60d0ac6b4e [SIL Opaque Value] Support checked_cast_br in Address Lowering with loadable source type and opaque target type (#58441) 2022-05-05 11:55:00 -07:00
Meghana Gupta
90a114ea26 AddressLowering: Support checked_cast_br (#42487) 2022-04-22 12:42:34 -07:00
Meghana Gupta
d110b6d82d Move DefRewriter::setStorageAddress above 2022-04-12 12:31:36 -07:00
Meghana Gupta
dcf0803c8c Address Lowering: Add support for unconditional_checked_cast 2022-04-12 12:31:31 -07:00
Meghana Gupta
d50005b4d6 Add support for open_existential_box_value in Address Lowering 2022-04-07 11:52:04 -07:00
Meghana Gupta
16c277f8fb Add new api replaceAllTypeDependentUsesWith 2022-04-07 09:19:42 -07:00
Meghana Gupta
425d457708 [SIL Opaque values] Add support for unchecked_bitwise_cast in AddressLowering 2022-03-28 12:10:09 -07:00
Andrew Trick
1a6d7c1ba5 Merge pull request #41947 from atrick/opv-silgen
[nfc-5.7] Initial round of SILGen fixes and tests for opaque value
2022-03-23 12:01:26 -07:00
Nate Chandler
97cfeb1162 Only define ValueStorageMap::dump in DEBUG. 2022-03-22 20:40:26 -07:00
Andrew Trick
1625a44ded [SIL-opaque] [NFC] clang-format AddressLowering.cpp 2022-03-22 17:04:13 -07:00
Andrew Trick
3ec96fa6f7 [SIL-opaque] Add an assert for open_existential_value.
Add comments.

Add a basic dominance sanity check.
2022-03-22 17:04:13 -07:00
Andrew Trick
a133549e00 [SIL-opaque] Add @in_guaranteed function argument support.
Temporarily map storage to a fake load_borrow.
2022-03-22 17:04:13 -07:00
Andrew Trick
4e3f0dfecc [SIL-opaque] use generated SILLocations
Anywhere that code is not obviously inserted immediately adjacent to
the origin instruction.
2022-03-22 17:04:13 -07:00
Andrew Trick
2fd4de411e [SIL-opaque] Removed [Unconditional]CheckedCastValue 2022-03-22 17:04:13 -07:00
Andrew Trick
6f3a0c3df0 [SIL-opaque] rename initializeComposingUse 2022-03-09 22:27:11 -08:00
Andrew Trick
72817dfd70 [SIL-opaque] rename materialization functions. 2022-03-09 22:16:31 -08:00
Andrew Trick
7f88908402 [SIL-opaque] minor NFC review feedback 2022-03-09 22:16:28 -08:00
Andrew Trick
ef2bf97a14 [SIL-opaque] remove cleanupAfterCall helper 2022-03-09 17:18:16 -08:00
Andrew Trick
355ca16897 [SIL-opaque] Add section-level comment explaining storage allocation 2022-03-09 17:18:16 -08:00
Andrew Trick
fd45bd0192 [SIL-opaque] More file-level documentation
Explain high-level objectives and terminology with more precision.
2022-03-09 17:18:16 -08:00
Andrew Trick
d50c8f67ee [SIL-opaque] avoid handling operands past 64k 2022-03-09 17:18:16 -08:00
Andrew Trick
71175f7115 Rename "phi copy" to "phi move" for consistency with documentation.
In classic compiler terminology, this is a "phi copy" algorithm. But
the documentation now tries to clearly distinguish between "semantics
copies" vs. moves, where moves are "storage copies".
2022-03-09 17:18:16 -08:00
Andrew Trick
c4e167f48f Fix alloc_stack placement for open_existential.
Compute the latestOpeningInst, not the firstOpeningInst.
2022-03-09 17:18:15 -08:00
Andrew Trick
f4176b9111 [SIL-opaque] Code review suggestions
Mostly documentation and typos.
2022-03-09 17:18:15 -08:00
Andrew Trick
b187ba0dde Add support for indirect tuple-type results.
This could happen as a result of specialization or concrete
address-only values.

For now, it's just tested by SIL unit tests.
2022-03-09 17:18:15 -08:00
Andrew Trick
b90007a98c Update and reimplement AddressLowering pass (for SIL opaque values).
Merge the AddressLowering pass from its old development branch and update
it so we can begin incrementally enabling it under a flag.

This has been reimplemented for simplicity. There's no point in
looking at the old code.
2022-03-09 17:18:15 -08:00
Andrew Trick
2907c61203 SILModule::hasLoweredAddress 2022-03-09 17:18:15 -08:00
Andrew Trick
8a7e955b0d Move -enable-sil-opaque-value to SILOptions. 2022-03-09 17:18:15 -08:00
Slava Pestov
7ccc41a7b7 SIL: Preliminary support for 'apply [noasync]' calls
Refactor SILGen's ApplyOptions into an OptionSet, add a
DoesNotAwait flag to go with DoesNotThrow, and sink it
all down into SILInstruction.h.

Then, replace the isNonThrowing() flag in ApplyInst and
BeginApplyInst with getApplyOptions(), and plumb it
through to TryApplyInst as well.

Set the flag when SILGen emits a sync call to a reasync
function.

When set, this disables the SIL verifier check against
calling async functions from sync functions.

Finally, this allows us to add end-to-end tests for
rdar://problem/71098795.
2021-03-04 22:41:46 -05:00
Michael Gottesman
c026e95cce [ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.
This makes it easier to understand conceptually why a ValueOwnershipKind with
Any ownership is invalid and also allowed me to explicitly document the lattice
that relates ownership constraints/value ownership kinds.
2020-11-10 14:29:11 -08:00
Andrew Trick
5ae231eaab Rename getFieldNo() to getFieldIndex().
Do I really need to justify this?
2020-09-24 22:44:13 -07:00
Arnold Schwaighofer
147144baa6 SIL: Thread type expansion context through to function convention apis
This became necessary after recent function type changes that keep
substituted generic function types abstract even after substitution to
correctly handle automatic opaque result type substitution.

Instead of performing the opaque result type substitution as part of
substituting the generic args the underlying type will now be reified as
part of looking at the parameter/return types which happens as part of
the function convention apis.

rdar://62560867
2020-05-04 13:53:30 -07:00