Commit Graph

393 Commits

Author SHA1 Message Date
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
Chris Lattner
fd465ff520 Merge pull request #526 from practicalswift/fix-typos-30
Fix typos (30 of 30)
2015-12-14 18:13:19 -08:00
practicalswift
54e808c88c Fix typo: visiblity → visibility 2015-12-14 00:12:38 +01:00
practicalswift
abbb6a09be Fix typo: convencience → convenience 2015-12-14 00:11:28 +01:00
John McCall
5fddd4a704 Remove the autorelease_return and strong_retain_autoreleased instructions.
There's a buggy SIL verifier check that was previously tautological,
and it turns out that it's violated, apparently harmlessly.  Since it
was already doing nothing, I've commented it out temporarily while
I figure out the right way to fix SILGen to get the invariant right.
2015-12-09 14:50:20 -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
Adrian Prantl
8ab1e2dd50 Unify debug scope and location handling in SILInstruction and SILBuilder.
The drivers for this change are providing a simpler API to SIL pass
authors, having a more efficient of the in-memory representation,
and ruling out an entire class of common bugs that usually result
in hard-to-debug backend crashes.

Summary
-------

SILInstruction

Old                   New
+---------------+     +------------------+    +-----------------+
|SILInstruction |     |SILInstruction    |    |SILDebugLocation |
+---------------+     +------------------+    +-----------------+
| ...           |     | ...              |    | ...             |
|SILLocation    |     |SILDebugLocation *| -> |SILLocation      |
|SILDebugScope *|     +------------------+    |SILDebugScope *  |
+---------------+                             +-----------------+

We’re introducing a new class SILDebugLocation which represents the
combination of a SILLocation and a SILDebugScope.
Instead of storing an inline SILLocation and a SILDebugScope pointer,
SILInstruction now only has one SILDebugLocation pointer. The APIs of
SILBuilder and SILDebugLocation guarantees that every SILInstruction
has a nonempty SILDebugScope.

Developer-visible changes include:

SILBuilder
----------

In the old design SILBuilder populated the InsertedInstrs list to
allow setting the debug scopes of all built instructions in bulk
at the very end (as the responsibility of the user). In the new design,
SILBuilder now carries a "current debug scope" state and immediately
sets the debug scope when an instruction is inserted.
This fixes a use-after-free issue with with SIL passes that delete
instructions before destroying the SILBuilder that created them.

Because of this, SILBuilderWithScopes no longer needs to be a template,
which simplifies its call sites.

SILInstruction
--------------

It is neither possible or necessary to manually call setDebugScope()
on a SILInstruction any more. The function still exists as a private
method, but is only used when splicing instructions from one function
to another.

Efficiency
----------

In addition to dropping 20 bytes from each SILInstruction,
SILDebugLocations are now allocated in the SILModule's bump pointer
allocator and are uniqued by SILBuilder. Unfortunately repeat compiles
of the standard library already vary by about 5% so I couldn’t yet
produce reliable numbers for how much this saves overall.

rdar://problem/22017421
2015-11-19 09:31:26 -08:00
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Erik Eckstein
e5f6eb3671 Add a convenience function hasName in SILFunction to be used in the debugger.
This is a replacement for getName().equals("..."), which is no longer callable from the debugger with the latest llvm changes.



Swift SVN r32895
2015-10-26 21:52:37 +00:00
Slava Pestov
255a1e63ac Random comment typo fixes, NFC
Swift SVN r32492
2015-10-07 18:33:46 +00:00
Nadav Rotem
7c1e5236a7 Refactor the code that checks for owned parameters. NFC.
Swift SVN r32478
2015-10-06 23:53:55 +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
Erik Eckstein
c1833c94bc Add an assert in SILFunction.
Swift SVN r31642
2015-09-02 22:36:32 +00:00
Erik Eckstein
3fc233e313 Refactoring, mainly to reuse code. NFC.
Swift SVN r31513
2015-08-27 00:04:50 +00:00
Erik Eckstein
0cb122b310 FunctionSignatureOpts: correct removal of release_value in throw blocks.
Fixes rdar://problem/22347336



Swift SVN r31352
2015-08-19 21:51:18 +00:00
Roman Levenstein
19a3821a56 Implementation of the pre-specialization for the most popular stdlib generic types.
This patch implements the pre-specialization for the most popular generic types from the standard library. If there are invocations of generic functions from the standard library in the user-code and the compiler can find the specialized, optimized versions of these functions, then calls of generic functions are simply replaced by the calls of the specialized functions.

This feature is supposed to be used with -Onone to produce much faster (e.g. 5x-10x faster) executables in debug builds without impacting the compile time. In fact, the compile-time is even improved, because IRGen has less work to do. The feature can be considered a light-weight version of the -Odebug, because pre-specialization is limited in scope, but does not have a potentially negative compile-time impact compared to -Odebug. It is planned to enable it by default in the future.

This feature is disabled by default for the time being. It can be enabled by using a hidden flag: -Xllvm -use-prespecialized.

