Commit Graph

581 Commits

Author SHA1 Message Date
Max Moiseev
02006f20bc Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-09 16:05:03 -08:00
Xin Tong
43fcb6c20c More refactoring in FSO. NFC 2016-03-09 16:33:23 -05:00
Xin Tong
ae745ccaed Split SignatureOptimzer::analyze(). NFC.
Do some preparations to split function signature into 3 function passes.

analyze() has become a dumping ground for code to analyze parameters and result.

Split it into 2 functions.
2016-03-09 15:22:45 -05:00
Joe Groff
77dd9b2992 Split exact-subclass and bindable-to-subclass queries.
In many places, we're interested in whether a type with archetypes *might be* a superclass of another type with the right bindings, particularly in the optimizer. Provide a separate Type::isBindableToSuperclassOf method that performs this check. Use it in the devirtualizer to fix rdar://problem/24993618. Using it might unblock other places where the optimizer is conservative, but we can fix those separately.
2016-03-09 11:14:45 -08:00
Xin Tong
8eedb43c4c Implement partially dead argument elimination.
This change includes an option on how IsLive is defined/computed. the ProjectionTree
can now choose to ignore epilogue releases and mark a node as dead if its only non-debug
user is epilogue release.

It can also mark a node as alive even its only user is epilogue release as before.

Imagine a case where one passes in an array and not access its owner
besides to release it. In such a case, we *do* want to be able to eliminate
that argument even though there is a release in the function epilogue.

This will help to get rid of the retain and release pair at the callsite. i.e.
the guaranteed paramter is elimininated.

rdar://21114206
2016-03-08 23:12:38 -05:00
Arnold Schwaighofer
3676671b7f Merge pull request #1587 from aschwaighofer/stack_promote_with_unsafe_mutable_buffer_pointer
Mark Array.withUnsafeMutableBuffer as not escaping the array storage.
2016-03-08 19:39:28 -08:00
Arnold Schwaighofer
b5f018a4b1 Mark Array.withUnsafeMutableBuffer as not escaping the array storage.
This is safe because the closure is not allowed to capture the array according
to the documentation of 'withUnsafeMutableBuffer' and the current implementation
makes sure that any such capture would observe an empty array by swapping self
with an empty array.

Users will get "almost guaranteed" stack promotion for small arrays by writing
something like:

  func testStackAllocation(p: Proto) {
    var a = [p, p, p]
    a.withUnsafeMutableBufferPointer {
      let array = $0
      work(array)
    }
  }

It is "almost guaranteed" because we need to statically be able to tell the size
required for the array (no unspecialized generics) and the total buffer size
must not exceed 1K.
2016-03-08 19:37:47 -08:00
Michael Gottesman
40b2d5f2d6 Merge pull request #1585 from gottesmm/count-countif-range-adaptors
Count countif range adaptors
2016-03-08 16:18:14 -08:00
Arnold Schwaighofer
fc96c2e53d Teach escape analysis about the semantics of copy_addr instructions
If the copy_addr cannot release the destination then it behaves just like a load
followed by a store.

This allows us to stack promote protocol typed array literals.

  protocol Proto { func at() -> Int }

  func testStackAllocation(p: Proto) {
    var a = [p, p, p]

    for e in a {
      print(e.at())
    }
  }
2016-03-08 15:07:25 -08:00
Michael Gottesman
bb15808554 Convert some trivial std::count_if invocations on ranges to use the provided range adaptor. 2016-03-08 14:58:13 -08:00
Michael Gottesman
5f72810ad3 Add a range adaptor for std::count and update various trivial usages in the compiler to use this API instead. 2016-03-08 14:58:13 -08:00
Max Moiseev
1fae0d1325 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-08 12:48:48 -08:00
practicalswift
37bf58399a [gardening] Fix formatting of two recently introduced file headers 2016-03-08 11:23:45 +01:00
Mark Lacey
4f2f993c68 Fix use-after-free in SimplifyCFG's block argument splitter.
We were creating new uses of an argument just prior to erasing it from
the block argument list.

We need to replace references to that value in the side structure we
generate with references to the new value that we're replacing it with.

