Commit Graph

6634 Commits

Author SHA1 Message Date
Michael Gottesman
c9baa6d739 [devirtualization] Extract the method SILModule::lookUpSILFunctionFromVTable from optimizeClassMethodInst. NFC.
Swift SVN r17133
2014-05-01 02:08:57 +00:00
Michael Gottesman
5449d6f673 [devirtualizer] Refactor findFuncInWitnessTable -> SILModule::findFuncInWitnessTable.
Swift SVN r17130
2014-05-01 01:06:06 +00:00
Joe Groff
164870c0c3 SILGen: Reenable partial application of ObjC methods.
Make ObjC method partial applications go through a native-to-foreign thunk so that we properly handle bridging conversions in the resulting function value. Partial applications through dynamic lookup are still broken because they apparently go through a different path.

Swift SVN r17108
2014-04-30 19:57:44 +00:00
Nadav Rotem
e406e43060 Disable the inlining of non-direct recursions (where A->B->A).
Swift SVN r17101
2014-04-30 18:45:13 +00:00
Michael Gottesman
2d026d7bd1 [devirtualization] Expose TypeBase::gatherAllSubstitutions as
SILType::gatherAllSubstitutions wrapped to be SIL level friendly.

Swift SVN r16908
2014-04-27 02:47:46 +00:00
Michael Gottesman
e2cde3c7f4 [devirtualization] Properly substitute in types for upcast when handling
a specialized inherited conformance.

Swift SVN r16900
2014-04-27 00:06:46 +00:00
Michael Gottesman
e8f981ab6c [devirtualization] Teach the devirtualizer how to handle specialized protocol conformances.
Now we can devirtualize conformances like the following:

protocol P {
  func doSomething()
}

struct X { }

struct B<T> : P {
  func doSomething() { ... }
}

func whatShouldIDo(p : P) {
  p.doSomething()
}

var b = B<X>()
whatShouldIDo(b)

rdar://16638833

Swift SVN r16874
2014-04-26 06:51:00 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00
Michael Gottesman
46d5660768 [devirtualization] Add SILType::substInterfaceGenericArgs a SIL level
wrapper for SILFunctionType::substInterfaceGenericArgs.

By exposing this we reduce the need for SIL level passes to touch the
AST when they need to specialize with just a subst list.

Swift SVN r16765
2014-04-24 19:41:18 +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
Michael Gottesman
61d7421fba [sil-gen] Emit class methods for in protocol methods for classes so that
inherited conformances can result in virtual calls to overriding
subclass methods.

Previously given the following swift code:

  protocol P {
    func x()
  }
  class B : P {
    func x() { ... }
  }
  class B2 : B {
    func x() { ... }
  }
  func doX<T : P>(t : T) {
    t.x()
  }

  var b2 = B2()
  doX(b2)

We would have b2 reference the protocol method for B.x. But since the
protocol method B.x would have a direct function reference to B.x, we
would not get the correct behavior that doX(b2) should invoke B2.x. This
is fixed by changing SILGen to emit class_method calls in protocol
methods for classes.

Swift SVN r16645
2014-04-22 04:45:09 +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
Mark Lacey
924e30ea61 Rewrite BB args whose only use is in struct/tuple extract.
If we have BB args that are only used in a struct/tuple extract, and
that are generated in each predecessor with a struct/tuple instruction,
retype the BB arg and replace the argument with what would have been the
extracted value.

This provides more opportunties for jump threading to kick in.

Swift SVN r16509
2014-04-18 07:19:33 +00:00
Mark Lacey
739eba9f2e Reformat assert so that the message isn't split.
Swift SVN r16507
2014-04-18 07:19:30 +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
Michael Gottesman
2feed65c65 [constant-propagation] Teach constant propagation how to fold expect of a constant.
Swift SVN r16389
2014-04-16 02:13:25 +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
Joe Groff
f7cf592777 Add a SIL-only '@block_storage T' type to represent on-stack storage for blocks.
Blocks need to be born on the stack, so we need a way to represent that on-stack storage. @block_storage T will represent the layout of a block that contains storage for a capture of type T.

Swift SVN r16355
2014-04-15 03:56:09 +00:00
Mark Lacey
6ac1e51370 Add an assert to detect an instruction being added as an operand of itself.
Swift SVN r16303
2014-04-14 05:40:31 +00:00
Michael Gottesman
7fbb22ef1e Revert "[sil-opt] When dumping a module, deterministically sort globals/functions/vtables/witness tables so that it is possible to diff modules."
This reverts commit r16267. Need to update tests.

