Commit Graph

75 Commits

Author SHA1 Message Date
Nadav Rotem
0f63546369 Rename the semantics tag name from never to sil.never. NFC.
Swift SVN r27486
2015-04-20 17:27:32 +00:00
Nadav Rotem
680c565af5 Refactor the code that checks if a function is marked with noopt semantics. NFC.
Swift SVN r27485
2015-04-20 17:27:31 +00:00
Nadav Rotem
926042ff81 Add @semantics("optimize.never") to disable optimizations of a specific function.
This commit adds a flag to disable optimizations on a specific functions. The
primary motivation of this patch is to allow the optimizer developers to reduce
testcasese by disabling optimizations of parts of the code without having to
recompile the compiler or inspect SIL. The annotations  "inline(never)"
and "optimize.none" can go a long way.

The second motivation for this patch is to allow our internal adopters to work
around compiler bugs.

rar://19745484

Usage:

@semantics("optimize.never")
public func miscompile() { ... }

Swift SVN r27475
2015-04-20 05:06:55 +00:00
Mark Lacey
ed66cfd544 Use a callback in the linker to notify clients of newly deserialized functions.
Previous attempts to update the callgraph explicitly after calls to
linkFunction() weren't completely effective because we can deserialize
deeply and introduce multiple new function bodies in the process.

This gets us a bit closer, but only adds new call graph nodes. It does
not currently add edges for everything that gets deserialized (and this
is not fatal, so it is a step forward).

Swift SVN r27120
2015-04-08 06:46:15 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Mark Lacey
a85cc9c6e9 Update call graph to track FullApplySites rather than ApplyInsts.
Use FullApplySite rather than ApplyInst through data structures and
function signatures.

This change does not update the call graph to actually look at
TryApply. That will happen in a future change.

Swift SVN r26893
2015-04-02 20:22:10 +00:00
Mark Lacey
23b6bd84f6 Do not build the call graph just to maintain it.
Before this commit, passes that were attempting to maintain the call
graph would actually build it if it wasn't already valid, just for the
sake of maintaining it.

Now we only maintain it if we already had a valid call graph built.

Swift SVN r26873
2015-04-02 17:16:01 +00:00
Nadav Rotem
50803a7653 Create FunctionAnalysisBase to handle the boiler plate of caching and invalidating function specific analysis.
Swift SVN r26642
2015-03-27 20:54:22 +00:00
Nadav Rotem
f0fa502d56 Split the RCIdentityAnalysis analysis to allow per-function invalidation.
Before the change the RCIdentityAnalysis kept a single map that contained
the module's RC information. When function passes needed to invalidate the
analysis they had to clear the RC information for the entire module. The
problem was mitigated by the fact that we process one function at a time, and
we start processing a new function less frequently.

II adopted the DominanceAnalysis structure. We should probably implement
this functionality as CRTP.

Swift SVN r26636
2015-03-27 16:55:36 +00:00
Mark Lacey
62065f7f50 Update function sig opts to work with upcoming call graph changes.
Small tweak to function signature optimization so that it filters out
applies that might have multiple targets, as well as applies of partial
applies, which will take some updates to handle.

Resolves rdar://problem/19632244 and rdar://problem/20049782.

I've opened rdar://problem/20306331 to consider handling
apply-of-partial-apply at some point in the future.

Swift SVN r26585
2015-03-26 09:00:32 +00:00
John McCall
35b7db3ae1 Parsing support for error results from SILFunctionType.
Swift SVN r26566
2015-03-26 00:01:32 +00:00
Mark Lacey
08bfb01db7 Tweak exclusion logic in function signature optimizations.
We no longer force-inline transparent functions that make it to the
performance inliner, so bailing on these makes less sense.

Swift SVN r26536
2015-03-25 09:03:39 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +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
f6337d9688 Make call graph edge sets be SmallPtrSets rather than SmallVectors.
Re-apply r26072 with a fix to ensure that we get stable bottom-up
orderings in the call grpah.

Using SmallPtrSet here makes sense, and paves the way to more reasonable
code for editing the call graph by clients.

One unfortunate casualty of this is the ArrayRevView that was used by
one client.

Swift SVN r26093
2015-03-13 07:33:57 +00:00
Mark Lacey
1936396a5b Revert "Make call graph edge sets be SmallPtrSets rather than SmallVectors."
This reverts commit r26072, which could result in non-deterministic
bottom-up ordering in the call graph.

I'll reapply with a fix soon.

Swift SVN r26074
2015-03-13 00:58:51 +00:00
Mark Lacey
0163c66c1e Make call graph edge sets be SmallPtrSets rather than SmallVectors.
It makes more sense, and paves the way to more reasonable code for
editing the call graph by clients.

One unfortunate casualty of this is the ArrayRevView that was used by
one client.

