Commit Graph

104 Commits

Author SHA1 Message Date
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Andrew Trick
2396e7d3cc [SILOpt][NFC] Print projections readably and efficiently.
Begin to make the RLE pass debuggable.
Overhaul the ProjectionPath printing feature and fixup tests.
2017-03-31 16:51:34 -07:00
Hugh Bellamy
36100bf21c Fix errors and warnings building swift/SIL on Windows using MSVC 2017-01-09 09:11:20 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Groff
3871cda205 Push SILBoxType::getFieldType into SIL and make it take a SILModule.
Applying nontrivial generic arguments to a nontrivial SIL layout requires lowered SILType substitution, which requires a SILModule. NFC yet, just an API change.
2016-12-09 16:21:13 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Joe Groff
e4c67e2d5a SIL: Give project_box a field index operand.
Allow project_box to get the address of any field in a multi-field box.
2016-10-24 13:10:41 -07:00
Erik Eckstein
34a4e6df0a SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-16 11:02:19 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Xin Tong
7842e5ccf0 Small comment fix in FSO 2016-08-20 13:33:45 -07:00
practicalswift
57bccc8b06 [gardening] Fix inconsistent formatting. 2016-06-04 00:37:15 +02:00
Xin Tong
920410f6f5 Remove some dead code 2016-05-25 15:25:48 -07:00
Xin Tong
db9ee7c614 Fix a memory leak in FSO
Make sure the destructor of the SmallVector in ProjectionTreeNode gets
called when the BumpPtrAllocator is destroy'ed.
2016-05-25 15:08:18 -07:00
Xin Tong
fb3eb0b646 Simplify function signature optimzation.
Several functionalities have been added to FSO over time and the logic has become
muddled.

We were always looking at a static image of the SIL and try to reason about what kind of
function signature related optimizations we can do.

This can easily lead to muddled logic. e.g. we need to consider 2 different function
signature optimizations together instead of independently.

Split 1 single function to do all sorts of different analyses in FSO into several
small transformations, each of which does a specific job. After every analysis, we produce
a new function and eventually we collapse all intermediate thunks to in a single thunk.

With this change, it will be easier to implement function signature optimization as now
we can do them independently now.

Small modifications to the test cases.
2016-05-25 11:12:27 -07:00
Xin Tong
57e2bdb123 Revert "Simplify function signature optimization" 2016-04-25 16:33:17 -07:00
Xin Tong
633ca2e92b Simplify function signature optimzation.
Several functionalities have been added to FSO over time and the logic has become
muddled.

We were always looking at a static image of the SIL and try to reason about what kind of
function signature related optimizations we can do.

This can easily lead to muddled logic. e.g. we need to consider 2 different function
signature optimizations together instead of independently.

Split 1 single function to do all sorts of different analyses in FSO into several
small transformations, each of which does a specific job. After every analysis, we produce
a new function and eventually we collapse all intermediate thunks to in a single thunk.

With this change, it will be easier to implement function signature optimization as now
we can do them independently now.

Minimal modifications to the test cases.
2016-04-25 15:28:51 -07:00
Xin Tong
cff61d7fe7 Implement a function signature cloner and rewriter.
This split the function signature module pass into 2 functin passes.

By doing so,  this allows us to rewrite to using the FSO-optimized
function prior to attempting inlining, but allow us to do a substantial
amount of optimization on the current function before attempting to do
FSO on that function.

And also helps us to move to a model which module pass is NOT used unless
necesary.

I do not see regression nor improvement for on the performance test suite.

functionsignopts.sil and functionsignopt_sroa.sil are modified because the
mangler now takes into account of information in the projection tree.
2016-03-19 23:57:37 -07:00
Xin Tong
5f7f05da9b Reinstate "Moves SignatureAnalyzer and ArgumentDescriptor/ResultDescriptor into
a separate analysis pass.

This pass is run on every function and the optimized signature is return'ed through the
getArgDescList and getResultDescList.

Next step is to split to cloning and callsite rewriting into their own function passes.

rdar://24730896
"
2016-03-16 07:00:57 -07:00
Xin Tong
48ed191ca4 Revert "Moves SignatureAnalyzer and ArgumentDescriptor/ResultDescriptor into a separate"
This reverts commit 069612bccc.

Reverts because it

Breaks compiling the stdlib (optimized, no stdlib assertions), while i try to reproduce and fix.
2016-03-15 14:17:01 -07:00
Xin Tong
069612bccc Moves SignatureAnalyzer and ArgumentDescriptor/ResultDescriptor into a separate
analysis pass.

This pass is run on every function and the optimized signature is return'ed through the
getArgDescList and getResultDescList.

Next step is to split to cloning and callsite rewriting into their own function passes.

