Commit Graph

368 Commits

Author SHA1 Message Date
Roman Levenstein
882d72b0df Extend SILModule with an API to serialize its content
The `serialize` method can be called multiple times, but it will perform the actual serialization only the first time.
By means of this API we get the flexibility to serialize the SILModule not only after all the optimizations, but  e.g. at any time during optimizations.
2017-10-13 23:19:07 -07:00
Roman Levenstein
8e9ce01852 Remove even more dead code after -sil-serialize-all is gone 2017-10-04 14:20:53 -07:00
Roman Levenstein
5e67f755e0 Remove the -sil-serialize-all option 2017-10-04 14:20:53 -07:00
Roman Levenstein
fb0761d97a Add predicates to check if a SILModule is representing the (optimized) OnoneSupport
It is cleaner to use these predicates rather than checking for a complex condition in different places.
2017-09-29 12:36:35 -07:00
Joe Shajrawi
75939510cd PGO: Use ProfileCounter instead of Optional<uint64_t> to hold profile counts 2017-09-26 13:34:46 -07:00
Joe Shajrawi
2c03144436 Add support for function_entry_count Profile counter 2017-09-26 11:10:52 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Slava Pestov
a7ff2d2ddc SIL: Refactor SILVTable::getImplementation() into getEntry()
This will allow IRGen to recover the entry kind when emitting
class metadata.
2017-08-14 22:45:59 -04:00
Roman Levenstein
2a10d8692b Clean-up the code that stored and passes the SILSerializeAll flag around.
- SILSerializeAll flag is now stored in the SILOptions and passed around as part of it
- Explicit SILSerializeAll/wholeModuleSerialized/makeModuleFragile API parameters are removed in many places
2017-06-16 17:50:33 -07:00
practicalswift
8c40c65c80 [gardening] Fix typos. 2017-05-09 21:50:04 +02:00
Andrew Trick
195da33d1d [Exclusivity] Add deserialization callbacks from the optimizer.
AccessMarkerElimination now registers a callback so that any subsequently
deserialized function bodies will have access markers stripped for optimization.

rdar:31908496 Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of
              incompatible type!") in SILPerformanceInliner
2017-05-01 21:50:44 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Huon Wilson
b59f95418c [SIL] Extract ClassVisibility from SILFunction to SubclassScope in SILLinkage. 2017-04-13 14:17:29 -07:00
Joe Groff
d6ced9d9e4 SIL: Rework KeyPathInst to accommodate computed components.
- Separate out a uniquable KeyPathPattern that describes the context-free shape of the key path, with generic parameters and (eventually) subscript index slots factored out.
- Add component kinds for gettable and settable properties.
2017-04-12 20:09:17 -07:00
Huon Wilson
31b92b1b46 Merge pull request #8473 from huonw/symbol-list-2
Remove dependency on IRGenModule of some linkage computations
2017-04-05 16:39:04 -07:00
Huon Wilson
65c6bdca90 [IRGen] Remove IGM argument, factor out conformance fragility logic. 2017-04-05 09:54:19 -07:00
Slava Pestov
00d5b45733 Frontend: Add a new -sil-merge-partial-modules flag
Previously we would drop all serialized SIL from partial swiftmodule
files generated while compiling source in non-WMO mode; all that was
missing was linking it in.

This adds a frontend flag, and a test; driver change is coming up
next.

Progress on <rdar://problem/18913977>.
2017-04-03 21:28:40 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Michael Gottesman
81dcdba0a9 Revert "Make sure we always de-serialize transparent functions."
This reverts commit 821b365054.

It caused a bunch of execution time regressions.
2017-02-18 13:36:34 -08:00
Erik Eckstein
821b365054 Make sure we always de-serialize transparent functions.
We didn’t do that if an optimization looked up a witness table.

Fixes rdar://problem/30544344

