Commit Graph

1057 Commits

Author SHA1 Message Date
Michael Gottesman
7aac6817d4 [opt-remark] Handle inline locations correctly.
Specifically, now we properly identify the SILLocation for the final inlined
call site of a Source Location and put the remark there instead of in the
callee.
2020-08-22 14:30:59 -07:00
Nathan Hawes
607e2b8822 Manually merge remote-tracking branch 'upstream/master' into HEAD 2020-08-04 13:47:48 -07:00
Varun Gandhi
3882beb85d [NFC] Use consistent naming scheme for predicate methods. (#33265)
bool throws() -> isThrowing(), bool async() -> isAsync()
2020-08-03 16:37:29 -07:00
swift-ci
a0a181159c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-31 16:07:19 -07:00
Slava Pestov
0ef12ec8aa SIL: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:02 -04:00
swift-ci
33f953d35a Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-29 12:23:30 -07:00
Michael Gottesman
d52ddf4c21 Merge pull request #33171 from gottesmm/pr-97b9d62b30e73e019e7a9558e9cbf317d157c609
[opt-remark] Print out the type when we retain/release.
2020-07-29 12:05:44 -07:00
swift-ci
0d8e3e1d71 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-29 09:14:39 -07:00
Michael Gottesman
ce298e94de [opt-remark] Print out the type when we retain/release.
This can be useful if we can't recognize a retain/release and one needs to
reason about what is being retained/released.
2020-07-28 18:35:34 -07:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Nathan Hawes
b0a2230860 Manually merge remote-tracking branch 'upstream/master' into merge-in-master 2020-07-27 09:25:01 -07:00
Michael Gottesman
96097b0879 [opt-remark] Add @_semantics("optremark{.$SIL_PASS_NAME}") that force opt remarks on functions.
More specifically, if one wants to force emit /all/ opt-remarks on a function, mark it with:

```
@_semantics("optremark")
```

If one wants to emit opt-remarks only for a specific SIL pass (like lets say
sil-opt-remark-gen), one can write:

```
@_semantics("optremark.sil-opt-remark-gen")
```

I made the pattern matching strict so if you just put in a '.' or add additional
suffixes, it will not pattern match. I think that this is sufficient for a
prototyping tool.

This is useful if one wants to play around with opt-remarks when optimizing code
in Xcode or any IDE that can use serialized diagnostics.
2020-07-26 14:55:02 -07:00
Michael Gottesman
c3595ad7f0 Merge pull request #33115 from gottesmm/pr-3b1ab9c8196e6decb2b6b49cbf4f5b44435ed2c9
[opt-remark] Move Argument::inferArgumentFromValue into OptRemarkGenerator.
2020-07-25 10:12:58 -07:00
Meghana Gupta
c042638a37 Merge pull request #33098 from meg-gupta/updatestyle
Update code as per Apple Style Guide
2020-07-25 07:44:44 -07:00
Michael Gottesman
2f3670f754 [opt-remark] Move Argument::inferArgumentFromValue into OptRemarkGenerator.
I noticed that I kept on needing to hack on this as I added stuff to
OptRemarkGenerator and felt the need to tie it even closer to
OptRemarkGenerator. As I began to think about it, this is really something
specific to that algorithm, so it really doesn't make sense to have it as part
of the general SIL library.

This is a NFC refactoring.
2020-07-24 21:15:34 -07:00
Michael Gottesman
750c8d32ac [opt-remark] Have OptEmitter store a SILFunction instead of a SILModule.
In all of these cases, we already had a SILFunction and were just grabbing its
SILModule instead of passing it in. So this is just an NFC change.

The reason why I am doing this is so that I can force emit opt-remarks on
functions with the semantics attribute "optremark", so I need to be able to
access the SILFunction in the optimization remark infrastructure.
2020-07-24 17:11:47 -07:00
Meghana Gupta
b34791a0a0 Update code as per Apple Style Guide
whitelist -> allowlist
blacklist -> denylist
2020-07-24 11:37:15 -07:00
swift-ci
cf3f9e7602 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-22 02:43:56 -07:00
Michael Gottesman
a7404710bc Merge pull request #33024 from gottesmm/pr-5c5c78e98bdffbe1da91f38512d5c62904b8a68b
[opt-remark] Teach arg inference how to handle simple loads from globals.
2020-07-22 02:43:48 -07:00
Michael Gottesman
f8d0f474b8 [opt-remark] Teach arg inference how to handle simple loads from globals.
Just adding new patterns.
2020-07-21 22:10:53 -07:00
swift-ci
a22ab2650d Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-21 21:24:31 -07:00
Andrew Trick
191adb0cd7 Merge pull request #33017 from atrick/really-add-class-tail-storage
Add AccessedStorage::Tail access kind and remove more exclusivity checks.
2020-07-21 21:08:52 -07:00
swift-ci
131ee3bbbf Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-20 22:24:28 -07:00
swift-ci
0c2574f637 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-20 20:23:20 -07:00
Michael Gottesman
2c9a34fa01 [opt-remark] Teach opt-remark how to emit notes that point to the value being retained/released.
This is just an initial implementation and doesn't handle all cases. This works
by grabbing the rc-identity root of a retain/release operation and then seeing:

1. If it is an argument, we use the ValueDecl of the argument.
2. If it is an instruction result, we try to infer the ValueDecl by looking for debug_value uses.
3. In the future, we should add support for globals and looking at addresses.

I may do 3 since it is important to have support for that due to inout objects.
2020-07-20 19:43:47 -07:00
Michael Gottesman
aea6d7df80 [opt-remark] Teach opt-remark how to emit "NOTE" arguments that use the loc of the original remark instead of the args own.
This is useful if one wants to emit a note explanation (in my case that we
couldn't find any values) but do not have any other source loc but the original
remark.
2020-07-20 19:43:47 -07:00
Michael Gottesman
9a828bc78f [opt-remark] Teach opt-remarks how to emit notes.
I did this by adding a kind to Arguments and making it so we have a kind that
emits as a separate NOTE when we emit diagnostics, but is emitted as a normal
argument when emitting to the bitstream.
2020-07-20 19:43:47 -07:00
Andrew Trick
6ecbeefd50 Add AccessedStorage::Tail access kind and remove more checks.
Distinguish ref_tail_addr storage from the other storage classes.

We didn't have this originally because be don't expect a begin_access
to directly operate on tail storage. It could occur after inlining, at
least with static access markers. More importantly it helps ditinguish
regular formal accesses from other unidentified access, so we probably
should have always had this.

At any rate, it's particularly important when AccessedStorage is
generalized to arbitrary memory access.

The immediate motivation is to add an AccessPath utility, which will
need to distinguish tail storage.

In the process, rewrite AccessedStorage::isDistinct. This could have a
large positive impact on exclusivity performance.
2020-07-20 16:42:53 -07:00
Andrew Trick
5091aee6f2 Add an AccessedStorageDumper pass to verify findAccessedStorage.
Rename the existing pass to AccessedStorageAnalysisDumper.

AccessedStorage is useful on its own as a utility without the
analysis. We need a way to test the utility itself.

Add test cases for the previous commit that introduced
FindPhiStorageVisitor.
2020-07-20 16:42:28 -07:00
Nathan Hawes
9d4ed5f39c Manually merge remote-tracking branch 'upstream/master' into manually-merge-master-to-master-rebranch 2020-07-20 16:09:55 -07:00
Michael Gottesman
7a5f525575 Merge pull request #32986 from gottesmm/pr-967e8caef81ac33bc24c69828271796b964db211
[opt-remark] Add support for emitting opt-remark-generator remarks when compiling with optimization.
2020-07-20 14:40:34 -07:00
Josh Learn
768a404c0c Merge pull request #32911 from guitard0g/oslog_profiling
[Constant Evaluator] Skip code-coverage instrumentation during constant evaluation
2020-07-20 15:29:01 -04:00
Michael Gottesman
76c7c3e579 [opt-remark] Add support for emitting opt-remark-generator remarks when compiling with optimization.
In order to test this, I implemented a small source loc inference routine for
instructions without valid SILLocations. This is an optional nob that the
opt-remark writer can optionally enable on a per remark basis. The current
behaviors are just forward/backward scans in the same basic block. If we scan
forwards, if we find a valid SourceLoc, we just use ethat. If we are scanning
backwards, instead we grab the SourceRange and if it is valid use the end source
range of the given instruction. This seems to give a good result for retain
(forward scan) and release (backward scan).

The specific reason that I did that is that my test case for this are
retain/release operations. Often times these operations due to code-motion are
moved around (and rightly to prevent user confusion) given by optimizations auto
generated SIL locations. Since that is the test case I am using, to test this I
needed said engine.
2020-07-20 12:01:34 -07:00
Andrew Trick
0a5ba3f402 Refine AccessUseDefChainVisitor.
Prepare to reuse this visitor for an AccessPath utility.

Remove visitIncomplete. Add visitCast and visitPathComponent.

Handle phis in a separate visitor. This simplifies the main
visitor. In the long-term, we may be able to eliminate the pointer-phi
visitor entirely. For now, this lets us enforce that all phi paths
follow the same access path.
2020-07-19 19:15:44 -07:00
Josh Learn
7cbc21b60a Allow constant interpreter to skip builtin instructions from profiling instrumentation 2020-07-17 13:30:30 -04:00
Andrew Trick
5826e75b00 Generalize the MemAccessUtils API.
For use outside access enforcement passes.

Add isUniquelyIdentifiedAfterEnforcement.

Rename functions for clarity and generality.

Rename isUniquelyIdentifiedOrClass to isFormalAccessBase.

Rename findAccessedStorage to identifyFormalAccess.

Rename findAccessedStorageNonNested to findAccessedStorage.

Part of generalizing the utility for use outside the access
enforcement passes.
2020-07-17 10:13:20 -07:00
Andrew Trick
3766962f28 Teach stripCasts (and getUnderlyingObject) about begin_access.
This was blocking EscapeAnalysis and many other analyses from handling
access markers.
2020-07-11 16:32:01 -07:00
Michael Gottesman
5e36ae1c7c [sil] Add a forwarding cast called unchecked_value_cast.
Today unchecked_bitwise_cast returns a value with ObjCUnowned ownership. This is
important to do since the instruction can truncate memory meaning we want to
treat it as a new object that must be copied before use.

This means that in OSSA we do not have a purely ossa forwarding unchecked
layout-compatible assuming cast. This role is filled by unchecked_value_cast.
2020-07-09 21:14:32 -07:00
Andrew Trick
3543cf85c4 Cleanup MemAccessUtils.
Organize the utilities in this file by section to make subsequent
diffs easier to read and prepare for adding more utilities.
2020-07-09 14:31:45 -07:00
Nathan Hawes
3957574a7b Fixup code that was using the now-removed DominatorTreeBase::getRoots()
Use the new roots(), roots_begin(), etc. instead.
2020-07-07 17:55:28 -07:00
Michael Gottesman
0750b0b203 [generics] Add an option that causes the generic specializer to validate newly specialized functions earlier when we have more information that we can put into a pretty stack trace.
I also added support for creating a PrettyStackTraceSILFunction from a twine.
2020-06-30 13:43:20 -07:00
Meghana Gupta
5f40bf253b Merge pull request #32328 from meg-gupta/fixrledump
[NFC] Fix Projection print for Enum kind
2020-06-12 09:49:09 -07:00
Zoe Carver
ee1d76ed44 [opt] Re-work broadenSingleElementStores to use projections. (#32318)
* Fixes loadable edge case for address-only types.
* Re-work, generalize, and simplify by using projections.
* Support `-enable-cxx-interop` in sil-opt.
2020-06-11 23:10:19 -07:00
Meghana Gupta
0c1b062ac0 [NFC] Fix Projection print for Enum kind 2020-06-11 16:11:03 -07:00
Michael Gottesman
142aa42f0d [semantic-arc-opts] Teach semantic-arc-opts how to handle tuples with multiple non-trivial operands.
<rdar://problem/63950481>
2020-06-05 19:56:09 -07:00
Michael Gottesman
3cb33ac7ef [semantic-arc-opts] Teach semantic-arc-opts how to handle structs with multiple non-trivial values.
Just like br inst, structs are phis in the ownership graph that one can induce
on top of the def-use graph. In this commit, I basically fill in the relevant
blanks in the ADT for such phis for struct so that the optimization for branches
is generalized onto structs.

<rdar://problem/63950481>
2020-06-03 20:01:39 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Erik Eckstein
33c8e16ce0 SIL optimizer: Support begin_cow_mutation and end_cow_mutation in some optimizations.
Mostly this is about "looking through" a begin_cow_mutation or end_cow_mutation.
2020-05-26 18:01:17 +02:00
Saleem Abdulrasool
cebe79d482 SIL: use object libraries instead of globbing
This simplifies the handling of the subdirectories in the SIL and
SILOptimizer paths.  Create individual libraries as object libraries
which allows the analysis of the source changes to be limited in scope.
Because these are object libraries, this has 0 overhead compared to the
previous implementation.  However, string operations over the filenames
are avoided.  The cost for this is that any new sub-library needs to be
added into the list rather than added with the special local function.
2020-05-18 18:56:34 +00:00
Erik Eckstein
8f2632939a Builtins to support copy-on-write SIL instructions
* Builtin.COWBufferForReading -> ref_element_addr [immutable] / ref_tail_addr [immutable]
* Builtin.beginCOWmutation -> begin_cow_mutation
* Builtin.endCOWmutation -> end_cow_mutation
2020-05-14 08:39:54 +02:00