Commit Graph

457 Commits

Author SHA1 Message Date
Michael Gottesman
5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
Slava Pestov
1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov
1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Michael Gottesman
8f5a4859f2 [sil] Add some more utilities for working with destructure operations.
Just slicing off some code from my pred-memopts patch since Slava needs this
functionality for some other work he is doing.
2017-11-19 17:24:33 -08:00
Michael Gottesman
ac8aa12486 [sil-builder] Add utility method emitDestructureValueOperation.
This just abstracts the creation of a destructure_store or destructure_tuple
without the caller needing to know.

Just slicing simple code off of a larger commit.

rdar://31521023
2017-11-14 09:54:34 -08:00
John McCall
045998544f Add begin_apply, abort_apply, and end_apply instructions to allow
yield_once coroutines to be executed.
2017-11-13 04:03:54 -05:00
Michael Gottesman
b17935aff2 [pred-memopt] Rather than extracting values at the load site, extract at the store site.
Previously in PredMemOpts, we would insert any extracts at the load site, i.e.:

  store %foo to %0
  ...
  %1 = struct_element_addr %0, $Type, $Type.field
  %2 = load %1
  ...
  apply %use(%2)

would transform to:

  store %foo to %0
  ...
  %2 = struct_extract %foo
  apply %use(%2)

This framework will not work with Ownership enabled since the value stored is
considered consumed by the store. This change fixes the issue by moving such
non-destructive extracts to occur while %foo is considered live, i.e. before the
store:

  %2 = struct_extract %foo
  store %foo to %0
  ...
  apply %use(%2)

This means that we have to store insertion points for each store that provides
us with available values and insert the extracts at those points. This creates
some complications in the case where we have multiple stores since we need to
deal with phi nodes. Rather than dealing with it by hand, we just insert the
extracts at each point and then use the SSA updater to insert the relevant phi
nodes.

rdar://31521023
2017-11-08 10:40:39 -08:00
John McCall
14d6390352 Add "yield" and "unwind" instructions to SIL. 2017-11-07 03:51:54 -05:00
Michael Gottesman
b4bfd2f9d3 [pred-memopt] Add convenience begin/end borrow operation on SILBuilder.
These APIs make it easy to create borrow/end_borrow operations in a pass that
has to handle both ownership and non-ownership SIL.

rdar://31521023
2017-11-06 11:27:21 -08:00
Michael Gottesman
ec573ba213 [sil] Allow createTrivial{Store,Load}Or to optionally handle non-ownership sil functions.
This is just convenient if you want to have a pass work transparently with both
ownership and non-ownership SIL.

Chopped off from the larger pred-memopt update commit to ease review.

rdar://31521023
2017-11-03 23:07:22 -05:00
Michael Gottesman
36a8d0d5c0 [sil] Add support for the destructure_{struct,tuple} instructions.
rdar://31521023
2017-10-24 18:36:37 -07:00
Slava Pestov
0acf3ac8d9 SIL: Remove is_nonnull instruction 2017-10-13 17:38:32 -07:00
Slava Pestov
e806b6248d SIL: Remove dynamic_method instruction 2017-10-04 03:53:16 -07:00
Slava Pestov
42a4f1d0a8 SIL: Allow objc_method instruction to have type-dependent operands
This will allow us to remove dynamic_method, emitting objc_method
in its place. It will also allow objc_method to be used for
Objective-C protocol method calls, with witness_method used
for Swift native protocol method calls only.
2017-10-04 03:53:15 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
Slava Pestov
a85f602636 SILGen: Clean up class_method instruction construction a bit 2017-10-03 18:48:19 -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
f4e6bb3725 PGO: add support for checked_cast__br 2017-09-26 11:14:55 -07:00
Joe Shajrawi
64830c2d5e PGO: add support for checked_cast_addr_br 2017-09-26 11:14:31 -07:00
Joe Shajrawi
2cba745df8 PGO: Add support for switch-case statements + initial support for building switch and/or select SIL Instructions with profile count 2017-09-26 11:10:51 -07:00
Vedant Kumar
831d2eb44b [SwiftPGO] Store branch taken counts in CondBranchInst (NFC)
Update the SILBuilder and other relevant bits of SILGen s.t we pass
along branch taken counts whenever we create conditional branches.

