Commit Graph

32 Commits

Author SHA1 Message Date
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Nadav Rotem
240ff14db1 Split DominanceAnalysis into Dom and PDom using FunctionAnalysisBase.
This commit splits DominanceAnalysis into two analysis (Dom and PDom) that
can be cached and invalidates using the common FunctionAnalysisBase interface
independent of one another.

Swift SVN r26643
2015-03-27 20:54:28 +00:00
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Mark Lacey
2e08afb386 Fix for 80-column violation.
Swift SVN r26383
2015-03-21 02:06:15 +00:00
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +00:00
Arnold Schwaighofer
e2543507bf [CopyForwarding] Make my comments clearer
NFC

Swift SVN r25457
2015-02-21 02:31:33 +00:00
Arnold Schwaighofer
f94376f926 [CopyForwarding] Handle single definition source take copy forwarding
This handles the case were we copy a single definition "%src" live range that is
destroyed imediately. The destination address is known to be initialized by only
this copy or by writes dominated by this copy.

For example:

foo(@in Protocol) {
bb(%src: $*Protocol)
  %dst = alloc_stack Protocol
  copy_addr [take] %src, [initialization] %dst#1
  ... [use %dst#1]
}

=>

foo(@in Protocol) {
bb(%src: $*Protocol)
  ... [use %src#1]
}

O improvments > 10% (time before/after)
 DollarMap 1.13226
 DollarReduce 1.11044
 JSONHelperDeserialize 1.1365
 StringWalk 1.13523
 SwiftStructuresLinkedList 2.1201
 SwiftStructuresQueue 1.86783
 SwiftStructuresStack 1.22642

O regression:
 SwiftStructuresBubbleSort 0.912005

Onone improvements > 10% (time before/after)
 Dictionary 1.25214
 Dictionary2 1.28772
 Dictionary3 1.25364
 DictionaryLiteral 1.12717
 DictionaryRemove 1.14766
 DictionarySwap 1.16806
 DollarMap 1.14829
 DollarReduce 1.11194
 Forest 1.15122
 Histogram 1.15321
 JSONHelperDeserialize 1.14257
 Prims 1.25893
 RGBHistogram 1.11035
 Richards 1.14413
 StrSplitter 1.13805
 SwiftStructuresGraphBFS 1.40441
 SwiftStructuresLinkedList 1.60171
 SwiftStructuresQueue 1.38401
 SwiftStructuresStack 1.17395
 TwoSum 1.14819

rdar://19851003

Swift SVN r25431
2015-02-20 19:18:45 +00:00
Andrew Trick
ccbba65835 CopyForwarding pass: make destroy hoisting conservative if the addess is also loaded from.
We never run into this case in the stdlib/PerfTestSuite. So for Xcode 6.4, be conservative.
Longer term, I was planning to follow def-use chains through projections.
When we do this, we can also follow projects of loaded values to find any retain points.
That would give us a proper indication of the lifetime of referenced objects.

Fixes <rdar://problem/19724405> [NSObject] as! [NSWindow] sends messages to deallocated __NSArrayI

Swift SVN r25188
2015-02-11 19:34:01 +00:00
Andrew Trick
db6a37ddbb Enable the CopyForwarding pass in -O.
If there are any nontrivial issues with this pass, aside from random inlining
noise, we should disable it for Xcode 6.4. This can be verified via:

--extra-swift-args=".;-Xllvm\;enable-copyforwarding=false\;-Xllvm\;-enable-destroyhoisting=false"

This is not enabled at -Onone. We don't currently have a way to
control the optimization without potentially affecting the debugging
experience. People may expect debug values for variables past their
last use.

It looks like this is about a 3% compile time improvement on stdlib-RA
due to reducing SIL early in the pipeline.

Performance:

Most of the big gains with this optimization disappeared when generic
inlining was enabled. This is good, because it means generic inlining
is doing its job. CopyForwarding mainly benefits generic code that
doesn't get inlined. There are still plenty of significant performance
improvements, along with reducing the size of the SIL code early.

The regressions shown below related to inlining heuristics, not the
optimization itself. CopyForwarding is actually a speedup or neutral
in all of these cases when we just increase the inlining threshold. By
reducing the size of the SIL code, inlining decisions are very
different because we use a silly bottom-up threshold approach. I've
been fixing regressions for months in preparation for enabling the
feature, but it's a losing battle. e.g the Ary and PrimeNum
regressions did not exist before generic inlining was enabled this
week. Instead, I'm just tracking the inlining issues, which are in the
process of being fixed.

-O slowdowns
|_RangeAssignment___________|____-81.6%_|
|_Ary_______________________|____-38.7%_|
|_Ary2______________________|____-29.9%_|
|_PrimeNum__________________|____-22.6%_|
|_EditDistance______________|____-13.2%_|
<rdar://problem/19426897> [Inliner] Fail to fully optimize RangeAssignment (especially with copy forwarding)
<rdar://problem/19430635> [Inliner] 2x regression on Ary and Ary2 with copyforwarding
<rdar://problem/19431694> [Inliner] 24% slowdown in PrimeNum with CopyForwarding
<rdar://problem/19432662> [Inliner] 19% slowdown in EditDistance with CopyForwarding

-O speedups
|_Phonebook_______________|_____57.2%_|
|_ProtocolDispatch________|_____36.4%_|
|_SwiftStructuresTrie_____|_____32.5%_|
|_StdlibSort______________|_____27.7%_|
|_StringWalk______________|_____20.4%_|
|_ArrayOfRef______________|_____19.7%_|
|_ArrayOfGenericRef_______|_____18.3%_|
|_JSONHelperDeserialize___|_____14.1%_|
|_DollarFilter____________|_____14.0%_|
|_NSXMLParser_____________|_____13.9%_|
|_CaptureProp_____________|_____12.6%_|
|_Havlak__________________|_____10.7%_|
|_DollarMap_______________|_____10.3%_|
|_SortStrings_____________|______9.5%_|
|_DollarReduce____________|______9.5%_|
|_SwiftStructuresStack____|______9.1%_|
|_NopDeinit_______________|______8.7%_|
|_Dictionary3_____________|______8.6%_|
|_DollarChain_____________|______6.4%_|
|_DollarFunction__________|______5.6%_|
|_StrSplitter_____________|______5.4%_|
|_PolymorphicCalls________|______5.4%_|
|_GenericStack____________|______5.3%_|
|_NSDictionaryImplicitConversion_|______5.4%__|

Possible_improvements,_but_likely_noise:
|_Random__________________|_5.5%_(!)_|
|_RecursiveOwnedParameter_|_5.2%_(!)_|

-Ounchecked slowdowns
|_RangeAssignment______|_-69.4%_|
|_Ary__________________|_-41.8%_|
|_Ary2_________________|_-32.6%_|
|_PopFrontArrayGeneric_|_-14.2%_|
|_EditDistance_________|_-10.3%_|
|_ImageProc____________|__-8.7%_|
|_PrimeNum_____________|__-7.3%_|
<rdar://problem/19433097> [Inliner] 10% slowdown in PopFrontGeneric with CopyForwarding and -Ounchecked
(the rest are covered by -O)

-Ounchecked speedups
|_Phonebook_________________|____53.7%_|
|_SwiftStructuresTrie_______|____25.4%_|
|_ArrayOfGenericRef_________|____25.0%_|
|_ArrayOfRef________________|____23.7%_|
|_StdlibSort________________|____21.7%_|
|_StringWalk________________|____17.9%_|
|_JSONHelperDeserialize_____|____14.1%_|
|_ArrayOfGenericPOD_________|____12.3%_|
|_Havlak____________________|____11.8%_|
|_Dictionary2_______________|____11.6%_|
|_ArrayOfPOD________________|____11.2%_|
|_SortStrings_______________|____10.9%_|
|_DollarReduce______________|____10.5%_|
|_SwiftStructuresStack______|____10.2%_|
|_DollarFilter______________|_____9.5%_|
|_StrComplexWalk____________|_____8.6%_|
|_DeltaBlue_________________|_____8.5%_|
|_StringBuilder_____________|_____7.5%_|
|_SwiftStructuresBubbleSort_|_____6.5%_|
|_Life______________________|_____6.2%_|
|_GenericStack______________|_____6.2%_|
|_ArrayLiteral______________|_____6.2%_|
|_Histogram_________________|_____6.1%_|
|_NSXMLParser_______________|_____5.2%_|
|_StrCat____________________|_____5.0%_|

Swift SVN r24391
2015-01-13 05:45:43 +00:00
Andrew Trick
e90150a432 CopyForwarding: insignificant change to ignore inout parameters.
Swift SVN r24390
2015-01-13 05:45:43 +00:00
Andrew Trick
85c1ef5b01 CopyForwarding: Be conservative with address users.
Until we can peek through projections, if it projects the address at
all, do not consider it a "known use" of the value.

Swift SVN r24389
2015-01-13 05:45:42 +00:00
Andrew Trick
58ba2659ee CopyForwarding comments.
Swift SVN r24388
2015-01-13 05:45:41 +00:00
Andrew Trick
5223fb4ff8 CopyForwarding: handle the in_guaranteed parameter convention.
Swift SVN r24317
2015-01-09 17:51:39 +00:00
Chris Lattner
5d8613c7c9 Introduce a new "Indirect_In_Guaranteed" SIL parameter convention. This
isn't used yet, but will be for modeling the self argument passed to an 
address-only witness implementation.   NFC since all this code is dead :-)



Swift SVN r23857
2014-12-11 01:41:29 +00:00
Andrew Trick
b0d7f6fc17 CopyForwarding: Comment materializeForSet handling.
Swift SVN r23836
2014-12-10 06:21:02 +00:00
Andrew Trick
0922f8f6a8 CopyForwarding: Disable global hoisting in transparent functions (NFC/disabled).
Swift SVN r23835
2014-12-10 06:21:01 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Andrew Trick
a0b9c04878 Added temporary -enable-destroyhoisting flag (NFC).
This transformation can interfere with some mandatory optimizations.
The flag will help performance investigation.

Swift SVN r22862
2014-10-21 16:48:08 +00:00
Andrew Trick
a32a5665ee CopyForward: reset postorder traversal each iteration.
Swift SVN r22861
2014-10-21 16:48:07 +00:00
Joe Groff
3f23b82e6d SIL: Rename SILGlobalAddr to GlobalAddr.
All globals are SIL globals now.

Swift SVN r22827
2014-10-18 17:08:28 +00:00
Joe Groff
ea65d1e60b SIL: Remove the builtin_function_ref instruction.
Swift SVN r22797
2014-10-16 16:18:40 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Andrew Trick
d1cef594d0 Do copy forwarding across inout args.
I also added temporary bisect flags.

Swift SVN r22686
2014-10-11 02:28:12 +00:00
Andrew Trick
bef9edd5f4 Revamp the CopyForwarding pass, NRVO, various corner cases, unit tests (NFC).
This is still disabled as I haven't fixed the IRGen issue yet.

Swift SVN r22518
2014-10-04 01:23:11 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Joe Groff
782833f054 SIL: Remove the project_existential* instructions.
Swift SVN r22457
2014-10-02 04:06:10 +00:00
Joe Groff
3a606b9eb8 SIL: Drop the protocol_method instruction.
Swift SVN r22446
2014-10-01 23:35:41 +00:00
Andrew Trick
149abe164d CopyForwarding cleanup, and add a check for alloc_stack after copy_addr (NFC, disabled).
Swift SVN r22288
2014-09-25 20:59:33 +00:00
Andrew Trick
ff3f8c0bbd CopyForwarding: fix new isInit() helper to handle StoreInst. (NFC, disabled)
Swift SVN r22284
2014-09-25 16:13:37 +00:00
Andrew Trick
054b8f2cc3 Change the way CopyForwarding updates uses. Still disabled (NFC).
Make sure that we see a "deinit" of the copy and only replace uses in
the same block between the copy and the deinit. This should cover all
the cases I care about but is robust and no longer uses dominance.

While doing this cleanup, I added logic to handle Arnold's cases
where we need backward copy propagation.

This isn't super-pretty, still exposes bugs, and needs tests for the
cases that are actually working.

Swift SVN r22274
2014-09-25 08:24:11 +00:00
Andrew Trick
15f100f9f6 New SIL-Opt pass: CopyForwarding (disabled, NFC).
This should hugely improve performance in generic code. However, it
exposes a downstream issue with phi node generation.

e.g.
PHI node has multiple entries for the same basic block with different incoming values!
  %497 = phi i64 [ %177, %570 ], [ 0, %570 ], [ %494, %492 ], [ %493, %492 ]
label %492
  %494 = phi i64 [ %177, %547 ], [ %402, %491 ]
  %493 = phi i64 [ %558, %547 ], [ %489, %491 ]

Swift SVN r21965
2014-09-16 01:56:42 +00:00