Commit Graph

240 Commits

Author SHA1 Message Date
Chris Lattner
ef93c81ffb Introduce a new SIL-level "undef" value, useful for SIL transformations.
IRGen support is missing, Joe volenteers to implement it.


Swift SVN r9776
2013-10-30 00:58:09 +00:00
Manman Ren
b2bd2e9f8d SIL Serialization: handle SILVTable.
We add two records in sil_block to specify a Vtable and its entry list. Two
records are also added in sil_index_block for mapping from name to ID and
from ID to bit offset.

Two functions are added to SerializedSILLoader: to look up a specific VTable
given the class name or to deserialize all VTables in all SILModules. The latter
is mostly used for testing.

We serialize a VTable if the class is fragile and deserialize it via
SerializedSILLoader::lookupVTable.


Swift SVN r9746
2013-10-28 23:38:48 +00:00
Manman Ren
c293d6dedb SIL Serialization: add helper function writeTable to write out a table to
sil_index_block.

No functionality change.


Swift SVN r9738
2013-10-28 23:02:28 +00:00
Manman Ren
d38b1a1637 SIL Serialization: seperate sil_index_block from sil_block.
Use generic layout for Lists and Offsets in sil_index_block. This will help
handling of VTable.

Records for VTable are added.


Swift SVN r9735
2013-10-28 22:27:23 +00:00
Manman Ren
b5a3f2fe60 SIL Serialization: add helper functions to handle SILDeclRef.
Two helper functions handleSILDeclRef and getSILDeclRef are added for
serialization and deserialization.

No functionality change.


Swift SVN r9728
2013-10-28 20:54:44 +00:00
Joe Groff
00dcdf394f SIL: Introduce CondFailInst.
This instruction will conditionally trigger a runtime failure if its operand is true.

Swift SVN r9588
2013-10-22 15:53:04 +00:00
Joe Groff
61360ba7a4 SIL: Remove ConvertCCInst.
Swift SVN r9577
2013-10-22 03:16:27 +00:00
Stephen Lin
a6108dbd48 Rename FunctionRefInst::getFunction() and BuiltinFunctionRefInst::getFunction() to FunctionRefInst::getReferencedFunction() and BuiltinFunctionRefInst::getReferencedFunction() to avoid shadowing SILInstruction::getFunction().
Swift SVN r8929
2013-10-04 20:26:41 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Joe Groff
a2672e9313 SIL: Turn conditional checked casts into a branch instruction.
Replace the existing suite of checked cast instructions with:

- unconditional_checked_cast, which performs an unconditional cast that aborts on failure (like the former downcast unconditional); and
- checked_cast_br, which performs a conditional pass and branches on whether the cast succeeds, passing the result to the true branch as an argument.

Both instructions take a CheckedCastKind that discriminates the different casting modes formerly discriminated by instruction type. This eliminates a source of null references in SIL and eliminates null SIL addresses completely.

Swift SVN r8696
2013-09-26 18:24:44 +00:00
Joe Groff
cbfe3710f6 SIL: Rename the 'isObjC' SILDeclRef specifier to 'isForeign'.
Doug pointed out that 'isObjC' incorrectly excludes C functions, for which we'll also need to be able to independently reference Swift and foreign entries.

Swift SVN r8669
2013-09-25 21:59:03 +00:00
Manman Ren
92f560911f SIL serialization: add testing cases based on SIL/Parser/basic.sil.
We generate a module from .sil, then deserialize the module using
sil-link-all.

Fix serialization and deserialization of CopyAddrInst.
Fix serialization of ProjectExistentialRefInst.
Add registration of ReferenceStorageTypeLayout, which we forgot to register.

We now have testing coverage of 70+ SILInstructions.


Swift SVN r8635
2013-09-25 18:44:51 +00:00
Manman Ren
3f02cc82c4 SIL serialization: clean up using macro
Also fix serialization of ProjectExistentialRefInst. Add asserts
in SIL deserializer to make sure SIL serializer is using the
correct layout.


Swift SVN r8598
2013-09-24 20:00:27 +00:00
Manman Ren
6ff9cee5e5 "transparent" attribute on SILFunction
Update SILPrinter, SILParser, SILSerializer and SILDeserializer to handle
the attribute.


Swift SVN r8597
2013-09-24 19:06:05 +00:00
Manman Ren
3b41274354 SIL Serialization: SIL blocks can be optional.
Check the existance in SILDeserializer.


Swift SVN r8584
2013-09-24 01:13:22 +00:00
Manman Ren
be3a4101ed SIL Serialization: perform SIL linking right after SILGen.
Add a SILLinkage mode "Deserialized" to make sure IRGen will emit
hidden symbols for deserialized SILFunction.

Inside SIL linker, set Linkage to external if we only have a declaration for
a callee function.

Both sil block and decl block in a module can emit an array of substitutions.
To share the serialization between SILSerializer and Serializer, we modify
the interface to pass in the abbreviation codes to write functions and to
pass in a cursor to read functions.

We now correctly handle the serialization of Substitutions in SpecializeInst.