rdar://24730896
2016-03-15 12:21:20 -07: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
Xin Tong
cf7614eeb6 Remove a small whitespace. NFC
I do not know how it got into there.

Thanks @gottesmm  for catching this.
2016-03-07 21:59:54 -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
Michael Gottesman
375a7bfde8 [gardening] Fix doxygen comment. NFC. 2016-02-18 01:10:51 -08:00
Xin Tong
99ca08e4af Check whether epilogue releases cover all non-trivial fields.
When we have all the epilogue releases. Make sure they cover all the non-trivial
parts of the base. Otherwise, treat as if we've found no releases for the base.

Currently. this is a NFC other than epilogue dumper. I will wire it up with
function signature with next commit.

This is part of rdar://22380547
2016-02-15 16:00:02 -08:00
Xin Tong
4f66bc88b4 Move ProjectionTree::isRedundantRelease to ConsumedArgToEpilogueReleaseMatcher::isRedundantRelease.
NFC.
2016-02-15 10:22:47 -08:00
Xin Tong
40ff0895d6 Improve epilogue release matcher to handle exploded release_value.
So instead of only being able to match %1 and release %1 in (1). we
can also match %1 with (release %2, and release%3, i.e. exploded release_value)
in (2).

(1)
foo(%1)
  strong_release %1

(2)
foo(%1)
  %2 = struct_extract %1, field_a
  %3 = struct_extract %1, field_b
  strong_release %2
  strong_release %3

This will allow function signature to better move the release instructions to
the callers.

Currently, this is a NFC other than testing using the epilogue match dumper.
2016-02-12 15:22:13 -08:00
Xin Tong
81c69fee4d Rename LeafIndices to LiveLeafIndices in ProjectionTree. NFC 2016-02-11 09:56:06 -08:00
Xin Tong
d59d567a77 Clean up the newly created Projection. NFC.
- Update comments.
- Correct 80 col violations mostly due to renaming NewProjection to Projection.
- Remove dead functions
2016-02-10 14:46:08 -08:00
Xin Tong
f22239b8f1 Remove 2 unused fields in ProjectionTreeNode. NFC. 2016-02-09 22:48:29 -08:00
Xin Tong
84a6ff1d98 And lastly rename NewProjection to Projection. This is a NFC. rdar://24520269 2016-02-09 22:20:10 -08:00
Xin Tong
042c6e033d And finally get rid of old projection. This is a NFC. rdar://24520269 2016-02-09 22:20:10 -08:00
Xin Tong
d9671f5b0e Migrate SILCombiner to new projection. This should be a NFC 2016-02-09 22:20:09 -08:00
Xin Tong
111af0322f Using ProjectionTree to create NewProjectionTree and wire NewProjectionTree up
with function signature optimizations to make sure it passes some basic testing.

We are one step closer to get rid of the old projection.
2016-02-09 22:20:09 -08:00
Xin Tong
51e89de905 [function-signature-opt] Explode argument level by level and lazily.
Previously, we exploded argument to the most-derived fields, i.e. the field that
can no longer be exploded further. And in the spliced (newly created) function,
we form aggregates if necessary.

Changing this to explode only to the deepest level accessed, this enables us to
create the projection tree nodes for fields of which its level is accessed, instead of
all fields on all levels.

Note: this also changes the definition of a leaf node. Leaf node now means the node
which does not have children based on current explosion (it however could have children
if exploded further).

I am refining the old projection tree first before (mostly copying) it to create the
new projection tree.
2016-02-09 14:52:10 -08:00
Xin Tong
d5dfe57e14 Migrate to use new projection for COWArrayOpt. This should be a NFC.
This is part of rdar://24520269
2016-02-07 13:56:12 -08:00
Xin Tong
17e3f35758 Migrate to use new projection for PerformanceInliner. This should be a NFC.
This is part of rdar://24520269
2016-02-07 13:56:12 -08:00
Xin Tong
0258e8e816 Migrate to use new projection for SimplifyCFG. This should be a NFC.
This is part of rdar://24520269
2016-02-06 08:27:05 -08:00
Xin Tong
ae86ef2b72 Implement more conservative debugging value support on function arguments in
function signature opt.

Instead of replacing %1 with UNDEF in debugvalueinst %1, we form an aggregate,
taking the alive part of %1 and fill the dead part with undef.

rdar://23727705
2016-02-04 10:50:26 -08:00
Xin Tong
8ce00e3989 Implement index_addr in alias analysis. We make use the new projection code
to disamuguite index_address with same base but different indices.

But the indices here have to be constant. This is a limitation/design choice
made in the projection code.

In order to handle non-constant indices, we need an analysis to compute the index
difference.