Fixes SR-884 / rdar://problem/25008398.
2016-03-07 23:22:34 -08:00
Xin Tong
da37e94f3c change DEBUG_TYPE. And update some comments. NFC 2016-03-07 23:03:22 -05:00
Xin Tong
64e2710102 Move LSBase.x to SILOptimizer/Utils/. NFC. 2016-03-07 22:07:13 -05:00
Xin Tong
2fe08d9cda Move LSBase.cpp to lib/SILOptimzer/Utils/ 2016-03-07 22:04:15 -05:00
Xin Tong
56a09b67da Update some comments and delete abit dead code. NFC 2016-03-07 21:26:57 -05:00
Xin Tong
9d118f28c0 Improve on how final release is found.
Improve when to bail while finding the final releases.

The ConsumedArgToEpilogueReleaseMatcher finds the final releases
in the following way.

1. If an instruction, which is not releaseinst nor releasevalue, that
could decrement reference count is found. bail out. This may well be the
real epilogue release.

2. If a release is found and the release that can not be mapped to any
@owned argument. bail as this release may well be the final release of
an @owned argument, but somehow rc-identity fails to prove that.

3. A release that is mapped to an argument, but we already has a release
that (partially or completely) overlaps with this release. This release
for sure is not the final release.
2016-03-07 21:26:57 -05:00
Xin Tong
ba0249c924 Rename SILValueProjection.x to LSBase.x. NFC 2016-03-07 21:26:56 -05:00
Xin Tong
55377e727a Move createExtract to ProjectionPath::createExtract. NFC. 2016-03-07 21:26:56 -05:00
Xin Tong
bfc258f628 Simplify LSValue::reduce for redundant load elimination
LSValue::reduce reduces a set of LSValues (mapped to a set of LSLocations) to
a single LSValue.

It can then be used as the forwarding value for the location.

Previously, we expand into intermediate nodes and leaf nodes and then go bottom
up, trying to create a single LSValue out of the given LSValues.

Instead, we now use a recursion to go top down. This simplifies the code. And this
is fine as we do not expect to run into type tree that are too deep.

Existing test cases ensure correctness.
2016-03-07 21:26:56 -05:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Chris Lattner
e6dccdabaa use "!empty()" instead of "size()", since it is more specific. NFC. 2016-03-06 21:21:17 -08:00
Kevin Yu
8f193c856e [gardening] Fix typos "cant" -> "can't", "dont" -> "don't" 2016-03-06 00:25:14 +00:00
Erik Eckstein
bd548db88d ClosureSpecializer: always make a new specialized function a thin function.
This fixes a crash in IRGen (which I found with a modified compiler).
2016-03-04 11:00:25 -08:00
Joe Groff
be71ab28e2 SIL: Add an MarkUninitializedBehavior instruction for behavior DI.
This instruction creates a "virtual" address to represent a property with a behavior that supports definite initialization. The instruction holds references to functions that perform the initialization and 'set' logic for the property. It will be DI's job to rewrite assignments into this virtual address into calls to the initializer or setter based on the initialization state of the property at the time of assignment.
2016-03-03 15:04:38 -08:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Slava Pestov
874607ba48 SIL: Include all witnesses in SILDefaultWitnessTable, not just resilient defaults
Previously SILDefaultWitnessTables only included "resilient" default
implementations, which are currently defined as those that appear at the
end of a protocol, after any requirements without defaults.

However, this was too inflexible. Instead, include all entries in the
SILDefaultWitnessTable, with invalid entries standing in for requirements
without defaults.

Previously, the minimum witness table size was a separate parameter, also
appearing in SIL syntax; now it can be calculated by looking at the entries
themselves. The getResilientDefaultEntries() method of SILDefaultWitnessTable
returns the same result as getEntries() did previously.
2016-03-03 07:00:20 -08:00
Mark Lacey
5394f41a3b Add a check to avoid infinite looping in the pass manager.
It's possible to construct programs where the optimization pass manager
will just continually execute, never making progress.

Add a check to the pass manager that only allows us to optimize a
limited number of functions with the function passes before moving on.

Unfortunately even the tiny test case that I have for this takes minutes
before we bail out with the limit I've set (which is not *that* much
bigger than the maximum that I saw in our build). I don't think it would
be prudent to add that test to the test suite, and I haven't managed to
come up with something that finishes in a more reasonable amount of time.

rdar://problem/21260480
2016-03-03 06:47:36 -08:00
practicalswift
5c7bb57f7c [gardening] Fix recently introduced typo: "an retain" → "a retain" 2016-03-02 09:34:36 +01:00
Xin Tong
5176173cc8 Rename ConsumedReturnValueToEpilogueRetainMatcher.
Rename to ConsumedResultToEpilogueRetainMatcher

Also remove some dead code in ConsumedResultToEpilogueRetainMatcher.

