Commit Graph

3719 Commits

Author SHA1 Message Date
Michael Gottesman
5a86d42c1e [gardening] Clean up BranchPropagatedUser. 2019-09-16 18:31:22 -07:00
Ravi Kandhadai
b59cc7ad6a [Constant Evaluator] Add support to the constant evaluator for:
1. builtin "int_expect", which makes the evaluator work on more
integer operations such as left/right shift (with traps) and
integer conversions.

2. builtin "_assertConfiguration", which enables the evaluator
to work with debug stdlib.

3. builtin "ptrtoint", which enables the evaluator to track
StaticString

4. _assertionFailure API, which enables the evaluator to report
stdlib assertion failures encountered during constant evaluation.

Also, enable attaching auxiliary data with the enum "UnknownReason"
and use it to improve diagnostics for UnknownSymbolicValues,
which represent failures during constant evaluation.
2019-09-16 15:12:22 -07:00
swift-ci
4ff9de7565 Merge remote-tracking branch 'origin/master' into master-next 2019-09-16 10:50:01 -07:00
swift-ci
520527d374 Merge pull request #27129 from gottesmm/pr-8fee81e00841b8044b3368fabdcd84dd5fbd5f68 2019-09-16 10:43:02 -07:00
Michael Gottesman
bb4df032e7 [ownership] Add a new class BorrowScopeIntroducingValue that enables code to work abstractly with values that introduce a new borrow scope.
The idea is that this can be used to work with things like load_borrow,
begin_borrow, SILFunctionArgument, results of begin_apply(in the future) and the like in a
generic way using exhaustive switches to make sure this code stays up to date.

I refactored code in SemanticARCOpts and some utilities in OwnershipUtils.cpp to
use these new APIs. The code looks a lot nicer and should be quite easy to
expand to handle new borrow introducers (e.x.: end_apply).
2019-09-16 09:33:49 -07:00
swift-ci
1b531a3491 Merge remote-tracking branch 'origin/master' into master-next 2019-09-13 11:50:18 -07:00
Sasha Krassovsky
63a81fd864 Fix warnings in SIL 2019-09-13 09:57:48 -07:00
Mike Ash
1758566d35 Merge branch 'master' into master-next 2019-09-11 16:56:06 -04:00
Erik Eckstein
3d0b12e7bc MemoryLifetime: fix a problem where DestroyHoisting moved a destroy_addr before a use of a trivial type.
Even if a destroy_addr of a trivial type is a no-op, we must not end up with using such a value after a destroy_addr.
The fix is to also handle aggregate fields of trivial types in MemoryLifetime.

