Commit Graph

2610 Commits

Author SHA1 Message Date
Erik Eckstein
aa16864a2c SIL: verify store_borrow
Verify that
* the destination address is an alloc_stack
* the stack location is not modified beside a store_borrow
* the stack location has been initialized when used
2021-03-02 12:02:54 +01:00
Erik Eckstein
d6736e93e0 MemoryLifetime: support partial_apply arguments in memory lifetime verification. 2021-03-02 12:02:54 +01:00
Andrew Trick
ecc7127be8 Merge pull request #36183 from atrick/fix-dce-fixlifetime
Disable fix_lifetime DCE.
2021-02-26 14:37:31 -08:00
Andrew Trick
f470b29747 Disable fix_lifetime DCE.
Unless the type is a trivial scalar. As a follow-up we could try to
prove that the referenced object is unique, but that seems more
natural for DeadObjectElimination.

This optimization was never correct because references may alias. See
rdar://36038096 ([SR-6608] DeadCodeElimination removes fix_lifetime
instructions.)

Fixes rdar://74759728 (The compiler/optimizer seems to be shortening
the lifetime too early)
2021-02-26 11:06:10 -08:00
swift-ci
08638f23b5 Merge pull request #36182 from eeckstein/fix-destroyhoisting-debuginfo 2021-02-26 10:24:21 -08:00
Doug Gregor
3dec40cc05 Merge pull request #35874 from ktoso/wip-no-escape-group
[Concurrency] Reimplement Task.Group with accordance to Pitch #3
2021-02-26 08:57:26 -08:00
Erik Eckstein
9262c23b63 DestroyHoisting: create the correct debug info location kind for inserted destroys
Such locations should be cleanup locations and not regular locations.
Otherwise it could trigger a false unreachable-code warning.

rdar://74241814
2021-02-26 16:39:31 +01:00
Meghana Gupta
5e16e75e4f Merge pull request #36056 from meg-gupta/rlefixes
Fix ownershipKind of the phi's that the SILSSAUpdater creates for RLE
2021-02-25 19:13:51 -08:00
Michael Gottesman
34e4e42642 [simplify-cfg] Only check if we can remove releases by performing simple jump threading if our block argument is not a trivial type.
Eliminates unnecessary work and reduces compile time.
2021-02-25 12:21:49 -08:00
Meghana Gupta
7445c5d7bb Fix ownershipKind of the phi's that the SILSSAUpdater creates for RLE
When the available values have none ownership on one side and owned on the other,
we need to merge their ownershipKind for their phi argument
2021-02-25 11:48:00 -08:00
Konrad `ktoso` Malawski
6e525d7469 Merge branch 'main' into wip-no-escape-group 2021-02-25 10:37:20 +09:00
Andrew Trick
ba9f52071b OSSA: simplify-cfg support for trivial block arguments.
Enable most simplify-cfg optimizations as long as the block arguments
have trivial types. Enable most simplify CFG unit tests cases.

This massively reduces the size of the CFG during OSSA passes.

Test cases that aren't supported in OSSA yet have been moved to a
separate test file for disabled OSSA tests,

Full simplify-cfg support is currently blocked on OSSA utilities which
I haven't checked in yet.
2021-02-23 22:47:59 -08:00
Andrew Trick
b908b9fe04 EagerSpecializer: only run SIL verification when needed
This was running the SIL verifier in the asserts build unconditionally
on every function even if this pass did nothing.
2021-02-23 22:47:59 -08:00
Konrad `ktoso` Malawski
6f4fca8721 Merge branch 'main' into wip-no-escape-group 2021-02-24 08:59:53 +09:00
Erik Eckstein
65a6d9a22a MemoryLifetimeVerifier: support verifying enum memory locations.
This is kind of complicated, because an enum can be trivial for one case and not trivial for another case. We need to check at which parts of the function we can prove that the enum does (or could) have a trivial case. In such a branch, it's not required in SIL to destroy the enum location.

Also, document the rules and requirements for enum memory locations in SIL.rst.

