Commit Graph

6634 Commits

Author SHA1 Message Date
Nadav Rotem
ccf3a127f2 Add a simple generic specialization pass.
Swift SVN r10885
2013-12-05 22:20:05 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Manman Ren
cae5ebace2 isDefinition() should return IsDefinition.
Swift SVN r10825
2013-12-05 01:32:35 +00:00
Chris Lattner
3194e88697 add a helper for ref_element_addr that doesn't require a result type,
mirroring tuple_ and struct_element_addr


Swift SVN r10808
2013-12-04 23:08:45 +00:00
Chris Lattner
e4c2231718 Add some operator-> implementations to iterators to match their operator*
implementations.


Swift SVN r10777
2013-12-04 06:04:07 +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
John McCall
007d3974d6 Use a proper mangling to try to share reabstraction thunks.
Swift SVN r10764
2013-12-03 23:23:52 +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
55a05b4951 [cse] Actually follow the directions from Hashing.h and put hash_value into swift namespace. Also remove a few const.
Swift SVN r10754
2013-12-03 21:38:17 +00:00
Michael Gottesman
faea4d5f60 [cse] Implement hash_value for SILValue and SILType.
*NOTE* I followed the hashing conventions used in the DenseMap hashing
implementations.

Swift SVN r10745
2013-12-03 01:07:54 +00:00
Michael Gottesman
9e77cf2103 Canonicalize the header guards for SILType.h and SILValue.h.
Swift SVN r10744
2013-12-03 01:06:14 +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
Michael Gottesman
177f48a897 Change SILSuccessorIterator++() to be a canonical preincrement and add in a postincrement operator.
Swift SVN r10737
2013-12-02 22:52:01 +00:00
Michael Gottesman
90082a51f1 Add in a swift namespace typedef DominanceInfoNode for llvm::DomTreeNodeBase<SILBasicBlock>.
This complements the DominanceInfo class.

Swift SVN r10736
2013-12-02 22:52:00 +00:00
Michael Gottesman
7e95367de9 [PatternMatch] Change m_Apply_Ty => Apply_match to match the rest of the matcher structs.
Swift SVN r10734
2013-12-02 22:20:08 +00:00
Chris Lattner
27a94b9309 add some helpers to SILBuilder, NFC.
Swift SVN r10699
2013-12-01 05:08:45 +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
Michael Gottesman
81ab6382b9 Add a template specialization to PatternMatch::match for SILValue to eliminate need for match(&*Value) to match.
I also updated the relevant code to use match(Value) instead of match(&*Value).

Swift SVN r10659
2013-11-22 06:37:13 +00:00
Chris Lattner
e84acdb107 one more lvalue -> addr in a parameter name.
Swift SVN r10655
2013-11-22 01:39:01 +00:00
Chris Lattner
eb88f82168 parameter naming changes: refer to addresses, not lvalues in SIL.
Swift SVN r10653
2013-11-22 00:47:16 +00:00
Chris Lattner
0e6bec9fb0 Enhance emitDestroyAddr to return the instruction it produces, if it does.
Swift SVN r10628
2013-11-21 07:18:31 +00:00
John McCall
4bba9b38f8 Make several new interfaces traffic in AbstractionPatterns.
Swift SVN r10621
2013-11-21 02:19:46 +00:00
Adrian Prantl
6e075ae220 Add the missing debug scopes to functions cloned by the capture promotion
pass.

Swift SVN r10618
2013-11-21 00:50:53 +00:00
Chris Lattner
07ce5306f3 add a SILType::isTrivial helper function.
Swift SVN r10610
2013-11-20 22:53:49 +00:00
Doug Gregor
84cf9d1183 Cope with local functions within a generic context that have no captures.
Previously, we were just ignoring the generic parameters. Should
finish off <rdar://problem/15463549>.