Swift SVN r26072
2015-03-12 23:15:35 +00:00
Michael Gottesman
c898b2b0ff [+0 self] Remove fix lifetime from FunctionSignature Opts.
With the improvements I have made to the ARC optimizer, these are no longer
necessary. This will give us an idea if guaranteed is being respected properly
without enabling +0 self.

The main effect that this could cause are use-after-frees. I checked with guard
malloc and asan that we are not performing any use-after-frees on the
PerfTestSuite and asan with ninja check.

Swift SVN r25654
2015-03-01 06:49:48 +00:00
Mark Lacey
64af0798df Rename members and interfaces of the call graph for clarity.
Small clean-up to try to improve on the clarity of the call graph code.

I think this is an overall improvement although there is still some
clunky naming that could be improved in the future.

Swift SVN r25492
2015-02-24 00:08:19 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Arnold Schwaighofer
d892d5159e FuncSigOpts: Change the calling conv from method to freestanding if we change self
We could explode or dce the argument. Make sure we change the calling convention
of the specialized method if we do so.

rdar://19733030

Swift SVN r25030
2015-02-06 01:23:41 +00:00
Arnold Schwaighofer
bbb81a4c4a FuncSigOpts: Don't transfer array.semantic attributes
Array semantic clients rely on the signature being as in the original
unspecialized function.

Swift SVN r25028
2015-02-06 01:23:40 +00:00
Erik Eckstein
9dfd349faf Add a new Thunk-flag in SILFunction which specifies that a function is a thunk.
This will have an effect on inlining into thunks.
Currently this flag is set for witness thunks and thunks from function signature optimization.
No change in code generation, yet.



Swift SVN r24998
2015-02-05 16:45:05 +00:00
Mark Lacey
9afc924fdf Cast away constness in client, not in call graph code.
Swift SVN r24789
2015-01-28 05:57:08 +00:00
Michael Gottesman
0ac649d87b [proj-tree] Use a passed in BumpPtrAllocator instead of SmallVector for memory.
Previously I was using a large SmallVector to create Nodes for the
ProjectionTree. This created an issue when the SmallVector would convert
from small to large representation in the middle of a method on an
object that is stored in the SmallVector. Thus the 'this' pointer will
be invalidated and all sorts of fun times will occur.

I switched now to using a BumpPtrAllocator which is passed into the tree
and used in FunctionSignatureOptimization for all projection trees.

<rdar://problem/19534462>

Swift SVN r24706
2015-01-24 09:12:50 +00:00
Michael Gottesman
897325b096 Codebase Gardening. NFC.
1. Eliminate unused variable warnings.
2. Change field names to match capitalization of the rest of the field names in the file.
3. Change method names to match rest of the file.
4. Change get,set method for a field to match the field type.

Swift SVN r24501
2015-01-19 00:34:07 +00:00
Michael Gottesman
39817d5fd8 Remove arc namespace.
Swift SVN r24500
2015-01-19 00:10:48 +00:00
Michael Gottesman
f111d29fae [func-sig-opts] The projection tree knows how to explode address arguments... but the rest of func sig opts doesn't. So do not try to optimize in such cases.
I do not think that function signature opts is the right place to handle
promotion of @in, @out arguments. The right place to do such things is when we
perform specialization. That is the natural place to do it since that is where
we transition from address only to loadable types.

Swift SVN r23940
2014-12-15 18:42:20 +00:00
Michael Gottesman
7e39f33f98 [mangle] Include a pass id in the mangling, just to be careful.
I am starting to reuse manglings for different passes. I want to make sure that
when we reuse functions we actually get a function created by the same pass.

Swift SVN r23924
2014-12-14 10:29:11 +00:00
Erik Eckstein
14af3a57e8 Enable elimination of dead methods which are in classes of higher visibility.
The underlying problem is that e.g. even if a method is private but its class is public, the method can be referenced from another module - from the vtable of a derived class.
So far we handled this by setting the SILLinkage of such methods according to the visibility of the class. But this prevented dead method elimination.
Now I set the SILLinkage according to the visibility of the method. This enables dead method elimination, but it requires the following:
1) Still set the linkage in llvm so that it can be referenced from outside.
2) If the method is dead and eliminated, create a stub for it (which calls swift_reportMissingMethod).



Swift SVN r23889
2014-12-12 17:35:40 +00:00
Michael Gottesman
1e63e0e22d [mangle] Add support for mangling dead, owned2guaranteed, and sroa args. Wire up function sig opts.
Now all SIL function specialization passes use the new mangling infrastructure.
Lets keep it that way for future passes as well. = ).

Implements:
<rdar://problem/18831609>

Fixes:
<rdar://problem/19065735>
<rdar://problem/18906781>
<rdar://problem/18956916>

Swift SVN r23859
2014-12-11 05:51:26 +00:00
Michael Gottesman
cb8760148d Reapply "Revert "[func-sig-opts] If we know all callsites of a function, delete the old unoptimized function instead of creating a thunk.""
This reverts commit r23725. This time with fixes so we don't hit that
assertion.

