Commit Graph

260 Commits

Author SHA1 Message Date
John McCall
aff457381c Change ApplyInstBase to not try to handle trailing objects itself. NFC.
The goal is to make it more composable to add trailing-objects fields in
a subclass.

While I was doing this, I noticed that the apply instructions provided
redundant getNumArguments() and getNumCallArguments() accessors, so I
went ahead and unified them.
2017-11-13 04:03:21 -05:00
John McCall
14d6390352 Add "yield" and "unwind" instructions to SIL. 2017-11-07 03:51:54 -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
e806b6248d SIL: Remove dynamic_method instruction 2017-10-04 03:53:16 -07:00
Slava Pestov
aea309d43c SIL: Move a comment 2017-10-04 03:53:15 -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
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
f9e58ce851 PGO fixups: rebase on latest master 2017-09-26 11:21:26 -07:00
Joe Shajrawi
f4e6bb3725 PGO: add support for checked_cast__br 2017-09-26 11:14:55 -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
Joe Shajrawi
7cb5b5a759 PGO: Move profile counts to SILSuccessor 2017-09-26 10:55:05 -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
c1fcfa0003 SIL: Fix reference tracking for equals/hash helpers in KeyPath instructions with operands. 2017-09-18 11:59:20 -07: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
Slava Pestov
38bf9349a0 SIL: Require exact conformances in witness_method instructions
The SIL witness_method instruction takes a protocol method and a
protocol conformance. IRGen lowers this as a load of a function
pointer from a fixed offset in the witness table for the
conformance.

IRGen also handled the case where the conformance is to a
protocol that refines the protocol containing the requirement,
by calling ProtocolConformanceRef::getInherited() to map the
conformance stored in the instruction to the correct conformance
for the protocol requirement being called.

It appears that this possibilty is not exercised through our
test suite, and if this does come up it is better to fix
SILGen and the optimizer to construct witness_method calls
using exact conformances only instead.

Furthermore, ProtocolConformanceRef::getInherited() only handles
a single level of refinement. So for example, if a protocol R
refines Q which refines R, we would crash when lowering a
witness_method instruction that calls P.foo() with a conformance
to R.

Therefore, code that emits witness_method instructions with a
conformance to a protocol that doesn't match the requirement was
likely going to do the wrong thing in this case anyway. Moving
the assertion earlier in the pipeline will help shake out these
cases.
2017-09-01 00:46:18 -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
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
bae290cdab Always put SILFunctions into a zombie list, when they are erased.
This removes the function body, but preserves the SILFunction object, which may be still referenced by different kinds of meta-information e.g. debug info for inlined functions, generic specializations information, etc.

Doing this unconditionally simplifies the code and makes it less error-prone to reference SILFunctions from any kind of meta-information. It just works. No need to set any special flags, etc.
2017-08-11 11:14:41 -07:00
Roman Levenstein
a920e32e54 Allocate GenericSpecializationInformation using SILModule's memory allocator. 2017-08-06 23:04:46 -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
swift-ci
7063af3307 Merge remote-tracking branch 'origin/master' into master-next 2017-07-18 00:28:52 -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
Greg Parker
7b009eccde Merge remote-tracking branch 'origin/master' into master-next 2017-06-28 15:25:17 -07:00
Joe Groff
3c82e981f9 KeyPaths: Add support for optional chaining/forcing components.
rdar://problem/31768715
2017-06-26 09:40:31 -07:00
Max Moiseev
614bb13cbf Merge remote-tracking branch 'origin/master' into master-next 2017-05-11 11:29:22 -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
swift-ci
4ebe4afe2a Merge remote-tracking branch 'origin/master' into master-next 2017-05-09 13:28:49 -07:00
Slava Pestov
edb1e97a35 SIL: Remove uncurryLevel from SILDeclRef
All we need to store is whether the SILDeclRef directly
references the declaration, or if it references a curry
thunk, and we already have an isCurried bit for that.
2017-05-09 00:56:35 -07:00
swift-ci
f1539d0a2e Merge remote-tracking branch 'origin/master' into master-next 2017-05-02 08:08:58 -07:00
Joe Groff
224120f54b SIL: Don't DFE functions referenced from KeyPath patterns.
Fixes rdar://problem/31776015.
2017-05-01 17:32:50 -07:00
swift-ci
eb6f0906c2 Merge remote-tracking branch 'origin/master' into master-next 2017-04-28 12:08:34 -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
swift-ci
4ef7b46971 Merge remote-tracking branch 'origin/master' into master-next 2017-04-21 18:08:32 -07:00
Joe Groff
3d178be169 Merge pull request #8875 from jckarter/keypaths
Keypaths
2017-04-21 17:51:17 -07:00
swift-ci
94a4e5f9e7 Merge remote-tracking branch 'origin/master' into master-next 2017-04-21 17:48:32 -07:00
Joe Groff
d5cdf658da KeyPaths: Generate _kvcKeyPathString for ObjC-compatible keypaths. 2017-04-21 16:56:17 -07:00
Roman Levenstein
8f39486bd7 Bugfix: alloc_ref object type may contain open archetypes that need to be tracked.
Fixes rdar://problem/31758765
2017-04-21 16:09:34 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Joe Groff
a6cd471c2b IRGen/stdlib: Instantiate non-generic computed key path components. 2017-04-18 21:51:12 -07:00
Joe Groff
ee66ff35c5 SILGen: Lower computed property key path components. 2017-04-14 17:13:38 -07:00
Joe Groff
9ade487689 SIL: Allow computed components in KeyPathInst.
A computed component needs:

- A stable identifier for equality checking. This can be either a static function reference for concrete property implementations, or a reference into a vtable or witness table for a dynamically dispatched property. This should correspond to a public ABI interface for public things.
- Getter and setter (TODO: and materializeForSet) references. These might be thunks to reach the necessary abstraction level for the keypath implementation, so they can't be used as stable identifiers directly.
2017-04-13 14:18:28 -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
swift-ci
5ba89103a7 Merge remote-tracking branch 'origin/master' into master-next 2017-04-11 09:28:31 -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