Commit Graph

159 Commits

Author SHA1 Message Date
Erik Eckstein
3a83cee006 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

The exposed crash in the ClosureSpecializer is fixed.
2016-02-26 14:05:48 -08:00
Adrian Prantl
310b0433a9 Reapply "Serialize debug scope and location info in the SIL assembler language.""
This ireapplies commit 255c52de9f.

Original commit message:

Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 13:28:57 -08:00
Adrian Prantl
255c52de9f Revert "Serialize debug scope and location info in the SIL assembler language."
Temporarily reverting while updating the validation test suite.

This reverts commit c9927f66f0.
2016-02-26 11:51:57 -08:00
Adrian Prantl
c9927f66f0 Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 10:46:29 -08:00
Erik Eckstein
f70b53b015 Revert "Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."""
This reverts commit c556d5cd39.

Hitting a new assert.
2016-02-25 09:50:11 -08:00
Erik Eckstein
c556d5cd39 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

After Xin's recent fix in ARC (6a9a430f68) the crash on i386 should be resolved.
2016-02-25 08:48:15 -08:00
Erik Eckstein
5b4c73ed3b Revert "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."
This reverts commit 4187959e66.

There is a crash in StdlibUnittests on i386 (Release-Assert build)
2016-02-23 08:29:41 -08:00
Erik Eckstein
4187959e66 GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.
With this re-abstraction a specialized function has the same calling convention as if it would have been written with the specialized types in the first place.
In general this results in less alloc_stacks and load/stores.
It also can eliminate some re-abstraction thunks, e.g. if a generic closure is used in a non-generic context.
It some (hopefully rare) cases it may require to add re-abstraction thunks.

In case a function has multiple indirect results, only the first is converted to a direct result. This is an open TODO.
2016-02-22 13:58:10 -08:00
Joe Groff
a1ef412815 Sema/SILGen: Get property behavior implementations to codegen.
Fix some interface type/context type confusion in the AST synthesis from the previous patch, add a unique private mangling for behavior protocol conformances, and set up SILGen to emit the conformances when property declarations with behaviors are visited. Disable synthesis of the struct memberwise initializer if any instance properties use behaviors; codegen will need to be redesigned here.
2016-02-20 15:01:06 -08:00
Arnold Schwaighofer
525f8ecbe1 Update the zombie function list if we create new functions
Dead function elimination deletes functions making them zombies. A zombie is a
function whose name only exists because debug info might still refer to it.

However, later passes of specialization might create a new function by the same
name again. We now have a zombie function (which is just an alias to a deleted
method stub) and a function definition.

No test case since I could not reduce this to a small test case.

rdar://24659988
2016-02-15 12:58:19 -08:00
Daniel Duan
efe230774b [AST] rename some isXXX methods to getAsXXX
There's a group of methods in `DeclContext` with names that start with *is*,
such as `isClassOrClassExtensionContext()`. These names suggests a boolean
return value, while the methods actually return a type declaration. This
patch replaces the *is* prefix with *getAs* to better reflect their interface.
2016-02-11 16:23:40 -08:00
Xin Tong
335dcdaf8c This moves back the Linker.h to lib/SIL/. As per LLVM coding standard,
Headers in include/ are meant to be used across libraries, headers in lib/
are only used within that library.

Thanks @jrose-apple for pointing this out.
2016-02-09 06:29:58 -08:00
Xin Tong
06ff2e60f5 Reorder headers. NFC 2016-02-07 23:21:48 -08:00
Xin Tong
b97ff7fb6b Move Linker.h to include/swift/SIL/. NFC. 2016-02-07 22:09:47 -08:00
practicalswift
b4996d3e0f [gardening] Fix recently introduced typo: "gnerates" → "generates" 2016-02-06 10:41:30 +01:00
Slava Pestov
bbbe307980 SIL: Introduce SILDefaultWitnessTable and start plumbing
This will be used to help IRGen record protocol requirements
with resilient default implementations in protocol metadata.

To enable testing before all the Sema support is in place, this
patch adds SIL parser, printer and verifier support for default
witness tables.

For now, SILGen emits empty default witness tables for protocol
declarations in resilient modules, and IRGen ignores them when
emitting protocol metadata.
2016-02-05 20:57:11 -08:00
Slava Pestov
b9951ade1b SIL: Rename some identifiers, NFC
"VTableLookupTable" just doesn't look right to me.
2016-02-04 17:34:55 -08:00
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
Michael Gottesman
389238e801 Add support for multiple @_semantics attributes at the SIL level.
This is something that we have wanted for a long time and will enable us to
remove some hacks from the compiler (i.e. how we determine in the ARC optimizer
that we have "fatalError" like function) and also express new things like
"noarc".
2016-01-02 04:17:07 -06:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Nadav Rotem
07d4558c1c [Mangler] Change the Swift mangler into a symbol builder.
This commit changes the Swift mangler from a utility that writes tokens into a
stream into a name-builder that has two phases: "building a name", and "ready".
This clear separation is needed for the implementation of the compression layer.

Users of the mangler can continue to build the name using the mangleXXX methods,
but to access the results the users of the mangler need to call the finalize()
method. This method can write the result into a stream, like before, or return
an std::string.
2015-12-25 21:40:25 -08: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
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