I couldn’t come up with an isolated test case, but this should be covered with our existing tests.
(The problem shows up when inlining of generics are enabled)
2017-02-16 17:04:58 -08:00
practicalswift
1c64f04997 [gardening] Fix header inconsistencies 2017-02-14 20:04:05 +01:00
Roman Levenstein
fc7b9e1081 [sil-linker] Minor clean-ups of function lookup code in SILModule and SIL linker. NFC.
Stop using SILLinkage::Private as a flag for "linkage doesn't matter". Use Optional instead.
2017-02-14 08:15:51 -08:00
Andrew Trick
15699805ac SILModule.h comments 2017-02-13 17:10:02 -08:00
Andrew Trick
855918c620 [Lowering] Add an AddressLowering pass. 2017-02-13 17:10:02 -08:00
Jordan Rose
1c60910198 Revert "Merge pull request #6092 from swiftix/wip-generics-inlining-flag-4"
This reverts commit 1b3d29a163, reversing
changes made to b32424953e.

We're seeing a handful of issues from turning on inlining of generics,
so I'm reverting to unblock the bots.
2017-02-13 10:52:17 -08:00
Roman Levenstein
199e76d6d4 Fixes for a lookup of functions by name
Among other things it fixes a bug in the function signature optimization where it would use an already existing mangled name for a different function
2017-02-10 18:07:30 -08:00
Michael Gottesman
284a028e61 [sil] Add a new API SILModule::isNoReturnBuiltinOrIntrinsic(Identifier).
This is just refactoring code from DiagnoseUnreachable into a centralized
location.

rdar://29791263
2017-02-09 11:29:41 -08:00
Adrian Prantl
4d1ae142c6 Remove the redundant DeclCtx field in SILFunction.
In all cases the DeclCtx field was supposed to be initialized from the
SILLocation of the function, so we can save one pointer per
SILFunction.

There is one test case change where a different (more precise)
diagnostic is being generated after this change.
2017-02-06 11:07:50 -08:00
Huon Wilson
92e9d2d84f [SIL] Extract reoccuring allocation patterns.
No need to write a pile of manual memcpy's.
2017-01-26 12:42:13 -08:00
Erik Eckstein
44f35b9160 Remove dead witness tables, including dead witness functions.
A witness table is dead if it is not used outside the module (private/internal) and it’s not used by any instruction or other witness table in the module.
Also the meta-type of the conforming type must not escape, because it’s possible to test any opaque type if it conforms to a protocol.

rdar://problem/23026019
2017-01-19 09:41:09 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Groff
0ca4a374d5 Move SILLayout from SIL to AST.
Trying to contain it in SIL doesn't really work if we want to be able to print or parse SIL box types, since the type parser and printer doesn't otherwise depend on the SIL module.
2016-12-02 12:23:45 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Erik Eckstein
a01e9d4e41 Remove dead code in SIL linker
... which is not only dead but also broken.
NFC
2016-11-02 10:30:10 -07:00
Michael Gottesman
4d370a2814 [semantic-arc] When running the verifier, use the qualified ownership flag on the SILFunction to determine whether ownership is enabled or not.
Previously I was going to just set a flag and run the verifier once with that
flag enabled. Then I realized that given that the OwnershipModelEliminator is a
function pass, I really need to put the state on whether or not ownership is
enabled on functions. Now this commit refactors the verifier to use the state on
the function when determining if it should allow for ownership qualified
instructions or not in a specific function.

