Commit Graph

2260 Commits

Author SHA1 Message Date
Erik Eckstein
f082584230 Use the new side effects in CSE 2022-12-21 17:41:46 +01:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Valeriy Van
ab0e89a362 Fix bug wrong return value 2022-12-19 15:43:56 +02:00
Valeriy Van
2265e1d4a1 Remove one of two identical sub-expressions 'accessKind == AccessStorage::Class' to the left and to the right of the '||' operator 2022-12-17 18:36:40 +02:00
Michael Gottesman
9e44011e4d [sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
I am adding this to make it easy to determine if a SILFunction that is not inout
aliasable is captured. This is useful when emitting certain types of
diagnostics like I need to emit with move only.
2022-12-14 15:16:43 -08:00
eeckstein
9cebd69654 Merge pull request #62556 from eeckstein/remove-dead-metatype-insts
Performance annotations: make `UnsafeMutableRawBufferPointer.bindMemory` allocation/lock free
2022-12-14 06:26:35 +01:00
John McCall
f524f3de69 [NFC] Support instructions that define multiple opened archetypes
I've also fixed this so that it should work on instructions that
define multiple values.  Someday we'll change all the open_existential
instructions to produce different values for the type dependency and
the value result; today is not that day, though.
2022-12-13 13:28:13 -05:00
Erik Eckstein
fc30ac2431 Performance annotations: make UnsafeMutableRawBufferPointer.bindMemory allocation/lock free
Remove dead `metatype` instructions which only have `debug_value` uses.
We lose debug info for such type variables, but this is a compromise we need to accept to get allocation/lock free code.

rdar://103270882
2022-12-13 17:10:53 +01:00
Erik Eckstein
c180d1363e SIL: simplify deleting instruction while iterating over instructions.
Add `deletableInstructions()` and `reverseDeletableInstructions()` in SILBasicBlock.
It allows deleting instructions while iterating over all instructions of the block.
This is a replacement for `InstructionDeleter::updatingRange()`.
It's a simpler implementation than the existing `UpdatingListIterator` and `UpdatingInstructionIteratorRegistry`, because it just needs to keep the prev/next pointers for "deleted" instructions instead of the iterator-registration machinery.
It's also safer, because it doesn't require to delete instructions via a specific instance of an InstructionDeleter (which can be missed easily).
2022-12-12 19:08:54 +01:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
nate-chandler
d5e8625db9 Merge pull request #62442 from nate-chandler/opaque-values/1/20221201
[AddressLowering] Handle indirectly yielded values used outside of coroutine range.
2022-12-09 07:00:16 -08:00
Nate Chandler
e1cb0b5522 [MemAccessUtils] Look thru nested for guar roots.
Previously, findGuaranteedReferenceRoots always stopped searching when
finding a begin_borrow, because it's not an ownership-forwarding
instruction.  Here, it is conditionally allowed to keep search through
the borrowee of that begin_borrow if it itself is guaranteed.
2022-12-08 18:29:14 -08:00
Ben Rimmington
0b29450a3d [SE-0368] StaticBigInt (#40722) 2022-12-06 21:59:42 +00:00
Erik Eckstein
d80d7ddcde MandatoryGenericSpecializer: add the partial_apply -> apply peephole optimization
In performance-annotated functions optimize the pattern where a partial_apply is immediately applied.
This remove the partial apply and thus avoids an allocation.

Fixes an unnecessary performance violation error.

rdar://95155145
2022-12-01 07:05:02 +01:00
Erik Eckstein
6d0903ad7b AllocBoxToStack: handle begin_borrow when checking if a partial_apply escapes. 2022-12-01 07:05:02 +01:00
swift-ci
ec2d7fc847 Merge pull request #62198 from nate-chandler/opaque-values/3/20221118
[AddressLowering] Don't end_borrow trivial args.
2022-11-29 17:07:24 -08:00
swift-ci
d30878a575 Merge pull request #62267 from apple/maxd/specializer-comment-typo
GenericSpecializer.cpp NFC: fix typo in comment
2022-11-28 11:05:40 -08:00
Max Desiatov
0112763a90 GenericSpecializer.cpp: fix typo in comment
`save side` -> `safe side`
2022-11-27 13:42:51 +00:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Nate Chandler
42aa21cc81 [NFC] Moved inlining printing to PassManager. 2022-11-18 16:29:51 -08:00
Erik Eckstein
0403a21d34 use the new side effects in the performance inliner 2022-11-09 08:06:19 +01:00
Erik Eckstein
13dad3ad47 PerformanceInliner: tweak the inlining heuristic for callees which return an allocated object
There are examples of such functions, which were previously captured by `isPureCall` in the inliner. But the implementation of `isPureCall` was wrong.
With the new (and correct) side effect analysis we need to correctly handle such functions in the inlining heuristic.
2022-11-09 08:06:19 +01:00
Erik Eckstein
53caa42bec ARCCodeMotion: support bisecting individual optimized release-instructions when debugging this pass. 2022-11-08 17:46:08 +01:00
nate-chandler
db9a140c44 Merge pull request #61887 from nate-chandler/opaque-values/1/20221102
[OpaqueValues] Handle Builtin.addressOfBorrow.
2022-11-03 14:46:02 -07:00
Meghana Gupta
c640bcaa69 Merge pull request #61826 from meg-gupta/rleisuniq
Consider is_unique as a barrier for optimization in OSSA RLE
2022-11-03 10:19:04 -07:00
Nate Chandler
520dfc26cd [OpaqueValues] Added variants of addressOfBorrow.
The variants are produced by SILGen when opaque values are enabled.
They are necessary because otherwise SILGen would produce
address_to_pointer of values.

They will be lowered by AddressLowering.
2022-11-02 14:41:35 -07:00
Meghana Gupta
dbc06502e9 Consider is_unique as a barrier for optimization in OSSA RLE 2022-11-02 13:32:09 -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
Andrew Trick
e989c9b0e9 SpeculativeDevirtualizer - Fix OSSA support
The OSSA verifier was never enabled for block terminators. So we could
blindly give terminator results any ownership without knowing.
2022-10-22 21:57:47 -07:00
Meghana Gupta
79565a4f9e Merge pull request #61676 from meg-gupta/followup
Followup for #61505
2022-10-22 20:37:19 -07:00
Meghana Gupta
ff4ab7de11 Enable SimplifyCFG::canonicalizeSwitchEnums and add unit tests 2022-10-21 23:08:43 -07:00
Meghana Gupta
8934ca74a2 Revert "Update ConditionForwarding for @guaranteed forwarding phi support"
This reverts commit 4acfd4d8da.
2022-10-21 22:31:04 -07:00
Meghana Gupta
97013100dc [NFC] Move SimplifyCFG class to its own header so that it can be accessed by the unit test infra 2022-10-21 16:48:28 -07:00
Meghana Gupta
e54939262d Merge pull request #61670 from meg-gupta/dceguaranteedphi
DCE: Don't generate end_borrow for GuaranteedForwardingPhi
2022-10-21 16:44:33 -07:00
Meghana Gupta
d6399e2626 Don't generate end_borrow for GuaranteedForwardingPhi in DCE 2022-10-21 11:53:50 -07:00
Erik Eckstein
ed54253d29 SIL Optimizer: remove legacy C++ passes
They were used as a backup during the transition to Swift passes. Now they are not needed anymore.
2022-10-20 18:31:06 +02:00
Erik Eckstein
ecbcacdecf SIL Analysis: Rename InvalidationKind::FunctionData to InvalidationKind::Effects
This invalidation kind is used when a compute-effects pass changes function effects.
Also, let optimization passes which don't change effects only invalidate the `FunctionBody` and not `Everything`.
2022-10-20 09:20:28 +02:00
Meghana Gupta
4acfd4d8da Update ConditionForwarding for @guaranteed forwarding phi support 2022-10-19 19:54:28 -07:00
Meghana Gupta
5ede08ca3c Update DCE for @guaranteed forwarding phi support 2022-10-19 19:54:28 -07:00
Nate Chandler
4b85d0a9ca [DestroyHoisting] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This enables
LexicalDestroyHoisting to hoist destroys over applies of functions which
are not deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
f85074d1ba [ShrinkBorrowScope] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This will allow
ShrinkBorrowScope to hoist end_borrows over applies of functions which
are not deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
a2a621a3aa [SSADestroyHoisting] Barriers use callee analysis.
Pass a BasicCalleeAnalysis instance to isDeinitBarrier.  This will
enable SSADestroyHoisting to hoist destroy_addrs over applies of
functions that are not themselves deinit barriers.
2022-10-18 21:23:22 -07:00
Nate Chandler
7ea336367d [NFC] Port isDeinitBarrier to Swift.
Added new C++-to-Swift callback for isDeinitBarrier.

And pass it CalleeAnalysis so it can depend on function effects.  For
now, the argument is ignored.  And, all callers just pass nullptr.

Promoted to API the mayAccessPointer component predicate of
isDeinitBarrier which needs to remain in C++.  That predicate will also
depends on function effects.  For that reason, it too is now passed a
BasicCalleeAnalysis and is moved into SILOptimizer.

Also, added more conservative versions of isDeinitBarrier and
maySynchronize which will never consider side-effects.
2022-10-18 21:23:22 -07:00
Nate Chandler
03253dbf48 [CanonicalizeOSSALifetime] Extend Onone lifetimes.
To improve the debugging experience of values whose lifetimes are
canonicalized without compromising the semantics expressed in the source
language, when canonicalizing OSSA lifetimes at Onone, lengthen
lifetimes as much as possible without incurring copies that would be
eliminated at O.

rdar://99618502
2022-10-08 16:08:35 -07:00
Nate Chandler
79c2f1e693 [Gardening] Tweaked comments. 2022-10-08 15:16:41 -07:00
Nate Chandler
4fc42a63a3 [CanonicalizeOSSALifetime] Renamed file.
Matched to the name of the utility.
2022-10-05 17:07:05 -07:00
Andrew Trick
8f34d9cc2f Add a comment regarding an optimizer rule for self-loops. 2022-10-04 13:27:48 -07:00
Andrew Trick
40e03ef782 Update passes to use SSAPrunedLiveness or MultiDefPrunedLiveness 2022-10-04 13:27:47 -07:00
Allan Shortlidge
c7ce7b75e0 Merge pull request #42514 from jsoref/spelling-siloptimizer
Spelling siloptimizer
2022-10-03 22:50:19 -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