For a deserialized SILFunction, we now temporarily set its SILLocation and 
DebugScope to an empty FileLocation. Once mandatory inliner sets the SILLocation
to the location of ApplyInst, a null SILLocation and a null DebugScope
may work for a deserialized SILFunction.

Update testing cases to reflect that we are now inlining transparent functions
from modules, or to disable SILDeserializer for now (I am not sure how to update
those testing cases).


Swift SVN r8582
2013-09-24 00:44:54 +00:00
Manman Ren
f6cd12c643 SIL Serialization: handle newly-added SILInstructions (CopyValue, DestroyValue).
Also clean up code using macro.


Swift SVN r8532
2013-09-20 23:28:01 +00:00
Manman Ren
fb97bef441 SIL Serialization: rename layout from TODO to NO_OPERAND.
Also add llvm_unreachable to make sure all SILInstructions are handled.


Swift SVN r8528
2013-09-20 23:11:07 +00:00
Manman Ren
6af99231f0 SIL Serialization: always generate two top-level blocks for SIL.
This simplifies deserialization.


Swift SVN r8522
2013-09-20 22:40:22 +00:00
Manman Ren
17d9d66881 SIL Serialization: handle SwitchIntInst.
All SILInstructions should be handled.


Swift SVN r8513
2013-09-20 20:42:49 +00:00
Manman Ren
af7fc037b7 SIL Serialization: handle SpecializeInst.
Also handle forward references of local SILValues.
Add testing case for SpecializeInst.


Swift SVN r8510
2013-09-20 20:22:42 +00:00
Manman Ren
11b436abd6 SIL Serialization: fix issues.
Clear up data for basic blocks and local values at beginning of
handling a SILFunction.
Fix a bug in handling of StructElementAddr and add testing cases for
enum, initialize_var and struct_element_addr.
Fix a problem in handling types of a SILArgument.

Turn SIL serialization on by default, add a command line "enable-sil-linking"
to turn on SIL deserialization.

Also for readability, change from Name.ResultVal != ~0U to !Name.isMRV()
in SILParser.


Swift SVN r8508
2013-09-20 19:10:04 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Manman Ren
8324827297 SIL Serialization: handle more instructions.
InitExistentialInst, InitExistentialRefInst, BuiltinZeroInst, GlobalAddrInst,
IndexAddrInst, UpcastExistentialInst, MarkFunctionEscapeInst,
DeinitExistentialInst, IsNonnullInst, InitializeVarInst,
MarkUninitializedInst, CopyAddrInst, StructElementAddrInst,
UnionInst, UnionDataAddrInst, InjectUnionAddrInst,
RefElementAddrInst, ArchetypeMethodInst, ProtocolMethodInst, ClassMethodInst,
SuperMethodInst, DynamicMethodInst, DynamicMethodBranchInst

We are missing implementations for SpecializeInst and SwitchInst.
Testing cases will be added in follow-up patches.


Swift SVN r8463
2013-09-19 20:45:15 +00:00
Manman Ren
faffef3379 SIL Serialization: handle switch instructions.
Swift SVN r8434
2013-09-19 00:30:04 +00:00
Manman Ren
39ff7707ea SIL Serialization: handle branch instructions.
Swift SVN r8428
2013-09-18 23:37:47 +00:00
Manman Ren
6eab362023 SIL Serialization: handle more SILInstructins.
Handle the following SILInstructions:
DeallocBoxInst ArchetypeMetatypeInst ClassMetatypeInst ProtocolMetatypeInst
AllocRefInst DeallocRefInst StoreWeakInst AssignInst

Add an optional 2-bit field for instruction attributes to
SILOneValueOneOperandLayout.


Swift SVN r8418
2013-09-18 21:03:01 +00:00
Manman Ren
6178f3b4d1 SIL Serialization: handle more SILInstructins.
Handle the following SILInstructions:
LoadWeakInst,
Checked Conversion instructions:
  DowncastInst, SuperToArchetypeRefInst,
  DowncastArchetypeAddrInst, DowncastArchetypeRefInst,
  ProjectDowncastExistentialAddrInst, DowncastExistentialRefInst

Add an optional 2-bit field for instruction attributes to SILOneOperandLayout
and SILOneTypeOneOperandLayout.

Update SILPrinter to print [take] for LoadWeakInst.


Swift SVN r8416
2013-09-18 20:28:54 +00:00
Manman Ren
86a0721c48 SIL Serialization: handle more SILInstructins.
ProjectExistentialInst, ProjectExistentialRefInst
StrongRetainAutoreleasedInst, AutoreleaseReturnInst,
StrongRetainUnownedInst, UnownedRetainInst, UnownedReleaseInst


Swift SVN r8415
2013-09-18 19:51:35 +00:00
Manman Ren
7b631ad74c SIL Serialization: handle float_literal and string_literal.
Also add command line argument to disable sil serialization by default,
use enable-sil-serialization to enable it.


Swift SVN r8413
2013-09-18 19:31:22 +00:00
Manman Ren
b78939e748 SIL Serialization: handle partial_apply.
Add command line argument -sil-link-all and -sil-serialize-all for testing
purpose.