rdar://22484392
2016-01-26 20:41:10 -08:00
Erik Eckstein
250cac1a91 Remove some function overloads for SILValue/ValueBase*
They are not needed anymore because now SILValue is nothing more than a wrapper around ValueBase*
2016-01-26 09:37:08 -08:00
Xin Tong
8a1dd8abc8 Optimize how most derived type is computed in the new projection path Instead of walking the
entire projection path to find the most derived type, we cache it and invalidate when the projectionpath is
append'ed to.

stdlib -O

=== Before ===
Running Time        Self (ms)               Symbol Name
25741.0ms   37.3%   0.0                 swift::runSILOptimizationPasses(swift::SILModule&)
25523.0ms   37.0%   0.0                  swift::SILPassManager::runOneIteration()
20654.0ms   29.9%   36.0                  swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>)
19663.0ms   28.5%   87.0                   swift::SILPassManager::runPassesOnFunction(llvm::ArrayRef<swift::SILFunctionTransform*>, swift::SILFunction*)
3279.0ms    4.7%    5.0                     (anonymous namespace)::SimplifyCFGPass::run()
3205.0ms    4.6%    11.0                    (anonymous namespace)::ARCSequenceOpts::run()
2550.0ms    3.7%    7.0                     (anonymous namespace)::SILCombine::run()
2177.0ms    3.1%    42.0                    (anonymous namespace)::RedundantLoadElimination::run()
2151.0ms    3.1%    115.0                   (anonymous namespace)::SILCSE::run()
1255.0ms    1.8%    18.0                    (anonymous namespace)::GenericSpecializer::run()
1080.0ms    1.5%    49.0                    (anonymous namespace)::DeadStoreElimination::run()
926.0ms    1.3%     189.0                   (anonymous namespace)::DCE::run()
488.0ms    0.7%     3.0                     (anonymous namespace)::SILCodeMotion::run()

=== After ===
Running Time        Self (ms)               Symbol Name
24065.0ms   36.8%   0.0                 swift::runSILOptimizationPasses(swift::SILModule&)
23865.0ms   36.5%   0.0                  swift::SILPassManager::runOneIteration()
19245.0ms   29.4%   42.0                  swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>)
18273.0ms   27.9%   65.0                   swift::SILPassManager::runPassesOnFunction(llvm::ArrayRef<swift::SILFunctionTransform*>, swift::SILFunction*)
3096.0ms    4.7%    10.0                    (anonymous namespace)::ARCSequenceOpts::run()
3081.0ms    4.7%    9.0                     (anonymous namespace)::SimplifyCFGPass::run()
2381.0ms    3.6%    8.0                     (anonymous namespace)::SILCombine::run()
1990.0ms    3.0%    128.0                   (anonymous namespace)::SILCSE::run()
1828.0ms    2.8%    65.0                    (anonymous namespace)::RedundantLoadElimination::run()
1200.0ms    1.8%    10.0                    (anonymous namespace)::GenericSpecializer::run()
918.0ms    1.4%     58.0                    (anonymous namespace)::DeadStoreElimination::run()
867.0ms    1.3%     140.0                   (anonymous namespace)::DCE::run()
479.0ms    0.7%     11.0                    (anonymous namespace)::SILCodeMotion::run()
294.0ms    0.4%     1.0                     (anonymous namespace)::ConstantPropagation::run()
2016-01-25 20:12:37 -08:00
Xin Tong
546471ac4d Port dead store elimination and redundant load elimination to use the new projection.
This patch also implements some of the missing functions used by RLE and DSE in new projection
that exist in the old projection.

New projection provides better memory usage, eventually we will phase out the old projection code.

New projection is now copyable, i.e. we have a proper constructor for it.  This helps make the code
more readable.

We do see a bit increase in compilation time in compiling stdlib -O, this is a result of the way
we now get types of a projection path, but I expect this to go down (away) with further improvement
on how memory locations are constructed and cached with later patches.

=== With the OLD Projection. ===

Total amount of memory allocated.
--------------------------------
Bytes Used	Count		   Symbol Name
13032.01 MB      50.6%	2158819    swift::SILPassManager::runPassesOnFunction(llvm::ArrayRef<swift::SILFunctionTransform*>, swift::SILFunction*)
2879.70 MB      11.1%	3076018    (anonymous namespace)::ARCSequenceOpts::run()
2663.68 MB      10.3%	1375465	   (anonymous namespace)::RedundantLoadElimination::run()
1534.35 MB       5.9%	5067928	   (anonymous namespace)::SimplifyCFGPass::run()
1278.09 MB       4.9%	576714	   (anonymous namespace)::SILCombine::run()
1052.68 MB       4.0%	935809	   (anonymous namespace)::DeadStoreElimination::run()
 771.75 MB       2.9%	1677391	   (anonymous namespace)::SILCSE::run()
 715.07 MB       2.7%	4198193	   (anonymous namespace)::GenericSpecializer::run()
 434.87 MB       1.6%	652701	   (anonymous namespace)::SILSROA::run()
 402.99 MB       1.5%	658563	   (anonymous namespace)::SILCodeMotion::run()
 341.13 MB       1.3%	962459	   (anonymous namespace)::DCE::run()
 279.48 MB       1.0%	415031	   (anonymous namespace)::StackPromotion::run()

