Commit Graph

812 Commits

Author SHA1 Message Date
John McCall
e507341c1b SILModule lookup: now with that magic O(1) flavor.
Swift SVN r11978
2014-01-07 01:21:10 +00:00
John McCall
bb63d2312b Hide the constructors of SILFunction/SILGlobalVariable
behind factory methods.

Swift SVN r11967
2014-01-07 00:22:15 +00:00
Manman Ren
93243ca683 SIL serialization: do not use attribute field for cast kind.
Attribute field is a fixed 2-bit field, but cast kind exceeds 4,
so using 2-bit attribute field for cast kind will cause overflow.
The fix is to add a record for the cast instruction with a 4-bit
kind field instead of a 2-bit attribute field.


Swift SVN r11938
2014-01-06 19:35:29 +00:00
Doug Gregor
c76017754f Return an error if we couldn't handle the deserialized literal encoding in SIL.
Swift SVN r11923
2014-01-06 16:36:24 +00:00
John McCall
12b1c9daf7 Add support for multiple encodings to the string_literal
SIL instruction.  Implement IR-gen support for same.  Fix
the parsing of SIL string literals to properly unescape them.

SIL-gen still emits UTF8 literals unconditionally.

Swift SVN r11904
2014-01-04 11:42:57 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Adrian Prantl
d405aa3ccc Hush!
Swift SVN r11257
2013-12-13 17:35:19 +00:00
Adrian Prantl
c610ac94ef Add an IsBare attribute to SILFunction for functions that do not have an
AST.

Swift SVN r11236
2013-12-13 04:48:37 +00:00
Manman Ren
44a714a45a SILDeserializer: We expect SIL_FUNC_NAMES first, then SIL_VTABLE_NAMES, then
SIL_GLOBALVAR_NAMES. But each one can be omitted if no entries exist in the
module file.

rdar://15626995


Swift SVN r11088
2013-12-10 19:30:55 +00:00
Adrian Prantl
42fd177c01 silence warning
Swift SVN r11087
2013-12-10 19:23:35 +00:00
Joe Groff
02a0e996c4 SIL: Kill initialize_var instruction.
Remove the initialize_var instruction now that DI fully diagnoses initialization problems. Change String-to-NSString bridging to explicitly invoke String's default constructor; it was the last remaining user of initialize_var. Remove dead code to emit an implicit default constructor without a body.

Swift SVN r11066
2013-12-10 03:36:59 +00:00
Chris Lattner
a0499d90d5 remove the SIL builtin_zero instruction.
Swift SVN r11052
2013-12-09 23:41:35 +00:00
Joe Groff
27d96bbdc9 SIL: Generalize archetype_method to accept concrete types.
Allow archetype_method to look up a witness from a concrete ProtocolConformance record. This will allow generic specialization to apply to constrained generic functions independent of archetype_method devirtualization. <rdar://problem/14748543>

Swift SVN r10950
2013-12-07 00:00:51 +00:00
Manman Ren
395b8f4eda SILSerializer: handle sil_global and sil_global_addr.
Always serialize global variables and deserialize a global variable lazily
when deserializing SILGlobalAddr.

rdar://15493552


Swift SVN r10884
2013-12-05 21:56:02 +00:00
Chris Lattner
567a3175dc extend the mark_initialized SIL instruction to have a "kind" enum field.
Existing uses use a "globalvar" kind.  Add a new "rootinit" kind which
will be used for root initializers (i.e. init methods of structs, enums, 
and root classes).



Swift SVN r10772
2013-12-04 02:02:15 +00:00
Chris Lattner
ad05efc481 Redesign the BuiltinFunctionRefInst to contain an Identifier instead of
a FuncDecl.  This makes it much more straight-forward for SIL passes to
introduce a new one - without doing name lookup in the builtin module!



Swift SVN r10694
2013-11-30 01:49:36 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
f6b1745650 SIL: Remove 'ModuleInst'.
Module values could never be used for anything, and we have SILUndef now, so when SILGen sees a ModuleExpr, we can just emit 'undef'.

Swift SVN r10548
2013-11-18 21:36:08 +00:00
Joe Groff
4c0ebedc6a SIL: Add SILGlobalAddrInst.
Like GlobalAddrInst, but for SILGlobalVariables. These would become the same instruction when SILGlobalVariable can replace AST-level global references.

Swift SVN r10510
2013-11-16 00:50:18 +00:00
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
425819ac07 Change the SIL string_literal instruction to produce three results
(the same way alloc_box returns two) instead of returning a tuple.

This eliminates a ton of tuple_extract instructions, which just
bloat the generated SIL.  This resolves rdar://15378135.



Swift SVN r10416
2013-11-13 06:43:09 +00:00
Manman Ren
c2188c8328 SIL Serializer: vtable can trigger serialiation of a SILFunction declaration.
Also add serialization of resilience attributes: Fragile, InherentlyFragile
and Resilient. Serialize VTables before SILFunctions because it may trigger
serializations of non-transparent SILFunctions.

Update funcOrOffset and vTableOrOffset when a SILFunction or a VTable is
de-serialized.

rdar://15165644


Swift SVN r9926
2013-11-04 18:17:34 +00:00
Chris Lattner
a2a1b2af55 Clean up tuple and extract SILBuilder stuff:
- Introduce emitTupleExtract / emitStructExtract, which fold when their operand is a tuple/struct.
- Rename SILBuilder::createTupleExtractInst -> createTupleExtract, "Inst" isn't used as a suffix.
- Switch capture promotion and DI to use the new functions.

This trims 300 lines out of the stdlib.


Swift SVN r9897
2013-11-03 04:47:40 +00:00
Manman Ren
313bd88d88 SIL Serializer: fix a bug in handling of forward-referenced values.
In serializer, we pre-assign a value ID in order, to each basic block
argument and each SILInstruction that has a value.
In deserializer, we use LocalValues to store the definitions and
ForwardMRVLocalValues for forward-referenced values (values that are
used but not yet defined). LocalValues are updated in setLocalValue where
the ID passed in assumes the same ordering as in serializer: in-order
for each basic block argument and each SILInstruction that has a value.
We update ForwardMRVLocalValues in getLocalValue and when a value is defined
in setLocalValue, the corresponding entry in ForwardMRVLocalValues will be
erased.

rdar://15351123


Swift SVN r9884
2013-11-01 22:37:05 +00:00
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
00ca99b2ed SIL Deserialization: readSILFunction handles the case where the input
SILFunction is null.

When the input SILFunction is null, we create a SILFunction. A null input
SILFunction can happen when deserializing SILVTable.


Swift SVN r9736
2013-10-28 22:44:56 +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
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +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
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
Adrian Prantl
c4ece4ec9f Revisit scopes and locations in the light of SIL-based transparent inlining.
Swift SVN r8625
2013-09-25 16:14:47 +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
Joe Groff
014f270516 SIL: Have project_existential_ref project to a protocol Self archetype.
This mirrors the behavior of project_existential and simplifies some special cases in SILGen. It unfortunately makes dynamic_lookup sequences a bit noisier because of the need to explicitly cast the projection from DynamicLookup.Self to Builtin.ObjCPointer, but I think this modeling is more solid and will fit better with my planned redesign of archetype_method/protocol_method.

Swift SVN r8572
2013-09-23 21:57:12 +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
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