Swift SVN r16269
2014-04-13 03:13:49 +00:00
Michael Gottesman
02ba8db0cf [sil-opt] When dumping a module, deterministically sort globals/functions/vtables/witness tables so that it is possible to diff modules.
Swift SVN r16267
2014-04-12 22:35:03 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
Michael Gottesman
0bc4f9c936 Call SILFunction destructor when we cleanup functions so that if the function contains a function_ref, the function referenced by the function_ref has its refcount properly decrement.
Otherwise a function_ref which was supposed to be deallocated would keep
functions alive.

rdar://16287331

Swift SVN r16192
2014-04-11 01:44:38 +00:00
Michael Gottesman
274d0ec4c2 [inst-simplify] Simplify expect hints with constant value.
Since our value is constant, we have no need to generate an expect hint
since we know the value at compile time.

Swift SVN r16179
2014-04-10 23:04:40 +00:00
Joe Groff
7e97b48e60 SIL: Allow copy_block to apply to optional block types.
Unprincipled, but expedient, and precedented by a similar hack for return_autoreleased.

Swift SVN r16173
2014-04-10 22:35:39 +00:00
Michael Gottesman
67351cf0a2 Since SILVTables and SILWitnessTables are bump ptr allocated, we need to call their destructor when we remove them so that the functions they reference have a decremented ref count.
Swift SVN r16171
2014-04-10 22:10:59 +00:00
Michael Gottesman
2c191278d8 Fix header of SILDeclRef to be 80 columns.
Swift SVN r16097
2014-04-09 04:40:20 +00:00
Joe Groff
d149851607 SILGen: Copy blocks received as function arguments.
We want to generally treat blocks as heap objects until proven stack-able by escape analysis, like we do generally with other heap entities. The only place we should be exposed to stack blocks is when they're passed as arguments, so handle this by copy_block'ing any block arguments we get in the function prolog. Optimization can eliminate them when analysis shows the block doesn't escape or is already on the heap.

Swift SVN r16096
2014-04-09 04:35:17 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Michael Gottesman
90f7864293 Implement John's suggestion of using "using SILCloner<ImplClass>::asImpl" to make calling Base::asImpl everywhere unnecessary.
Swift SVN r16048
2014-04-08 05:48:21 +00:00
Michael Gottesman
01b05fdc96 [specialization] SILCloner should always reference its builder SILBuilder via getBuilder().
Also fixed some 80+ issues.

This is in preparation for generic mandatory inlining.

Swift SVN r16046
2014-04-08 03:33:13 +00:00
Michael Gottesman
3525fac72d [specialization] Refactor SILCloner/SILVisitor to use an asImpl() method instead of directly calling static_cast.
NFC.

Swift SVN r16045
2014-04-08 03:25:29 +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
Doug Gregor
a87d65d617 Bridge NSArray <-> AnyObject[].
Allows AnyObject[] to occur in @objc methods/properties/etc., then
bridges between the two in SILGen based on the new array
implementation. <rdar://problem/16535097>.

Note that this commit does not change the Clang module importer to
import NSArray* as AnyObject[] (yet).


Swift SVN r16004
2014-04-07 05:49:48 +00:00
John McCall
a7a4f67f1b Bump the reference count of a function as long as it's sitting
around in the deserializer's .
1,2d
1i
Bump the reference count of a SILFunction as long as it's sitting
around in the deserializer's cache.

If we deserialize a function, then delete it, then deserialize
another reference to it, we'll end up pointing to a deleted
function.  This was causing the bug where IRGen would assert
with "no order number for SIL function definition?"; I can't
seem to find a radar for that, though.

Also, deserialization test cases are hard to write and probably
inherently unstable.

Swift SVN r15908
2014-04-04 00:53:55 +00:00
Joe Groff
fea886d048 SILGen: Bridge the C*VoidPointer types to COpaquePointer.
Swift SVN r15868
2014-04-03 15:03:48 +00:00
Joe Groff
8102dee6f0 SILGen: Bridge ObjCMutablePointer.
Make ObjCMutablePointer @objc-able for (potentially optional) class types, and bridge it down to UnsafePointer when calling @objc entry points.

Swift SVN r15838
2014-04-02 22:49:32 +00:00
Chris Lattner
f6e87dec54 Rework SILGen's emission of release_value to have it auto-merge into
retain_value instructions, just like we do for strong_retain/release.

This wraps up rdar://15889208, which is admittedly more of a moral 
victory than a practical one.


Swift SVN r15804
2014-04-02 16:39:53 +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
a0a65c0ea2 change the sil parser/printer to use retain_value instead of copy_value.
Swift SVN r15776
2014-04-02 05:22:41 +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
Michael Gottesman
2dcc1e7a8e Remove unnecessary Resolver argument from SILType::isSuperclassOf since SILTypes are only used after type checking.
Thanks Joe!

Swift SVN r15759
2014-04-01 22:55:43 +00:00