Commit Graph

2592 Commits

Author SHA1 Message Date
Nate Chandler
220597e68e [NFC] Removed unneeded variable.
No need to bind to the StoreBorrowInst to get the source because it's
already bound to the local variable `stored`.  And no need to bind to a
more specific type to find the next instruction.
2023-02-15 18:16:33 -08:00
Nate Chandler
a805179188 [Mem2Reg] Never borrow lifetimed stored_borrows.
Extend the definition of isGuaranteedLexicalValue--by means of which
Mem2Reg determines whether to borrow introducing a begin_borrow
[lexical] of a value which is store_borrow'd to an alloc_stack
[lexical]--to include every guaranteed lexical value.
2023-02-15 18:16:33 -08:00
Nate Chandler
b8c2269ff5 [NFC] Changed function name.
Because lexical borrows are already avoided for store_borrows of lexical
values, the function is already misnamed: it's not that Mem2Reg should
necessarily _add_ a lexical lifetime, but rather that it should ensure
that there is one.  Considering that we should do the same for owned
lexical values, the renaming will remain appropriate later.  Finally,
name it so that it can switch from being a boolean to returning a
tristate (none, guaranteed, owned) when that becomes necessary (as it
will when we need to distinguish among the states to determine what phis
look like).
2023-02-15 18:16:33 -08:00
Nate Chandler
06ed5d7801 [NFC] Removed spurious templating.
Now that StackAllocationPromoter::initializationPoints maps to either a
StoreInst or a StoreBorrowInst, there is no longer a subtype of
SILInstruction * at which the BlockToInstMap could be specialized, so
just eliminate the template argument and erase some angle brackets.
2023-02-15 18:16:33 -08:00
Erik Eckstein
748264c45f Add a unprotectedStackAlloc builtin
It's like `Builtin.stackAlloc`, but doesn't set the `[stack_protection]` flag on its containing function.
2023-02-15 08:09:38 +01:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Nate Chandler
469c3ec3bd [ObjectOutliner] See through move_value insts.
Enables the outlining of the ContiguousArrayStorage<StaticString> used
when initializing a RawRepresentable enum whose RawValue is String into
a global value to continue even when ContiguousArrayStorage has a
lexical lifetime.

Addresses the following regressions

StringEnumRawValueInitialization    400     7680    +1820.0%   **0.05x**
ArrayLiteral2                       78      647     +729.5%    **0.12x**
DataCreateSmallArray                1750    8850    +405.7%    **0.20x**

seen when enabling lexical lifetimes in the standard library.
2023-01-25 11:39:42 -08:00
Erik Eckstein
7d8bf37e5e change to the new llvm::Optional APIs
This is a follow-up of https://github.com/apple/swift/pull/62217
2023-01-25 09:18:36 +01:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Erik Eckstein
edce513580 SIL: simplify replaceBranchTarget
Instead of re-creating all kind of terminator instructions, just re-assign the terminator's successor.
2023-01-16 18:55:35 +01:00
Robert Widmann
6275e2298c Merge pull request #62681 from valeriyvan/SILCodeMotion
Fix bug wrong return value
2023-01-13 08:19:39 -07:00
Anthony Latsis
3bfe7a4d6e Merge pull request #62658 from valeriyvan/AccessStorage
Remove one of two identical sub-expressions 'accessKind == AccessStorage::Class' to the left and to the right of the '||' operator
2023-01-12 15:17:04 +03:00
John McCall
9aeddd0b41 Merge pull request #62955 from rjmccall/open_pack_element
Add the open_pack_element instruction
2023-01-11 13:17:46 -05:00
swift-ci
93a0a6d905 Merge pull request #62914 from ktoso/wip-task-group-twotypes
[Concurrency] DiscardingTaskGroup (rev 3)
2023-01-11 01:37:33 -08:00
John McCall
d673a45c88 More opened-existential vs. local-archetype fixes in SIL 2023-01-11 03:11:30 -05:00
nate-chandler
fb01580e41 Merge pull request #62873 from nate-chandler/bug/20230105/1
[SSADestroyHoisting] Don't fold over trivial use.
2023-01-09 07:05:22 -08:00
Meghana Gupta
0c29ebb57d Fix typo 2023-01-08 00:15:17 -08:00
Meghana Gupta
dac6c0303f Add tests for simple jump threading 2023-01-08 00:15:17 -08:00
Meghana Gupta
5d2967ca75 Fix SimplifyCFG::simplifySwitchEnumOnObjcClassOptional for OSSA 2023-01-08 00:15:17 -08:00
Meghana Gupta
cdbd0f4743 Fix SimplifyCFG::simplifyArgs for OSSA 2023-01-08 00:15:12 -08:00
Meghana Gupta
3660a1e6a9 Remove borrow scope adjustment for @guaranteed phi args 2023-01-06 23:50:07 -08:00
Meghana Gupta
900d8c3f63 Add ossa unit tests for SimplifyCFG::simplifyTermWithIdenticalDestBlocks 2023-01-06 23:50:07 -08:00
Meghana Gupta
73cd7a9dc1 Add ossa unit tests for SimplifyCFG::simplifySwitchEnumUnreachableBlocks 2023-01-06 23:50:07 -08:00
Meghana Gupta
1fc0d0aba1 SimplifyCFG: Modify DestBB before replacing branch target 2023-01-06 23:50:07 -08:00
Meghana Gupta
94f8841374 Fix SimplifyCFG::simplifySwitchEnumBlock for OSSA 2023-01-06 23:50:07 -08:00
Meghana Gupta
cdeb55a20a Fix DCE of begin_borrow with @guaranteed operand
For the lower most begin_borrows with @guaranteed operands, there
was no @guaranteed phi computation, restructure the code and fix this case.
2023-01-06 09:23:42 -08:00
Nate Chandler
4dec48f9a6 [SSADestroyHoisting] Don't fold over trivial use.
Given an aggregate addr `%agg` with trivial subobject addr `%triv` and
nontrivial subobject addr `%sub` which `%triv` is projected from,
```
  Aggregate   <- %agg
    Subobject <- %sub
      Trivial <- %triv
      ...
    ...
```

after `%sub` is destroyed, `%triv` is no longer initialized.  As a
result, it's not valid to fold a destroy_addr of %agg into a sequence of
`load [copy]`s and `copy_addr`s if there's an access to `%triv` after
the `load [copy]`/`copy_addr` of `%sub` (or some intermediate
subobject).

In other words, transforming
```
  copy_addr %sub
  load [trivial] %triv
  destroy_addr %agg
```
into
```
  copy_addr [take] %sub
  load [trivial] %triv
```
is invalid.

During destroy_addr folding, prevent that from happening by keeping
track of the trivial fields that have already been visited.  If a
trivial field is seen more than once, then bail on folding.  This is
the same as what is done for non-trivial fields except that there's no
requirement that all trivial fields be destroyed.
2023-01-05 15:18:36 -08:00
Konrad `ktoso` Malawski
f8b85015c1 prepare flags
wip on options

implement discardResults as a flag passed to grout init
2023-01-05 16:19:05 +09:00
Erik Eckstein
0c6f0bb982 StringOptimization: preserve debug scopes when creating calls to the string initializer 2023-01-02 13:52:21 +01:00
Erik Eckstein
cd45058e66 ReleaseCodeMotion: use a SmallVector instead of a SetVector for RCRootVault.
We don't need a set for this vector.
2023-01-02 13:52:21 +01:00
Erik Eckstein
ef12ec7b2c COWOpts: fix a crash in case a buffer "escapes" to a cond_br condition
rdar://103638121
2022-12-22 17:04:42 +01:00
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