Commit Graph

163 Commits

Author SHA1 Message Date
Doug Gregor
3023a710fc Split TypeBase::isDependentType() into isTypeParameter() and hasTypeParameter().
The isDependentType() query is woefully misunderstood. Some places
seem to want it to mean "a generic type parameter of dependent member
type", which corresponds to what is effectively a type parameter in
the language, while others want it to mean "contains a type parameter
anywhere in the type". Tease out these two meanings in
isTypeParameter() and hasTypeParameter(), respectively, and sort out
the callers.

Swift SVN r29945
2015-07-07 21:20:54 +00:00
Erik Eckstein
11705b346c Fix wrong call graph update when deserializing a vtable.
The callback (which is used for creating CG nodes) was lost when deserializing the functions of a vtable.

Fixes rdar://problem/21609902



Swift SVN r29838
2015-07-01 10:51:59 +00:00
Nadav Rotem
f2169f8103 Silence a few more warnings in Release builds.
Swift SVN r27334
2015-04-15 21:38:23 +00:00
Roman Levenstein
49331b986b Fix segfaults when -debug is used.
When debugging a compiler, using -debug would crash the compiler on some witness_method instructions, because sometimes their conformances are empty (e.g. if the type being looked-up is an archetype or an existential).

Swift SVN r27325
2015-04-15 20:23:00 +00:00
Michael Gottesman
8762675eb7 Verify SILSelf parameter type when we create the function in SILModule::getOrCreateFunction instead of moving it into the verifier.
This allows me to remove the map I added to SILModule.

Swift SVN r27242
2015-04-12 22:39:11 +00:00
Michael Gottesman
bffbc8f92f Create a map from SILFunction -> SILDeclRef if a SILDeclRef was used to create the function.
The two ways functions are created currently is via the two
SILModule::getOrCreateFunction(). One of the methods, takes in a raw mangled
name and uses that to create the function. The other takes in a SILDeclRef to
generate the mangled name. Most function emission (besides some thunk creation
functions) goes through the latter. For now we update the map there. This is ok,
since this map will only be used to provide extra verification that guaranteed
self is occuring everywhere that it is supposed to (since constructors and
destructors still have @owned self).

Swift SVN r27240
2015-04-12 21:10:50 +00:00
Roman Levenstein
d593d584de [sil-gen] Implement getFunction in terms of SILModule::getFunction to avoid a code duplication. NFC.
Swift SVN r27155
2015-04-09 01:52:01 +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
Roman Levenstein
0c2fc7c1a4 [sil-module] Add a helper method to lookup or create a SILFunction based on the SILDeclRef.
This API is more convenient than using the old getOrCreate API, which requires 9 parameters to be provided.
I'm going to use this API in the subsequent commits.

Swift SVN r27097
2015-04-07 22:53:49 +00:00
Roman Levenstein
1f875b9bcb Extend SILModule with an API for linking of SILFunctions by their SILDeclRef.
Before, providing a full SILFunction declaration object with a proper SILType was the only way to link a function. And constructing such a SILFunction declaration by hand using low-level SIL APIs is very annoying and requires a lot of code to be written. This new linkFunction API allows for a lookup using SILDeclRef and essentially performs linking of a SILFunction by its mangled name (assuming this name is unique), which is much easier to invoke. The new API is useful, e.g. when you need to link a well-known function from a standard library.

Swift SVN r26252
2015-03-18 06:11:22 +00:00
Doug Gregor
a09704bf0a Replace a conformance-walking loop with ProtocolConformance::getRootNormalConformance().
NFC cleanup.

Swift SVN r25994
2015-03-11 21:55:09 +00:00
Michael Gottesman
ae85fa3cfb Refactor SILLinkerVisitor into its own local files, Linker.{h,cpp}. This is still hidden in the SIL library.
This is only used by SILModule but is not integral to a SILModule so it makes
sense to have it in its own file. It keeps SILModule.cpp more focused. We still
keep it in a private header though since it is only meant to be used by
SILModule.cpp.

