Commit Graph

30 Commits

Author SHA1 Message Date
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
Michael Gottesman
91e621df64 Reapply "[func-sig-opts] Teach func sig opts how to handle multiple @owned arguments."
This reverts commit r22965. I forgot to commit some necessary LLVM changes to
MapVector before committing this. These have hit trunk now so I am recommitting.

Swift SVN r22973
2014-10-27 18:20:06 +00:00
Erik Eckstein
f2a0e331ef Revert "[func-sig-opts] Teach func sig opts how to handle multiple @owned arguments."
It breaks the build:

/Users/erik/proj/main-swift/swift/lib/SILPasses/FunctionSignatureOpts.cpp:125:9: error: no template named 'reverse_iterator' in 'llvm::MapVector<unsigned int, swift::SILInstruction *, llvm::SmallDenseMap<unsigned int, unsigned int, 8, llvm::DenseMapInfo<unsigned int> >, llvm::SmallVector<std::__1::pair<unsigned int, swift::SILInstruction *>, 8> >'; did you mean 'std::reverse_iterator'?
  Range<ArgIndexInstMapTy::reverse_iterator>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        std::reverse_iterator
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:529:29: note: 'std::reverse_iterator' declared here
class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
                            ^
/Users/erik/proj/main-swift/swift/lib/SILPasses/FunctionSignatureOpts.cpp:125:9: error: use of class template 'ArgIndexInstMapTy::reverse_iterator' requires template arguments
  Range<ArgIndexInstMapTy::reverse_iterator>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:529:29: note: template is declared here
class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
                            ^
/Users/erik/proj/main-swift/swift/lib/SILPasses/FunctionSignatureOpts.cpp:127:12: error: no matching function for call to 'reversed'
    return reversed(ConsumedArgumentIndexToReleaseMap);
           ^~~~~~~~
/Users/erik/proj/main-swift/swift/include/swift/Basic/Range.h:62:15: note: candidate template ignored: substitution failure [with T = llvm::MapVector<unsigned int, swift::SILInstruction *, llvm::SmallDenseMap<unsigned int, unsigned int, 8, llvm::DenseMapInfo<unsigned int> >, llvm::SmallVector<std::__1::pair<unsigned int, swift::SILInstruction *>, 8> > &]: no member named 'rbegin' in 'llvm::MapVector<unsigned int, swift::SILInstruction *, llvm::SmallDenseMap<unsigned int, unsigned int, 8, llvm::DenseMapInfo<unsigned int> >, llvm::SmallVector<std::__1::pair<unsigned int, swift::SILInstruction *>, 8> >'
  inline auto reversed(T &&container)
              ^
3 errors generated.



Swift SVN r22965
2014-10-27 14:40:07 +00:00
Michael Gottesman
82c0e90eb6 [func-sig-opts] Teach func sig opts how to handle multiple @owned arguments.
Swift SVN r22964
2014-10-27 13:50:50 +00:00
Michael Gottesman
e79bdc899e [func-sig-opts] Refactor func-sig-opts to make it easier to handle multiple @owned arguments.
The main change was to create a FunctionAnalyzer structure which stores
all of the data that we carry around. This reduces the number of
arguments for a bunch of functions and also enables the beginning of a
split in the pass in between the analysis part and the execution
part. There are still some things I need to clean up which I will do in
a little bit.

Swift SVN r22962
2014-10-27 09:15:58 +00:00
Michael Gottesman
1bbd69dbb5 [func-sig-opts] Enable function sig opts on fragile functions.
Previously, we used shared linkage and did not specialize fragile functions
since this exposed serialization issues. These serialization issues have been
dealt with but I realized the model did not make sense: We do not specialize
functions with "external" linkage. This means that we only specialize functions
in the module in which it is defined. Thus shared provides no benefit in terms
of the linker being able to squash the function. Instead we just copy whatever
linkage the original function used.

rdar://16917049

Swift SVN r22940
2014-10-25 02:47:02 +00:00
Michael Gottesman
a0a66e3883 Reapply "[func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction."
This reverts commit r22933. Now with fixes so this actually compiles!

Swift SVN r22935
2014-10-25 00:14:39 +00:00
Jordan Rose
ef30948e4e Revert "[func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction."
This reverts r22923, which doesn't actually compile. The fix is probably
obvious (s/F/this/) but I didn't want to mess with it in case it's wrong.

