Commit Graph

2592 Commits

Author SHA1 Message Date
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Arnold Schwaighofer
a9fa8c9c2b Merge pull request #14514 from aschwaighofer/wip_closure_capture_abi_part2
WIP: Closure ABI - Make @noescape Swift closures trivial
2018-02-14 05:19:25 -08:00
Arnold Schwaighofer
d490c22bb4 SimplifyCFG: Skip convert_escape_to_noescape in try_apply -> apply optimization 2018-02-13 09:38:02 -08:00
Joe Shajrawi
102b6f0b61 Merge pull request #14587 from shajrawi/newinstr
Optimizer peephole for tagged BridgeObjects
2018-02-13 07:38:53 -08:00
Joe Shajrawi
f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
Andrew Trick
4734920222 Don't rerun diagnostic passes on deserialized SIL. 2018-02-09 09:55:47 -08:00
Andrew Trick
0dfce6c0f6 Don't rerun mandatory lowering passes on deserialized SIL. 2018-02-09 09:55:47 -08:00
Andrew Trick
0d937d1c15 Make MarkUninitialized a function pass. 2018-02-09 09:55:47 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Andrew Trick
5c4c6e2ed7 Fix AllocBoxToStack to notify the PassManager of cloned functions.
If the pass does not register a new function, that new function will never be
passed through the current function pipeline. We were getting lucky that enough
of the mandatory passes were module passes that it didn't seem to matter in
practice (until I convert them to function passes).