There is a lot of unfinished work here: we need to teach ParseSIL,
DeserializeSIL, and the SILOptimizer about profile data. And add a
stable AST hasher. And add tests for it all.

Let's skip all of that for now. Next, we'll wire in some actual profile
data.
2017-09-26 10:54:01 -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
Joe Groff
78d75428d6 SILGen: Lower key path subscript indexes.
And fill out SIL support for parsing, printing, and serializing key path
patterns with captured indexes.
2017-09-15 10:00:32 -07:00
Andrew Trick
443e244d37 [sil-opaque-values] NFC, Allow SIL conventions to be set within SILBuilder.
This keeps the `create*` API simple for *normal* users and forces
AddressLowering to declare conventions when creating a builder.
2017-09-10 18:11:05 -07:00
Erik Eckstein
9c6fe76927 SIL, IRGen: add instructions "object" and "global_value” to support statically initialized objects.
This commit contains:
-) adding the new instructions + infrastructure, like parsing, printing, etc.
-) support in IRGen to generate global object-variables (i.e. "heap" objects) which are statically initialized in the data section.
-) IRGen for global_value which lazily initializes the object header and returns a reference to the object.

For details see the documentation of the new instructions in SIL.rst.
2017-08-23 09:15:49 -07:00
Erik Eckstein
1ab582e121 SIL: A new representation of static initializers for global variables.
Static initializers are now represented by a list of literal and aggregate instructions in a SILGlobalVariable.
For details see SIL.rst.

This representation is cleaner than what we did so far (point to the initializer function and do some pattern matching).

One implication of that change is that now (a subset of) instructions not necessarily have a parent function.
Regarding the generated code it's a NFC.
Also the swift module format didn't change because so far we don't serializer global variables.
2017-08-23 09:15:01 -07:00
Erik Eckstein
c6a466ca40 SIL: allow some literal and aggregate instructions to be constructed without a function context
just refactoring, NFC
2017-08-23 09:15:00 -07:00
Andrew Trick
5aac427ee0 SIL Ownership: Remove consumptionKind from SIL unconditional cast and related logic.
Remove the cast consumption kind from all unconditional casts. It
doesn't make sense for unconditional casts, complicates SIL ownership,
and wasn't fully supported for all variants. Copies should be
explicit.
2017-08-18 20:44:54 -07:00
Roman Levenstein
a73fbdb3fe Define a GenericSpecializationInformation class which can be used to track the history of generic specializations
GenericSpecializationInformation contains information regarding how a given specialized function was created, e.g. which caller function triggered this specialization, which substitutions were used, etc. Provide some debugging flags to dump the collected specialization information.

The information about generic specializations is referenced by the specialized functions and by call-sites originating from specialized functions.

This information can be created/used by the generic specializer to detect generic call-sites whose specialization would result in non-terminating sequence of subsequent generic specializations.
2017-08-06 12:51:49 -07:00
Andrew Trick
b48b3b02e1 [sil-opaque-values] Add support for createLoadBorrow. 2017-07-18 09:02:43 -07:00
Andrew Trick
4db2a46cff Add SIL instruction: open_existential_box_value.
This has the same semantics as open_existential_box, but returns an object value
instead of an address.

This is used in SIL opaque values mode. Attempting to reuse open_existential_box
in this mode causes SIL type inconsistencies that are too difficult to work
around. Adding this instruction allows for consistent handling of opaque values.

