Commit Graph

806 Commits

Author SHA1 Message Date
Erik Eckstein
4187959e66 GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.
With this re-abstraction a specialized function has the same calling convention as if it would have been written with the specialized types in the first place.
In general this results in less alloc_stacks and load/stores.
It also can eliminate some re-abstraction thunks, e.g. if a generic closure is used in a non-generic context.
It some (hopefully rare) cases it may require to add re-abstraction thunks.

In case a function has multiple indirect results, only the first is converted to a direct result. This is an open TODO.
2016-02-22 13:58:10 -08:00
Max Moiseev
fcad164e18 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-22 12:59:57 -08:00
Xin Tong
673054473d Reorder header. NFC 2016-02-21 21:35:38 -08:00
Dmitri Gribenko
3d3d4540e1 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-20 14:37:49 -08:00
Xin Tong
fa2daeb5b8 Fix headers. NFC 2016-02-19 16:22:41 -08:00
practicalswift
0b67f52823 [gardening] Fix recently introduced typo: "anyting" → "anything" 2016-02-19 14:20:02 +01:00
Dmitri Gribenko
0f36bec31f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-18 16:41:35 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Xin Tong
b69706734d Implement @owned to @unowned retain value conversion.
If a value is returned as @owned, we can move the epilogue retain
to the caller and convert the return value to @unowned. This gives
ARC optimizer more freedom to optimize the retain out on the caller's
side.

It appears that epilgue retains are harder to find than epilogue
releases. Most of the time they are not in the return block.

(1) Sometimes, they are in predecessors
(2) Sometimes they come from a call which returns an @owned return value.
This should be improved if we fix (1) and go bottom up.
(3) We do not handle exploded retain_value.

Currently, this catches a small number of opportunities.

We probably need to improve epilogue retain matcher if we are to handle
more cases.

This is part of rdar://24022375.

We also need some refactoring in the pass. e.g. break functions into smaller
functions. I will do with subsequent commit.
2016-02-17 21:59:55 -08:00
Dmitri Gribenko
dd75aed67a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-17 14:40:05 -08:00
Xin Tong
670df6dc9d Wire up improved epilogue release matcher with function signature
optimization.

We get some improvements on the # of parameters converted to guanrateed
from owned on the stdlib.

before
======
103 sil-function-signature-opts      - Total owned args -> guaranteed args

after
======
118 sil-function-signature-opts      - Total owned args -> guaranteed args

I see the following improvements by running benchmarks with and without this
change. Only difference >=1.05X

ErrorHandling         8154             7497      -657     -8.1%     1.09x
LinkedList            9973             9529      -444     -4.5%     1.05x
ObjectAllocation      239              222       -17     -7.1%     1.08x
RC4                   23167            21993     -1174     -5.1%     1.05x (!)

This is part of rdar://22380547
2016-02-15 16:10:40 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -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
84a6ff1d98 And lastly rename NewProjection to Projection. This is a NFC. rdar://24520269 2016-02-09 22:20:10 -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
Erik Eckstein
7971621f8b Inliner: reduce and improve debug output. NFC. 2016-02-09 10:32:19 -08:00
Mark Lacey
891ab087be Remove unnecessary call to invalidate dominator info.
We don't use this information after this point and are already
invalidating this (and everything else for this function body) at the
end of the pass, so this is not necessary.

NFC.
2016-02-08 15:34:15 -08:00
Mark Lacey
e301d41686 Remove tracking of previously inlined functions in the inliner.
Prior to splitting devirtualization out of inlining we needed this to
ensure that we would not go into an infinite loop in certain cases.

Now that these are split out and we no longer iterate within the inliner
over new opportunities, we only need to check for self-recursive
functions.

