Commit Graph

9332 Commits

Author SHA1 Message Date
John McCall
fcd998a48b PrettyStackTrace enhancements for SIL constructs.
Swift SVN r6966
2013-08-07 00:10:57 +00:00
John McCall
eaf693aace Constify SILLocation.
Swift SVN r6965
2013-08-07 00:10:56 +00:00
John McCall
b0084f7204 Prepare SILType for more than just isAddress.
Swift SVN r6946
2013-08-06 20:23:12 +00:00
John McCall
36aa6c2645 alloc_stack needs to return two values like alloc_box.
The current implementation of dealloc_stack in IR-gen is a
no-op, but that's very much wrong for types with non-trivial
local allocation requirements, e.g. archetypes.  So we need
to be able to do non-trivial code here.  However, that means
modeling both the buffer pointer and the allocated address
in SIL.

To make this more type-safe, introduce a SIL-specific
'[local_storage] T' type that represents the required
allocation for locally storing a T.  alloc_stack now returns
one of those in additon to a *T, and dealloc_stack expects
the former.

IR-gen still implements dealloc_stack as a no-op, but
that's now easy to fix.

Swift SVN r6937
2013-08-06 07:31:41 +00:00
John McCall
adfba641a8 Eliminate AllocInst, which does nothing for us.
Swift SVN r6936
2013-08-06 07:31:38 +00:00
John McCall
592732c6b4 Split *one* unimplemented dealloc_ref instruction into
*two* unimplemented instructions!  This is progress.

Swift SVN r6931
2013-08-06 01:23:51 +00:00
Anna Zaks
7a042cf44f [SIL] Issue a diagnostic on a non-exhaustive switch
The issue is truly diagnosed in SILGen and an unreachable instruction is
inserted in cases where the switch is not fully covered. However, we issue
the diagnostic later on in DataflowDiagnostics pass.

John has suggested that it's best to diagnose this after DCE because
we should not warn in cases where the switch is not fully covered,
but we can show that the non-covered cases are not reachable.

Swift SVN r6929
2013-08-06 01:13:48 +00:00
Manman Ren
bfe0c39884 SIL Parser: parse builtin_function_ref.
In SILParser, factor out lookupTopDecl and lookupMember.
lookupTopDecl finds the top-level ValueDecl or Module given a name and
lookupMember finds the ValueDecl given a type and a member name.
Update comments for parseSILDeclRef to match SIL.rst.
We now handle the case where the first component of a dotted path is a
module.

In SILPrinter, print the full path for builtin_function_ref, also
"!" is optional when printing SILDeclRef.


Swift SVN r6926
2013-08-06 00:53:07 +00:00
Chris Lattner
5b3ddf78c6 more scaffolding for the new memory promotion pass. This still doesn't
do anything yet, so I can't write a useful functionality test.


Swift SVN r6925
2013-08-05 23:56:35 +00:00
Chris Lattner
b3fadfc31b Add the outline of a new SIL memory promotion pass. This is what will handle
definite initialization, promoting boxes to stack, building ssa, and doing definite
initialization.

I'll build this in place, then kill off the other two passes when this subsumes them.


Swift SVN r6903
2013-08-05 16:39:26 +00:00
Chris Lattner
75302208f6 teach alloc_box promotion to promote boxes that are dealloc_ref'd instead of released.
Swift SVN r6893
2013-08-05 15:18:36 +00:00
Chris Lattner
117f47f527 remove the hasFixedLifetime bit from ValueDecl, now that AST-level
capture analysis is gone.  This functionality is subsumed by SIL passes,
which turn boxes into stack allocations.

One minor detail of this is that dealloc_ref isn't implemented yet in IRGen
(rdar://14648382) and SILGen produces it for destructors (e.g. see 
test/SILGen/lifetime.swift).  To unblock progress, I just removed the 
llvm_unreachable in IRGen.


Swift SVN r6890
2013-08-05 14:59:08 +00:00
Chris Lattner
beefd78270 teach the box to stack pass that ProtocolMethodInst doesn't
cause an existential to escape.  This (in conjunction with Joe's
patch to SILGen) allows us to handle the protocol case that the
old capture analysis was able to promote.



Swift SVN r6882
2013-08-03 15:09:40 +00:00
John McCall
b77c430848 Add SIL-gen and some missing runtime support for [unowned].
Swift SVN r6881
2013-08-03 08:46:54 +00:00
John McCall
d7b6009374 Introduce the concept of the "semantic" type of a lowered
type and audit a great deal of code to deal with it appropriately.

Spot fixes in a few other places.

Fixes rdar://14615768