NFC.
2016-03-01 20:21:00 -08:00
Xin Tong
6c0186b61c Reinstate "Improve funciton signature @owned return result to "not owned" conversion"
This enables function signature handles a case of self-recursion.

With this change we convert 11 @owned return value to "not owned", while
we convert 179 @owned parameter to @guanrateed.

rdar://24022375
2016-03-01 17:25:16 -08:00
Mark Lacey
27b63abeda Move RLE after inlining.
In theory we should be able to eliminate more loads if we run this after
the mem2reg that is after inlining. We aren't really relying heavily on
having promoted values like this prior to inlining.

Again, I see no significant performance delta, but this seems like the
best place to put this pass if we're only running it once per run of the
SSA passes.
2016-03-01 15:30:37 -08:00
Mark Lacey
014e312a2e Run redundant load elimination earlier in the pipeline.
Doing this earlier means that optimizations that are looking at SIL
values (rather than memory) have more opportunities earlier.

Minimal impact at the moment, but this may allow for removing some later
passes that are repeated.
2016-03-01 14:06:49 -08:00
Max Moiseev
859db53d87 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-01 12:56:26 -08:00
Erik Eckstein
115c50a5c7 DeadObjectElimination: Fix a problem with dead array elimination.
With the new ValueLifetimeAnalysis DOE did not handle case where a dead array is not released on a path at all (because it leads to an unreachable).
2016-03-01 12:30:52 -08:00
Xin Tong
d72ad28b08 Revert "Improve funciton signature @owned return result to "not owned" conversion"
This reverts commit c6de7c0123.

Broke OSS linux and OSX builds.
2016-03-01 11:17:06 -08:00
Xin Tong
c6de7c0123 Improve funciton signature @owned return result to "not owned" conversion
More specifically, this handles a case of self-recursion.

With this change we convert 11 @owned return value to "not owned", while
we convert 179 @owned parameter to @guanrateed.

rdar://24022375
2016-03-01 10:58:32 -08:00
Erik Eckstein
9a40e2dea4 Eventually fix the asan crash in ValueLifetimeAnalysis. 2016-02-29 13:19:02 -08:00
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Xin Tong
ddb9bba50e Improve the compilation time of redundant load elimination
For forwarding on allocstacks, we can invalidate the forwable bit when we
hit the deallocate stack.

This helps compilation time as we do not need to propagate these bits down
to subsequent basic blocks.
2016-02-29 10:11:40 -08:00
Erik Eckstein
68f0d5c202 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

It was reverted because of a bug in ValueLifetimeAnalysis which is now fixed.
2016-02-29 07:42:59 -08:00
Erik Eckstein
1730b90ae4 Reinstate "Rewrite the ValueLifetimeAnalysis."
Reinstates commit 0c2ca94ef7

With two bug fixes:
*) use after free asan crash
*) wrong check in ValueLifetimeAnalysis::isWithinLifetime
And some refactoring
2016-02-29 07:42:59 -08:00
Roman Levenstein
ae53c1c219 Fix a bug in LetPropertiesOptPass
The optimization should not proceed if there is more than one assignment to a let property inside an initializer.
In this case, the value of the let property is considered unknown.
2016-02-28 18:43:02 -08:00
Xin Tong
d0dc008fc1 Revert GenericSpecializer code.
This reverts commit

ed8126d050
ac0e7fd183
a11042eb05
b2d6e8ce6e
3a83cee006
0c2ca94ef7

First 4 commits are @practicalswift typo fixes which are implicated. Last 2 are
the culprits.

This causes an asan build crash.
2016-02-28 11:13:44 -08:00
Dmitri Gribenko
a9f8d97d3e Replace 'unsigned int' with 'unsigned'
'unsigned' is more idiomatic in LLVM style.
2016-02-27 16:20:27 -08:00
Chris Lattner
09c5ef4e10 Merge pull request #1470 from practicalswift/typo-fixes-20160227
[gardening] Fix recently introduced typos: "agains" → "against", "corrseponding" → "corresponding", "precessor" → "predecessor"
2016-02-27 14:07:45 -08:00
Chris Lattner
9a0c075ade Merge pull request #1473 from practicalswift/sort-cmakelists
[gardening] Sort file listings in CMakeLists.txt files
2016-02-27 14:05:42 -08:00
Chris Lattner
ed8126d050 Merge pull request #1474 from practicalswift/typo-fixes-20160227b
[gardening] Fix recently introduced typo: "ues" → "use"
2016-02-27 14:05:07 -08:00