Commit Graph

2592 Commits

Author SHA1 Message Date
Erik Eckstein
2a035432e7 SILOptimizer: make a separate SROA pass for high-level SIL, which doesn't split String types.
The StringOptimization relies on seeing String values a a whole and not being split.
2020-08-03 12:01:29 +02:00
Erik Eckstein
568c156c37 Mem2Reg: fix a wrong assert
An empty tuple doesn't need to be assigned before it is passed to destroy_addr.

I found this by experimenting with the pass pipeline. Not sure if this crash can happen with the current pipeline.
2020-08-03 12:01:29 +02:00
swift-ci
a0a181159c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-31 16:07:19 -07:00
Varun Gandhi
f219e58ada [NFC] Refactor ExtInfo to use a builder-pattern based API.
Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
2020-07-31 13:55:55 -07:00
Slava Pestov
0ef12ec8aa SIL: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:02 -04:00
swift-ci
8ba84b3351 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-30 05:03:25 -07:00
Erik Eckstein
5f3e79b84e StringOptimization: bug fixes
Fix some bugs in the optimization and in the test files.

rdar://problem/66283894
2020-07-30 11:32:39 +02: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
Nathan Hawes
fafe81a59e Merge pull request #33165 from nathawes/fix-string-conversion-issue-master-rebranch
[master-rebranch] Fix a StringRef -> std::string conversion failure.
2020-07-29 10:54:29 -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
swift-ci
930fe04f0e Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-28 15:43:48 -07:00
Arnold Schwaighofer
997fc5d070 Merge pull request #33140 from aschwaighofer/eager_specializer_function_pass
Convert the EagerSpecializer pass to a function pass
2020-07-28 15:27:46 -07:00
Nathan Hawes
774dfbf2af Fix an implicit StringRef -> std::string conversion issue in StringOptimization.cpp 2020-07-28 13:17:15 -07:00
Arnold Schwaighofer
ecf9fbd5f1 Move the EagerSpecializer pass to the Transforms directory
It is no longer a module transform.
2020-07-28 10:25:36 -07:00
swift-ci
fd57783e64 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-28 10:11:20 -07:00
eeckstein
5fffeb81fb Merge pull request #33128 from eeckstein/string-optimization
SIL optimizer: Add a new string optimization
2020-07-28 10:17:28 +02:00
Nathan Hawes
498e767765 Manually merge remote-tracking branch 'upstream/master' into merge-m-to-mr 2020-07-27 22:41:53 -07:00
Michael Gottesman
68052a3d1b Merge pull request #33135 from gottesmm/pr-bcb3de84050b91b600ff133d7d6902b97e6065af
[opt-remark] Add support for simple object projections.
2020-07-27 15:50:54 -07:00
Michael Gottesman
0bd6a58fae [opt-remark] Add support for simple object projections.
This ensures that we are able to properly look through struct_extract,
tuple_extract in cases where we have an aggregate with multiple non-trivial
subtypes (implying it is not-rc identical with those sub-types).

The end result is that we now emit good diagnostics for things like this:

```
func returnStructWithOwnerOwner(x: StructWithOwner) -> Klass {
    return x.owner // expected-remark {{retain}}
                   // expected-note @-7:33 {{of 'x.owner'}}
}
```
2020-07-27 12:35:00 -07:00
Erik Eckstein
7f684b62e2 SIL optimizer: Add a new string optimization.
Optimizes String operations with constant operands.

Specifically:
  * Replaces x.append(y) with x = y if x is empty.
  * Removes x.append("")
  * Replaces x.append(y) with x = x + y if x and y are constant strings.
  * Replaces _typeName(T.self) with a constant string if T is statically known.

With this optimization it's possible to constant fold string interpolations, like "the \(Int.self) type" -> "the Int type"

This new pass runs on high-level SIL, where semantic calls are still in place.

rdar://problem/65642843
2020-07-27 21:32:56 +02:00
Joe Groff
90f0f7c627 Merge pull request #32359 from jckarter/enable-prune-vtables
Add PruneVTables to the performance optimizer passes.
2020-07-27 11:10:53 -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
2b467adeff [opt-remark] Clean up remarks a little bit and emit the base name of each decl textually.
So now if one looks at remarks in an IDE, you will see in the NOTE itself the
decl to look for. I am going to expand this to include handling of projection
paths.
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
Meghana Gupta
f28bff1846 Enable CopyForwarding on ossa 2020-07-24 01:05:38 -07:00
Joe Groff
570e0ad326 PruneVTables: Add DEBUG logging of the pass decisions 2020-07-23 20:40:49 -07:00
Joe Groff
b4a0ceac71 Add PruneVTables to the performance optimizer passes. 2020-07-23 20:40:49 -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
f036767aaf Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-21 18:23:56 -07:00
Meghana Gupta
858fe6c593 Remove debug instructions on dead temporaries in CopyForwarding (#32941) 2020-07-21 18:14:58 -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
54779a1a38 [opt-remark] If we have a SIL remark streamer, always emit remarks. 2020-07-20 16:49:31 -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
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
Andrew Trick
8af488ed76 Merge pull request #32953 from atrick/generalize-memaccess
Generalize the MemAccessUtils API for use outside of access enforcement
2020-07-19 09:37:54 -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