(after pass reorganization, a one line fix that doesn't rely on
outrageous changes to the pass' function signatures.)
2018-02-05 21:17:32 -08:00
Andrew Trick
ee42bdc446 [NFC] Reorganize the AllocBoxToStackPass.
In preparation for fixing a bug.
- Separate general SIL utilities, liveness, escape analysis,
  and promotion.
- Give promotion routines access to the current pass.

Ideally, the current pass would be accessible via TLS. In the meantime,
pass routines should always have access to a state object that
encapsulates the pass information corresponding to a single invocation
of the pass.

Access to the pass' state should be consistent and idiomatic; it should
not depend on the where we are in the call stack. This makes the code much easier to understand and refactor, and it enables exploratory changes.
2018-02-05 21:17:32 -08:00
Michael Gottesman
950e55d899 [sil][typelowering] Inline (i.e. eliminate) the confusing method TypeLowering::getLoweringStyle() and change it to properly use TypeExpansionKind::None instead of TypeExpansionKind::DirectChildren for the non-expansion case.
Now we will consistently expand destroy_addr/copy_addr into either
{retain,release}_value or into ARC operations on its most derived descendents.
This will improve code-size (by not expanding when we didn't intend to), but
more importantly preserve invariants that the ARC optimizer depends upon.

rdar://36509461
2018-01-25 14:09:57 -08:00
Michael Gottesman
d14024acd3 [sil][typelowering] Rename the enum LoweringStyle => TypeExpansionKind and add a None case to make its usage clearer.
This enum controls how certain routines in TypeLowering potentially expand types
when performing copy_value/destroy_value operations. Its previous form was
problematic because:

1. The name LoweringStyle does't suggest anything related to expansion really.
The new has the word expansion in it explicitly.
2. The cases of LoweringStyle used to be Shallow, Deep. This caused confusion
since Shallow (the base case) was not a no-op. It just caused us to expand into
children. Now TypeExpansionKind has 3 cases to make this clear: None,
DirectChildren, and MostDerivedDescendents.

Confusion around this API caused us to canonicalize ARC operations differently
for different operations (e.g. copy_value/destroy_value vs
copy_addr/destroy_addr). This caused us to misout on some code-size wins (since
we were splitting some operations onto DirectChildren of aggregates), but more
importantly also caused the optimizer to break an invariant that the ARC
optimizer relied upon: local semantic pairings being at the same level of
abstraction. In a subsequent commit, I am going to fix that bug.

rdar://36509461
2018-01-24 16:28:03 -08:00
Erik Eckstein
3afd9c8eb4 ObjectOutliner: fix for handling set_deallocating instruction correctly.
rdar://problem/36692828
2018-01-23 18:21:33 -08:00
Erik Eckstein
e081392672 ObjectOutliner: handle set_deallocating instruction correctly.
rdar://problem/36692828
2018-01-22 17:04:56 -08:00
Davide Italiano
3c9fa1627c [AllocBoxToStack] Use SILBUilderWithScope instead of SILBuilder.
It's the correct thing to do, as we immediately switch the current
debug scope. In this case, it's NFC as the code was already doing
the right thing, but this is more concise/harder to get wrong.
2018-01-21 13:18:34 -08:00
Erik Eckstein
80a734ab30 DeadObjectElimination: handle objects for which the destructor is de-virtualized and inlined
Also: add an additional DeadObjectElimination pass in the low level pipeline because
redundant load elimination (which runs before) can turn an object into a dead object.
2018-01-19 11:33:26 -08:00
Erik Eckstein
44aafd950c Tuning the inliner heuristics:
* allow small class methods to be inlined with -Osize
* inline pure calls: references to objects, which are initialized with constants, are considered as constant arguments
2018-01-19 11:32:37 -08:00
Erik Eckstein
c3ef03fc37 ARCCodeMotion: add a small peephole optimization which removes adjacent retain/release pairs.
This reduces phase ordering problems, because it eliminates the need for a ARCSequenceOpt (which also does this optimization).
2018-01-19 11:32:36 -08:00
Erik Eckstein
bf87035a36 GlobalOpt: Move the object outlining from GlobalOpt into a separate pass "ObjectOutliner"
We run GlobalOpt multiple times in the pass pipeline but in some cases object outlining shouldn't be done too early.
Having it done in a separate pass enables to run it independently from GlobalOpt.
2018-01-19 11:32:36 -08:00
Erik Eckstein
4f8cccff68 SimplifyCFG: do constant folding also in SimplifyCFG.
This enables to optimize chains of constant-foldable terminal instructions, for which we would have needed multiple ConstantPropagaion-SimplifyCFG pass pairs in the pipeline otherwise.
See the test file for an example.
2018-01-19 11:32:33 -08:00
eeckstein
b126b62256 Revert "Optimization changes to completely fold OptionSet literals" 2018-01-18 22:05:07 -08:00
Erik Eckstein
442171bca6 DeadObjectElimination: handle objects for which the destructor is de-virtualized and inlined
Also: add an additional DeadObjectElimination pass in the low level pipeline because
redundant load elimination (which runs before) can turn an object into a dead object.
2018-01-18 18:27:17 -08:00
Erik Eckstein
8fb523e776 Tuning the inliner heuristics:
* allow small class methods to be inlined with -Osize
* inline pure calls: references to objects, which are initialized with constants, are considered as constant arguments
2018-01-18 18:27:17 -08:00
Erik Eckstein
d88b233f05 ARCCodeMotion: add a small peephole optimization which removes adjacent retain/release pairs.
This reduces phase ordering problems, because it eliminates the need for a ARCSequenceOpt (which also does this optimization).
2018-01-18 18:27:17 -08:00
Erik Eckstein
1f511ab846 GlobalOpt: Move the object outlining from GlobalOpt into a separate pass "ObjectOutliner"
We run GlobalOpt multiple times in the pass pipeline but in some cases object outlining shouldn't be done too early.
Having it done in a separate pass enables to run it independently from GlobalOpt.
2018-01-18 18:27:17 -08:00
Erik Eckstein
485463b8f7 SimplifyCFG: do constant folding also in SimplifyCFG.
This enables to optimize chains of constant-foldable terminal instructions, for which we would have needed multiple ConstantPropagaion-SimplifyCFG pass pairs in the pipeline otherwise.
See the test file for an example.
2018-01-18 18:27:17 -08:00
Adrian Prantl
c74ae5f375 Remove the redundant SILLocation::getCompilerGenerated interface (NFC) 2018-01-17 11:09:23 -08:00
Michael Gottesman
dfd40e4443 [cast-optimizer] Move the cast optimizer into its own .cpp file.
Local.cpp was ~3k lines of which 1.5k (i.e. 1/2) was the cast optimizer. This
commit extracts the cast optimizer into its own .cpp and .h file. It is large
enough to stand on its own and allows for Local.cpp to return to being a small
group of helper functions.

I am making some changes in this area due to the change in certain function
conventions caused by the +0-normal-arg work. I am just trying to leave the area
a little cleaner than before.
2018-01-13 18:26:22 -08:00
adrian-prantl
ecf9ee749d Merge pull request #13818 from vedantk/empty-locs
[DebugInfo] Add a free helper to get empty locations, NFC
2018-01-11 18:14:37 -08:00
Arnold Schwaighofer
fe16c809e1 Outliner: Can't handle generic ObjC classes
The outliner can't handle outlining calls to generic objective c
classes resulting in crashes if it attempted so.

rdar://36395452
2018-01-10 10:56:21 -08:00
swift-ci
212e72dfce Merge pull request #13780 from gottesmm/pr-5257f0f76ea8f8dcc8e00aff2734cf20d6bcdd50 2018-01-09 19:13:01 -08:00
Michael Gottesman
8160913cb1 [temp-rvalue] Teach the temprvalue to ignore @in_guaranteed uses.
This is a pattern that comes up very often in an all +0 normal argument
convention world.

rdar://34222540
2018-01-09 18:25:06 -08:00
Vedant Kumar
d60ff05265 Rename getEmptyLocation to getCompilerGeneratedLocation 2018-01-09 12:38:45 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Vedant Kumar
e33f3b663d [DebugInfo] Add a free helper to get empty locations, NFC 2018-01-08 17:59:16 -08:00
Michael Gottesman
ecc1ed4589 [dead-array] Handle initialization where we pass in an alloc_ref/apply in a +0 context.
rdar://34222540
2018-01-07 00:13:38 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Chris Lattner
415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
David Zarzycki
68c696dbc1 [SIL] NFC: Replace boilerplate projection with swift::ArrayRefView 2017-12-28 09:51:29 -05:00
Michael Gottesman
1209592421 Merge pull request #13536 from gottesmm/rdar_36032876
In SILCodeMotion, be sure to invalidate global enum tag dataflow state when deleting instructions
2017-12-19 16:09:16 -08:00
Michael Gottesman
af8d9b8c78 [silcodemotion] Instead of storing enum values directly into the block state structures, use a global "blotable" store to allow for invalidation without touching potentially free-ed pointers. Fix up all of the places where we violate this invariant.
rdar://36032876
2017-12-19 11:20:59 -08:00
Michael Gottesman
269c5e86cd [silcodemotion] Now that we have sunk the context into each block state, we do not need to pass in the context to any routines on the block state.
rdar://36032876
2017-12-19 10:55:36 -08:00
Michael Gottesman
77441fcdd1 [silcodemotion] For now stash a pointer to EnumCaseDataflowContext in each of the block states that we are tracking.
In a subsequent commit, I will change this to use a trailing objects
implementation so we can just use pointer arithmetic to find the offset. But for
now I am going for simplicity since this is a bug fix.

rdar://36032876
2017-12-19 10:21:31 -08:00
Michael Gottesman
48bb2d16f1 [silcodemotion] Rename BBToDataflowStateMap -> EnumCaseDataflowContext.
rdar://36032876
2017-12-19 10:13:10 -08:00
Michael Gottesman
9cda9056b6 [silcodemotion] Add support for dumping BBEnumTagDataflowState.
rdar://36032876
2017-12-19 10:11:56 -08:00
Michael Gottesman
42e1df166a [silcodemotion] Move generic code motion code below enum tag dataflow based code motion.
This gets rid of forward declaration issues in the file with some subsequent
changes I am going to be making.

rdar://36032876
2017-12-19 10:10:07 -08:00
Adam Nemet
5d7b8106c3 Add opt-remarks to the Speculative Devirtualizer pass 2017-12-18 13:29:46 -08:00
swift-ci
ac95e6116b Merge pull request #13503 from anemet/opt-remark-devirt 2017-12-18 12:09:22 -08:00
Adam Nemet
3a9012d742 Add opt-remarks to the Devirtualizer pass 2017-12-18 10:18:13 -08:00