Commit Graph

136 Commits

Author SHA1 Message Date
Mark Lacey
4b0cb97590 Remove SILExternalSource.
This was once used in lldb but no longer is. I'm cannot find any other
users, so I'm removing it as a small part of cleaning up and simplifying
the SIL linking process.
2015-12-20 16:37:02 -08:00
practicalswift
e4219b39fc Fix typo: decleration → declaration 2015-12-14 00:11:34 +01:00
Mark Lacey
b37bc91506 Remove unused callback from SIL linker.
This was once used to maintain the call graph when lazy linking was
happening, but all that is gone now.
2015-12-10 15:12:41 -08:00
Roman Levenstein
46b58ac699 Re-apply "Reduce memory footprint of the Swift compiler"
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

The use-after-free issues reported by build bots are fixed now.

rdar://23303031
2015-12-10 08:36:59 -08:00
Joe Groff
b1667ec705 SIL: Introduce a new @inout_aliasable parameter convention.
Modeling nonescaping captures as @inout parameters is wrong, because captures are allowed to share state, unlike 'inout' parameters, which are allowed to assume to some degree that there are no aliases during the parameter's scope. To model this, introduce a new @inout_aliasable parameter convention to indicate an indirect parameter that can be written to, not only by the current function, but by well-typed, well-synchronized aliasing accesses too. (This is unrelated to our discussions of adding a "type-unsafe-aliasable" annotation to pointer_to_address to allow for safe pointer punning.)
2015-12-08 14:35:47 -08:00
Nadav Rotem
9e311aff6c Make delete notifications elective
This commit adds a hook that allows passes, analysis or data structures that can
be registered as receivers of delete notifications to decide if they want to
receive notifications All of the analysis and the currently executing passes are
automatically registered to receive notifications and this hook is useful in
reducing the runtime overhead. With this change the only analysis that accepts
notifications is alias analysis.
2015-12-07 16:27:19 -08:00
Michael Gottesman
1e5aa72f2d Add in clang-format changes that I forgot to commit with the previous commit (sorry).
I clang-formatted the previous commit, but forgot to amend the changes.
2015-12-06 16:29:52 -08:00
Michael Gottesman
302632cefb Make SILFunction::create() private and change all direct uses of SILFunction::create() to instead use SILMod.getOrCreateFunction().
This centralizes the entrypoints for creating SILFunctions. Creating a
SILFunction is intimately tied to a specific SILModule, so it makes sense to
either centralize the creation on SILModule or SILFunction. Since a SILFunction
is in a SILModule, it seems more natural to put it on SILModule.

I purposely created a new override on SILMod that exactly matches the signature
of SILFunction::create so that beyond the extra indirection through SILMod, this
change should be NFC. We can refactor individual cases in later iterations of
refactoring.
2015-12-06 16:23:44 -08:00
Nadav Rotem
9233217ded [ValueHandle] Allow invalidation of BB arguments.
This commit changes the invalidation handler from SILInstruction to ValueBase,
and also invalidates SILArguments.
2015-12-04 17:32:16 -08:00
Roman Levenstein
3bc1bd93c8 Use ValueBase instead of SILInstructions for delete notifications.
This enables e.g. notifications about the removal of SILArguments.
2015-12-04 15:16:25 -08:00
Nadav Rotem
37991af1cf [SIL] Add support for delete notification handlers.
This commit adds the basic support for delete notification handlers. The SIL
Module is notified every time an instruction is deleted. The module will forward
notification messages to users who ask to be notified.  The motivation for this
work is described in the upcoming commit to OptimizerDesign.md.
2015-12-04 07:37:12 -08:00
Roman Levenstein
5a4888236d Revert "Re-apply "Reduce memory footprint of the Swift compiler""
This reverts commit bf2fdb6764.

One of the build bots reported a malloc/free error, while other bots had successful builds. It could indicate a non-deterministic failure.
Preventively revert this patch as it is the most likely cause of these issues.

rdar://23611346
2015-11-19 07:56:57 -08:00
Roman Levenstein
bf2fdb6764 Re-apply "Reduce memory footprint of the Swift compiler"
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

The use-after-free issue reported by build bots is fixed now.

rdar://23303031
2015-11-18 18:14:29 -08:00
Ted Kremenek
8b6d9e9edb Revert "Reduce memory footprint of the Swift compiler"
This reverts commit d58f9486b1.
2015-11-17 21:22:40 -08:00
Ted Kremenek
1389c41b79 Revert "Always use malloc/free for allocation of SIL instructions."
This reverts commit a312dad07b.
2015-11-17 21:22:30 -08:00
Roman Levenstein
a312dad07b Always use malloc/free for allocation of SIL instructions. 2015-11-17 17:54:44 -08:00
Roman Levenstein
d58f9486b1 Reduce memory footprint of the Swift compiler
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

rdar://23303031
2015-11-17 17:26:35 -08:00
Joe Groff
0bf05283d2 Add builtins for atomic load/store operations.
Swift SVN r32952
2015-10-28 23:04:28 +00:00
Slava Pestov
7cf72989b7 Re-apply "Fix linkage of 'static inline' Clang-imported definitions"
This re-applies commit r31763 with a change to the predicate we
use for determining the linkage of a definition. It turns out we
could have definitions with a Clang body that were still public,
so instead of checking for a Clang body just check if the Clang
declaration is externally visible or not.

Swift SVN r31777
2015-09-08 22:12:06 +00:00
Dave Abrahams
8269d8130b Revert "Fix linkage of 'static inline' Clang-imported definitions"
This reverts commit r31763, as it was breaking the bots:

Swift SVN r31765
2015-09-08 16:31:35 +00:00
Slava Pestov
fc0a18be3f Fix linkage of 'static inline' Clang-imported definitions
If an external SIL function has a Clang-generated body, I think this
means we have a static function, and we want to use Shared linkage,
not Public.

Add a new flag to SILFunction for this and plumb it through to
appease assertions from SILVerifier.

Swift SVN r31763
2015-09-08 06:26:35 +00:00
Roman Levenstein
b5d964d536 Add a function to remove a global variable from a SILModule.
This API is useful for some global optimizations. If we can prove that a global is not used in the application, we can remove it.

Swift SVN r31529
2015-08-27 18:08:35 +00:00
Roman Levenstein
f69c17568b Add the ability to lookup/link a SILFunction in the SILModule by its mangled name.
This feature is required for the implementation of pre-specialization, because one needs to check if a specialized SIL function with a given name exists in the standard library.

Swift SVN r30307
2015-07-17 06:52:04 +00:00
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