Swift SVN r6879
2013-08-03 05:59:19 +00:00
Adrian Prantl
69e1af34fd Adrian reviewed this.
Swift SVN r6875
2013-08-03 02:14:43 +00:00
Joe Groff
4316239f5d Kill Builtin.OpaquePointer.
It's not needed by SIL anymore.

Swift SVN r6873
2013-08-03 01:56:06 +00:00
Joe Groff
5a2128bc77 SIL: Model project_existential using an address.
Have project_existential return $*This instead of $Builtin.OpaquePointer, and have protocol_method do the same for methods of opaque protocols. This makes it easier for passes to reason about the semantics of the projected address, since it's restricted by the semantics of SIL addresses.

Swift SVN r6872
2013-08-03 01:48:15 +00:00
Joe Groff
ea4ace470d SILGen: Implement UnionElementPattern dispatch.
Build a switch_union instruction over all the matched union elements, and check for exhaustiveness to see if we need to emit a default branch either for subsequent matches or to fall off the end and emit unreachable if we run out of cases.

Swift SVN r6870
2013-08-02 23:26:18 +00:00
Joe Groff
a851072a25 SIL: Ensure all terminators are handled by TermInst::getSuccessors.
Create a separate TERMINATOR xmacro in SILNodes.def that only expands for terminators. Use it in TermInst::getSuccessors to automatically delegate to leaf terminator getSuccessors implementations without requiring additional maintenance work when new terminator instructions are added in the future.

Swift SVN r6869
2013-08-02 23:26:17 +00:00
Anna Zaks
aa0468a939 [DCE] Remove code after a call to a 'noreturn' function.
This also makes sure that the missing return diagnostic is not issued
on code following a call to a 'noreturn' function.

Swift SVN r6864
2013-08-02 22:49:33 +00:00
Anna Zaks
fcc25996eb [DCE] Remove a redundant FIXME.
Since in SIL the basic blocks do not store the incoming arguments
(no PHI-nodes), the successor's arguments do not need to be adjusted
when predecessor drops the terminator instruction.

Swift SVN r6863
2013-08-02 22:49:31 +00:00
John McCall
796e434f63 Make "isTake" and "isInitialization" flags type-safe.
Swift SVN r6860
2013-08-02 22:38:14 +00:00
Joe Groff
984266c300 SILGen: Refactor pattern dispatch to allow switch-like dispatch.
Emit the dispatch tree up-front instead of interleaving it with specializations. This doesn't have any user-visible effect yet, but will allow for dispatch to use switch-like instructions such as switch_oneof when appropriate.

Swift SVN r6847
2013-08-02 19:09:14 +00:00
John McCall
d7a72b93e1 Add ref_to_unowned and unowned_to_ref bitcast instructions.
Swift SVN r6838
2013-08-02 08:31:01 +00:00
Anna Zaks
29d2d8fb92 [SIL] Add memory behavior bit to SIL instruction definition.
As per code review discussion for r 6763.

The memory behavior enumeration is currently a subset of what it could be. Let’s add more kinds as needed.

Swift SVN r6830
2013-08-02 01:27:57 +00:00
John McCall
00a940ac1b Rename weak_retain to unowned_retain and change it to
require the correct [unowned] type as an argument.

Swift SVN r6825
2013-08-02 00:02:09 +00:00
Anna Zaks
ae94c8c48e [DCE] Propagate BB arguments when simplifying a conditional branch into unconditional one
Swift SVN r6819
2013-08-01 21:32:06 +00:00
Anna Zaks
2c529eb21a [SILParser] Parse basic block arguments in branch instructions
Added types when printing these args in the SIL printer.

As a side effect, I've removed the assertions that check
that we have the correct number of arguments in the Branch instruction
creation routines. The reason is that we do not have a complete block when
parsing and creating the branch instruction and it is possible to add
arguments to a basic block after creation. The assertion will be checked
by the SIL verifier.

Swift SVN r6818
2013-08-01 21:32:05 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Chris Lattner
ae14cb0b29 update location information more precisely in this pass. Nothing uses this, I just noticed this by inspection.
Swift SVN r6806
2013-08-01 05:57:55 +00:00
Joe Groff
3503ffe4fa IRGen: Set up LinkEntities for protocol witness tables.
We need to handle three cases:

- If a protocol conformance has no associated types, or the associated type witnesses all have statically resolvable metadata, we can expose a *direct* witness table symbol.
- If a protocol conformance has associated types with runtime-instantiated metadata, we need to gate the witness table behind a *lazy* initializer function to fill in the metadata fields.
- If a protocol conformance has associated types where the type or one of its conformances are *dependent* on its parent's generic parameters, we need to instantiate multiple witness tables at runtime.