Swift SVN r22933
2014-10-24 23:33:19 +00:00
Michael Gottesman
c42bdcf418 [func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction.
Swift SVN r22923
2014-10-24 22:21:48 +00:00
Michael Gottesman
dc4dde51bf Remove dead code. NFC.
Swift SVN r22618
2014-10-09 05:29:10 +00:00
Michael Gottesman
993d9c54eb [func-sig-opts] If we already made a specialized version of a function, do not respecialize, just bail.
This patch ensures that if we already have a version of a function with
an optimized function signature, we do not turn the original function
into a thunk or change the original function to call the already created
specialized version of it. The reason for doing this is:

1. It enables us to avoid the question of whether or not the callee and
caller properly mesh. To do this safely, we would really need to analyze
the specialized version of the function to make sure that it
meshes. This could be fragile.

2. This situation should not occur often since we only run function
signature specialization once in the pipeline and we do not specialize
external functions (* see below) implying linking will not affect this
optimization.

* We do not specialize functions with external linkage since:

1. Linking in a function to the current module does not provide any more
information about the internals or the signature of the function that
was available in the original module.

2. For function signature optimization to work, we need to be able to
optimize both the caller and the callee. External functions are not
emitted into the final object file implying that any changes we make to
the caller or callee will not be apparent in the final object file. So
we will not get any optimization benefit and could potentially introduce
miscompiles.

Swift SVN r22609
2014-10-09 00:50:07 +00:00
Michael Gottesman
7de8c10f20 [func-sig-opts] If we already have a specialization of a function, reuse it and
convert the current Function to a thunk. This ensures we can ignore whether or
not the function was originally a thunk which could potentially be fragile. This
should only occur rarely so we should not be doing more work in the common case.

Swift SVN r22600
2014-10-08 09:21:42 +00:00
Michael Gottesman
f444a3837a [func-sig-opts] Restrict the set of functions that we will optimize.
The sets not being considered are:

1. Any functions that will always be inlined. We ignore the inlined case since we can just
optimize the signature of the caller at each of the given function call sites.

2. Functions that have already been specialized once.

3. External functions. This is because for function signature
optimization to work, we need to be able to modify the caller and the
callee. Thus if the caller or callee is external since we can not modify
the external definition, we can not perform any specialization.

4. Generic functions. I am leaving this for a later iteration.

5. Non-Fragile functions. I am leaving this for a later iteration.

6. ObjCMethods and Witness Methods. We can never perform this
optimization on ObjCMethods and I am going to enable witness methods in
a later iteration.

7. Functions without call sites. Since we are only specializing fragile
functions, if a function without call sites is used in a different module, that
module will be able to deserialize it. Once I handle non-fragile functions, this
will change.

Swift SVN r22564
2014-10-07 08:50:14 +00:00
Michael Gottesman
1bd44a82a6 [func-sig-opts] When creating a new argument, pass in the decl from the old argument.
Swift SVN r22554
2014-10-06 23:16:53 +00:00
Michael Gottesman
c97ab1f11f [func-sig-opts] When splicing BB from one function to another, change
the debug scope of each instruction to be the debug scope of the new
function.

This will be tested by the functionality in function signature opts.

Swift SVN r22553
2014-10-06 23:16:52 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Michael Gottesman
4609513593 Remove SILValue::stripRCIdentityPreservingArgs and teach all uses of that method to use the new RCIdentityAnalysis.
Currently, the pass just calls a local version of that function. After OzU, I
will enable the full pass (which is currently disabled behind a flag).

Swift SVN r21894
2014-09-11 22:29:31 +00:00
Michael Gottesman
b23c3638d1 [func-sig-opts] Teach FunctionSignatureOpts how to perform @owned -> @guaranteed optimization.
Also use some higher order functions to clean some things up.

Swift SVN r21791
2014-09-08 23:34:24 +00:00
Michael Gottesman
9de15a3408 [func-sig-opts] Update to use the new callgraph and SILFunction::spliceBody to make FunctionSignatureOpts body transfer and thunk formation cheaper.
Swift SVN r21789
2014-09-08 22:26:25 +00:00
Michael Gottesman
5561b3f538 Convert Nothing_t::Nothing => Nothing.
Swift SVN r21605
2014-08-30 03:11:55 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Andrew Trick
bd299c9b16 Move getSpecializedLinkage into Local.cpp
Swift SVN r21247
2014-08-16 01:12:26 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Michael Gottesman
4ec0a81e5f Add linkage SILLinkage::SharedExternal for deserialized functions with shared linkage.
*NOTE* This linkage is different from {Public,Hidden}External in that it has no
extra semantic meaning beyond shared.

The use of this linkage is to ensure that we do not serialize deserialized
shared functions. Those shared functions can always be re-deserialized from the
original module. This prevents a whole class of bugs related to the
creation of module cross references since all references to the shared
item go straight to the original module.

<rdar://problem/17772847>

Swift SVN r20375
2014-07-23 05:04:48 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Manman Ren
ae9f2e25ae [@semantics] add SemanticsAttr to SILFunction.
Enable SIL parsing and SIL serialization of semantics.

We add one more field to SILFunctionLayout for semantics. We should refactor
handling of attributes at SIL level, right now they are in SILFunction as bool
or std::string and in SIL serializer as a 1-bit field or an ID field.

rdar://17525564


Swift SVN r19434
2014-07-01 22:49:46 +00:00
Manman Ren
7667b829bb [noinline attribute] add noinline attribute.
Propagate it to SILFunction and use it in PerformanceInliner. We also serialize
and parse the attribute.

rdar://15882816


Swift SVN r19150
2014-06-24 23:07:45 +00:00
Adrian Prantl
b1a7a7af1b Reference-count inlined functions to keep them alive until we emit debug
info for them and generally clean up the inline scope handling a bit.
Fix the debug scope handling for all clients of SILCloner, especially
the SIL-level spezializers and inliners.
This also adds a ton of additional assertions that will ensure that
future optimization passes won't mess with the debug info in a way that
could confuse the LLVM backend.

Swift SVN r18984
2014-06-18 22:34:10 +00:00
Michael Gottesman
b3d7d3e60e [function-signature-opts] Commit initial function sig optimization pass that eliminates dead arguments.
The way this pass works is very similar to generic specialization except
that it turns the old function into a thunk that calls the newly created
function that has had the dead arguments removed.

This ensures that any place in the code where we were unable to see that
the old function was being called still works and also enables us to
cut down on code size increase due to code duplication since the
marshalling code for the thunk should be very small.

This is just the first part of a larger body of work that optimizes
function signatures. The plan is to include transforming loadable
pointer args to pass by value and to convert @owned arguments to
@gauranteed arguments.

<rdar://problem/17319928>

Swift SVN r18970
2014-06-18 02:36:05 +00:00