Commit Graph

1328 Commits

Author SHA1 Message Date
Joe Groff
71379f5bad SILGen: Explicitly mark uninitialized locals with mark_uninitialized, and have DI only consider mark_uninitialized storage.
Have SILGen mark all variables bound from pattern bindings without initializers (and *only* ones without initializers) with mark_uninitialized [var] pseudo instructions. On the DI end, *only* consider mark_uninitialized instructions for DI analysis. This has many benefits:

- DI doesn't waste time analyzing locals that are trivially initialized in the original source code.
- DI doesn't try to mangle canonical SIL that has been inlined from transparent functions, which may have been optimized into a form DI isn't written to understand.

While we're here, fix an issue with DCE where it would try to kill unused MarkUninitialized instructions. Although MarkUninitialized has no side effects, it still is semantically important to raw SIL, and can't be killed.

Chris did most of the work here; I just finished updating tests and fixing bugs.

Swift SVN r13247
2014-01-31 22:50:21 +00:00
Nadav Rotem
bcb13736f3 Add block setters to the branch instructions.
Swift SVN r13241
2014-01-31 19:35:56 +00:00
Michael Gottesman
82a912cc45 Added SILInstruction::mayReadOrWriteMemory().
Swift SVN r12905
2014-01-24 06:13:56 +00:00
Joe Groff
92f7b5512d AST: Add a "Substitution::subst" API.
Substitute a...um...substitution by remapping its Replacement mapping and recursively remapping any ProtocolConformances it has. Modify the Specializer to use Substitution::subst when specializing the substitutions of ArchetypeMethod and Apply instructions.

Swift SVN r12900
2014-01-24 04:35:49 +00:00
Chris Lattner
c755b13aa0 update comments for the [attributes] -> @attributes syntax change.
Swift SVN r12795
2014-01-22 22:09:57 +00:00
Michael Gottesman
4aa5906fba Remove cruft that snuck into LiteralInst from my using ConversionInst as a template.
Swift SVN r12770
2014-01-22 19:35:18 +00:00
Michael Gottesman
38871aed5e Add in abstract base class LiteralInst for literal instructions and modify all the literal SIL classes to inherit from it appropriately.
Swift SVN r12764
2014-01-22 19:23:11 +00:00
Michael Gottesman
a33940734d Swap FunctionRefInst and BuiltinFunctionRefInst so that they match the order of instructions in SILNodes.def.
Swift SVN r12762
2014-01-22 19:23:08 +00:00
Chris Lattner
f5b85341a1 Expand out the "isComputed" property in AbstractStorageDecl to be an enum
with two kinds, and some more specific predicates that clients can use.

The notion of 'computed or not' isn't specific enough for how properties
are accessed.  We already have problems with ObjC properties that are 
stored but usually accessed through getters and setters, and a bool here
isn't helping matters.

NFC.



Swift SVN r12593
2014-01-20 18:16:30 +00:00
Chris Lattner
4a5dcf6029 tighten up StructInst::getOperandForField: it should abort if
the VarDecl passed in is null or computed, not just return null.


Swift SVN r12583
2014-01-20 16:51:16 +00:00
Doug Gregor
3a6db8292e Revert "Introduce the self_downcast SIL instruction to downcast the result of super.init."
We need to model the difference between Objective-C- and Swift-rooted
class hierarchies in SIL. IRGen is too late to handle nil returns.

This reverts commit 549db981ea0136a67aee3029aefe18a05d3c8833.

Swift SVN r12400
2014-01-16 06:01:21 +00:00
Doug Gregor
d19065048b Introduce the self_downcast SIL instruction to downcast the result of super.init.
No functional difference from the unconditional checked downcast we
had before, but this gives IRGen the chance to specialize the
implementation.

Swift SVN r12382
2014-01-16 04:24:56 +00:00
Doug Gregor
68e416bb21 SIL: Zap the unused "coerce" instruction.
The coercion doesn't represent anything interesting for SIL.


