Commit Graph

2260 Commits

Author SHA1 Message Date
Meghana Gupta
308704d335 Fix TempRVO on OSSA for load_borrow
This PR makes sure the destroy_addr of the copy source is inserted after
end_borrow of its direct or indirect load_borrow.
2021-10-11 23:37:28 -07:00
Nate Chandler
8b99d34221 [Gardening] Tweaked comment. 2021-10-11 09:12:37 -07:00
Nate Chandler
0827390188 [NFC] Marked endLexicalLifetimeInBlock static.
The function is currently only (and only ever intended to be) used only
within SILMem2Reg.
2021-10-11 09:12:37 -07:00
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
Meghana Gupta
5d6b6b7fe2 Migrate Outliner to OSSA 2021-10-09 08:42:50 -07:00
Arnold Schwaighofer
cd7283d059 SIL optimization 2021-10-06 04:54:49 -07:00
swift-ci
c51550f30e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-30 15:11:41 -07:00
Evan Wilde
514fc83639 Fix missing template member in SmallVector
The ubuntu 18.04 Linux builder fails to build when the SmallVector does
not include the number of elements. This is a known issue and is
incorrect, but that is the version of clang on that OS.

The definition of SmallVector is already available transitively since
there are values of that type, I've just made it explicit.

llvm::SmallVector has a default parameter for the number of elements
while swift::SmallVector doesn't. I've gone ahead and made it explicitly
use the llvm::SmallVector to receive that.
2021-09-28 23:25:21 -07:00
Nate Chandler
79bc4cba31 [Mem2Reg] Lexical allocs create lexical borrows.
SILGen turns vars into alloc_boxes.  When possible, AllocBoxToStack
turns those into alloc_stacks.  In order to preserve the lexical
lifetime of those vars, the alloc_stacks are annotated with the
[lexical] attribute.  When Mem2Reg runs, it promotes the loads from
and stores into those alloc_stacks to uses of registers.  In order to
preserve the lexical lifetime during that transformation, lexical borrow
scopes must be introduces that encode the same lifetime as the
alloc_stacks did.  Here, that is done.
2021-09-27 20:29:47 -07:00
Nate Chandler
16cbae367b [SILMem2Reg] Added explanation to assert. 2021-09-27 20:29:46 -07:00
Nate Chandler
63192bafa5 [AllocBoxToStack] Make alloc_stacks lexical.
When the -enable-experimental-lexical-lifetimes flag is enabled, the
alloc_stack instructions which the pass replaces alloc_box instructions
with have the lexical attribute.
2021-09-27 20:29:46 -07:00
Nate Chandler
d97a24a4bd SILSROA: Propagate lexical flag on alloc_stacks. 2021-09-27 20:29:45 -07:00
swift-ci
f0def9afc0 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-22 09:13:41 -07:00
Andrew Trick
e85228491d Rename AccessedStorage to AccessStorage
to be consistent with AccessPath and AccessBase.

Otherwise, the arbitrary name difference adds constant friction.
2021-09-21 23:18:24 -07:00
Andrew Trick
354b5c4e17 Add AccessBase abstraction as OSSA helper
Split AccessedStorage functionality in two pieces. This doesn't add
any new logic, it just allows utilities to make queries on the access
base. This is important for OSSA where we often need to find the
borrow scope or ownership root that contains an access.
2021-09-21 19:54:24 -07:00
swift-ci
a34e4eb804 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 16:32:59 -07:00
Andrew Trick
a5b1b5c3f8 SILOptimizer OSSA support for switch_enum & checked_cast_br
To create OSSA terminator results, use:
- OwnershipForwardingTermInst::createResult(SILType ValueOwnershipKind)
- SwitchEnumInst::createDefaultResult()

Add support for passing trivial values to nontrivial forwarding
ownership. This effectively converts None to Guaranteed ownership.