Swift SVN r10570
2013-11-20 00:01:19 +00:00
Michael Gottesman
a18e25f314 Add SILArgument/SILUndef includes to PatternMatch.h since we generate matchers for SILArgument, SILUndef.
Swift SVN r10567
2013-11-19 23:34:40 +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
Stephen Lin
4ebdf9c80f Capture Promotion: have new closures inserted before their original versions
Swift SVN r10554
2013-11-19 03:29:00 +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
Chris Lattner
22240080b1 move SILFunction::dump out of line, so that LLDB can find it.
Swift SVN r10544
2013-11-18 17:53:39 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +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
0cc9417fef SIL: Introduce a SILGlobalVariable concept.
This will let us control linkage and emit new variables independent of the AST in SILGen. In particular, for lazy global initialization, we need to emit a unique internal once predicate for every top-level pattern binding. Switching everything over is a bit much to reengineer all at once, so for now, it can coexist with the globals map that is already there.

Swift SVN r10509
2013-11-16 00:50:17 +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
9570e1fb0c Remove the "createStrongRetain" and "createStrongRelease" SILBuilder methods.
They are the same as createStrongRetainInst and createStrongReleaseInst, but
peephole away FunctionRefInst.  It turns out that there is only a couple
places in SILGen where this behavior is necessary, and this tramples on the
general pattern used in SILBuilder.


Swift SVN r10448
2013-11-14 02:00:41 +00:00
Chris Lattner
b2ac1db9f6 introduce a new helper to SILBuilder that emits a StrongRelease operation,
scanning up the local block to see if it immediately cancels a retain 
operation.

Use this in mandatory inlining to zap more retains and release.  Before
this patch, the result LogicValue allocation blocked this optimization,
preventing the partial_apply from being deleted from the case in 
rdar://15328833.




Swift SVN r10447
2013-11-14 01:50:28 +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
a4237e2c7d whitespace changes.
Swift SVN r10413
2013-11-13 05:46:28 +00:00
John McCall
4d51545508 Abstract out a function to print a SILLocation during
PrettyStackTrace and fix it to handle AST-less SILLocations.

Swift SVN r10340
2013-11-11 19:52:33 +00:00
John McCall
2ed33e4ffa Make convenient accessors for getting a lowered SILType for
a struct/class field or a tuple element.

Make DefiniteInitialization traffic in SILTypes more.

Swift SVN r10055
2013-11-08 22:04:04 +00:00
Joe Groff
9c0e07fe35 SIL: Capture generic parameters through nested closures.
We were failing to capture generic parameters from closure contexts that themselves capture generic parameters from context. This fixes <rdar://problem/15417783>. While we're here, eliminate some unnecessary splitting of 'ClosureExpr' and 'AutoClosureExpr' in the SILDeclRef::Loc PointerUnion; we can just use their base class AbstractClosureExpr in the PointerUnion.

Swift SVN r10031
2013-11-07 23:39:37 +00:00
Doug Gregor
eb7ce396db Use VarDecl::get[GS]etterType() and SubscriptDecl::get[GS]etterType() in SILGen
Eliminate SILGen's own computation of getter/setter types in favor of
the AST methods to compute the same.


Swift SVN r9992
2013-11-06 06:53:13 +00:00
Mark Lacey
0ec7617a2c Simplify enum and Int1 integer_literal instructions.
In cases like the one below, replace the integer_literal instructions
with the condition branching to the block that the instruction is in.

    cond_br %10, bb1, bb3

  bb1:
    %13 = integer_literal $Builtin.Int1, -1
    br bb2(%13 : $Builtin.Int1)

  bb3:
    %18 = integer_literal $Builtin.Int1, 0
    br bb2(%18 : $Builtin.Int1)

Similarly, for
    switch_enum %0 : $Bool, case #Bool.true!enumelt: bb1
  bb1:
    %1 = enum $Bool, #Bool.true!enumelt

  we'll replace the enum with %0.

Use this functionality from within the CFG simplification pass to
simplify basic block args in an attempt to expose opportunities for
further CFG simplification.

Swift SVN r9968
2013-11-05 19:11:45 +00:00