The original versions of several of these currently redundant instructions will
be removed once the SIL representation stabilizes.
2017-07-17 23:46:41 -07:00
Andrew Trick
f657ad2d3a Rename *ExistentialOpaque instructions to *ExistentialValue.
These instructions have the same semantics as the *ExistentialAddr instructions
but operate directly on the existential value, not its address.

This is in preparation for adding ExistentialBoxValue instructions.
The previous name would cause impossible confusion with "opaque existentials"
and "opaque existential boxes".
2017-07-17 23:46:41 -07:00
swift-ci
88aa00e7de Merge pull request #10944 from gottesmm/some_convenience_apis 2017-07-13 17:04:57 -07:00
Michael Gottesman
a36a4ec738 [sil] Add convenience APIs: createTrivial{Load,Store}Or to SILBuilder.
Often times one wants to create a load/store and you don't know if you have a
trivial type. These APIs allow you to use the correct semantic ownership
qualifier at the callsite without worrying: if you have a true trivial type, the
API will change the qualifier to trivial for you.
2017-07-13 14:23:49 -07:00
Michael Gottesman
90289277e8 [sil] Add assert to SILBuilder::createValueMetatype to ensure that its type is a lowered type of our expected formal instanceType.
It makes it easier to track down this type of bug since the assert occurs in
SILBuilder right where the invalid ValueMetatype is created.

rdar://problem/31880847
2017-07-12 17:32:00 -07:00
Roman Levenstein
647466d0b0 [sil-opened-archetype-tracker] Fix a memory leak
Placeholder global_addr instructions were never destroyed.
Now they are inserted in the entry basic block and later removed from there by the end of SIL deserialization.
2017-06-08 07:50:57 -07:00
Roman Levenstein
946b1d4225 Fix issues with the AddressLowering pass
Override the current SILModuleConvention of the SILModule when we perform the address lowering.
2017-05-10 11:59:43 -07:00
Roman Levenstein
45c2c4af0e Re-factoring: Get rid of useless arguments in "create*Apply" functions
Till now createApply, createTryApply, createPartialApply were taking some arguments like SubstCalleeType or ResultType. But these arguments are redundant and can be easily derived from other arguments of these functions. There is no need to put the burden of their computation on the clients of these APIs.

The removal of these redundant parameters simplifies the APIs and reduces the possibility of providing mismatched types by clients, which often happened in the past.
2017-05-10 08:03:37 -07:00
Joe Shajrawi
0d0cac357a retain_value_addr and release_value_addr SIL instructions: take as an input an address, load the value inside it and call retain_value and release_value respectively 2017-04-30 10:23:55 -07:00
Roman Levenstein
1731250dac [sil-open-archetypes-tracker] Add type dependent operands to more instructions
The following instructions were enhanced with type dependent operands:
- convert_function
- pointer_to_thin_function
- upcast_inst
- thin_to_thick_function

Fixes rdar://31879356
2017-04-28 09:35:06 -07:00
Roman Levenstein
202de40f05 [sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder
Fixes rdar://problem/31749245
2017-04-24 08:50:55 -07:00
John McCall
7b7f23ab33 Merge pull request #8945 from rjmccall/unpaired-accesses
Add unpaired access marker instructions for materializeForSet
2017-04-23 04:35:00 -04:00
Roman Levenstein
a60e037c48 Revert "[sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder" 2017-04-22 20:41:31 -07:00
John McCall
978f0e05fe Add unpaired access marker instructions and use them to implement
dynamic access tracking in materializeForSet.
2017-04-22 22:52:13 -04:00
Roman Levenstein
33c8bde859 [sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder
Fixes rdar://problem/31749245
2017-04-22 10:03:37 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -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
Arnold Schwaighofer
b167b4475d Add SIL and IRGen support for a ConstantStringLiteral instruction
This supports a utf8 or utf16 encoding.

rdar://30545013
2017-04-11 08:43:47 -07:00
Joe Groff
638759ac28 SIL: Add a "keypath" instruction for summoning literal keypath objects. 2017-04-04 11:31:15 -07:00