This is essential for handling ".none" enums as trivial values while
extracting a nontrivial payload with switch_enum. This converts None
to Guaranteed ownership. Generates a copy if needed to convert back to
Owned ownership.
2021-09-07 22:50:46 -07:00
swift-ci
ebad328a4f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-01 09:14:57 -07:00
Min-Yih Hsu
b769654305 Merge pull request #39082 from mshockwave/dev-deprecate-debug-val-addr
[SIL][DebugInfo] PATCH 3/3: Deprecate debug_value_addr SIL instruciton
2021-09-01 09:14:29 -07:00
swift-ci
87b44eeaf1 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-31 14:35:06 -07:00
Meghana Gupta
6c74c0ff2b Merge pull request #39097 from meg-gupta/rlefix
Fix an edge case in OSSA RLE for loops
2021-08-31 14:15:11 -07:00
Min-Yih Hsu
343d842394 [SIL][DebugInfo] PATCH 3/3: Deprecate debug_value_addr SIL instruciton
This patch removes all references to DebugValueAddrInst class and
debug_value_addr instruction in textual SIL files.
2021-08-31 12:01:04 -07:00
Min-Yih Hsu
e1023bc323 [DebugInfo] PATCH 2/3: Duplicate logics regarding debug_value_addr
This patch replace all in-memory objects of DebugValueAddrInst with
DebugValueInst + op_deref, and duplicates logics that handles
DebugValueAddrInst with the latter. All related check in the tests
have been updated as well.

Note that this patch neither remove the DebugValueAddrInst class nor
remove `debug_value_addr` syntax in the test inputs.
2021-08-31 11:57:56 -07:00
Meghana Gupta
5b3c687bf1 Fix an edge case in OSSA RLE for loops
In OSSA RLE for loops, in certain cases SSAUpdater will not create a new
SILPhiArgument to be used as the forwarding value. Based on dominator info
it may return the newly copied available value as the forwarding value.
This newly copied available value in the dominating predecessor
will have destroy values at leaking blocks.

Rename makeNewValueAvailable to makeValueAvailable and handle users so that only
additional required destroy_values are inserted.
2021-08-31 09:47:42 -07:00
swift-ci
4bb48a1f43 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-26 11:33:29 -07:00
Erik Eckstein
ec67d1bc5a COWOpts: handle debug_value instructions
Don't let debug_value instructions bail the optimization.