Swift SVN r23762
2014-12-06 23:08:17 +00:00
Mark Lacey
688d1d2eaa Revert "[func-sig-opts] If we know all callsites of a function, delete the old unoptimized function instead of creating a thunk."
This reverts commit r23715 because it breaks the build of the
StrSplitter.swift benchmark, hitting an assert about deleting a function
with references.

Swift SVN r23725
2014-12-05 05:19:12 +00:00
Michael Gottesman
eafef9b733 [func-sig-opts] If we know all callsites of a function, delete the old unoptimized function instead of creating a thunk.
<rdar://problem/19137435>

Swift SVN r23715
2014-12-05 02:08:37 +00:00
Michael Gottesman
3e513eac40 [func-sig-opts] SROA and delete partially dead arguments.
The reason why I am interested in doing this is that:

1. Performing partial dead argument elimination is just a good thing to
do since it reduces dead opaque uses of explosion values, helping other
optimizations.

2. By performing SROA on function arguments, I am able to avoid having
to teach the ARC optimizer about aggregates in arguments. It is
important to try to keep the ARC optimizer as slim as possible.

Additionally the projection tree infrastructure that was built for this
optimization will also allow me to easily "trim" and explode indirect
arguments as well.

On my machine I am seeing the following speedups:

Dictionary3||||||||||-33.53%
Dictionary2||||||||||-19.20%
StringBuilder||||||||-11.04%
StdlibSort|||||||||||-9.82%
StringInterpolation||-9.82%

rdar://17005816

Swift SVN r23587
2014-11-28 20:38:56 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Michael Gottesman
4bee99df2e [func-sig-opts] Change deletion of argument functions into a general updateOptimizedBBArgs methods since I will use the same code path to update the arguments when SROAing arguments.
Swift SVN r23540
2014-11-21 22:29:35 +00:00
Michael Gottesman
ddfe953554 [func-sig-opts] Remove DeadArgIndices now that each ArgumentDescriptor has its original index cached and refactor adding thunk args onto ArgumentDescriptor::addThunkArgs.
I also renamed ArgumentDescriptor::addNewArguments() =>
ArgumentDescriptor::addCallerArgs() to match addThunkArgs. This name fits better
and gives both concepts distinct names.

Swift SVN r23507
2014-11-21 01:50:42 +00:00
Michael Gottesman
3cda8c1bd3 [func-sig-opts] Make ArgToEpilogueReleaseMap a local variable instead of a field on FunctionAnalyzer since it is only needed in one location of the computation now.
Swift SVN r23501
2014-11-21 01:00:57 +00:00
Michael Gottesman
f6655c0f30 [func-sig-opts] Move computation of optimized arg types and optimized arguments from functions into methods on ArgumentDescriptor.
This allows me to SROA arguments without messing with any of the rest of
the machinery in FunctionSignatureOpts since now the main machinery of
FunctionSigOpts manipulates ArgumentDescriptors instead of SIL directly.

Swift SVN r23500
2014-11-21 01:00:56 +00:00
Michael Gottesman
09953020b6 [func-sig-opts] Track the original index of the argument in ArgumentDescriptor and use it to create fix lifetimes and releases.
This means that:

1. I can make the ConsumedArgToEpilogueReleaseMatcher a local variable
instead of being on the FunctionAnalyzer class. This will be done in a
latter commit.

2. When I SROA arguments, I always put the fix_lifetime, release_value
on the correct argument by reusing old values. In the case of creating
the thunk, I use the thunks arguments which are the same as the old args
and I use the argument list of the old ApplyInst in the caller functions
before I delete the old ApplyInst. This means that when I SROA the
arguments of a function, the @owned => @guaranteed argument will work
without any changes.

Swift SVN r23499
2014-11-21 01:00:56 +00:00
Michael Gottesman
df5a2a73cc [func-sig-opts] Add comments to ArgumentDescriptor fields.
Swift SVN r23498
2014-11-21 01:00:54 +00:00
Michael Gottesman
048d1a17c9 [func-sig-opts] Update comment. NFC.
Swift SVN r23316
2014-11-14 01:51:42 +00:00
Michael Gottesman
3d396f8b12 [arc-analysis] Refactor OwnedArgToEpilogueReleaseMatcher from FunctionSigOpts.
Given a function F, this utility class attempts to match up owned arguments with
releases in the epilogue of the function.

I am refactoring this from FunctionSigOpts so I can use it in the ARC optimizer.

<rdar://problem/18923030>

Swift SVN r23219
2014-11-11 00:42:30 +00:00
Michael Gottesman
d677cc7750 [func-sig-opts] Use the debug scope of the old function instead of the new function when turning the old function into a thunk.
This is tested via an assertion that Adrian put in.

Swift SVN r23022
2014-10-30 23:22:50 +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
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