Commit Graph

2768 Commits

Author SHA1 Message Date
Andrew Trick
d5bbb58eb5 Merge pull request #39672 from atrick/copyprop-reusedestroy
CopyPropagation: Avoid regenerating destroys.
2021-10-12 10:31:08 -07:00
Alex Hoppen
5f60aad8f1 Merge pull request #39633 from ahoppen/pr/fix-warnings
Fix a couple of build warnings
2021-10-12 12:46:23 +02:00
Arnold Schwaighofer
81dd5d9cb6 Delay import of prespecialize decls until generic specialization 2021-10-11 11:10:09 -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
Andrew Trick
6a38f579d8 CopyPropagation: Avoid regenerating destroys.
CanonicalizeOSSA is now used iteratively in SILCombine. To avoid
endless worklist iteration based on whether InstructionDeleter's
callbacks fired, ensure that destroys are only deleted and recreated
when necessary.
2021-10-09 15:29:22 -07:00
swift-ci
da3824acd9 Merge pull request #39662 from meg-gupta/fixbeginapplyinl 2021-10-08 20:58:58 -07:00
Meghana Gupta
2658cbec9b Fix begin_apply inlining when there are no yields
In this PR, preFixUp function in SILCloner is added which can be
overidden by implementations so that the SIL is cleaned for `commonFixup` processing.
For begin_apply inlining, blocks split due to end_apply and abort_apply
are fixed when no yields are found.
2021-10-08 14:45:08 -07:00
Andrew Trick
5830ceaca9 Merge pull request #39638 from atrick/cleanup-addressownership
Add AddressOwnership utility and cleanup OSSA rauw
2021-10-08 14:45:00 -07:00
Alex Hoppen
6e07ee8f90 Fix a couple of build warning
Fixes a couple of compiler warnings that occur frequently when building the compiler:
- Copy the nullability annotation definitions from `Visibility.h` to `BridgedSwiftObject.h` and wrap all code that contains nullability annotations in `SWIFT_BEGIN_NULLABILITY_ANNOTATIONS` and `SWIFT_END_NULLABILITY_ANNOTATIONS` (supressing the warning `type nullability specifier '_Nullable' is a Clang extension [-Wnullability-extension]`)
- Suppress warnings about using `$` (mangling prefix) as an identifier using pragmas (supressing the warning `'$' in identifier [-Wdollar-in-identifier-extension]`)
- Change the macro condition of `SWIFT_NODISCARD` from `__cplusplus >= 201402l` (which checked for >= C++14) to `__cplusplus > 201402l`. This appears to have been a copy-paste error from `LLVM_NODISCARD` (supressing the warning `use of the 'nodiscard' attribute is a C++17 extension [-Wc++17-extensions]`)
2021-10-08 10:11:33 +02:00
Andrew Trick
8ba105f5cb Use AddressOwnership in OSSA RAUW. Improves optimization.
This mainly simplifies the utility, but also improves optimization as
a side effect.

Update OSSA RAUW after replacing BorrowedAddress with AddressOwnership.

InteriorPointer is no longer needed. This simplifies the fixup
context. Eventually the fixup context will be very lightweight. This
is just the first step.
2021-10-07 15:48:25 -07:00
Andrew Trick
767e094cfe Add AddressOwnership OSSA utility
This replaces the recent BorrowedAddress utility (the address may not
be borrowed!)

APIs:

AddressOwnership::hasLocalOwnershipLifetime() - convenience on top of
AccessBase::hasLocalOwnershipLifetime().

AddressOwnership::getOwnershipReferenceRoot() - convenience on top of
AccessBase::getOwnershipReferenceRoot().

AddressOwnership::findTransitiveUses() - wrapper API over the internal
helper findTransitiveUsesForAddress()