Swift SVN r6805
2013-08-01 05:25:32 +00:00
Joe Groff
28c53dbf69 SILGen: Mark address-only missing returns unreachable too.
The epilog BB not taking an argument is enough by itself to determine whether we are allowed to fall into it; address-only returns do not use a BB argument to return. Break 'NeedsReturn' back out into its own bit and set it based on the Swift type passed to prepareEpilog.

Swift SVN r6802
2013-08-01 02:20:53 +00:00
John McCall
b6d49ea46d Give some dynamic behavior to TypeLowering and lay out
some groundwork for more customization.

Swift SVN r6799
2013-08-01 01:28:39 +00:00
John McCall
9f6e2bf9bb Permit Patterns in SILLocation as well.
Swift SVN r6798
2013-08-01 01:28:38 +00:00
John McCall
170fb49790 Prettify the stack trace when crashing in SIL-gen.
Swift SVN r6796
2013-08-01 01:28:36 +00:00
John McCall
f46ffb3382 Shorten "TypeLoweringInfo" to "TypeLowering".
Swift SVN r6795
2013-08-01 01:28:34 +00:00
Joe Groff
ba774364f1 SIL: Have SILModules track their SILStage.
Modules can be in either 'Raw' or 'Canonical' form, with different invariants on each. We don't actually distinguish those invariants yet, but this patch adds the field to SILModule and adds a "sil_stage" declaration to SIL printer/parser syntax.

Swift SVN r6793
2013-08-01 00:58:31 +00:00
Chris Lattner
5179d44ebb The FuncExpr hierarchy got refactored, remove this dead function.
Swift SVN r6785
2013-07-31 22:09:01 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Joe Groff
4322494ed1 SILGen: Emit a single epilog block for returns.
Funnel all top-level cleanups and returns through a single epilog block instead of re-emitting the cleanups and returns for every 'return' statement like an idiot.

This has some interesting interactions with other features that need additional work:

- ReturnInst's SILLocation is no longer naturally associated with a single source location, which complicates return analysis diagnostics. For now, I just save the location of the first ReturnStmt we see and tag the ReturnInst with that, but we should do better.

- We still duplicate cleanups below the top level like chumps. I still need to resurrect the CleanupOutflows stuff from the old IRGen backend.

- A DebugInfo test breaks. Adrian will have to look into that.

Swift SVN r6782
2013-07-31 20:55:29 +00:00
Joe Groff
88f3714b75 SILGen: Always emit materialized destruction as destroy_addr.
For nontrivial, non-address-only types, we want definitive analysis to be able to recognize destruction of unused, uninitialized variables without barfing on an apparent load of an uninitialized value. Definitive analysis will be responsible for canonicalizing destroy_addr to loads + releases for values where we can do so.

Swift SVN r6771
2013-07-31 02:32:33 +00:00
Joe Groff
1e31a93d90 SILGen: Don't leak ignored address-only arguments.
Swift SVN r6770
2013-07-31 02:18:42 +00:00
Anna Zaks
00f9b00051 [DCE] Add dead instruction removal stage.
Swift SVN r6766
2013-07-30 23:08:38 +00:00
Anna Zaks
930b95cdb0 [SIL] Add SILInstruction::mayHaveSideEffects helper.
Swift SVN r6765
2013-07-30 23:08:37 +00:00
Joe Groff
cc45633714 SIL: Don't print instruction labels for value-less instructions.
Swift SVN r6756
2013-07-30 22:33:34 +00:00
Joe Groff
26c00fd429 SIL: Add a switch_int instruction.
This will help represent cleanup blocks in the grown-up Clang way instead of the childish SILGen way, e.g.:

  retain %x
  retain %y
  ...
break_branch:
  %1 = int_literal 1 : $Builtin.Int64
  br cleanup(%1)
return_branch:
  %2 = int_literal 2 : $Builtin.Int64
  br cleanup(%2)
cleanup(%dest : $Builtin.Int64):
  release %z
  release %y
  switch %dest, case 1: break_dest, case 2: return_dest

Swift SVN r6753
2013-07-30 21:32:23 +00:00
Argyrios Kyrtzidis
21785c8a36 Call Type::print(), instead of TypeBase::print(); the former includes the null check.
Swift SVN r6751
2013-07-30 21:25:36 +00:00
Chris Lattner
bb82314400 teach stacktossa to completely remove alloc_stacks when it can.
Swift SVN r6738
2013-07-30 16:06:07 +00:00
Joe Groff
6fb008f9d1 SIL: Verify against upcasts and super_methods to same type.
These verifier rules will help catch bugs in a similar vein to <rdar://problem/14581294> in the future.

Swift SVN r6721
2013-07-29 22:52:05 +00:00