Commit Graph

373 Commits

Author SHA1 Message Date
Joe Groff
4d8d79712c SILGenPattern: Add debug output.
Give ClauseMatrix a dump method that gives nice columnar output of the current decision matrix, and add DEBUG output to emitSwitchStmt so there's more visibility into decision tree generation.

Swift SVN r9519
2013-10-20 05:20:03 +00:00
Joe Groff
a288f160ba SILGenPattern: Refactor clause matrix specialization to filter pattern set by each pattern.
No intended functionality change yet. For now this gives a slightly better constant factor to the O(n^2) linear scan for subsumed pattern nodes. Later on, for nominal type patterns, this will also give us an opportunity to collect the properties from all the equivalent patterns into one NominalTypePattern specialization.

Swift SVN r9297
2013-10-13 22:57:09 +00:00
Joe Groff
235f4e5017 SILGenPattern: Kill redundant helper function.
Swift SVN r8951
2013-10-07 02:18:17 +00:00
Joe Groff
9909ba275c SILGenPattern: Handle subsumption and orthogonality of superclasses in 'is' patterns.
Now that we can ask about superclasses outside of the type-checker, we can consider superclass relationships when pattern-matching 'is' patterns, producing better decision trees when a subclass checked is subsumed by a superclass check, a subclass check renders a superclass check redundant, or two classes or orthogonal and a check of one rules out the other.

Swift SVN r8769
2013-09-29 18:23:52 +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
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
John McCall
6f32a8464f Add a convenient method to create a new basic block.
Swift SVN r8326
2013-09-17 07:22:23 +00:00
Joe Groff
74aa05b724 SILGen: Handle () and arg-less union cases consistently in the face of substitutions.
Swift SVN r8259
2013-09-15 01:15:21 +00:00
Joe Groff
fcd8204042 SILGen: Substitute union element types when emitting union pattern matches.
Swift SVN r8257
2013-09-15 01:15:09 +00:00
Anna Zaks
a1f21b20d7 [SIL] Add a location to destructive_switch_union_addr + a couple more.
Swift SVN r7926
2013-09-05 00:01:56 +00:00
Anna Zaks
115a15830b [SIL] Replace empty locations with valid locations in tuple exploding/encoding and pattern gen code.
Tuple exploding happens during RValue construction, so changed the constructor and addElement() method to take the location parameter. The imploding happens on RValue::forwardAsSingleValue and RValue::getAsSingleValue(). Make sure the right SIL locations are passed to all of these

Also, added some missing locations in pattern matching code.

Swift SVN r7916
2013-09-04 21:57:52 +00:00
Joe Groff
1b07a4ed2b SILGenPattern: Spot fix. No functionality change.
Swift SVN r7829
2013-08-31 04:31:00 +00:00
Joe Groff
cfa8cb7518 SILGenPattern: Support address-only unions.
Switch on address-only unions using the destructive_switch_union_addr instruction. This is safe to do now thanks to r7812: The destructured value will now naturally be cleaned up instead of the invalidated union.

Swift SVN r7821
2013-08-30 23:50:34 +00:00
Joe Groff
3358955042 SILGenPattern: Destroy destructured subject rvalue before entering cases.
Before, we left the switch subject rvalue to be cleaned up at the close of the switch's scope. This is a bit wasteful because it keeps the rvalue live long after it's actually needed, and destroying the subject potentially requires replicating a bunch of destructuring we already do in the course of the pattern match. This patch changes things so that, just prior to entering a case, we clean up the destructured occurrence vector we have at the point of entering the case, which should be equivalent to but potentially more efficient than destroying the original subject rvalue.

Swift SVN r7814
2013-08-30 23:28:38 +00:00
Joe Groff
1e51c4992b SILGenPattern: Tidy up some weedy logic in ClauseRow::emitDispatch.
Swift SVN r7803
2013-08-30 21:42:26 +00:00
Joe Groff
e45792c084 SILGenPattern: Simplify tracking of ExprPattern guards.
We no longer need the separate pattern-to-value mapping in ClauseMatrix rows; that's handled by pattern variable binding now.

Swift SVN r7795
2013-08-30 19:12:48 +00:00
Anna Zaks
8f3c9002d0 [SIL] Add cleanup locations to SIL instructions.
I've decided to keep only the location of the scope AST node that corresponds to the cleanup. (Currently, there is no user that needs the originator expression, which caused the cleanup. So keeping things simple.)

Added the cleanup location to the Scope and JumpDest classes, which gets assigned on construction of those. The Scope's and JumpDest locations are used when we emit the cleanup instructions.

We now give better location info for 2 existing tests for definitive initialization.

(+ Rather sparse testing of all this.)

Swift SVN r7764
2013-08-29 23:14:22 +00:00
Joe Groff
202f65bb41 SILGen: Warm over some stale comments in SILGenPattern.
Swift SVN r7762
2013-08-29 23:08:12 +00:00
John McCall
02ce2fe199 Make is_nonnull produce a primitive Builtin.Int1 instead
of Bool, and use swift._getBool to turn that into a Bool
as necessary.

Swift SVN r7720
2013-08-29 06:47:15 +00:00
Dmitri Hrybenko
f7ab5bc7eb Change oneof -> union in a comment
Swift SVN r7662
2013-08-28 03:49:38 +00:00
Anna Zaks
b67f3c3552 [SIL] Use the ReturnLocation/ImplicitReturnLocation instead of generic SILLocations.
We mark the branch instructions leading into single epilog code with ReturnLocation/ImplicitReturnLocation. If SIL Gen simplifies the code and merges the code representing the return into the epilog block, the terminator of the epilog block (the ReturnInst) will have the return location info on it. Otherwise, the ReturnInst has the RegularLocation, which represents the enclosing FunctionExpr or Constructor/Destructor Decls.
(I've discussed dropping the optimization from SILGen, and keeping the epilog code canonical, with Adrian; but he said that there might not be any wins in doing so, so keeping it for now.)

Added AutoGeneratedLocation to represent segments of code generated by SILGen. This will be used for thunks and other auto-generated segments.

Swift SVN r7634
2013-08-27 22:16:24 +00:00
Adrian Prantl
a1c6b653ad Move DebugScopeStack from SILBuilder to SILGenFunction, using the swift new
InsertedInstrs facility.
No functionality change intended.

Swift SVN r7520
2013-08-23 20:11:44 +00:00
Stephen Lin
8d90466523 Reorganize SIL source tree: move lib/SIL/SILGen -> lib/SILGen, move lib/SIL/Passes -> lib/SILPasses, add lib/SILPasses/Utils
Swift SVN r7246
2013-08-14 23:47:29 +00:00