Swift SVN r25985
2015-03-11 20:18:34 +00:00
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +00:00
Mark Lacey
a9181b08ce Make witness/vtable look-up helper naming more consistent.
Swift SVN r25713
2015-03-03 09:14:18 +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
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
Nadav Rotem
789623daa8 Rename stdlib.noimport to stdlib_binary_only.
The name was proposed by Dave and Dmitry in an off-line conversation.

Swift SVN r24449
2015-01-15 19:05:23 +00:00
Nadav Rotem
6c012b5193 Disable the linking of stdlib functions that are marked with @semantics('stdlb.noimport')
Swift SVN r24403
2015-01-13 23:24:57 +00:00
Roman Levenstein
77fa044c8c Rename lookUpSILFunctionFromVTable into lookUpFunctionFromVTable. NFC.
Swift SVN r24265
2015-01-08 04:05:28 +00:00
Roman Levenstein
0368074f43 [sil-module] Fix a pretty serious bug when a wrong function was returned using SILModule::lookUpSILFunctionFromVTable.
This bug would manifest itself only when a module with multiple files is being compiled and some derived classes are defined in a file different from the one where a base class is defined. Due to this bug a method from a base class would be invoked instead of a method from a derived class when devirtualization was performed. The problem was that we were saying that failure to link a vtable is equivalent to failure to find a function in the vtable itself in which case we would go up to the parent vtable.

To avoid this kind of bug in the future a test case with a module consisting of multiple files is added to the test suite.

rdar://19334105 rdar://19337398

Swift SVN r24264
2015-01-08 04:05:27 +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
85e2502f96 Pass in SILOptions to SILModule.
This should have been done a long time ago since SILOptions are options that
should be able to effect everything SIL related. In this case I just want to
pass in a flag on the SILModule to enable +0 self. By putting it on the
SILModule I can conveniently check it in SILFunctionType without exposing any
internal state from SILFunctionType.cpp.

Swift SVN r23647
2014-12-03 07:43:52 +00:00
Erik Eckstein
60cb1a619a Support for eliminated witness methods in SILWitnessTable.
A method entry in SILWitnessTable can now be null.
This will be needed by dead method elimination.



Swift SVN r22914
2014-10-24 16:26:12 +00:00
Erik Eckstein
daeed72153 Simplify and chose a better name for invalidating the Deserializer's function cache.
Swift SVN r22838
2014-10-20 12:51:56 +00:00
Dave Abrahams
90a34d86fa Mangle names of globalinit_{token,func} like other private entities.
This allows making global addressors fragile (They use globalinit_{token,func} for initialization of globals).

It has no noticable performance impact on our benchmarks, but it removes an ugly hack which explicitly
prevented addressors from being fragile.

Swift SVN r22812
2014-10-17 06:02:22 +00:00
Dave Abrahams
e4588e4896 Revert "Mangle names of globalinit_{token,func} like other private entities."
This reverts r22795, because it broke my RelWithDebInfo,
SWIFT_OPTIMIZED=NO build.

Swift SVN r22802
2014-10-16 21:12:11 +00:00
Erik Eckstein
b5cfd00f74 Mangle names of globalinit_{token,func} like other private entities.
This allows making global addressors fragile (They use globalinit_{token,func} for initialization of globals).

It has no noticable performance impact on our benchmarks, but it removes an ugly hack which explicitly
prevented addressors from being fragile.



Swift SVN r22795
2014-10-16 08:24:18 +00:00
Doug Gregor
7d6ca8c2b8 Reinstate r22662 "Preserve the names of zombie functions and use them as linkage names in the debug info.""
It looks like Xcode badness caused the build breakage. Sorry, Erik!

