Commit Graph

2592 Commits

Author SHA1 Message Date
Erik Eckstein
74d44b74e7 SIL: remove SILValue::getDef and add a cast operator to ValueBase * as a repelacement. NFC. 2016-01-25 15:00:49 -08:00
Erik Eckstein
d3c975391f SIL: remove dump and print from SILValue
If you want to dump a SILValue from the debugger, use Value->dump()
2016-01-25 15:00:49 -08:00
Erik Eckstein
845b3fe08e SIL: remove isValid() from SILValue. NFC 2016-01-25 15:00:49 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Erik Eckstein
5a53b31f57 SIL: remove use-iteration functions from SILValue.
They are not needed anymore. NFC.
2016-01-25 15:00:49 -08:00
Erik Eckstein
b745691a38 SIL refactoring: Move some functions out of SILValue and Operand
SILValue.h/.cpp just defines the SIL base classes. Referring to specific instructions is a (small) kind of layering violation.
Also I want to keep SILValue small so that it is really just a type alias of ValueBase*.
NFC.
2016-01-25 10:37:03 -08:00
practicalswift
71e00fefa1 [gardening] Fix typos: "word word" (two spaces) → "word word" (one space) 2016-01-24 21:27:16 +01:00
practicalswift
8efa5f587e [gardening] Remove "-*- C++ -*-" tag from .cpp files
Emacs assumes .h files are C files by default which is why the
tag "-*- C++ -*-" is needed.

.cpp files do not have this problem.
2016-01-23 12:09:32 +01:00
practicalswift
33312eac6b [gardening] Remove unreachable/unused/redundant code
* Make parameter naming in forward declaration match definition
* Remove unused argument to function persistAsync(…)
* Remove unused enum ShouldHalt
* Remove unused enum class IsProtocol
* Remove unused function dumpTypeSubstitutionMap()
* Remove unused function template getFirstPairElt(…)
* Remove unused method addConstantWordInWords(…)
* Remove unused method asExistentialTI()
* Remove unused method currentTrackedState()
* Remove unused method getNumBodyParameters()
* Remove unused method getSuccIndex()
* Remove unused method getTypeOfDeclReference(…)
* Remove unused method hasStructWithAtMostOneNonTrivialField(…)
* Remove unused method initForDirectValues()
* Remove unused method nextIfNot(…)
* Remove unused method overwriteLoweredValue(…)
* Remove unused method removeColumn(…)
* Remove unused methods HasSingleDecl() and GetFirstDecl()
* Remove unused methods overwriteLoweredExplosion(…) and setLoweredSingleValue(…)
* Remove unused methods requireRetainablePointerValue(…), getMethodSelfInstanceType(…) and isSelfArchetype(…)
* Remove unused methods setAsEmptyDirect(), setAsSingleDirectUnmanagedFragileValue(…), setAsIndirectAddress(…) and getDirectValues()
* Remove unused struct CachedMemberInfo
* Remove unused struct CallEdit
* Remove unused struct ErrorImportInfo
* Remove unused synonym ConformancePair
* Remove unused variable SemaInfo
* Remove unused variable localDeclNameNode
* Remove unused variables kindToken and kindLoc
2016-01-22 09:43:24 +01:00
Erik Eckstein
ec172cde5b Remove SILValue::replaceAllUsesWith.
It's not needed anymore because we can use ValueBase::replaceAllUses
2016-01-21 16:04:30 -08:00
Erik Eckstein
f2c0283437 Simplify DebugUtils
With the changes in SILValue there is no need for template functions in DebugUtils anymore.
2016-01-21 16:04:30 -08:00
Erik Eckstein
2db6f3d213 SIL: remove multiple result values from SILValue
As there are no instructions left which produce multiple result values, this is a NFC regarding the generated SIL and generated code.
Although this commit is large, most changes are straightforward adoptions to the changes in the ValueBase and SILValue classes.
2016-01-21 10:30:31 -08:00
practicalswift
6d0eee9b8c Remove unused variables. 2016-01-21 10:33:17 +01:00
Xin Tong
894aa621cd Make Fix_lifetime instruction inert from a store prospective 2016-01-20 16:52:53 -08:00
Xin Tong
9f8dcfab07 Make Fix_lifetime instruction inert from a load prospective 2016-01-20 15:01:56 -08:00
Michael Gottesman
e25cd8860c Remove all uses of ilist_node::getNextNode() and ilist_node::getPrevNode() in favor of just using iterators.
This change is needed for the next update to ToT LLVM. It can be put
into place now without breaking anything so I am committing it now.

