Commit Graph

19 Commits

Author SHA1 Message Date
Erik Eckstein
4e6efcb617 Fix a DEBUG log message in ExternalFunctionDefinitionsElimination.
Now the function name is printed before the function is deleted.



Swift SVN r27207
2015-04-10 11:27:48 +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
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
Nadav Rotem
1558753ebf Invalidate analysis only for deleted functions (no need to invalidate all functions in the module). NFC.
Swift SVN r26460
2015-03-23 23:57:42 +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
Roman Levenstein
5831e7a5cc [sil-dead-function-elimination] Re-factoring of the external function definitions elimination pass.
Rename LateDeadFunctionElimination into ExternalFunctionDefinitionsElimination.
Move ExternalFunctionDefinitionsElimination  out of DeadFunctionElimination and make it a separate pass.
Move a common logic shared by  DeadFunctionElimination and ExternalFunctionDefinitionsElimination into a newly created base class.

Make ExternalFunctionDefinitionsElimination pass eliminate just those external functions which are only reachable via vtables and witness_tables, but leave directly reachable function definitions in place. This gives LLVM more chances to analyze directly reachable functions for side-effects and perform better optimizations based on this. Once we have a proper IPO support for Swift, we can eliminate all external function definitions, including directly reachable ones, as there will be other ways to get information about their side-effects.

Swift SVN r24546
2015-01-20 03:14:45 +00:00
Roman Levenstein
c5830745d7 Minor improvement: Perform removal of external functions bodies before dead function elimination.
Doing it before dead functions elimination creates more opportunities for dead function removal, because function references from bodies of external functions do not need to be taken into account any more.

Swift SVN r24431
2015-01-15 00:16:43 +00:00
Roman Levenstein
9f49a1096a [sil-dead-function-elimination] Add a LateDeadFunctionElimination entry point to remove external definitions.
This pass is an extension of the dead function elimination, which additionally performs removal of external function definitions (i.e. function bodies) for a sake of improving the compile times by reducing the amount of code running through IRGen.  It is safe, because such functions are defined elsewhere and where required only for analysis and optimization purposes.

This pass is supposed to run very late in the pipeline, after any passes that may need to look at the function bodies, i.e. after devirtualization, inlining and all specialization passes.

Swift SVN r24417
2015-01-14 18:57:36 +00:00
Erik Eckstein
70bb998e31 Fix problem with wrong elimination of methods in witness tables which are imported from stdlib.
This fixes <rdar://problem/19198675> Swift Stdlib (Unoptimized+Asserts) #1639 tests failed (1_stdlib/DictionaryUnchecked.swift et al.)




Swift SVN r23843
2014-12-10 15:41:56 +00:00
Erik Eckstein
ee41c8bdba Fix <rdar://problem/19157545> wrong dead function removal for a overridden method
Private methods were removed if the base class is public and not inside the current compilation unit.



Swift SVN r23807
2014-12-09 13:04:42 +00:00
Erik Eckstein
f40f3a93a0 New implementation of dead function elimination, which includes dead method elimination.
If vtable or witness methods are never called, e.g. because they are completely devirtualized,
then they are removed from the tables and eliminated.

Another improvement of the new algorithm is that it is able to eliminate dead function cycles
(e.g. A() calls B() and vice versa).



Swift SVN r22969
2014-10-27 16:41:02 +00:00
Erik Eckstein
6b6581aa25 Invalidate the deserializer caches after each SIL linking pass.
This avoids that the deserializer(s) keep references to deserialized functions during the whole optimization passes
(especially dead function elimination).

I have seen no negative effect on compiletime. It seems to be a seldom event that a function is
deserialized twice because of not keeping the cache alive between linking passes.

I also simplified the final dead function elimination by just using the regular dead function elimination pass.




Swift SVN r22837
2014-10-20 11:57:27 +00:00
Joe Groff
cac5807ae2 SILGen: Emit "main" as a SIL function.
Eliminate the intermediate top_level_code function. Now that SIL is expressive enough to express a "main" function, there's no reason for it, and this eliminates a bunch of mystery code in IRGen to thunk from main to top_level_code by reaching for hardcoded symbol names. Demystify the special code for setting up C_ARGC and C_ARGV by having SILGen look for a transparent "_didEnterMain" hook in the stdlib and emit a call to it.

Swift SVN r22525
2014-10-05 04:13:24 +00:00
Erik Eckstein
43f68b6974 Enable dead function removal for internal function in whole-module compilation.
This is controlled by a new isWholeModule() attribute in SILModule.

It gives about 9% code size reduction on the benchmark executables.
For test-suite reasons it is currently not done for the stdlib.



Swift SVN r22491
2014-10-03 14:14:23 +00:00
Mark Lacey
6a695f3099 Move DeadFunctionElimination to using the new call graph.
The old call graph remains, but the new call graph can obtained by
calling getCallGraph() on the analysis pass.

I'll move the few other passes that use the call graph over soon and
then rip out the old call graph.

No diffs in the stdlib.

Swift SVN r21565
2014-08-29 05:03:31 +00:00
Mark Lacey
c29df92a9f Small clean-up in dead function elimination.
Swift SVN r21562
2014-08-29 02:58:11 +00:00
Nadav Rotem
898bf23738 Move the CallGraphAnalysis to a new file.
Swift SVN r20714
2014-07-29 23:18:56 +00:00
Manman Ren
b3e72be9d9 Remove unused deserialized SILFunctions.
The deserializer holds a reference to the deserialized SILFunction, which
prevents Dead Function Elimination from erasing them. 

We have a tradeoff on how often we should clean up the unused deserialized
SILFunctions. If we clean up at every optimization iteration, we may
end up deserializing the same SILFunction multiple times. For now, we clean
up only after we are done with the optimization iteration.

rdar://17046033


Swift SVN r18697
2014-06-04 00:30:34 +00:00
Michael Gottesman
45c07489d2 Refactor Dead Function Elimination from SILCombine.cpp into its own file DeadFunctionElimination.cpp.
Swift SVN r16190
2014-04-11 01:10:28 +00:00