Commit Graph

6634 Commits

Author SHA1 Message Date
Michael Gottesman
8740666034 Change SILCloner to be able to remap additional non-instruction based SILValues such as SILUndef.
Previously we only supported SILArguments. In the process of changing this I
noticed that our densemap implementation for SILValues only hashes the wrapped
ValueBase instead of hash combining that hash with a hash of the result number.

The main use case for this is to enable the insertion of a Builtin.trap + RAUW
SILUndef of uses of an unconditional_checked_cast that is invalid after
specialization.

rdar://16490450

Swift SVN r15747
2014-04-01 21:09:41 +00:00
Michael Gottesman
0970880df3 Create a SILType wrapper for TypeBase::isSuperclassOf.
TypeBase::isSuperclassOf recursively determines if one type is a superclass of
another. I need this functionality to handle specialization of
unconditional_checked_cast archetype_to_archetype. Specifically if the
specialized types are sub/super classes I need to be able to ascertain that so I
can insert an upcast/downcast appropriately.

It makes sense to add this method to SILType itself since we should avoid
touching the AST as much as possible at the SIL level in order to make SIL as
self contained as we can.

rdar://16490450

Swift SVN r15746
2014-04-01 21:09:40 +00:00
Michael Gottesman
2c15c6b9b4 Add a helper function SILBuilder::createBuiltinTrap for creating traps.
I am going to use this in a forth coming fix to the Specializer. The reason I
refactored it out into SILBuilder is this seems like generic useful
functionality.

rdar://16490450

Swift SVN r15745
2014-04-01 21:09:36 +00:00
Michael Gottesman
4e73547a3e Change SerializedSILLoader::create to return a unique_ptr and use that everywhere so we don't leak SILLoaders.
Swift SVN r15700
2014-03-31 22:57:03 +00:00
Michael Gottesman
0d0c00ce15 [deserialization] Create the SILLoader for a SILModule lazily the first time deserialization occurs instead of when the SILModule is created.
This enables us to get around timing issues when we create a SILModule before we
have finished loading all Swift Modules.

This manifested itself in sil-opt where we were unable to deserialize from the
standard library when optimizing a separate *.sil file.

Swift SVN r15670
2014-03-31 08:40:35 +00:00
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
Joe Groff
cf4c03849d Typo
Swift SVN r15605
2014-03-29 02:53:52 +00:00
Joe Groff
86faf30617 SILGen: Emit bridging from C*Pointer to UnsafePointer.
When we see CConstPointer or CMutablePointer in a foreign function signature, transparently bridge it to UnsafePointer at the foreign entry point, lifetime-extending the C*Pointer value during foreign calls so that its owner reference is held for the duration of the call.

Swift SVN r15602
2014-03-29 02:50:35 +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
Michael Gottesman
9dd5fa3fcf Add in some comments to SILVTable. NFC.
Swift SVN r15562
2014-03-27 19:49:00 +00:00
Michael Gottesman
c4f407b058 Fix whitespace errors. NFC.
Swift SVN r15548
2014-03-27 03:56:34 +00:00
Michael Gottesman
fb8b3f3649 Remove unnecessary include of std::string. NFC.
Swift SVN r15546
2014-03-27 03:52:00 +00:00
Michael Gottesman
a571cd83f9 [deserialization] Add ClassDecl -> VTable map to SILModule.
Swift SVN r15545
2014-03-27 03:52:00 +00:00
Mark Lacey
f02cdba27b Minor cleanup - add accessors for a box's container result and address result.
Swift SVN r15519
2014-03-26 20:33:23 +00:00
Michael Gottesman
406bc0c19a [deserialization] Change SILLinking to use SILModule for linking instead of performing the linking itself.
This approach will allow us to go back to doing lazy linking if we want
to in the future.

Swift SVN r15498
2014-03-26 08:47:01 +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
59a44ca1f2 [deserialization] Add SILWitnessTable::convertToDefinition for converting SILWitnessTable declarations -> definitions.
This will be used for lazy deserialization of witness tables.

Swift SVN r15402
2014-03-24 05:07:21 +00:00
Michael Gottesman
f807249aa8 [deserialization] Store the mangled name of a SILWitnessTable on the instance itself.
The importance of this is that we will be able to use this name during
SIL serialization/deserialization to lookup partially deserialized
witness tables.

I left IRGen's original code alone until I can discuss with Joe/John
combining the logic together.

Swift SVN r15400
2014-03-24 05:07:20 +00:00
Michael Gottesman
e03f52638e Add in some documentation/comments to SILWitnessTable. Fix some whitespace issues.
Swift SVN r15380
2014-03-23 06:32:59 +00:00
Michael Gottesman
3ad6f33202 Teach the generic specializer how to create SILWitnessTable declarations if a specialized conformance does not have a witness table.
This also teaches IRGen not to emit WitnessTable declarations. This
causes them to be left as unknown symbols in the resulting executable.