The churn upstream on ilist_node is neccessary to remove undefined
behavior. Rather than updating the different ilist_node patches for the
hacky change required to not use iterators, just use iterators and keep
everything as ilist_nodes. Upstream they want to eventually do this, so
it makes sense for us to just do it now.

Please do not introduce new invocations of
ilist_node::get{Next,Prev}Node() into the tree.
2016-01-19 14:44:58 -06:00
Erik Eckstein
8110b1ebc8 [SIL] Let alloc_box return a single value.
And use project_box to get to the address value.
SILGen now generates a project_box for each alloc_box.
And IRGen re-uses the address value from the alloc_box if the operand of project_box is an alloc_box.
This lets the generated code be the same as before.

Other than that most changes of this (quite large) commit are straightforward.
2016-01-19 08:59:24 -08:00
Andrew Trick
e8fc64cdae [SILOpt] Fix speculative devirtualization miscompile.
Properly handle limiting the number of speculative checks.
This bug dates back to 2015-09-15, Swift 2.1.

Fixes rdar:23228386.
2016-01-17 17:08:59 -08:00
Erik Eckstein
afe9cf6091 CSE: handle project_box 2016-01-15 16:01:56 -08:00
Mark Lacey
ab138b9839 Don't assert on alloc_stack with only debug_value_addr uses.
This came up with other changes I have to modify the optimizer
pipeline. We shouldn't assert if we have an alloc_stack/dealloc_stack
where the only other use of the alloc_stack is a debug_value_addr.

It's easy to avoid this by removing allocations that don't have real
uses prior to attempting to handle the ones that do have real uses (as
opposed to the other way around).
2016-01-15 16:40:34 -05:00
Xin Tong
f5a77cd5ad Remove release instructions in non-arc-inert termination block. rdar://24011383 2016-01-14 15:37:10 -08:00
Michael Gottesman
5b1ebe12a9 Remove the case 'Invalid' from the TermKind enum and just use an unreachable in the ValueKind -> TermKind switch instead.
In all of the cases where this is being used, we already immediately perform an
unreachable if we find a TermKind::Invalid. So simplify the code and move it
into the conversion switch itself.
2016-01-11 15:44:05 -08:00
Michael Gottesman
24bd1e3974 Remove variable that is written to but never read. Found by the clang static analyzer. 2016-01-08 19:28:43 -08:00
Erik Eckstein
9ad406d5d6 Remove the local_storage type attribute and SIL value category.
They are not used anymore as alloc_stack now returns a single value.
2016-01-06 17:35:27 -08:00
Erik Eckstein
c3a769e1bd Fix code examples with alloc_stack in comments.
Reflecting the change that alloc_stack now returns a single value. NFC.
2016-01-06 17:35:27 -08:00
Erik Eckstein
6ff2f09796 [SIL] Let alloc_stack return a single value.
Having a separate address and container value returned from alloc_stack is not really needed in SIL.
Even if they differ we have both addresses available during IRGen, because a dealloc_stack is always dominated by the corresponding alloc_stack in the same function.

Although this commit quite large, most changes are trivial. The largest non-trivial change is in IRGenSIL.