rdar://73770085
2021-02-23 08:08:34 +01:00
Konrad `ktoso` Malawski
a226259d84 [Concurrency] TaskGroup moves out of AsyncTask, non escaping body 2021-02-22 13:26:27 +09:00
Meghana Gupta
dd1c37ae91 CSE OSSA: Enable lookThroughOwnershipInsts for some more instructions 2021-02-15 13:43:58 -08:00
Michael Gottesman
142c3bd1fc [simplify-cfg] Enable some simple opts during ownerships on br, cond_br that do not involve objects directly.
Just to reduce the size of the CFG.
2021-02-12 23:20:17 -08:00
Michael Gottesman
6c255734ba [simplify-cfg] Enable remove unreachable blocks to shrink the CFG a bit. 2021-02-12 23:20:17 -08:00
Erik Eckstein
214b7a9929 Use the new BasicBlockWorklist utility in various places in the compiler.
It's a refactoring which simplifies the code.
NFC.
2021-02-12 11:15:55 +01:00
Erik Eckstein
fe10f98cf0 SIL: rename the SILBitfield.h header file to BasicBlockBits.h
NFC
2021-02-12 11:15:55 +01:00
Meghana Gupta
319e9e0140 Merge pull request #35840 from meg-gupta/fixrpe
Fix redundant phi elimination for OSSA
2021-02-10 13:26:56 -08:00
Meghana Gupta
b9ac9a867c Fix redundant phi elimination for OSSA
In the common case, we cannot have redundant @owned and @guaranteed phi
args. However, if the incoming values had none ownership and were passed
as an @owned or an @guaranteed phi arg, they can be considered as redundant.

For such redundant @owned phi args, create a copy value, and use the
copy to replace all uses of the redundant phi arg.

For such redundant @guaranteed phi args, we turn off the optimization
currently. We cannot just create a borrow scope and use the new borrowed
value for replacement. We will also have to re-write the consuming uses of
the @guaranteed values such that the newly created borrow scope is
within the scope of its operand.
2021-02-09 12:09:53 -08:00
Erik Eckstein
542a378436 SIL: add FunctionRefInst::getReferencedFunction()
If we know that we have a FunctionRefInst (and not another variant of FunctionRefBaseInst), we know that getting the referenced function will not be null (in contrast to FunctionRefBaseInst::getReferencedFunctionOrNull).

NFC
2021-02-09 19:56:43 +01:00
Varun Gandhi
caf1a55eea Merge pull request #35229 from mininny/switch-find-to-contains
[NFC] Replace uses of find(x) != end() idiom with contains(x) for StringRef and Set-like types
2021-02-08 13:57:43 -08:00
Meghana Gupta
aed2dcb07b Fix Mem2Reg for store [assign]
This PR simplifies the handling of store [assign] in Mem2Reg by always
converting it to a store [init].
Also fixes an edge case where store [assign] in a non entry block was
not the first store of an alloc_stack with uses in multiple blocks.
2021-02-06 19:54:34 -08:00
Meghana Gupta
e2563e63d2 Merge pull request #35766 from meg-gupta/csechangespr
CSE OSSA: look through ownership instructions for some additional instructions
2021-02-05 12:50:40 -08:00
Meghana Gupta
10492c9efc Merge pull request #35718 from meg-gupta/dceossafixespr
Fixes for OSSA DCE
2021-02-04 15:16:13 -08:00
Meghana Gupta
b854df0ebb CSE OSSA: look through ownership instructions for some additional instructions 2021-02-04 12:50:31 -08:00
Meghana Gupta
691ead342f Merge pull request #35731 from meg-gupta/rlefixes
Fix lifetime of intermediate phis created by the SSAUpdater for RLE
2021-02-04 09:57:37 -08:00
Erik Eckstein
028afc0fb2 DeadObjectElimination: delete dead arrays for which the "destroyArray" builtin is inlined.
This is needed for non-OSSA SIL: in case we see a destroyArray builtin, we can safely remove the otherwise dead array.
This optimization kicks in later in the pipeline, after array semantics are already inlined (for early SIL, DeadObjectElimination can remove arrays based on semantics).