Swift SVN r15361
2014-03-22 05:05:47 +00:00
John McCall
79dbbd6c9c Bridge optional types when the value type is trivially bridgeable.
Swift SVN r15128
2014-03-17 05:05:08 +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
Doug Gregor
f94a5e5df4 Call a standard library entry point from initializer stubs.
Rather than simply trapping with no output, have the initializer stubs
call into a new standard library function _unimplemented_initializer
that emits a more reasonable diagnostic, containing the name of the
class, the name of the initializer, and the file/line/column where the
class itself is defined. This finishes <rdar://problem/16156996>.



Swift SVN r15049
2014-03-14 15:04:49 +00:00
John McCall
794360d312 Permit optional class types to be returned autoreleased.
Swift SVN r15042
2014-03-14 07:10:10 +00:00
John McCall
446a9bd4a7 Introduce CanType versions of the various "getXOrBoundGenericX"
accessors.

Optimize these accessors by making them check for
BoundGenericXType instead of BoundGenericType and dyn_cast'ing
the Decl.  (The latter used to be necessary before we split
BoundGenericType.)

Swift SVN r15037
2014-03-14 05:59:44 +00:00
Nadav Rotem
5f35d44ecf Remove unused arguments from the block argument list.
Swift SVN r15006
2014-03-13 21:29:56 +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
c5feea4697 SILGen: Emit conformances for external definitions.
Teach IRGen to honor the linkage of SILWitnessTables, and teach SILGen to emit witness tables and protocol witness thunks for external definitions with shared linkage. Fixes <rdar://problem/16264703>.

Swift SVN r14908
2014-03-11 05:08:58 +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
Mark Lacey
2f4b982051 Remove TrivialTypeCache and AddrOnlyTypeCache from SILModule.
Now that we have better hashing in type lowering, these do not provide a
benefit.

Swift SVN r14878
2014-03-10 21:34:06 +00:00
Mark Lacey
d67dce037a Improve hashing in type lowering.
The previous function was less than ideal.

I haven't actually measured the distribution of my replacement yet, but
it reduces stdlib build time by 33% when building with a debug build
compiler, so it seems useful to get in ASAP.

Swift SVN r14877
2014-03-10 21:34:05 +00:00
Michael Gottesman
90c6c9507b [performance-inliner] Do not inline a callee into a caller if the callee's body references a global/function with less visible linkage than caller.
*NOTE* This is only to keep any less visible items from being exposed by
the inliner. Whether or not the callee has the proper linkage is for the
frontend/etc to ascertain.

Swift SVN r14824
2014-03-08 02:49:36 +00:00
Michael Gottesman
b4430012b2 [deserialization] Change isPublic(SILLinkage) -> hasPublicVisibility(SILLinkage) which is makes it 100% clear what the function is attempting to do.
Swift SVN r14823
2014-03-08 02:49:35 +00:00
Michael Gottesman
fafe76240e [external-witnesstables] Store the entries of a witness table in bump-ptr allocated memory referenced via an ArrayRef instead of a tail allocated array.
This will enable the creation of external witness tables whose entries
can be initialized after the witness table itself has been constructed.
This can occur if the table is deserialized later from a different
module.

Swift SVN r14715
2014-03-06 01:59:15 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Michael Gottesman
d495eb8d9e All SILWitnessTables have public conformances now. Teach the verifier to ensure that we do not create private witness table SILFunction references until we are ready.
Swift SVN r14619
2014-03-03 23:04:30 +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
Nadav Rotem
0985124291 Read the name of the function before deleting it.
I found this problem while fixing another bug.



Swift SVN r14532
2014-02-28 19:38:40 +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
59d2a169f6 SIL: Rename 'archetype_method' to 'witness_method'.
It has been generalized to get a witness out of an arbitrary protocol conformance, not just for archetypes.

Swift SVN r14497
2014-02-28 05:09:11 +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
Michael Gottesman
29e1a53bbb [deserialization] Deserialize transparent functions lazily iff they will be used in mandatory inlining.
Swift SVN r14490
2014-02-28 01:05:01 +00:00
Michael Gottesman
a073096093 [deserialization] Begin move to lazy linking by putting a SerializedModuleLoader on SILModule.
Right now it is not wired up. That is coming in forthcoming commits. I am trying
to be very incremental about this.

This series of patches will fix an assertion triggered by us not deserializing
functions from vtables appropriately. Doing linking lazily fixes that issue and
does the "right thing".

The work is being done in consultation with John, Joe, and Jordan.

Swift SVN r14479
2014-02-27 21:30:54 +00:00
Michael Gottesman
137ca5f18f Remove trailing whitespace. NFC.
Swift SVN r14472
2014-02-27 20:54:10 +00:00
Nadav Rotem
bd83adcd7c Cache the isAddressOnly property since it is a major compile time win.
Swift SVN r14347
2014-02-25 18:42:09 +00:00
Nadav Rotem
bc6fcc4475 Cache the isTrivial property.
The check for isTrivial takes ~20% of the optimizer compile time (in debug
mode) and using a cache accelerates the compile time.



Swift SVN r14346
2014-02-25 18:15:45 +00:00