Commit Graph

137 Commits

Author SHA1 Message Date
Manman Ren
ae9f2e25ae [@semantics] add SemanticsAttr to SILFunction.
Enable SIL parsing and SIL serialization of semantics.

We add one more field to SILFunctionLayout for semantics. We should refactor
handling of attributes at SIL level, right now they are in SILFunction as bool
or std::string and in SIL serializer as a 1-bit field or an ID field.

rdar://17525564


Swift SVN r19434
2014-07-01 22:49:46 +00:00
Manman Ren
7667b829bb [noinline attribute] add noinline attribute.
Propagate it to SILFunction and use it in PerformanceInliner. We also serialize
and parse the attribute.

rdar://15882816


Swift SVN r19150
2014-06-24 23:07:45 +00:00
John McCall
385879beea Remove the CheckedCastKind from SIL dynamic casts.
It is straightforward and less redundant to recover this
information from the operand types.

Swift SVN r19056
2014-06-20 22:43:53 +00:00
Joe Groff
d9d451cea5 SIL: Add unchecked_{trivial,ref}_bit_cast instructions.
These instructions do a bitcast operation without stack traffic (at the SIL level). unchecked_trivial_bit_cast represents a conversion from a potentially nontrivial type to a trivial type, such as from a class reference to Int. unchecked_ref_bit_cast represents a conversion between types for which retain_value and release_value has equivalent effects when applied on the input or output values.

Swift SVN r19053
2014-06-20 22:02:38 +00:00
Doug Gregor
39e1b0886d Start using ConditionalCheckedCastExpr and ForcedCheckedCastExpr for collection downcasts.
NFC; just a cleanup.


Swift SVN r18979
2014-06-18 13:00:57 +00:00
John McCall
f0e14f7e65 Carry the formal types of the arguments in the indirect-cast
instructions.

Swift SVN r18934
2014-06-16 17:35:43 +00:00
Doug Gregor
5bb6969af3 Type checker support for dictionary downcasting.
This is the semantic-analysis portion of <rdar://problem/16847470>.


Swift SVN r18900
2014-06-14 18:27:38 +00:00
Nadav Rotem
bb0438f27b [Early Binding of Virtual Calls] Add a new kind of unconditional_checked_cast: Identical cast. This cast checks that the class that we inspect is exactly the type we expect, and not a subclass of that type.
Swift SVN r18859
2014-06-13 06:15:14 +00:00
Joe Groff
1f1c00cf9e SIL: Add instructions to convert metatypes to object references.
Add objc_metatype_to_object and objc_existential_metatype_to_object to convert metatypes to AnyObject, and objc_protocol to get a reference to an @objc protocol descriptor as a Protocol class instance.

Swift SVN r18824
2014-06-12 05:34:03 +00:00
John McCall
f5749cc037 Track the consumption behavior of the new indirect-cast
instructions.

Swift SVN r18785
2014-06-10 22:27:56 +00:00
John McCall
0f0874bb4b Add variants of the checked-cast instructions that
put the result in a different place.

WIP: no IRGen support yet.

This will eventually be the required form when casting
to an address-only type; the existing instructions will
have only scalar outputs.

Swift SVN r18780
2014-06-10 07:43:22 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Joe Groff
7d274e28a7 SIL: Add an unchecked_addr_cast instruction.
Cast an address to another address type without the silly address_to_pointer/pointer_to_address round trip.

Swift SVN r16743
2014-04-24 04:14:48 +00:00
Joe Groff
68f942117a SIL: Squash 'ref_to_native_object' and 'native_object_to_ref' into one 'unchecked_ref_cast' insn.
An unsafe cast from a base to a derived class isn't really all that different from one from Builtin.NativeObject to an arbitrary class, so relax this pair of instructions to allow an arbitrary bitcast. This only combines the instructions; it doesn't attempt to simplify any codegen that was emitting round-trip casts before yet.

Swift SVN r16736
2014-04-24 03:10:53 +00:00
Joe Groff
285ec1e2dd SIL: Add an unchecked_enum_data instruction.
This allows the payload for a loadable enum to be unsafely projected without branching, enabling more enum optimizations when switch branches can be culled or when indirect enum code can be promoted.

Swift SVN r16729
2014-04-24 00:41:08 +00:00
Joe Groff
55f6b925de SIL: Rename 'take_enum_data_addr' to 'unchecked_take_enum_data_addr'.
In preparation for adding an 'unchecked_enum_data' equivalent for loadable enums.

Swift SVN r16728
2014-04-24 00:40:47 +00:00
John McCall
b38a63950d Implement @unowned(unsafe).
This was part of the original weak design that
there was never any particular reason to rush the
implementation for.  It's convenient to do this now
so that we can use it to implement Unmanaged<T> for
importing CF types.