rdar://73569282
https://bugs.swift.org/browse/SR-14100
2021-02-04 07:53:32 +01:00
Meghana Gupta
d3acfee433 When DCE removes a dead terminator, insert appropriate lifetime ends 2021-02-03 11:38:43 -08:00
Meghana Gupta
a78acfe4b0 Disable handling of nested borrows in DCE
Nested borrow handling can be complex in the presence of reborrows. So
it is not handled currently.
2021-02-03 11:38:40 -08:00
Meghana Gupta
234d29ab51 Insert end_borrow before any destroy_value while ending lifetime of a reborrow with dependencies 2021-02-03 11:38:11 -08:00
Meghana Gupta
180b3bdcca Add reborrow dependencies to DCE
A reborrow's base value may change if the base value is also passed as
an operand on a branch. Record reborrow dependencies so that we can mark
the base value as live, if the reborrow was also live. This ensures we
do not insert destroy_value on the base value prematurely before the
lifetime of the reborrow ends.
2021-02-03 11:38:11 -08:00
Minhyuk Kim
e924cf6104 Replace usages of StringRef.find(Key) != StringRef::npos to StringRef.contains(Key) 2021-02-04 00:42:04 +09:00
Meghana Gupta
ecb5d65d6d Fix lifetime of intermediate phis created by RLE
We were adjusting the lifetime of the final phi created by the
SSAUpdater. The intermediate phi's lifetime needs to be adjusted as
well.
2021-02-02 21:54:09 -08:00
Meghana Gupta
df82a1a92c Allow DCE of load [copy] 2021-02-02 14:01:37 -08:00
Erik Eckstein
d33ea9f350 SIL: remove the JointPostDominanceSetComputer helper struct.
Instead make `findJointPostDominatingSet` a stand-alone function.
There is no need to keep the temporary SmallVector alive across multiple calls of findJointPostDominatingSet for the purpose of re-using malloc'ed memory. The worklist usually contains way less elements than its small size.
2021-02-02 10:20:35 +01:00
Meghana Gupta
aa76077173 Merge pull request #35674 from meg-gupta/fixtemplvalopt
TempLValueOpt : Cleanup debug_value_addr when combining a copy_addr and destroy
2021-02-02 00:22:42 -08:00
Meghana Gupta
abd1603c88 TempLValueOpt : Cleanup debug_value_addr when combining a copy_addr and destroy 2021-01-30 22:19:00 -08:00
Adrian Prantl
a9f05c8c30 Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	lib/IRGen/IRGenDebugInfo.cpp
2021-01-29 16:17:10 -08:00
Erik Eckstein
ec64f2a255 SILLocation: replace CleanupLocation::get(loc) with CleanupLocation(loc)
No need to have a static get function - the constructor can be used directly.
NFC
2021-01-29 20:28:21 +01:00
Erik Eckstein
462e58d3cb SILLocation: a big refactoring and reducing its size from 3 to 2 words
My goal was to reduce the size of SILLocation. It now contains only of a storage union, which is basically a pointer and a bitfield containing the Kind, StorageKind and flags. By far, most locations are only single pointers to an AST node. For the few cases where more data needs to be stored, this data is allocated separately: with the SILModule's bump pointer allocator.

While working on this, I couldn't resist to do a major refactoring to simplify the code:

* removed unused stuff
* The term "DebugLoc" was used for 3 completely different things:
    - for `struct SILLocation::DebugLoc` -> renamed it to `FilePosition`
    - for `hasDebugLoc()`/`getDebugSourceLoc()` -> renamed it to `hasASTNodeForDebugging()`/`getSourceLocForDebugging()`
    - for `class SILDebugLocation` -> kept it as it is (though, `SILScopedLocation` would be a better name, IMO)
* made SILLocation more "functional", i.e. replaced some setters with corresponding constructors
* replaced the hand-written bitfield `KindData` with C bitfields
* updated and improved comments
2021-01-29 20:28:21 +01:00
swift-ci
378b6d42d1 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-29 05:52:27 -08:00
Andrew Trick
67863c55b6 Revert "SimplifyCFG: fix an infinite jump-threading loop."
This reverts commit fe928d57ac.

This causes an ASAN failure. Reverting until it can be debugged.
2021-01-28 23:46:23 -08:00
Andrew Trick
0b2a6267f6 Revert "Comment SimplifyCFG JumpThreadingCost."
This reverts commit 7a1065cfc2.
2021-01-28 23:46:12 -08:00
swift-ci
f39cace82b Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 21:12:42 -08:00
Andrew Trick
7a1065cfc2 Comment SimplifyCFG JumpThreadingCost.
Explain how this actually works since it isn't directly obvious.
2021-01-27 16:34:02 -08:00
swift-ci
ccbfe36f97 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 16:32:44 -08:00