AddressOwnership::areUsesWithinLifetime() - wrapper adds a quick check
on top of BorrowedValue::areUsesWithinLifetime()
2021-10-07 15:34:09 -07:00
Erik Eckstein
7849f09e52 SIL: remove the unused alloc_value_buffer, project_value_buffer and dealloc_value_buffer instructions.
Those instructions were use for the materializeForSet implementation, which was replaced by modify-coroutines.
2021-10-07 07:41:54 +02:00
Andrew Trick
70a14ff61b Rename ForwardingOperand.getOwnershipKind()
to getForwardingOwnershipKind() just to distinguish it from
SILValue.getOwnershipKind() and be able to grep for them each.
2021-10-06 15:48:08 -07:00
Arnold Schwaighofer
a192f786aa Merge pull request #39596 from aschwaighofer/available_argument_for_at_specialize
Add support for `availability` to `@_specialize`
2021-10-06 15:03:37 -07:00
swift-ci
3f8fea8508 Merge remote-tracking branch 'origin/main' into rebranch 2021-10-06 10:17:29 -07:00
Andrew Trick
0bc30e6f49 Add ValueLifetimeBoundary::visitInsertionPoints
Given a computed ValueLifetimeBoundary, visit all the points at which
the lifetime needs to be terminated, e.g. via and end_borrow or
destroy_value.

Especially useful for creating a borrow scope over guaranteed uses.

This completely decouples the DeadBlocks analysis from the liveness
analysis.

It will allow phasing out the complex and bug-prone
ValueLifetimeAnalysis::Frontier API.
2021-10-06 09:23:17 -07:00
Andrew Trick
add3406cfe Move PrunedLiveness so it can be used as a lightweight OSSA helper.
For use in OwnershipUtils.
2021-10-06 09:23:02 -07:00
Arnold Schwaighofer
cd7283d059 SIL optimization 2021-10-06 04:54:49 -07:00
Andrew Trick
5d21e22da0 Comment: CanonicalOSSALifetime TODO (cleanup using PrunedLiveness) 2021-10-03 19:49:58 -07:00
swift-ci
c51550f30e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-30 15:11:41 -07:00
Nate Chandler
e1e750aeaa [SILInliner] NFC: Clarified conditional.
Made it clear that one code path was to be followed if
-enable-experimental-lexical-lifetimes was passed and an entirely
different one was to be followed otherwise.
2021-09-29 20:41:50 -07:00
Nate Chandler
90ab3826d1 [SILInliner] Removed lexical borrows of addrs.
In 79bc4cba31, when
-enable-experimental-lexical-lifetimes was passed, all non-trivial types
were given borrow scopes.  That is incorrect because address types
should not receive borrow scopes.  Here, that is fixed by only
introducing lexical borrow scopes for arguments whose types is not an
address type.
2021-09-29 20:41:50 -07:00
Nate Chandler
c8ae63f87f [SILInliner] Removed wrong lexical end borrows.
In 79bc4cba31, when
-enable-experimental-lexical-lifetimes was passed, every argument marked
to receive an end_borrow, although not every argument was borrowed (that
part was correct).  Fix the mistake by only marking arguments which are
actually borrowed as such.
2021-09-29 20:41:50 -07:00
Nate Chandler
6bcbb04bc1 [SILInliner] Added lexical lifetimes for arguments.
When the -enable-experimental-lexical-lifetimes flag is passed, added
lexical borrow scopes for every non-trivial argument when inlining a
function.
2021-09-28 17:48:29 -07:00
Nate Chandler
e7d5b5e3a2 [NFC] Inliner: throw blocks borrows end the same.
Previously, the SILInliner had a few lines of special-case code to
handle adding end_borrow instructions to the throw block corresponding
to a try_apply instruction.  Because there's a mechanism for tracking
all places where these end_borrows need to be inserted, just use that
mechanism rather than having a special case for the throw block.
2021-09-28 17:48:29 -07:00
Nate Chandler
cac03a6e77 [SIL] Let addArgumentToBranch accept plural args.
Previously, the addArgumentToBranch only allowed one to add a single
additional argument to a branch.  It then verified the argument count.
That is a problem if multiple arguments have to be added to arrive at
the correct argument count.

Specifically, that was a problem when running Mem2Reg on a lexical
alloc_stack, where three new phi arguments are added.