rdar://problem/55125020
2019-09-11 13:49:23 +02:00
Mike Ash
f5e7ab866c Merge branch 'master' into master-next 2019-09-09 12:11:25 -04:00
Stephen Canon
16b9ead9f5 Fix typo NDNEBUG -> NDEBUG to unbreak release builds (#27086) 2019-09-08 23:01:40 -04:00
Michael Gottesman
4c803c9583 [gardening] LLVM has its own enumerate impl now. Use that and delete the one swift had.
NFCI.
2019-09-07 00:13:29 -07:00
Michael Gottesman
bfec410b19 Merge pull request #27060 from gottesmm/pr-6e8972071ad9a8006749aecd85e288ae0cfb3a5f
[sil] Add new API ValueBase:getUsersOfType<T>().
2019-09-06 23:46:34 -07:00
Slava Pestov
01e65e18c4 SIL: Share TypeConverter between SILModules in batch mode 2019-09-06 21:50:15 -04:00
Slava Pestov
d434188157 SIL: Refactor TypeConverter to not require a SILModule
This mostly requires changing various entry points to pass around a
TypeConverter instead of a SILModule. I've left behind entry points
that take a SILModule for a few methods like SILType::subst() to
avoid creating even more churn.
2019-09-06 21:50:15 -04:00
Slava Pestov
3a59e7c53a SIL: Serialize availability with the SIL function, not just a weak imported flag
The weak imported flag is now only set if the attribute is unconditionally
weak linked, which is the case when it or one of its parent contexts has a
@_weakLinked attribute.

To correctly handle weak linking based availability with serialized SIL
functions, we need to serialize the actual version tuple when the SIL function
was introduced. This is because the deployment target of the client app can
be older than the deployment target that the original module was built with.

Fixes <rdar://problem/52783668>.
2019-09-06 20:08:40 -04:00
Slava Pestov
0fd7cb8a95 SIL: Micro-optimize SILFunction layout 2019-09-06 20:08:40 -04:00
Michael Gottesman
7b2fc076f7 [sil] Add new API ValueBase:getUsersOfType<T>().
For some time now we have had the API ValueBase::getSingleUserOfType<T>() but we
never implemented getUsersOfType<T>() using transform/filter iterators.

Since there wasn't a specific API, several incarnations of this API have been
created for BeginBorrow, LoadBorrow, BeginAccess.

In this commit, I introduce the API and use it to excise the redundant code in
those above mentioned 3 instructions.
2019-09-06 16:40:51 -07:00
swift-ci
cccbebab22 Merge remote-tracking branch 'origin/master' into master-next 2019-09-06 13:49:53 -07:00
Nate Chandler
20ee77fb6e [Gardening] Style tweaks to SILInstructionWorklist.
Noted reliance on LTO and eliminated an else following a return.
2019-09-06 13:13:00 -07:00
swift-ci
1d1e9adb15 Merge remote-tracking branch 'origin/master' into master-next 2019-09-06 13:10:29 -07:00
Nate Chandler
0dce4da603 [SIL] Tweaked worklist instruction methods' style.
Adjusted some variable names.
2019-09-06 11:54:34 -07:00
Nate Chandler
bf8f2666a6 [SIL] Extracted instruction methods from SILCombiner.
SILCombiner has a number of conveniences for inserting, replacing, and
removing instructions that involve modifying a worklist as part of their
behavior.  Here, that functionality is added to the
SILInstructionWorklist; in a subsequent commit it will be removed from
SILCombiner which will then call through to SILInstructionWorklist.
2019-09-06 11:50:54 -07:00
swift-ci
8b82982f5f Merge remote-tracking branch 'origin/master' into master-next 2019-09-06 11:29:41 -07:00
swift-ci
902da317e2 Merge pull request #27028 from nate-chandler/update-instruction-worklist 2019-09-06 11:10:00 -07:00
Nate Chandler
d2270b9e85 [SIL] Updated instruction worklist.
- Replaced usage of raw map and vector with the type that wraps the
  combination (BlotSetVector); that provided a significant deduplication
  since a sizeable portion of the worklist's implementation was in
  vector and map management now provided by the BlotSetVector.
- Templated over the type of map and vector used by the blot set vector.
- Added SmallSILInstructionWorklist where the map and vector are
  specified to be SmallDenseMap and SmallVector respectively.
- Replaced usages of bare ValueBase with usages of SILValue.
- Renamed zap to resetChecked.

Added a bit of functionality to BlotSetVector, specifically to support
SILInstructionWorklist:

- Made insert return not just the index that the potentially-inserted
  item is at on return but additionally whether an insertion occurred,
  matching the behavior of llvm::DenseMap::insert.
- Added a method to reserve capacity in the backing vector and map:
  BlotSetVector::reserve.
- Added a method to free extra storage used by the backing vector and
  map: BlotSetVector::clear.
- Modified SmallBlotSetVector's template parameters so that only a value
  and size can be specified--that type will always use SmallVector and
  SmallDenseMap for its superclass' VectorT and MapT template
  parameters.
- Updated variable names.
2019-09-06 09:10:26 -07:00
swift-ci
2359e82dd6 Merge remote-tracking branch 'origin/master' into master-next 2019-09-06 02:29:46 -07:00
Erik Eckstein
f1ae1dc40e Fix some debugging on SIL level (-gsil) problems
* Fix multi-threaded IRGen: store the DeclContext in a SILFunction explicitly instead of deriving it from the debug location. It's used in IRGen to decide into which module a function is emitted. With -gsil the debug location is changed and that should not change the module decision.

* Erase debug_value/debug_value_addr instructions when using -gsil. Those instructions are not needed anymore. They can also trigger a verifier error.
2019-09-06 09:58:16 +02:00
Jordan Rose
eefb0d0644 Merge remote-tracking branch 'origin/master' into master-next 2019-09-04 14:01:43 -07:00
Nate Chandler
4968dcc80e [SIL] Took SILInstructionWorklist from SILCombine.
SILCombine had a dedicated worklist type that is generally useful.  Here
that type is extracted into SIL as SILInstructionWorklist so that it can
be reused.  Minor style changes were made as well.
2019-09-04 11:24:27 -07:00
swift-ci
404a849364 Merge remote-tracking branch 'origin/master' into master-next 2019-08-29 18:50:45 -07:00
Joe Groff
c0ec48c76e Merge pull request #26896 from jckarter/accessed-storage-chain-visitor
[WIP] Visitor for AccessedStorage use-def chain walk
2019-08-29 18:41:06 -07:00
Joe Groff
0e3987a4fc Factor out a visitor from findAccessedStorage.
The same logic for looking through projection paths is useful elsewhere.
2019-08-29 16:08:17 -07:00
swift-ci
5a327571aa Merge remote-tracking branch 'origin/master' into master-next 2019-08-28 10:51:07 -07:00
Erik Eckstein
0e08976600 SILOptimizer: a new optimization to hoist destroys of memory locations
DestroyHoisting moves destroys of memory locations up the control flow as far as possible.
Beside destroy_addr, also "store [assign]" is considered a destroy, because is is equivalent to an destroy_addr + a "store [init]".
The main purpose of this optimization is to minimize copy-on-write operations for arrays, etc. Especially if such COW containers  are used as enum payloads and modified in-place. E.g.

switch e {
  case .A(var arr):
    arr.append(x)
    self = .A(arr)
...

In such a case DestroyHoisting can move the destroy of the self-assignment up before the switch and thus let the array buffer only be single-referenced at the time of the append.

When we have ownership SIL throughout the pass pipeline this optimization will replace the current destroy hoisting optimization in CopyForwarding.
For now, this optimization only runs in the mandatory pipeline (but not for -Onone) where we already have ownership SIL.

SR-10605
rdar://problem/50463362
2019-08-28 15:40:05 +02:00
Erik Eckstein
9e67408307 MemoryLifetime: Make the dataflow solving functions of MemoryDataflow more flexible.
Add the possibility to solve with a custom join operator.
2019-08-28 12:14:38 +02:00
swift-ci
781f823f57 Merge remote-tracking branch 'origin/master' into master-next 2019-08-27 14:51:17 -07:00
Michael Gottesman
a2d383eb82 Merge pull request #26810 from jckarter/class-let-property-borrow
[WIP] SemanticARCOpts: Don't copy let properties of classes.
2019-08-27 14:43:26 -07:00
swift-ci
b0c8170a22 Merge remote-tracking branch 'origin/master' into master-next 2019-08-27 13:10:43 -07:00
Joe Groff
7ca6587248 SemanticARCOpts: Don't copy let globals or properties of classes.
If the lifetime of a value copied out of a let property in a class is dominated by the lifetime
of the base object it was copied from, then we don't need to copy at all, since the value of the
`let` is guaranteed as long as the base object is. `let` globals are in turn always guaranteed.
rdar://problem/54531607
2019-08-27 11:49:09 -07:00
Michael Gottesman
af565e7cc0 [sil-parser] Fix harmless bug when parsing ossa.
Specifically, we were preferring the always correct ownership kind specified by
the FunctionType and ignoring what we parsed from the argument. This PR changes
ossa to give a nice error when this is detected and fixes the places where this
tests were written incorrectly.
2019-08-27 10:18:49 -07:00
swift-ci
3a59c360ba Merge remote-tracking branch 'origin/master' into master-next 2019-08-26 19:50:26 -07:00
swift-ci
c212cafb10 Merge pull request #26808 from atrick/comment-memaccess 2019-08-26 19:43:10 -07:00
Arnold Schwaighofer
20efacf2d6 Merge remote-tracking branch 'upstream/master' into master-next 2019-08-26 13:30:41 -07:00
Doug Gregor
c8ac000fbb Record specialized signature in (SIL)SpecializeAttr.
Rather than storing the set of input requirements in a
(SIL)SpecializeAttr, store the specialized generic signature. This
prevents clients from having to rebuild the same specialized generic
signature on every use.
2019-08-26 09:54:56 -07:00
swift-ci
892aeaa634 Merge remote-tracking branch 'origin/master' into master-next 2019-08-26 09:29:54 -07:00
Arnold Schwaighofer
2b41f8d8d5 Merge remote-tracking branch 'origin/master' into master-next 2019-08-26 08:57:42 -07:00
Michael Gottesman
5fc1d1d349 [ownership] Define a new instruction copy_unmanaged_value.
This provides a singular instruction for convert an unmanaged value to a ref,
then strong_retain it. I expanded the definition of UNCHECKED_REF_STORAGE to
include these copy like instructions. This instruction is valid in all SIL.

The reason why I am adding this instruction is that currently when we emit an
access to an unowned (unsafe) ivar, we use an unmanaged_to_ref and a strong
retain. This can look to the optimizer like a strong retain that can potentially
be optimized. By combining the two together into a new instruction, we can avoid
this potential problem since the pattern matching will break.
2019-08-25 21:26:40 -07:00
Andrew Trick
d26d9a7719 Add comments to MemAccessUtils.h.
The name doesn't mean "memory access" colloquially. It specifically
refers to memory operations that take part in formal access scopes
marked by begin_access/end_access instructions. If you aren't working
with those instructions it really doesn't make sense to use it.
2019-08-25 00:57:40 -07:00
Vedant Kumar
9606717bae [Coverage] Drop records for functions DCE'd after builtin lowering
A function may be eliminated as dead code after initial builtin lowering
occurs. When this happens, an entry in the profile symbol table for the
function is not guaranteed. Its coverage record should be dropped.

rdar://42564768
2019-08-23 18:55:31 -07:00