rdar://28685236
2016-10-21 17:42:39 -07:00
Joe Groff
cabaa0a51a SIL: Introduce lowered SILLayouts.
This gives us a concept we can eventually use to cache the lowered physical layout of fragile structs and classes, and more immediately, concretize the layout of closure boxes in a way that lets us represent the capture of generic environments and multiple captured values without compromising the "nominal" nature of box layouts. To start exercising the basic implementation, change the representation of SILBoxType to be in terms of a SILLayout, though avoid any immediate functionality change by preserving the single-boxed-type interface for now.
2016-10-21 14:19:56 -07:00
Michael Gottesman
277528f1ed [semantic-arc] When compiing with -enable-sil-ownership, run the OwnershipModelEliminator right after SILGen and verify with SIL Ownership Enabled.
rdar://28685236
2016-10-15 22:17:28 -07:00
Joe Shajrawi
9b2c0cde5e add a sidetable cache in the module for VTable entries, replacing linear lookup 2016-09-29 11:07:43 -07:00
Slava Pestov
772cf3a2fa SIL Optimizer: More principled substitution remapping in devirtualizer
When devirtualizing witness method and class method calls, we
transform apply instructions operating on the result of a SIL
witness_method or class_method instruction to direct calls of
a function_ref.

The generic signature of the dynamic call site might not match
the generic signature of the static thunk, so the substitution
list from the dynamic apply instruction cannot be used directly;
instead, we must transform it to a substitution list suitable
for the static thunk.

- With witness methods, the method is called using the protocol
  requirement's signature, <Self : P, ...>, however the
  witness thunk has a generic signature derived from the
  concrete witness.

  For example, the requirement might have a signature
  <Self : P, T>, where the concrete witness thunk might
  have a signature <X, Y>, where the concrete conforming type
  is G<X, Y>.

  At the call site, we substitute Self := G<X', Y'>; however
  to be able to call the witness thunk directly, we need to
  form substitutions X := X' and Y := Y'.

- A similar situation occurs with class methods when the
  dynamically-dispatched call is performed against a derived
  class, but devirtualization actually finds the method on a
  base class of the derived class.

  The base class may have a different number of generic
  parameters than the derived class, either because the
  derived class makes some generic parameters of the base
  class concrete, or if the derived class introduces new
  generic parameters of its own.

In both cases, we need to consider the generic signature of the
dynamic call site (the protocol requirement or the derived
class method) as well as the generic signature of the static
thunk, and carefully remap the substitutions from one form
into another.

Previously the optimizer would implicitly rely on substitutions
being in AllArchetypes order, in particular that concatenating
outer substitutions with inner substitutions makes sense.

This assumption is about to go away, so this patch refactors
the optimizer to use some new abstractions for remapping
substitution lists.
2016-09-06 11:51:13 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
Slava Pestov
2e52338d7c SIL: Rename long form of getOrCreateFunction() to createFunction(), NFC
This made call sites confusing to read because it doesn't actually
check if the function already exists.

Also fix some minor formatting issues. This came up while I was working
on a fix for a bug that turned out to not be a bug.
2016-04-21 17:58:10 -07:00
Erik Eckstein
8f78085e8b Refactor SILPrinter.
Introduce a new SILPrintContext class which is the main handle passed to the SILModule's and SILFunction's print functions.
It also allows to let derived classes implement call backs on instruction printing.
NFC for now, but needed for the upcoming SIL-debuginfo change.
2016-03-18 14:01:38 -07:00
Slava Pestov
be3631a878 SIL: Introduce SILModule::lookUpFunctionInDefaultWitnessTable() 2016-03-17 10:39:35 -07:00
Slava Pestov
116ac3d1f2 SIL Serialization: Serialize default witness tables
This will be used by SILGen to look up default witnesses for
requirements of protocols in other modules.
2016-03-17 10:39:34 -07:00
Slava Pestov
b13457daaa SILGen: Add linkage to SILDefaultWitnessTable
This is only used in the verifier, to ensure that default witness
thunks are suffiently visible.

Also this patch removes the asserts enforcing that only resilient
protocols have a default witness table. This will change in an
upcoming patch, and in this patch is necessary for the test to work.
2016-03-17 03:57:23 -07:00
Roman Levenstein
94c3ae4c3c Add APIs to check if a function with a given name exists and to invalidate a SIL linker entry for a function.
These APIs are useful e.g. for quickly finding pre-specialisations by their names.
The existence check is very light-weight and does not try to deserialize bodies of SIL functions.
2016-02-26 22:10:59 -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
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