Here, the function name is changed to addArgumentsToBranch (plural
arguments) and the function accepts a SmallVector<SILValue> rather than
a single SILValue, allowing one to add all the arguments that are
necessary in order to verify that the resulting number of arguments is
correct.
2021-09-27 20:29:45 -07:00
swift-ci
899723065c Merge remote-tracking branch 'origin/main' into rebranch 2021-09-27 09:13:14 -07:00
Alastair Houghton
8be084f30a Merge pull request #39187 from al45tair/problem/79725187
[Demangler] Improve remangler error handling
2021-09-27 17:03:49 +01:00
swift-ci
8fba532a11 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-20 18:33:34 -07:00
adrian-prantl
7e7333e20d Merge pull request #39341 from adrian-prantl/min-salvage-pr
Support additional salvage debug info opportunities
2021-09-20 16:38:52 -07:00
Robert Widmann
e545d7f760 Lift getCanonicalTypeInContext up to GenericSignature 2021-09-20 15:43:07 -07:00
swift-ci
7adf077f7c Merge remote-tracking branch 'origin/main' into rebranch 2021-09-20 13:13:49 -07:00
Andrew Trick
ffb7ecc1f7 Add a BorrowedLifetimeExtender utility.
Handle SSA update (phi creation) when extending an owned lifetime over
a borrowed lifetime.

This is a layer of logic above BorrowedValue but below
OwnershipLifetimeExtender and other higher-level utilities.
2021-09-17 20:09:58 -07:00
swift-ci
ebc9a3d560 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-12 15:14:17 -07:00
Michael Gottesman
5590c7b526 [sil] Add a move_value instruction.
This is a new instruction that can be used by SILGen to perform a semantic move
in between two entities that are considered separate variables at the AST
level. I am going to use it to implement an experimental borrow checker.

This PR contains the following:

1. I define move_value, setup parsing, printing, serializing, deserializing,
   cloning, and filled in all of the visitors as appropriate.
2. I added createMoveValue and emitMoveValueOperation SILBuilder
   APIs. createMoveValue always creates a move and asserts is passed a trivial
   type. emitMoveValueOperation in contrast, will short circuit if passed a
   trivial value and just return the trivial value.
3. I added IRGen tests to show that we can push this through the entire system.

This is all just scaffolding for the instruction to live in SIL land and as of
this PR doesn't actually do anything.
2021-09-12 11:07:42 -07:00
Min-Yih Hsu
69ffafe146 (Stash) Salvage debug info from deleted index_addr instruction
And calling `swift::salvageDebugInfo` in more places.

NOTE: The latter change seems to break stdlib build.
2021-09-10 14:17:38 -07:00
Min-Yih Hsu
b52fdc6628 (Stash) Salvaging debug info from deleted struct instruction 2021-09-10 14:17:38 -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
Alastair Houghton
3f01f853a6 [Demangling] Add error handling to the remangler.
Mangling can fail, usually because the Node structure has been built
incorrectly or because something isn't supported with the old remangler.
We shouldn't just terminate the program when that happens, particularly
if it happens because someone has passed bad data to the demangler.

rdar://79725187
2021-09-06 17:49:09 +01:00
adrian-prantl
f76ac1a85f Merge pull request #39166 from adrian-prantl/82313550
Assign variable names for anonymous function arguments in SILGen.
2021-09-04 19:34:36 -07:00
Adrian Prantl
2673256a0c Remove spurious anonymous function arguments introduced by PartialApplyCombiner.
Looks like this was a well-intentioned, but counterproductive attempt to
introduce new debug info in for partial applies. SILVerifier is now stricter
about finding clashing anonymous arguments so this becomes a SIL verifier error
rather than a late LLVM crash.
2021-09-04 12:01:36 -07:00
swift-ci
cb32b553de Merge remote-tracking branch 'origin/main' into rebranch 2021-09-04 11:32:57 -07:00
Hamish Knight
dc60996f89 Merge pull request #38836 from hamishknight/toil-and-tuple 2021-09-04 19:30:04 +01:00
Adrian Prantl
97b07f91ca Delete unnecessary artificial debug function argument debug info. 2021-09-03 17:46:42 -07:00
Anthony Latsis
b81db7a4fc Devirtualize: Skip requirements with covariant 'Self' nested inside a collection
The devirtualizer does not support handling these yet, which wasn't anticipated in #34140
2021-09-03 07:01:49 +03:00
swift-ci
6fb243ff06 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-02 17:35:00 -07:00
Meghana Gupta
5c684042f0 Fix debug location is some ownership utils (#39148)
Insert point may have invalid LocationKind. Use auto-generated loc.
2021-09-02 17:13:37 -07:00
Hamish Knight
cead30d639 [SIL] Adopt ArgumentList 2021-09-01 18:40:27 +01:00
swift-ci
ebad328a4f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-01 09:14:57 -07:00