Swift SVN r16693
2014-04-23 08:51:23 +00:00
Andrew Trick
f58ebbc251 Add a global_init attribute to SILFunction.
The implied semantics are:
- side-effects can occur any time before the first invocation.
- all calls to the same global_init function have the same side-effects.
- any operation that may observe the initializer's side-effects must be
  preceded by a call to the initializer.

This is currently true if the function is an addressor that was lazily
generated from a global variable access. Note that the initialization
function itself does not need this attribute. It is private and only
called within the addressor.

Swift SVN r16683
2014-04-23 01:09:47 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Joe Groff
dcad7fb248 SIL: Add an autorelease_value instruction.
Give us a way to formally represent autoreleases in SIL separate from autoreleased returns, allowing us to lifetime-extend inner pointer parameters the lazy way and hopefully clean up some asmname hacks in the stdlib implementation too.

Swift SVN r16632
2014-04-21 23:11:38 +00:00
Manman Ren
a28a08d1ba [SILSerializer] Fix issues in deserializing SILFunction with generic outer parameter.
Before this fix, we can't deserialize any SILFunction with generic outer
parameters.

We do not have the decl associated with the generic parameter list at SIL level,
so instead of using a nullptr decl, we serialize the outer generic parameters
directly.

rdar://16630493


Swift SVN r16562
2014-04-19 01:53:12 +00:00
Justin Bogner
098701c416 Teach users of OnDiskHashTable to define hash_value and offset types
This is needed for an upcoming LLVM API change.

Swift SVN r16547
2014-04-18 20:33:14 +00:00
Justin Bogner
64c572e0d2 Serialization: Updates to use llvm/Support/OnDiskHashTable.h
The on-disk hashtable is moving from clang to llvm. This updates some
consumers for the new path and namespace. I've also shortened the
make_range(data_begin(), data_end()) calls on the hash table to just
use data().

Swift SVN r16537
2014-04-18 18:05:35 +00:00
Joe Groff
eaa6088102 SIL: Remove the now-obsolete bridge_to_block instruction.
Swift SVN r16487
2014-04-18 02:26:10 +00:00
Joe Groff
acdc425dfb SIL: Add instructions to initialize and project block storage.
Add project_block_storage, to project the capture storage from within a block_storage, and init_block_storage_header, to represent filling out the block header.

Swift SVN r16358
2014-04-15 04:48:34 +00:00
Michael Gottesman
5b82d84b0a [serialization] Improve comment to make it clear we are only checking the functions/globals referenced by F's instructions not transitively forever. NFC.
Swift SVN r16153
2014-04-10 05:21:36 +00:00
Michael Gottesman
9d54b8591a [serialization] Always serialize sil with shared linkage.
Entities with shared linkage are allowed to be discarded if they are unused even
in a library context.

Previously we implemented this in the serializer, which introduced
needless complications. Now we leave that responsibility to the optimizer giving
simplicity.

Swift SVN r16150
2014-04-10 04:34:05 +00:00
Michael Gottesman
cf15f748b8 [serialization] Extract shouldEmitFunctionBody into its own function. Its easier to read this way.
Swift SVN r16149
2014-04-10 04:34:00 +00:00
Michael Gottesman
c68d6347df [serialization] Split writeModule into two methods: writeSILBlock and writeIndexTables. Also integrate writeTables into writeIndexTables.
The fact that we were using extra scopes in writeSILBlock suggests that we
needed to split them into separate functions. NFC.

Swift SVN r16137
2014-04-09 23:39:49 +00:00
Michael Gottesman
b74a433d3a Add in some comments to SIL Serialization. NFC.
Swift SVN r16103
2014-04-09 05:58:10 +00:00
Michael Gottesman
9bf29592cd A few small debug print out related changes to SerializeSIL.
1. We call DEBUG() so we should set DEBUG_TYPE.
2. Print out the function name when printing out its abbrCode, bitno, etc.
3. Dump the SIL after printing the function information. This makes it easier to navigate the resulting output.

Swift SVN r16102
2014-04-09 05:46:54 +00:00
Joe Groff
fd9a9b5881 SIL: Add a CopyBlockInst instruction.
This maps down to a _Block_copy call that gives us the result, which may be different from the original object, back.

Swift SVN r16042
2014-04-08 02:43:17 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00
Doug Gregor
323b1829b3 Adapt to upstream changes in LLVM and Clang.
Swift SVN r15622
2014-03-29 17:08:09 +00:00
Joe Groff
afd59130f0 SIL: Add a FixLifetime instruction.
This will be a signal to ARC optimization, RVO, and other lifetime-affecting optimizations that they should not shorten the lifetime of a value past a certain point. We need this for C pointer bridging. This adds the instruction, but does not add any knowledge of it to the ARC optimizers.

