Commit Graph

367 Commits

Author SHA1 Message Date
Erik Eckstein
2db6f3d213 SIL: remove multiple result values from SILValue
As there are no instructions left which produce multiple result values, this is a NFC regarding the generated SIL and generated code.
Although this commit is large, most changes are straightforward adoptions to the changes in the ValueBase and SILValue classes.
2016-01-21 10:30:31 -08:00
John McCall
2df6880617 Introduce ProtocolConformanceRef. NFC.
The main idea here is that we really, really want to be
able to recover the protocol requirement of a conformance
reference even if it's abstract due to the conforming type
being abstract (e.g. an archetype).  I've made the conversion
from ProtocolConformance* explicit to discourage casual
contamination of the Ref with a null value.

As part of this change, always make conformance arrays in
Substitutions fully parallel to the requirements, as opposed
to occasionally being empty when the conformances are abstract.

As another part of this, I've tried to proactively fix
prospective bugs with partially-concrete conformances, which I
believe can happen with concretely-bound archetypes.

In addition to just giving us stronger invariants, this is
progress towards the removal of the archetype from Substitution.
2016-01-08 00:19:59 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
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
7b2dfcbbe2 Fix typo: causeing → causing 2015-12-14 00:11:22 +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
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
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
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
Slava Pestov
406d448db2 SIL: Rename Module to ModuleDecl due to FIXME, NFC
Swift SVN r32943
2015-10-28 18:28:59 +00:00
Xin Tong
2a8f010e11 Revert "When printing the SILModule for the standard library, do not import Swift. We are compiling Swift so this will cause an error."
This reverts commit r32837.

Swift SVN r32841
2015-10-23 02:38:00 +00:00
Michael Gottesman
9787441f84 Allow for dumping a sil file to disk with the SwiftModule to make it easier to debug modules from the debugger. This is not meant for normal use.
Swift SVN r32838
2015-10-23 01:38:05 +00:00
Michael Gottesman
afef8a73ea When printing the SILModule for the standard library, do not import Swift. We are compiling Swift so this will cause an error.
Swift SVN r32837
2015-10-23 01:38:03 +00:00
Michael Gottesman
72fe9e609d Fix style. NFC.
Swift SVN r32501
2015-10-07 21:59:45 +00:00
Mark Lacey
263cbdce03 Revert "Hook instruction insertion & removal."
This reverts commit r32359.

I'll look into doing fine-grained rebuilds of portions of the call graph
after some other changes go in that will make that more reasonable to
do.

Swift SVN r32379
2015-10-01 20:31:19 +00:00
Mark Lacey
48b0e18e23 Hook instruction insertion & removal.
Call back to the SILModule to notify of instructions being inserted or
removed from basic blocks.

The intent is to use this to notify the call graph (if one exists and
the module knows about it). We can then use these notifications to
automatically update the call graph.

Swift SVN r32359
2015-10-01 02:43:33 +00:00
Adrian Prantl
0acbc9bbd1 Thread -emit-verbose-sil into SILPasses, so it can be combined with
-sil-print-all & friends.

Swift SVN r32251
2015-09-25 23:46:50 +00:00
Roman Levenstein
4cef619c19 Revert "Verify SIL modules at the beginning and at the end of the SIL optimization pipelines, if -sil-verify-all is provided"
This reverts commit r31863, which was committed by mistake.

Swift SVN r31864
2015-09-10 22:32:36 +00:00
Roman Levenstein
141b8f814d Verify SIL modules at the beginning and at the end of the SIL optimization pipelines, if -sil-verify-all is provided
Till now, a SIL module would be only verified if an optimization has changed it. But if there were no changes, then no verification would happen and some SIL module format errors would stay unnoticed. This was happening in certain cases when reading a textual SIL module representation, which turned out to be broken, but SIL verifier wouldn't catch it.

Swift SVN r31863
2015-09-10 22:26:37 +00:00
Roman Levenstein
66e13af73e Add support for whole-module optimizations for SIL files.
To invoke the front-end on a SIL with whole-module optimizations enabled, execute:
swiftc -frontend myfile.sil

To invoke the front-end on a SIL without whole-module optimizations enabled, add a -primary-file option:
swiftc -frontend -primary-file myfile.sil