This commit is a NFC regarding the generated code. Even the generated SIL is the same (except removed #0, #1 and @local_storage).
2016-01-06 17:35:27 -08:00
practicalswift
e0eba97b98 Fix typos. 2016-01-06 00:48:22 +01:00
Xin Tong
6ce0f00f54 Remove a *pass* keyword for consistency 2016-01-04 22:21:03 -08:00
Mark Lacey
cdc41078bd Move cases for switch_enum_addr and checked_cast_addr_br in switch.
These should be with the other cases we do not expect block arguments
for.
2016-01-04 15:40:11 -08:00
Nadav Rotem
b8c4eddf27 Merge pull request #873 from practicalswift/typo-fixes-20160104b
[gardening] Fix recently introduced typos
2016-01-04 15:07:43 -08:00
practicalswift
ca92efc8e6 Use consistent formatting of header comments.
Correct format:
```
//===--- Name of file - Description ----------------------------*- Lang -*-===//
```

Notes:
* Comment line should be exactly 80 chars.
* Padding: Pad with dashes after "Description" to reach 80 chars.
* "Name of file", "Description" and "Lang" are all optional.
* In case of missing "Lang": drop the "-*-" markers.
* In case of missing space: drop one, two or three dashes before "Name of file".
2016-01-04 23:00:53 +01:00
practicalswift
7b2bc2a0f4 Fix recently introduced typos. 2016-01-04 21:22:33 +01:00
Xin Tong
ba40b3f1a7 Take a more displined approach in DSE as to how to a function is optimized.
Now we have 3 cases.

1. OptimizeNone (for functions with too many basicblocks and too many locations). Simply return.
2. Pessimisitc single iteration data flow (for functions with many basic blocks and many locations).
3. Optimistic multiple iteration data flow (for functions with some basic blocks and some locations
   and require iterative data flow).

With this change stdlib and stdlibunittest has some changes in dead store(DS)
eliminated.

stdlib: 202 -> 203 DS.
stdlibunittest: 42 - 39 DS.

Compilation time improvement: with this change on a RELEASE+ASSERT compiler for stdlibunittest.

Running Time        Self (ms)               Symbol Name
5525.0ms    5.3%    25.0                     (anonymous namespace)::ARCSequenceOpts::run()
3500.0ms    3.4%    25.0                     (anonymous namespace)::RedundantLoadElimination::run()
3050.0ms    2.9%    25.0                     (anonymous namespace)::SILCombine::run()
2700.0ms    2.6%    0.0                      (anonymous namespace)::SimplifyCFGPass::run()
2100.0ms    2.0%    75.0                     (anonymous namespace)::SILCSE::run()
1450.0ms    1.4%    0.0                      (anonymous namespace)::DeadStoreElimination::run()
750.0ms    0.7%     75.0                     (anonymous namespace)::DCE::run()

Compilation time improvement: with this change on a DEBUG compiler for stdlibunittest.

Running Time        Self (ms)               Symbol Name
42300.0ms    4.9%   50.0                      (anonymous namespace)::ARCSequenceOpts::run()
35875.0ms    4.1%   0.0                       (anonymous namespace)::RedundantLoadElimination::run()
30475.0ms    3.5%   0.0                       (anonymous namespace)::SILCombine::run()
19675.0ms    2.3%   0.0                       (anonymous namespace)::SILCSE::run()
18150.0ms    2.1%   25.0                      (anonymous namespace)::SimplifyCFGPass::run()
12475.0ms    1.4%   0.0                       (anonymous namespace)::DeadStoreElimination::run()
5775.0ms    0.6%    0.0                       (anonymous namespace)::DCE::run()

I do not see a compilation time change in stdlib.

Existing tests ensure correctness.
2016-01-04 10:04:54 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
practicalswift
f91525a10f Consistent placement of "-*- [language] -*-===//" in header. 2016-01-04 09:46:20 +01:00
practicalswift
50baf2e53b Use consistent formatting in top of file headers. 2016-01-04 02:17:48 +01:00
practicalswift
6c32688275 Fix recently introduced typos. 2016-01-03 21:16:23 +01:00
Xin Tong
4ea79fec2b There are simply too many locations and too many basic blocks in some
functions for dead store elimination to handle.  In the worst case, The number of
memory behavior or alias queries we need to do is roughly linear to
the # BBs x(times) # of locations.

Put in some heuristic to trade off accuracy for compilation time.

NOTE: we are not disabling DSE for these offending functions. instead we are running
a one iteration pessimistic data flow as supposed to the multiple iteration optimistic
data flow we've done previously.

With this change. I see compilation time on StdlibUnitTest drops significantly.
50%+ drop in time spent in DSE in StdlibUnit with a release compiler.

I will update more Instruments data post-commit once i get close to my desktop.

I see a slight drop in # of dead stores (DS) elimination in stdlib and stdlibUnit test.

stdlib: 203 DS -> 202 DS. (RLE is affected slightly as well. 6313 -> 6295 RL).

stdlibunittest :  43 DS -> 42. (RLE is not affected).

We are passing all existing dead store tests.
2016-01-03 10:48:02 -08:00
Xin Tong
013d08d439 Add a bailout location # threshold in DSE.
In StdlibUnitTest, there is this function that has too many (2450) LSLocations
and the data flow in DSE takes too long to converge.

StdlibUnittest.TestSuite.(addForwardRangeReplaceableCollectionTests <A, B where A: Swift.RangeReplaceableCollectionType, B: Swift.RangeReplaceableCollectionType, A.SubSequence: Swift.CollectionType, B.Generator.Element: Swift.Equatable, A.SubSequence == A.SubSequence.SubSequence, A.Generator.Element == A.SubSequence.Generator.Element> (Swift.String, makeCollection : ([A.Generator.Element]) -> A, wrapValue : (StdlibUnittest.OpaqueValue<Swift.Int>) -> A.Generator.Element, extractValue : (A.Generator.Element) -> StdlibUnittest.OpaqueValue<Swift.Int>, makeCollectionOfEquatable : ([B.Generator.Element]) -> B, wrapValueIntoEquatable : (StdlibUnittest.MinimalEquatableValue) -> B.Generator.Element, extractValueFromEquatable : (B.Generator.Element) -> StdlibUnittest.MinimalEquatableValue, checksAdded : StdlibUnittest.Box<Swift.Set<Swift.String>>, resiliencyChecks : StdlibUnittest.CollectionMisuseResiliencyChecks, outOfBoundsIndexOffset : Swift.Int) -> ()).(closure #18)

This function alone takes ~20% of the total amount of time spent in DSE in StdlibUnitTest.

And DSE does not eliminate any dead store in the function either. I added this threshold
to abort on functions that have too many LSLocations.

I see no difference in # of dead store eliminated in the Stdlib.
2016-01-02 17:37:53 -08:00
Michael Gottesman
9e551dd237 Doxygenify file level comment. 2016-01-02 16:41:36 -06:00
Michael Gottesman
389238e801 Add support for multiple @_semantics attributes at the SIL level.
This is something that we have wanted for a long time and will enable us to
remove some hacks from the compiler (i.e. how we determine in the ARC optimizer
that we have "fatalError" like function) and also express new things like
"noarc".
2016-01-02 04:17:07 -06:00
Xin Tong
310f48eab0 Improve dead store elimination compilation time.
If we know a function is not a one iteration function which means its
its BBWriteSetIn and BBWriteSetOut have been computed and converged,
and a basic block does not even have StoreInsts, there is no point
in processing every instruction in the last iteration of the data flow
again as no store will be eliminated.

We can simply skip the basic block and rely on the converged BBWriteSetIn
to process its predecessors.

Compilation time improvement: 1.7% to 1.5% of overall compilation time.
on stdlib -O. This represents a 4.0% of all SILOptimzations(37.2%)

Existing tests ensure correctness.
2016-01-01 10:16:42 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
2e995a8ba4 Fix recently introduced typos. 2015-12-31 15:28:54 +01:00
Xin Tong
a35eabd6f7 Instead of enumerating all the LSValues before RLE is ran on the function. we
enumerate them lazily.

This leads to compilation time improvement, as some of the LSValues previously
enumerated do not be created in this approach.

i.e. we enumerate LSValues created by loads previously, but the LoadInsts could be
target for RLE. In such case, the enumerated LSValues are not used.

Compilation time improvement: 1775ms to 1721ms (2.7% to 2.6% of the entire
compilation time for stdlib -O).

Existing tests ensure correctness.

Note: we still enumerate locations, as we need to know how many locations there are
in the function to resize the bitvector appropriately before the data flow runs.
2015-12-30 14:35:59 -08:00
Xin Tong
0c162cd3d1 Refactor in redundant load elimination. NFC.
1. Update some comments.
2. Rename a few functions, e.g. runIterativeDF -> runIterativeRLE, getLSValueBit -> getValueBit.
3. Remove unused headers.
4. Remove no-longer used function, mergePredecessorStates and mergePredecessorState.
5. A few other small NFCs.
2015-12-29 15:35:49 -08:00
practicalswift
6dac32e416 Fix typos in code merged today 2015-12-29 23:19:48 +01:00
Xin Tong
be4bf816bd Update some comments and rename runIterativeDF -> runIterativeDSE,
mergeSuccessorStates -> mergeSuccessorLiveIns in DSE. Also fix some includes.
2015-12-29 10:13:02 -08:00
practicalswift
fb314c37aa Fix typos introduced yesterday :-) 2015-12-29 13:16:02 +01:00
Aaron Raimist
b196e79b88 SimplifyCFG: Fix typo, Fist to First 2015-12-28 23:04:24 -06:00