760 Commits

Author SHA1 Message Date
Joe Groff
c098645f34 SIL: Conformances relate to formal types, so change witness_method's lookup type to a CanType.
Should be NFC in practice, since only nominal types can currently conform to protocols anyway, but improves modeling of the system.

Swift SVN r22360
2014-09-29 20:44:00 +00:00
Joe Groff
152aa9e244 Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22345.

Swift SVN r22353
2014-09-29 13:46:41 +00:00
Joe Groff
1e343fb430 SIL: Drop the upcast_existential* instructions.
Swift SVN r22345
2014-09-28 19:24:33 +00:00
Joe Groff
0518f2067f Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22333.

Swift SVN r22337
2014-09-28 18:41:05 +00:00
Joe Groff
727c9b5ed7 SIL: Drop the upcast_existential* instructions.
Swift SVN r22333
2014-09-28 16:38:13 +00:00
Joe Groff
a3126706da SIL: Eliminate the dead 'alloc_array' insn.
Swift SVN r22292
2014-09-26 02:28:10 +00:00
Jordan Rose
06986b7dca Re-apply the series of commits to remove redundantly-serialized conformances.
I can't actually reproduce the buildbot failure that happened last night, so
hopefully it will (a) happen again, so I can investigate, or (b) not happen
again.

Swift SVN r22230
2014-09-23 20:50:51 +00:00
Doug Gregor
6559392293 Start re-namespacing APINotes and its dependencies.
FixNum.h and BCRecordLayout.h will move down into LLVM, APINotes
will move into Clang. Get the namespaces right before we start to move
files around.

Swift SVN r22218
2014-09-23 17:52:17 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Dmitri Hrybenko
45c2005c9d Revert the series of commits to remove redundantly-serialized
conformances (22195 to 22199).

It broke tests:

Failing Tests (4):
   Swift :: Interpreter/SDK/Foundation_NSString.swift
   Swift :: SIL/Serialization/deserialize_appkit.sil
   Swift :: SIL/Serialization/deserialize_foundation.sil
   Swift :: stdlib/NSStringAPI.swift

Swift SVN r22214
2014-09-23 11:40:23 +00:00
Jordan Rose
a5685d6dac [Serialization] SIL witness tables should reference existing conformances.
Part of a series of commits to remove redundantly-serialized conformances.

Swift SVN r22197
2014-09-23 02:06:22 +00:00
Jordan Rose
82011c98ef [Serialization] witness_method should reference existing conformances.
Part of a series of commits to remove redundantly-serialized conformances.

Swift SVN r22196
2014-09-23 02:06:21 +00:00
Jordan Rose
eea6c17456 [Serialization] init_existential should reference existing conformances.
Part of a series of commits to remove redundantly-serialized conformances.

Swift SVN r22195
2014-09-23 02:06:20 +00:00
Manman Ren
9491a0e190 [Global Opt] get ready to replace GlobalAddrInst with SILGlobalAddrInst.
We add two more fields to SILGlobalVariable: a VarDecl and a flag to see if this
is a declaration. VarDecl is mainly used for debugger support, it is also used
to check if the variable is weak imported.

We also modify the serializer to serialize the extra two fields.


Swift SVN r21883
2014-09-11 18:13:04 +00:00
Joe Groff
e004ad7df4 SIL: Carry AST types through init_existential instructions.
This is necessary to be able to properly stash values with nontrivial lowerings, such as metatypes and functions, inside existential containers. Modify SILGen to lower values to the proper abstraction level before storing them in an existential container. Part of the fix for rdar://problem/18189508, though runtime problems still remain when trying to actually dynamicCast out a metatype from an Any container.

Swift SVN r21830
2014-09-10 05:56:36 +00:00
Doug Gregor
c504086266 Revert r21707 "Remove the SIL is_nonnull instruction. It's no longer useful."
We want to be able to work around problems with non-failable
Objective-C initializers actually failing, which can happen when the
API audit data incorrectly marks an initializer as non-failable.