Do not create new SILFunction for de-serialized SIL, instead update the
existing declaration with the de-serialized SILFunction.

Add testing case to cover partial_apply.


Swift SVN r8410
2013-09-18 18:51:04 +00:00
Manman Ren
2287c78778 SIL Serialization: handle more conversion instructions.
Swift SVN r8374
2013-09-18 00:32:40 +00:00
Manman Ren
8cd676143a SIL Serialization: handle more SILInstructions
Add serialization/deserialization of the following SILInstructions:
BuiltinFunctionRefInst, IndexRawPointerInst, ModuleInst,
Conversion instructions:
  RefToObjectPointerInst, UpcastInst, CoerceInst, AddressToPointerInst,
  PointerToAddressInst, ObjectPointerToRefInst, RefToRawPointerInst,
  RawPointerToRefInst, RefToUnownedInst, UnownedToRefInst
DestroyAddrInst, LoadInst, StrongReleaseInst, StrongRetainInst,
TupleElementAddrInst, TupleExtractInst

Make getModule in ModuleFile public to be used by SILDeserializer, also
make addModuleRef in Serializer public to be used by SILSerializer.

Update testing case to cover the above SILInstructions.


Swift SVN r8372
2013-09-18 00:25:23 +00:00
Manman Ren
e3f542cf73 SIL Serialization: handle more SILInstructions
Use a worklist in SIL linking to traverse the newly serialized SILFunction.
Add serialization/deserialization of the following SILInstructions:
AllocArray, Apply, FunctionRef, IntegerLiteral, Metatype, StructExtract,
Struct and Tuple.

Make getDecl and getIdentifier in ModuleFile public to be used by
SILDeserializer, also make addDeclRef and addIdentifierRef in Serializer
public to be used by SILSerializer.

Update testing case to cover the above SILInstructions.

TODO: lookupSILFunction should replace the existing empty SILFunction instead
of creating a new SILFunction.


Swift SVN r8339
2013-09-17 18:39:20 +00:00
Manman Ren
8d3c48874c SIL Serialization: able to serialize then deserialize a simple SIL function.
Add implementation to deserialize SILBasicBlock and some SILInstructins.
Add handling of local SIL values.
Add serialization of SILType category and SILValue result number.


Swift SVN r8292
2013-09-16 20:44:57 +00:00
Manman Ren
e797f23df0 SIL Serialization: add handling of types.
For PolymorphicFunctionType used in a SILFunction, we don't have a
corresponding Decl to share the parameter list with. In that case,
we set the owning Decl ID to 0 and add a trailing param lists.

We add a helper function to find the TypeAliasDecl for a Builtin type.
If the lookup is expensive, we can cache the lookup.

Deserializing SILBasicBlock and SILInstruction is not implemented yet.

SIL serializer and deserializer are implicitly tested when a module
contains transparant SILFunctions.


Swift SVN r8230
2013-09-13 23:54:33 +00:00
Manman Ren
fa0acc9328 SIL Serialiation: add implementation to deserialize SIL and a wrapper class
SerializedSILLoader to hold a list of SIL deserializers.

Also add an intial implementation of a linking pass that is run right after
SILGen to link the declaration of SILFunction to the actual definition in
the serialized module.

We add two blocks to the serialized module: a sil index block that
maps identifier to a function ID and also holds a list of function offsets,
and a sil block for the actual SILFunctions. We can probably use subblock
instead of two top-level blocks.

The serialization/de-serialization of the function hash table and the function
offsets are implemented. But we are missing handling of types (see FIXME in
the code).

ModuleFile::Serialized is made public to be used by SIL deserializer, as well
as ModuleFile::getType.

The SIL deserializer holds a pointer to the ModuleFile, it gets the sil cursor
and the sil index cursor from the ModuleFile. The other option is for SIL
deserializer to find the start of the two sil blocks within itself, thus having
less coupling with ModuleFile.

No testing case yet because we are missing handling of types.


Swift SVN r8206
2013-09-13 17:44:41 +00:00
Manman Ren
ddd7fb4d46 SIL Serialiation: add implementation to serialize SIL basic block and a
few SIL instructions types.

This will be tested when we have a SIL deserializer. Testing cases covering
each implemented SIL instruction will be added.


Swift SVN r8094
2013-09-11 17:52:05 +00:00
Manman Ren
ad318b0cee SIL Serialiation: add Transparent to SILFunction so we can decide which
functions should be serialized.

Transparent is added as a 1-bit field. In SILGen, we set SILFunction's
transparent attribute according to the attribute of the ValueDecl.


Swift SVN r7882
2013-09-04 00:16:34 +00:00
Manman Ren
64ccd88c8c SIL Serialiation: pass in a SILModule to serialize and a few other functions.
Add SerializeSIL.cpp for basic implementation of a SIL serializer.

serialize, serializeToStream, Serializer::writeToStream, and
Serializer::writeTranslationUnit all take an additional SILModule to pass it
to Serializer::writeSILFunctions.

Serializer::writeSILFunctions goes through all SILFunctions in a SILModule, and
serializes all SILFunctions that are transparent.


Swift SVN r7875
2013-09-03 22:57:37 +00:00