This fixes a couple of performance regressions, which were introduced by adding more debug_value instructions (https://github.com/apple/swift/pull/38736).

rdar://82327743
2021-08-26 13:54:26 +02:00
swift-ci
4bc13fcda7 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-25 18:33:25 -07:00
Meghana Gupta
9ab8763d61 Merge pull request #38965 from meg-gupta/fixdestroyhoisting
Fix use-after-free in DestroyHoisting
2021-08-25 18:29:18 -07:00
Meghana Gupta
4c9cb0c768 Fix use-after-free in DestroyHoisting
Due to mismatch in the instructions handled in DestroyHoisting::getUsedLocationsOfInst
and MemoryLocations::analyzeLocationUsesRecursively, certain users of addresses
were not considered and the destroys were hoisted before valid uses causing use-after-frees
2021-08-25 13:07:21 -07:00
Meghana Gupta
95215d40d4 Remove call to splitCriticalEdges
OSSA cannot have critical edges. And DestroyHoisting works only on OSSA.
2021-08-19 12:09:54 -07:00
swift-ci
3a9a382d8d Merge remote-tracking branch 'origin/main' into rebranch 2021-08-19 10:53:10 -07:00
Meghana Gupta
990fc4b815 Merge pull request #38945 from meg-gupta/fixcopyfwd
Cleanup dead debug_value_addr in CopyForwarding
2021-08-19 10:37:37 -07:00
Meghana Gupta
f4b585e933 Cleanup dead debug_value_addr in CopyForwarding
After hoisting the destroy of the copy src, debug_value_addr users of the
copy src become dead, this PR cleans them so that MemoryLifetimeVerifier does not
complain later.
2021-08-18 16:58:16 -07:00
swift-ci
e393330007 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-12 13:57:26 -07:00
Meghana Gupta
6bafc8498d Remove end_lifetime being considered as an end of scope marker (#38851)
OSSA rauw cleans up end of scope markers before rauw'ing.
This can lead to inadvertant deleting of end_lifetime, later
resulting in an ownership verifier error indicating a leak.

This PR stops treating end_lifetime scope ending like end_borrow/end_access.
2021-08-12 13:49:06 -07:00
swift-ci
a8089662bd Merge remote-tracking branch 'origin/main' into rebranch 2021-08-09 16:13:32 -07:00
Andrew Trick
a93a1f80bf Merge pull request #38797 from atrick/ossa-isborrowedaddress
OSSA support for Box types. AccessedStorage Box handling. isBorrowedAddress utility.
2021-08-09 16:05:48 -07:00
swift-ci
2f0d81d58e Merge remote-tracking branch 'origin/main' into rebranch 2021-08-08 20:53:47 -07:00
Meghana Gupta
bb3a0e3892 Fix SROA for alloc_stack [dynamic_lifetime] (#38793) 2021-08-08 20:46:37 -07:00
Andrew Trick
9984b81de7 MemAccessUtils cleanup: rename hasIdenticalBase
to hasIdenticalStorage.

Be precise in preparation for unifying and clarifying the access base model.
2021-08-07 15:26:46 -07:00
swift-ci
8a4df5677c Merge remote-tracking branch 'origin/main' into rebranch 2021-08-06 09:33:44 -07:00
Min-Yih Hsu
9a8f2ed642 [SILOptimizer][DebugInfo] Preliminary support for DIExpression in SROA and Mem2Reg
SROA and Mem2Reg now can leverage DIExpression -- op_fragment, more
specifically -- to generate correct debug info for optimized SIL. Some
important highlights:
 - The new swift::salvageDebugInfo, similar to llvm::salvageDebugInfo,
   tries to restore / transfer debug info from a deleted instruction.
   Currently I only implemented this for store instruction whose
   destination is an alloc_stack value.
 - Since we now have source-variable-specific SIL location inside a
   `debug_value` instruction (and its friends), this patch teaches
   SILCloner and SILInliner to remap the debug scope there in addition
   to debug scope of the instruction.
 - DCE now does not remove `debug_value` instruction whose associating
   with a function argument SSA value that is not used elsewhere. Since
   that SSA value will not disappear so we should keep the debug info.
2021-08-05 17:27:45 -07:00
Arnold Schwaighofer
c288cbb6ab Fix some more SmallVector usage without an on stack size 2021-08-05 12:15:23 -07:00
Joe Groff
fc67ba57f2 Merge pull request #37938 from jckarter/async-let-multi-suspend
Handle multiple awaits and suspend-on-exit for async let tasks.
2021-07-23 07:36:54 -07:00
Joe Groff
439edbce1f Handle multiple awaits and suspend-on-exit for async let tasks.
Change the code generation patterns for `async let` bindings to use an ABI based on the following
functions:

- `swift_asyncLet_begin`, which starts an `async let` child task, but which additionally
  now associates the `async let` with a caller-owned buffer to receive the result of the task.
  This is intended to allow the task to emplace its result in caller-owned memory, allowing the
  child task to be deallocated after completion without invalidating the result buffer.
- `swift_asyncLet_get[_throwing]`, which replaces `swift_asyncLet_wait[_throwing]`. Instead of
  returning a copy of the value, this entry point concerns itself with populating the local buffer.
  If the buffer hasn't been populated, then it awaits completion of the task and emplaces the
  result in the buffer; otherwise, it simply returns. The caller can then read the result out of
  its owned memory. These entry points are intended to be used before every read from the
  `async let` binding, after which point the local buffer is guaranteed to contain an initialized
  value.
- `swift_asyncLet_finish`, which replaces `swift_asyncLet_end`. Unlike `_end`, this variant
  is async and will suspend the parent task after cancelling the child to ensure it finishes
  before cleaning up. The local buffer will also be deinitialized if necessary. This is intended
  to be used on exit from an `async let` scope, to handle cleaning up the local buffer if necessary
  as well as cancelling, awaiting, and deallocating the child task.
- `swift_asyncLet_consume[_throwing]`, which combines `get` and `finish`. This will await completion
  of the task, leaving the result value in the result buffer (or propagating the error, if it
  throws), while destroying and deallocating the child task. This is intended as an optimization
  for reading `async let` variables that are read exactly once by their parent task.

To avoid an epoch break with existing swiftinterfaces and ABI clients, the old builtins and entry
points are kept intact for now, but SILGen now only generates code using the new interface.

This new interface fixes several issues with the old async let codegen, including use-after-free
crashes if the `async let` was never awaited, and the inability to read from an `async let` variable
more than once.

rdar://77855176
2021-07-22 10:19:31 -07:00
Andrew Trick
19007a63b1 SimplifyCFG add tracing 2021-07-17 19:37:12 -07:00
Andrew Trick
ca1c46b09a OSSA: SimplifyCFG. Add DeadEndBlocks and pass it to jump-threading. 2021-07-17 18:31:25 -07:00
Andrew Trick
e6ec4e4691 SimplifyCFG OSSA support for trivial switch_enum. 2021-07-17 18:31:25 -07:00
Meghana Gupta
54933624f1 Add IsInfiniteJumpThreadingBudget for testing 2021-07-17 18:31:25 -07:00
Andrew Trick
74e928b39e Add -enable-ossa-simplifycfg and -enable-ossa-jumpthread-simplifycfg
as temporary flags to gradually stage in OSSA tests.
2021-07-17 18:31:25 -07:00