Compilation time breakdown.
--------------------------
Running Time	Self (ms)	    Symbol Name
25716.0ms   35.8%	0.0	    swift::runSILOptimizationPasses(swift::SILModule&)
25513.0ms   35.5%	0.0	    swift::SILPassManager::runOneIteration()
20666.0ms   28.8%	24.0	    swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>)
19664.0ms   27.4%	77.0	    swift::SILPassManager::runPassesOnFunction(llvm::ArrayRef<swift::SILFunctionTransform*>, swift::SILFunction*)
3272.0ms    4.5%	12.0	    (anonymous namespace)::SimplifyCFGPass::run()
3266.0ms    4.5%	7.0	    (anonymous namespace)::ARCSequenceOpts::run()
2608.0ms    3.6%	5.0	    (anonymous namespace)::SILCombine::run()
2089.0ms    2.9%	104.0	    (anonymous namespace)::SILCSE::run()
1929.0ms    2.7%	47.0	    (anonymous namespace)::RedundantLoadElimination::run()
1280.0ms    1.7%	14.0	    (anonymous namespace)::GenericSpecializer::run()
1010.0ms    1.4%	45.0	    (anonymous namespace)::DeadStoreElimination::run()
966.0ms    1.3%	191.0	 	    (anonymous namespace)::DCE::run()
496.0ms    0.6%	6.0	 	    (anonymous namespace)::SILCodeMotion::run()

=== With the NEW Projection. ===

Total amount of memory allocated.
--------------------------------
Bytes Used	Count		    Symbol Name
11876.64 MB      48.4%	22112349    swift::SILPassManager::runPassesOnFunction(llvm::ArrayRef<swift::SILFunctionTransform*>, swift::SILFunction*)
2887.22 MB      11.8%	3079485	    (anonymous namespace)::ARCSequenceOpts::run()
1820.89 MB       7.4%	1877674	    (anonymous namespace)::RedundantLoadElimination::run()
1533.16 MB       6.2%	5073310	    (anonymous namespace)::SimplifyCFGPass::run()
1282.86 MB       5.2%	577024	    (anonymous namespace)::SILCombine::run()
 772.21 MB       3.1%	1679154	    (anonymous namespace)::SILCSE::run()
 721.69 MB       2.9%	936958	    (anonymous namespace)::DeadStoreElimination::run()
 715.08 MB       2.9%	4196263	    (anonymous namespace)::GenericSpecializer::run()

Compilation time breakdown.
--------------------------
Running Time	Self (ms)	    Symbol Name
25137.0ms   37.3%	0.0	    swift::runSILOptimizationPasses(swift::SILModule&)
24939.0ms   37.0%	0.0	    swift::SILPassManager::runOneIteration()
20226.0ms   30.0%	29.0	    swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>)
19241.0ms   28.5%	83.0	    swift::SILPassManager::runPassesOnFunction(llvm::ArrayRef<swift::SILFunctionTransform*>, swift::SILFunction*)
3214.0ms    4.7%	10.0	    (anonymous namespace)::SimplifyCFGPass::run()
3005.0ms    4.4%	14.0	    (anonymous namespace)::ARCSequenceOpts::run()
2438.0ms    3.6%	7.0	    (anonymous namespace)::SILCombine::run()
2217.0ms    3.2%	54.0	    (anonymous namespace)::RedundantLoadElimination::run()
2212.0ms    3.2%	131.0	    (anonymous namespace)::SILCSE::run()
1195.0ms    1.7%	11.0	    (anonymous namespace)::GenericSpecializer::run()
1168.0ms    1.7%	39.0	    (anonymous namespace)::DeadStoreElimination::run()
853.0ms    1.2%	150.0	 	    (anonymous namespace)::DCE::run()
499.0ms    0.7%	7.0	 	    (anonymous namespace)::SILCodeMotion::run()
2016-01-25 20:08:29 -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
1383612ad6 Projection: project_box is an address projection 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
Xin Tong
63713e044e Port alias analysis to use the NewProjection from the (old) Projection. This passes all validation
tests, including alias analysis SIL tests based on AAdumper.
2016-01-21 09:29:08 -08:00