Swift SVN r15601
2014-03-29 02:50:34 +00:00
Doug Gregor
51672965f4 Remove the unused @fragile, @resilient, and @born_fragile attributes.
Swift SVN r15518
2014-03-26 19:47:08 +00:00
Michael Gottesman
f4bb049bfc [deserialization] Enable lazy deserialization of witness tables.
This patch adds in the necessary infrastructure for lazily deserializing
witness tables. This is done by following the same approach as the
deserialization/serialization of SILFunction.

Now if one calls SILModule::lookUpWitnessTable and the given witness table is a
definition, the SILModule will attempt to deserialize it from one of the other
modules.

Swift SVN r15403
2014-03-24 09:16:09 +00:00
Michael Gottesman
df649b724b [serialization] Do not serialize the bodies of sil functions with external linkage.
They should always be deserialized from their original modules.

Swift SVN r15089
2014-03-14 23:11:54 +00:00
Michael Gottesman
5b88963e78 [SIL] Implement external SIL Witness Table declarations.
This will help with ensuring that we do not create multiple witness
table "definitions" one of which is null. That situtation yields an
IRGen assertion to be hit since the external declaration (in the guise
of a definition) has a different type from the actual deserialized
definition.

Swift SVN r14999
2014-03-13 19:52:59 +00:00
Joe Groff
945fbaf167 SIL: Add a linkage specifier to SILWitnessTables.
In the short term, we need to be able to emit shared symbols for SILWitnessTables corresponding to Clang-imported modules, and soon, the generic specializer will need to be able to reference *_external witness tables deserialized from library modules.

Swift SVN r14887
2014-03-10 23:14:16 +00:00
Michael Gottesman
ed0cfcaa10 [deserialization] Do not serialize function_refs or sil_global_addrs that reference functions or globals which are not always serializable.
Currently this consists of private functions and shared functions. Even
though shared functions are technically serializable, we only want to
serialize them if their serialization is requested.

Swift SVN r14825
2014-03-08 02:49:36 +00:00
Michael Gottesman
adabc5675b [deserialization] Clean up shouldEmitFunctionBody + fix an incorrect comment + add comments.
Swift SVN r14790
2014-03-07 20:46:17 +00:00
Doug Gregor
82c1ba2e29 Remove peer_method instruction; we're no longer using it.
Swift SVN r14599
2014-03-03 17:13:06 +00:00
Doug Gregor
5d8bd84dfa Introduce the SIL instruction alloc_ref_dynamic.
alloc_ref_dynamic allocates an instance of a class type based on the
value in its metatype operand. Start emitting these instructions for
the allocating constructor of a complete object initializer (not yet
tested) and for the allocating constructor synthesized for an imported
Objective-C init method.

Still missing:
  - IRGen still does the same thing as alloc_ref right now. That
  change will follow.
  - There are devirtualization opportunities when we know the value of
  the metatype that would turn an alloc_ref_dynamic into an alloc_ref;
  I'm not planning to do this optimization.



Swift SVN r14560
2014-03-01 21:55:50 +00:00
Joe Groff
67ca7ce1e9 SIL: Rename 'protocol_metatype' to 'existential_metatype'.
It's not forming the metatype for the protocol type (exists t: P. t).metatype, it's forming the existential of a metatype of a conforming type, exists t: P. (t.metatype).

Swift SVN r14520
2014-02-28 16:14:00 +00:00
Joe Groff
88b6efcc43 Rename ArchetypeMethodInst -> WitnessMethodInst more thoroughly.
Swift SVN r14501
2014-02-28 06:41:18 +00:00
Joe Groff
9424de6787 SIL: Rename 'archetype_metatype' to 'value_metatype'.
Since it can grab a metatype from any value now.

Swift SVN r14500
2014-02-28 06:33:05 +00:00
Joe Groff
545f173507 SIL: Fold 'archetype_metatype' and 'class_metatype'.
Having one instruction to get the dynamic metatype of a (non-existential) value makes more sense from a generic specialization standpoint and should stave off inevitable crashers when archetype_metatypes get specialized. protocol_metatype remains separate because metatype existentials are more interesting.

Swift SVN r14499
2014-02-28 06:32:58 +00:00
Joe Groff
855ea99063 SIL: Combine 'archetype_ref_to_super' and 'upcast'.
We were wantonly applying 'upcast' to archetypes in some cases, and really, that's OK, since these instructions do the same thing (and generic specialization could turn archetype_ref_to_super into upcast). Make everyone's life easier by folding archetype_to_super into upcast. Fixes <rdar://problem/16192324>.

Swift SVN r14496
2014-02-28 04:33:18 +00:00