Swift SVN r21711
2014-09-04 17:26:34 +00:00
Doug Gregor
cdf94885ae Remove the SIL is_nonnull instruction. It's no longer useful.
Swift SVN r21707
2014-09-04 15:56:12 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Doug Gregor
6bf57e9010 Revert "Serialization: introduce a conformance cross-reference so we don’t serialize normal protocol conformances in modules that didn’t declare them."
This reverts commit r20792.

Conflicts:
	include/swift/Serialization/ModuleFormat.h

Swift SVN r20834
2014-07-31 17:30:08 +00:00
Doug Gregor
e098ce84fb Serialization: introduce a conformance cross-reference so we don’t serialize normal protocol conformances in modules that didn’t declare them.
Swift SVN r20792
2014-07-31 01:00:17 +00:00
Michael Gottesman
4ec0a81e5f Add linkage SILLinkage::SharedExternal for deserialized functions with shared linkage.
*NOTE* This linkage is different from {Public,Hidden}External in that it has no
extra semantic meaning beyond shared.

The use of this linkage is to ensure that we do not serialize deserialized
shared functions. Those shared functions can always be re-deserialized from the
original module. This prevents a whole class of bugs related to the
creation of module cross references since all references to the shared
item go straight to the original module.

<rdar://problem/17772847>

Swift SVN r20375
2014-07-23 05:04:48 +00:00
Pete Cooper
d6877f60a4 Add enum_is_tag instruction.
This returns an i1 given an enum and enum element, and allows us to check the tag without the control flow required by switch_enum

Note, the following -O3 performance numbers are with r20242 reverted.

benchmark      ,  baserun0  ,  optrun0   ,  delta,   speedup
2Sum           ,  1613.00   ,  1656.00   ,  43.00    ,        -2.6%
Ackermann      ,  4560.00   ,  4473.00   ,  87.00    ,        1.9%
DeltaBlue      ,  22122.00  ,  22181.00  ,  59.00    ,        -0.3%
Dictionary     ,  927.00    ,  898.00    ,  29.00    ,        3.2%
EditDistance   ,  1573.00   ,  1564.00   ,  9.00     ,        0.6%
ForLoops       ,  2122.00   ,  2142.00   ,  20.00    ,        -0.9%
Forest         ,  1131.00   ,  1130.00   ,  1.00     ,        0.1%
GlobalClass    ,  2926.00   ,  2712.00   ,  214.00   ,        7.9%
Hash           ,  1970.00   ,  1280.00   ,  690.00   ,        53.9%
Histogram      ,  1860.00   ,  1606.00   ,  254.00   ,        15.8%
Life           ,  1669.00   ,  1750.00   ,  81.00    ,        -4.6%
LinkedList     ,  1555.00   ,  1558.00   ,  3.00     ,        -0.2%
Memset         ,  328.00    ,  333.00    ,  5.00     ,        -1.5%
NBody          ,  114.00    ,  46.00     ,  68.00    ,        147.8%
Phonebook      ,  1434.00   ,  1379.00   ,  55.00    ,        4.0%
Prims          ,  1833.00   ,  1669.00   ,  164.00   ,        9.8%
QuickSort      ,  107.00    ,  106.00    ,  1.00     ,        0.9%
R17315246      ,  1103.00   ,  817.00    ,  286.00   ,        35.0%
RC4            ,  884.00    ,  57.00     ,  827.00   ,        1450.9%
Rectangles     ,  1624.00   ,  1624.00   ,  0.00     ,        0.0%
SmallPT        ,  1067.00   ,  1012.00   ,  55.00    ,        5.4%
StringBuilder  ,  942.00    ,  921.00    ,  21.00    ,        2.3%
StringWalk     ,  1253.00   ,  1260.00   ,  7.00     ,        -0.6%
Totals         ,  55770.00  ,  52317.00  ,  3453.00  ,        6.6%

Swift SVN r20361
2014-07-23 02:53:43 +00:00
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