The implementation consists of two logical steps:
- When the standard library is being built, we force a creation of specializations for the most popular generic types from the stdlib, e.g. Arrays of integer and floating point types, Range<Int>, etc. The list of specializations is not fixed and can be easily altered by editing the Prespecialized.swift file, which is responsible for forcing the specialization of generic types (this is simple solution for now, until we have a proper annotation to indicate which specializations of a given generic type or function we want to generate by means of the pre-specialization). These specializations are then optimized and preserved in the stdlib dylib and in the Swift SIL module. The size increase of the stdlib due to creation of pre-specializations is currently about 3%-7%.

- When a user-code is being compiled with -Onone, the compiler would run a generic specializer over the user-code. If there are calls of generic functions from the standard library, the specializer would check if there is an existing specialization matching these invocations. If such a specialization is found, the original call is replaced by the call of this more efficient specialized version.

Swift SVN r30309
2015-07-17 06:52:07 +00:00
Arnold Schwaighofer
7f98df29c6 Serialize whether a function is a reabstraction thunk
A follow up patch will add a peephole to remove superflous reabstraction thunk
combinations.

Swift SVN r30225
2015-07-15 20:17:19 +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
Adrian Prantl
1daaf310fb Revert "Reverting commits 29181-29187 to investigate buildbot breakage."
This reverts commit 29189.

Swift SVN r29191
2015-05-31 17:38:32 +00:00
Adrian Prantl
b994bde5b5 Reverting commits 29181-29187 to investigate buildbot breakage.
Swift SVN r29190
2015-05-31 06:13:03 +00:00
Adrian Prantl
6830021b4e Debug Info: Use the AST instead of SIL to determine the argument ordering.
The old SIL-based approach failed to recognize function arguments of
SIL-inlined functions as arguments.

Post-Xcode 7 it would be better to lower this information during SILGen
and emit a debug_value for every function argument so we don't need
to reconstruct them after all the SIL optimizations.

rdar://problem/21109015

Swift SVN r29180
2015-05-31 05:39:26 +00:00
Andrew Trick
1ba9b58668 Add SILFunction::hasSelfMetadataParam() and getSelfMetadataArgument().
I want IRGen and the SIL optimizer to use consistent logic.

Swift SVN r28785
2015-05-19 20:54:07 +00:00
Mark Lacey
9442ccb0a9 Do not disable mandatory passes when optimize.sil.never is specified.
Swift SVN r27667
2015-04-24 01:45:23 +00:00
Nadav Rotem
32211041d2 Rename @semantics -> @_semantics.
Swift SVN r27533
2015-04-21 17:10:06 +00:00
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
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
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
bb66f0f9c0 Fix typo and reword sentence in comment.
Swift SVN r26517
2015-03-25 02:48:12 +00:00
Michael Gottesman
aaab6d4668 When emitting sorted SIL, emit BBs in RPOT order.
This makes it easier to diff and read SIL output. Since it is behind the -emit-sorted-sil
flag, there is no effect on normal compilation.

Swift SVN r26101
2015-03-13 15:56:26 +00:00
Dave Abrahams
e88572391e Revert "Make sure that we do not try to create shared versions of stdlib_binary_only functions when specializing."
This reverts commit r26001; it broke validation-tests/stdlib/String.swift

Swift SVN r26005
2015-03-12 00:52:38 +00:00
Michael Gottesman
d88f3767c3 Make sure that we do not try to create shared versions of stdlib_binary_only functions when specializing.
This can only happen in the closure specializer and the generic
specializer since all other specializations either copy the linkage of
the original function (function signature opts) or clone closures/thunks
which have shared linkage.

I put in a verifier check that makes sure we do not create shared
versions of these functions. The real problem has to do with serializing
these sorts of functions, but since we always serialize shared
functions, it makes sense to just ban it.

rdar://20082696

Swift SVN r26001
2015-03-11 23:18:56 +00:00
Michael Gottesman
617ea48e8b Refactor getForwardingSubstitutions onto SILFunction. NFC.
This is also useful in general SIL passes when generating thunks. I am going to
use this in function signature optimization and closure specialization.

Swift SVN r25356
2015-02-17 21:03:24 +00:00
Michael Gottesman
18d6f3cc42 Add small TODO. NFC.
Swift SVN r25047
2015-02-06 21:59:50 +00:00
Michael Gottesman
59a1db1933 [silfunction] Add helper for returning arguments of a SILFunction.
Swift SVN r25005
2015-02-05 19:11:34 +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
Michael Gottesman
3d28921607 Add pass ExternalDefsToDecls that changes all available_external functions into declarations.
This is useful to ascertain how much code size comes from available_external functions.

Swift SVN r24471
2015-01-16 03:17:53 +00:00
John McCall
b6eb086af8 Add a rather hacky builtin function for constructing
a materializeForSet callback from a closure.

Swift SVN r23993
2014-12-17 22:23:26 +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
355f791621 [mangle] Add support for function signature specialization mangling and teach closure specialization how to use it.
Swift SVN r23816
2014-12-09 23:21:08 +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
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
652b5aeeea Add a verifier check to make sure that functions that have a function signature that should have a self parameter coming out of SILGen actually do so.
This was discovered while I was refactoring SILGen convention code.

Swift SVN r23611
2014-12-02 05:29:54 +00:00