NFC.
2016-02-08 15:34:15 -08:00
Xin Tong
7808fb3034 Make dead function elim respect optimize.sil.never. Its possible these functions
can be called from something external of the program, e.g. debugger
2016-02-08 13:35:23 -08:00
Slava Pestov
6a254042ee SILOptimizer: Functions referenced from sil_default_witness_table are alive 2016-02-08 00:05:57 -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
3391140ed1 Remove unnecessary header. NFC. 2016-02-05 22:43:29 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -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
Mark Lacey
82fd057eaf Remove devirtualization and specialization from the inliner.
Now that we process functions in bottom-up order in the pass manager and
have a mechanism to restart the pass pipeline on the current
function (or on a newly created callee function), we can split these
passes back out from the inliner and end up with the same benefits we
had from initially integrating them. We get the further benefit of fully
optimizing newly created callee functions before continuing with the
function that resulted in the creation of those callee
functions (e.g. as a result of a specialization pass running).
2016-02-04 08:52:01 -08:00
Arnold Schwaighofer
755bfe3185 Revert "Split the method isProfitableToInline."
This reverts commit 670f193e4a.

It has broken a build bot.
2016-02-03 18:10:17 -08:00
Nadav Rotem
670f193e4a Split the method isProfitableToInline.
This commit refactors the parts of isProfitableToInline that compute the cost
and benefit of inlining into a separate function. NFC.
2016-02-03 16:24:06 -08:00
Nadav Rotem
6d92a15b29 Sink the loop depth calculation into the IF that uses it. NFC. 2016-02-03 14:11:33 -08:00
Nadav Rotem
1c29dc49ae Remove whitespace. NFC.
I am doing this commit to test the internal infrastructure.
2016-02-03 13:44:50 -08:00
Mark Lacey
a97164656f Disallow inlining of self-recursive functions into other functions.
This effectively returns us to the code from dc65f70.

With the recent pass manager changes, combined with upcoming inliner
changes, we can potentially run the inliner more than we currently
do. Allowing self-recursive functions to be inlined, and running the
inliner more often, can result in a lot of code bloat, which increases
binary sizes and compile times. Even with a relatively small value (10)
for the number of times we allow a function to run through the pass
pipeline, we end up with a significant increase in the stdlib and
stdlib unit test build times.

This results in some performance regressions, but I think the trade-off
here is reasonable.
2016-02-02 20:19:39 -08:00
Mark Lacey
4f65f6dc8f Split out the analysis code for function signature optimization.
The split here is rough and will be improved before I create an actual
SILAnalysis out of the analysis piece.
2016-01-29 21:44:54 -08:00
Chris Lattner
061c7eb475 Merge pull request #1142 from Saisi/niggling_typos
Fixed niggling typos
2016-01-29 20:19:54 -08:00
saisi
535d400dc6 Fixed niggling typos 2016-01-29 23:16:25 -05:00
Adrian Prantl
75fc840126 Merge the parent scope and function fields of SILDebugScope into a
PointerUnion.

This saves 8 bytes per SILDebugScope.

rdar://problem/22706994
2016-01-29 17:21:26 -08:00
Erik Eckstein
fd6ded4efd Inliner: introduce a new limit for the number of caller blocks.
This avoids too much inlining into a caller function (so far we only had limits based on the callee).
rdar://problem/23228386
2016-01-28 16:21:03 -08:00
Mark Lacey
a7cd2d215a Remove unused getArgList().
There is a method getArgDescList() that is used throughout the code instead.
2016-01-27 15:27:42 -08:00
Mark Lacey
3723b4946b Convert a member variable to a local variable. 2016-01-27 14:21:18 -08:00
Mark Lacey
dd1801898a Remove unused local variable. 2016-01-27 14:21:18 -08:00
Mark Lacey
033934deeb Rename FunctionAnalyzer to SignatureOptimizer.
This is a first step towards moving the analysis portion of function
signature optimization into an actual SILAnalysis. I'll split this class
into two pieces (one for the analysis it does, and one for the rewrites
it does) next.
2016-01-27 11:05:56 -08:00
Mark Lacey
c78cbc3587 Fix typo: not -> no 2016-01-26 23:02:53 -08:00
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
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
practicalswift
16ec9e6ae6 [gardening] Make parameter name in forward declaration match name in definition 2016-01-22 11:21:50 +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
Roman Levenstein
696aad7582 [sil-global-opt] Teach GlobalOpt to handle alloc_global
Global let propagation works again with this change. The corresponding test-case is enabled again.

rdar://24229640
2016-01-20 16:33:58 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00