Swift SVN r12261
2014-01-13 23:50:12 +00:00
Doug Gregor
c6b880a9b7 Definite initialization for initializers relying on a separate ivar initializer.
When we decide to emit a separate ivar initializer method (via the
Objective-C entry point -.cxx_construct), we no longer initialize the
ivars within the initializer. This only happens for derived classes,
so teach DI about uninitialized 'self' values that require a
super.init call but don't require the ivars to be initialized.



Swift SVN r12240
2014-01-13 19:41:16 +00:00
Chris Lattner
d82df1e073 make the SIL Printer print the var decl associated with a debug_value[_addr],
like this:
  debug_value %0 : $Int64  // let a               // id: %2



Swift SVN r12191
2014-01-11 01:40:15 +00:00
Chris Lattner
1c7803a1f9 Introduce new debug_value and debug_value_addr instructions to
give 'let' declarations debug info.  This is part of rdar://15785053.

IRGen is just stubbed out and nothing generates these yet (other than
the sil parser).


Swift SVN r12179
2014-01-11 01:07:36 +00:00
Doug Gregor
3f09a9891d Add an [objc] bit to the alloc_ref instruction to indicate when to use Objective-C's +allocWithZone:.
Swift SVN r12099
2014-01-09 21:35:55 +00:00
Joe Groff
8f6a58b998 SIL: Split address-only enum dispatch from destructive projection.
Split 'destructive_switch_enum_addr' into separate 'switch_enum_addr' and 'take_enum_data_addr' instructions. This should unblock some optimization work we would like to do with enums.

Swift SVN r12015
2014-01-07 22:58:21 +00:00
Joe Groff
530e948cb2 SIL: Rename 'enum_data_addr' to 'init_enum_data_addr'.
Emphasize the fact that this address is only intended for initialization. When we split destructive_switch_enum_addr, there will be another similar instruction for destructively taking the payload out of an already-initialized enum.

Swift SVN r12000
2014-01-07 18:40:00 +00:00
Doug Gregor
1cf3bdbe8c Use objc_msgSendSuper[Stret] for foreign initializer delegation.
Introduce the SIL instruction peer_method, which references a method
in the given class or one of its superclasses (but not a subclass). It
IRGen's to objc_msgSendSuper[Stret] (vs. super_method IRGen'ing to
objc_msgSendSuper[Stret]2 for superclass lookup).

Use peer_method for initializer delegation to a foreign initializer
(i.e., an init-family method written in Objective-C) to close the
safety loophole introduced by initializer delegation in r11965. The
loophole still exists, but can only be triggered from Objective-C.

Teach definite initialization that peer_method really isn't a use of
self.



Swift SVN r11992
2014-01-07 17:33:41 +00:00
Chris Lattner
7e69153d14 merge the MUI flags for delegating self: there is no need to
differentiate the 'derived' and 'base' cases for delegating
initializers.  One is better than two.


Swift SVN r11981
2014-01-07 05:39:21 +00:00
Chris Lattner
6406e54138 teach silgen to produce the right mark_unintialized tags for delegating inits.
Swift SVN r11964
2014-01-06 23:33:06 +00:00
Chris Lattner
3f6ce3f888 introduce new flavors of MarkUninitializedInst to model delegating ctors to DI.
Swift SVN r11961
2014-01-06 23:13:41 +00:00
Michael Gottesman
51a25d965b Add code to CopyAddr for replacing its Src/Dest arguments.
Swift SVN r11954
2014-01-06 21:28:04 +00:00
Michael Gottesman
e99add7ea9 Add a helper method for setting an arbitrary operand to SILInstruction.h
Swift SVN r11953
2014-01-06 21:28:03 +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
Nadav Rotem
20410a3b92 CondBranchInst: Save the number of true and false arguments.
The current implementation depends on the target basic block to record the number of argumens, but this is a bad idea because it makes it difficult to modify the argument list.