Swift SVN r22677
2014-10-10 22:03:58 +00:00
Doug Gregor
5338a29f7f Revert "Preserve the names of zombie functions and use them as linkage names in the debug info."
This reverts commit r22662, which is causing the stdlib build to crash.

Swift SVN r22670
2014-10-10 17:46:30 +00:00
Erik Eckstein
bdfb461569 Preserve the names of zombie functions and use them as linkage names in the debug info.
Swift SVN r22662
2014-10-10 13:26:28 +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
Joe Groff
3a606b9eb8 SIL: Drop the protocol_method instruction.
Swift SVN r22446
2014-10-01 23:35:41 +00:00
Michael Gottesman
27363b24fb Fix 80+. NFC.
Swift SVN r22380
2014-09-30 03:08:50 +00:00
Erik Eckstein
35cfa7d2a0 fix a memory corruption introduced in r22301
(Don't increment refcounts of inlined SILFunctions for the purpose of debug info generation.)



Swift SVN r22349
2014-09-29 09:12:27 +00:00
Dmitri Hrybenko
fb6f195cd1 Portability: use std::make_tuple instead of relying on a libc++
extension (an implicit constructor in std::tuple)

Swift SVN r22331
2014-09-28 02:21:23 +00:00
Erik Eckstein
92dc4ee237 Don't increment refcounts of inlined SILFunctions for the purpose of debug info generation.
This prevented dead function removal of inlined dead functions. Beside the stdlib it's mostly
an issue of SIL size (and therefore compiletime), because llvm did remove such functions anyway.



Swift SVN r22301
2014-09-26 16:07:26 +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
Manman Ren
53151b90bd [Global Opt] add SILFunction *InitializerF to SILGlobalVariable.
It is defaulted to nullptr. When it is set, we increment the SILFunction's
ref count to keep it alive.

It will be used in followon patches for globals that can be statically
initialized.


Swift SVN r21983
2014-09-16 21:50:56 +00:00
Nadav Rotem
54458fb892 Enable access control based devirtualization.
Patch (mostly) by Jordan Rose.

rdar://17890078. 



Swift SVN r21139
2014-08-12 00:43:18 +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
9f4c417095 SIL: Forward-declare witness tables with correct linkage.
Fixes <rdar://problem/16997968>.

Swift SVN r19680
2014-07-08 05:30:35 +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
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +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
Mark Lacey
cd00cfbf8f Fix some build warnings.
DEBUG_TYPE should be defined before the inclusion of LLVM's Support/Debug.h.

Swift SVN r18640
2014-05-26 20:17:54 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Michael Gottesman
2c373a8cf4 [sil-module] Change DEBUG_TYPE to "sil-module" from "libsil"
I don't know why someone chose that name, but it makes no sense.

Swift SVN r17978
2014-05-12 23:59:50 +00:00
Michael Gottesman
e5191519e6 [linker] Link in closures references via function_refs during mandatory inlining.
Pattern matching on whether or not the function was applied is fragile
in the face of various possible compositions in between the function_ref
and the apply (i.e. thin_to_thick_function as an example).

Lets be conservative and just always deserialize references to closures
during mandatory inlining when referenced via a function_ref so we avoid
this problem if additional instructions like this are added.

Swift SVN r17977
2014-05-12 23:59:48 +00:00
Michael Gottesman
a7bb61265c [deserialization] Tighten up deserialization of witness tables.
We now enforce via an assert that each witness table is unique and that
every protocol conformance that is referenceable from SIL must have a
witness table matched to it.

Also, I taught the linker that it should deserialize witness tables for
InitExistentialRefInst instructions, something that was missed before.

Swift SVN r17283
2014-05-02 22:28:13 +00:00
Michael Gottesman
0f8733867b [deserialization] Change the return value of findFuncInWitnessTable to match the
ordering of SILWitnessTable, ArrayRef<Substitution> in lookUpWitnessTable.

Swift SVN r17266
2014-05-02 19:15:41 +00:00