To invoke a sil-opt with whole-module optimizations enabled, use the -wmo option:
sil-opt myfile.sil -wmo

This change was need to be able to write SIL unit tests which should be compiled in the WMO mode.

Swift SVN r31862
2015-09-10 22: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
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
Dmitri Hrybenko
37a4335b88 Replace swift::Range with llvm::iterator_range
Due to inreased use of llvm::make_range in LLVM headers and ADL for
types defined in the swift namespace, some of the LLVM headers started
to trigger ambiguity errors between llvm::make_range and
swift::make_range.

Swift SVN r29700
2015-06-25 22:01:39 +00:00
Erik Eckstein
9703e3407f Add dump-to-file convenience functions in SILModule and SILFunction.
This is useful for dumping modules/functions into a file from lldb during debugging.



Swift SVN r29364
2015-06-12 12:16:54 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +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
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
Luqman Aden
3f83973928 Handle multiple sib inputs.
Swift SVN r26572
2015-03-26 01:21:21 +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
Mark Lacey
a9181b08ce Make witness/vtable look-up helper naming more consistent.
Swift SVN r25713
2015-03-03 09:14:18 +00:00
Justin Bogner
59bb06b0fb InstrProf: SIL-level coverage mapping and lowering to LLVM
The adds the sil_coveragemap construct to SIL and the needed IRGen to
turn these into LLVM's coverage maps.

Swift SVN r25210
2015-02-12 00:28:39 +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
Joe Groff
842d8aee03 Recommit r24666, r24667 with a fix for Optional object reference variance.
Give our assumption that T: class and Optional<T> are ABI-compatible a pass.

Swift SVN r24677
2015-01-23 04:15:34 +00:00
Dmitri Hrybenko
e90e1c6ab5 Revert "SIL verifier: Require convert_function not to change function ABI."
This reverts commit r24666.  It broke the performance benchmarks.

Swift SVN r24672
2015-01-23 03:09:54 +00:00
Joe Groff
67009e492c SIL verifier: Require convert_function not to change function ABI.
Write up a requireABICompatibleFunctionTypes check to make sure two function types share the same ABI. The real target here is to be able to apply this to vtable entries in order to uncover variance bugs like rdar://problem/19321484, but convert_function is a convenient testbed.

Swift SVN r24666
2015-01-23 01:15:00 +00:00
Roman Levenstein
77fa044c8c Rename lookUpSILFunctionFromVTable into lookUpFunctionFromVTable. NFC.
Swift SVN r24265
2015-01-08 04:05:28 +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
Manman Ren
16cc4dfa65 Revert r23713
Swift SVN r23739
2014-12-05 18:41:27 +00:00
Manman Ren
d0068877f5 [PGO] Add SILMetadata for branch weights.
SILMetadata is the base class with a single enum member (MDKind).
SILBranchNode is the derived class with additional members:
  unsigned NumOperands
  an array of uint32_t

A static member function SILBranchNode::get is implemented to get or create
SILBranchNode. All SILMetadata created are uniqued and saved in SILModule's
member variable:
  llvm::FoldingSet<SILMetadata> Metadatas

Usage of SILMetadta by SILInstruction is captured in SILModule's member variable:
  llvm::DenseMap<const SILInstruction *, SILMetadata *> MetadataStore
This is similar to LLVM's Metadata. Another option is to add a SILMetadata* to
SILInstruction. The disadvantage is the waste of space when we don't have PGO on.

This commit also enables parsing and printing of SILMetadata.

We add keyword sil_metadata to define SILMetadata:
  sil_metadata !0 = {"branch_weights", 3, 5}

For parsing, we add a map in SILModule
  llvm::DenseMap<unsigned, SILMetadata *> NumberedMetadata
that maps from ID to SILMetadata* to help matching usage of "!id" in SILFunction
with definition of "!id" in sil_metadata section.

For printing, we assign IDs to SILMetadata at SILModule scope, we then pass in
an optional argument of
  llvm::DenseMap<const SILMetadata *, unsigned> *MetadataMap
to SILFunction::print in order to get the ID of SILMetadata used in
SILInstruction.

Post-commit review will be appreciated.

rdar://18269754


Swift SVN r23713
2014-12-05 01:47:11 +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