Swift SVN r11597
2013-12-23 06:23:02 +00:00
Adrian Prantl
1f927d9ffc Overhaul the handling of return locations for auto-generated code.
- change SILGenFunction to use Cleanup and Implicit return locations for
  auto-generated cleanups/returns where sensible.
- Fix a bug in where ConstructorDecl that would return the wrong
  source range.
- Move the expected locations of some errors to the end of the function
  where they should belong.

Fixes <rdar://problem/15609768> Line tables for classes that don't have
init but just initialize ivars are odd

Swift SVN r11086
2013-12-10 19:23:34 +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
Chris Lattner
bf3948139d introduce a new "derived self" form of mark_uninitialized.
Swift SVN r11021
2013-12-09 15:25:46 +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
Chris Lattner
50f0de5937 rename the still-unused "rootinit" enum in MarkUninitialized to "RootSelf".
Teach silprinter to print the new flag.


Swift SVN r10776
2013-12-04 05:43:28 +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
Michael Gottesman
878cf0bb98 Rename SILInstructionMemoryBehavior => MemoryBehavior and move MemoryBehavior into SILInstruction.
Swift SVN r10770
2013-12-04 01:38:13 +00:00
Michael Gottesman
f81f8bdab1 Change mayWrite => mayWriteToMemory and mayRead => mayReadFromMemory to match the same methods in LLVM.
Swift SVN r10765
2013-12-03 23:36:28 +00:00
Michael Gottesman
301a42f140 Move SILInstruction::replaceAllUsesWith -> SILValue::replaceAllUsesWith.
This commit corrects, as Jim likes to put it, a "thinko".

Swift SVN r10760
2013-12-03 22:37:10 +00:00
Michael Gottesman
08181f9f75 Refactor out all result replaceAllUsesWith from SILCombine into SILInstruction::replaceAllUsesWith.
Swift SVN r10758
2013-12-03 22:24:48 +00:00
Michael Gottesman
d8d1393611 Implement SILInstruction::isIdenticalTo for all literal types in preparation for CSE.
The code here is a simple checklist. It performs the following checks in order:

1. Quick check to see if the kind/number of operands/number of types match up.
2. Comparison all of the types/operands.
3. Finally use a switch to perform specialized per instruction comparisons on
state not represented in the instructions types/operands (i.e. vardecls,
structdecls, etc.).

Additionally the switch is setup so that instructions which have not been fully
implemented in the switch will cause an unreachable to be hit. Once all
instructions have isIdenticalTo implementations (implying the switch is
covered), I will remove the unreachable.

*NOTE* The primary use case for this now is CSE. In CSE we can control which
instructions we process so during the review process I am only going to process
literals for the sake of simplicity (and thus this patch contains only code for
checking literals).

Swift SVN r10743
2013-12-03 00:26:10 +00:00
Michael Gottesman
38b9b2546d Add getTupleType/getStructDecl to TupleInst/StructInst respectively to wrap getting TupleTypes/StructDecls from the AST.
Also refactored out a little code in StructDecl to use the new method.

Swift SVN r10739
2013-12-03 00:02:44 +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
Chris Lattner
3b954ed44d strength reduce SILGenModule::getBuiltinInfo/getIntrinsicInfo to
take an identifier instead of a FuncDecl.


Swift SVN r10692
2013-11-30 00:57:46 +00:00
Chris Lattner
ec283ac8b9 add a SILInstruction::clone method that does a trivial copy of an instruction.
Swift SVN r10686
2013-11-29 23:36:51 +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
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
Chris Lattner
2909a0e129 teach simplifycfg to constant fold switch_enum instructions, now that
all the tuple stuff is out of the way.  This kicks in 600 times in the
stdlib and ends up shrinking the stdlib by 2500 lines (down to 53209).


Swift SVN r9903
2013-11-03 16:52:50 +00:00
Chris Lattner
8083f2d9c8 add setOperand() to unary instructions.
Swift SVN r9899
2013-11-03 05:53:23 +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