Commit Graph

826 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
cd799f8e46 Revert "Add an inline(late) attribute"
This reverts commit r21286.

Discussions ongoing.

Swift SVN r21289
2014-08-19 18:15:25 +00:00
Arnold Schwaighofer
7aa62ce835 Add an inline(late) attribute
This disables inlining at the SIL level. LLVM inlining is still enabled. We can
use this to expose one function at the SIL level - which can participate in
dominance based optimizations but which is implemented in terms of a cheap check
and an expensive check (function call) that benefits from LLVM's inlining.

Example:

The inline(late) in the example below prevents inlining of the two checks. We
can now perform dominance based optimizations on isClassOrObjExistential.
Without blocking inlining the optimizations would apply to the sizeof check
only and we would have multiple expensive function calls.

@inline(late)
func isClassOrObjExistential(t: Type) -> Bool{
  return sizeof(t) == sizeof(AnyObject) &&
    swift_isClassOrObjExistential(t)
}

We do want inlining of this function to happen at the LLVM level because the
first check is constant folded away - IRGen replaces sizeof by constants.

rdar://17961249

Swift SVN r21286
2014-08-19 18:05:44 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +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
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +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
Adrian Prantl
588fb22c40 Get rid of the DebugScope variable here and just assign the scope of the
enclosing function, which happens to be the correct thing to do anyway.

Swift SVN r18983
2014-06-18 22:34:09 +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
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +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
Manman Ren
b3e72be9d9 Remove unused deserialized SILFunctions.
The deserializer holds a reference to the deserialized SILFunction, which
prevents Dead Function Elimination from erasing them. 

We have a tradeoff on how often we should clean up the unused deserialized
SILFunctions. If we clean up at every optimization iteration, we may
end up deserializing the same SILFunction multiple times. For now, we clean
up only after we are done with the optimization iteration.

rdar://17046033


Swift SVN r18697
2014-06-04 00:30:34 +00:00
Mark Lacey
cd00cfbf8f Fix some build warnings.
DEBUG_TYPE should be defined before the inclusion of LLVM's Support/Debug.h.

Swift SVN r18640
2014-05-26 20:17:54 +00:00
Andrew Trick
fa898f5562 Force generic parameter types declared in module context to belong to
the current SIL module, unless the AST sees them first.

This turns out to be important when we deserialize generic
reabstraction thunks, which have shared linkage so get serialized
again in the current SIL module.

There are some fundamental inconsistencies in the way parameter type
decls are handled, but we need a quick workaround to unblock progress
on the stdlib.

Fixes
<rdar://problem/16807985> Building Foundation overlay crashes in stdlib deserialization in r17377

Swift SVN r18173
2014-05-16 04:27:09 +00:00
Joe Groff
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Manman Ren
1bca09fe25 Remove FIXMEs that are already done.
Swift SVN r17709
2014-05-08 19:01:07 +00:00
Ted Kremenek
3b4b3006bb Add some default initializations to placate -Wconditional-uninitialized.
It's not clear if all of these are always initialized before their
uses, so it seems reasonable to default initialize them to
predictable behavior.

Swift SVN r17612
2014-05-07 07:34:44 +00:00
Michael Gottesman
fce2851de7 [deserialization] Enable dumping of modules/overlays that reference SDKs by fixing latent deserialization bug.
I also put in deserialization tests to make sure we do not regress on
this.

Swift SVN r17470
2014-05-05 18:15:23 +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
Michael Gottesman
afa464f980 [deserialization] Do not allow SILModule to attempt to deserialize a witness table lazily while we are already deserializing.
When deserializing, the serialized sil loader attempts to first lookup
from its SILModule the witness table to attempt to grab a witness table
declaration. Before this patch if the SILModule could not find it, it
would attempt to deserialize it. In certain edge cases this would cause
us to attempt to deserialize a function definition which violates the
invariant that that should never happen.

This patch adds an argument to SILModule::lookUpWitnessTable that
enables you to turn off the lazy deserialization behavior. The default
argument gives the current behavior which should be used everywhere
except for the deserializer.

Swift SVN r16740
2014-04-24 03:37:33 +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
Chris Lattner
a3916614ef respond to mainline API changes in the Debug.h header, by defining the
DEBUG_TYPE macro in all .cpp files that use the DEBUG macro.  Hopefully
this will unbreak the build.


Swift SVN r16638
2014-04-22 02:54:55 +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
Chris Lattner
84d360bbb9 remove two dead functions.
Swift SVN r16573
2014-04-20 00:22:15 +00:00
Justin Bogner
c7070b0ac2 Teach more users of OnDiskHashTable to define hash_value and offset types
I'd missed a few of these on the first pass. This should get the
builds going again.

Swift SVN r16570
2014-04-19 18:36:45 +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
Manman Ren
94e5b86de8 Revert r16543 due to testing failures.
Swift SVN r16553
2014-04-18 22:57:26 +00:00
Manman Ren
1b8c55b2af [SILSerializer] Fix issues in deserializing SILFunction with generic outer parameter.
Before this small fix, we can't deserialize any SILFunction with generic outer
parameters.

rdar://16630493


Swift SVN r16543
2014-04-18 20:04:46 +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
Adrian Prantl
50d130cb23 Reapplying: [clang update] Update uses of OnDiskChainedHashTable to the
OnDiskIterableChainedHashTable interface introduced in CFE 206189.

Thanks to Justin for guiding me through this!
The test-failures I was worried about after I originally committed this
turned out to be unrelated.

Swift SVN r16340
2014-04-14 23:29:47 +00:00