Commit Graph

3719 Commits

Author SHA1 Message Date
Michael Gottesman
3571b1dfcd Merge pull request #27405 from gottesmm/pr-daa53ba2f8269780ddc64f9c0e0423ec9b63ac32
[apply-site] Refactor out a helper function called insertAfterApply -…
2019-09-30 12:27:32 -07:00
Michael Gottesman
471c7479c7 [debug-utils] Split deleteAllDebugUses(ValueBase *) into SILValue and SILInstruction variants.
The SILInstruction variant calls the SILValue version for each of its results.
2019-09-30 10:33:52 -07:00
swift-ci
46823c086d Merge pull request #27236 from apple/vg-doc-siltype-getASTType 2019-09-27 17:17:23 -07:00
Michael Gottesman
2940e7d561 [apply-site] Refactor out a helper function called insertAfterApply -> ApplySite.insertAfter().
Often times when one is working with apply sites, one wants to insert
instructions after both terminator apply sites and normal apply sites. This can
get ackward and result in unnecessary if-else code that is all really doing the
same thing, once for terminator instructions and once for normal instructions.

insertAfterApply is a helper method that MandatoryInlining uses for this purpose
and it is so useful that I want to use it somewhere else in closure lifetime
fixup as well. I am moving it onto apply site since that is the true abstraction
that insertAfterApply works with.
2019-09-27 09:54:11 -07:00
Harlan Haskins
d4247942c4 Merge remote-tracking branch 'upstream/master' into master-next 2019-09-26 20:19:25 -07:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Varun Gandhi
a744607896 [NFC] Add some notes to getASTType()'s docstring. 2019-09-26 15:16:55 -07:00
swift-ci
6945d6192d Merge remote-tracking branch 'origin/master' into master-next 2019-09-26 09:29:43 -07:00
nate-chandler
b9b4196470 Merge pull request #27239 from nate-chandler/39957093-argument-explosion-heuristic
[SILOptimizer] Alter FSO arg explosion heuristic.
2019-09-26 09:19:15 -07:00
swift-ci
a51f101f2f Merge remote-tracking branch 'origin/master' into master-next 2019-09-25 20:29:37 -07:00
Michael Gottesman
f9f3f53420 [ownership] Add support for adding {end,abort}_apply to the regular user list of owned parameters passed as guaranteed parameters to a begin_apply.
This just follows automagically from the recent work that I did with introducing
BorrowScopeIntroducingOperands.

I confirmed locally that the negative tests do not fail as expected when
visiting the destroys of the guaranteed parameters.
2019-09-25 19:06:59 -07:00
Michael Gottesman
59a57ed044 [ownership] Introduce a new BorrowScopeIntroducingOperand that is used to work with implicit uses of owned parameters implied by their use by a borrow scope introducing value.
For now this only is used for ensuring that an owned value that has a
begin_borrow use, adds the end_borrows matched to the begin_borrow to the owned
values implicit regular user list.

I am going to use this same functionality to model the requirements around
begin_apply and mark_dependence (when I add an end_mark_dependence instruction).
2019-09-25 19:06:59 -07:00
swift-ci
37ab3895b9 Merge remote-tracking branch 'origin/master' into master-next 2019-09-25 17:30:19 -07:00
Ravi Kandhadai
7189c09720 Merge pull request #27344 from ravikandhadai/constexpr-arrays
[Constant Evaluator] Support Arrays in the constant evaluator.
2019-09-25 17:15:20 -07:00
swift-ci
ea4d408732 Merge remote-tracking branch 'origin/master' into master-next 2019-09-24 21:29:40 -07:00
Doug Gregor
9b20012ee1 Merge pull request #27322 from DougGregor/property-wrapper-composition-di
[DI] Support definite initialization for composed property wrappers.
2019-09-24 21:22:43 -07:00
swift-ci
7681a7e900 Merge remote-tracking branch 'origin/master' into master-next 2019-09-24 16:49:41 -07:00
adrian-prantl
5ad6bee628 Merge pull request #27238 from adrian-prantl/silcloner-varinfo
Debug Info: Add missing debug info propagation to SILCloner.
2019-09-24 16:48:35 -07:00
Marc Rasi
874bb1df25 [Constant Evaluator] Support Array constants in the constant
evaluator. Add support for evaluating array initializations
and array append.
2019-09-24 15:18:14 -07:00
Adrian Prantl
5b92814a0e Debug Info: Add missing debug info propagation to SILCloner.
While tightening the requirements of the debug info generator in
IRGenSIL I noticed that SILCloner didn't correctly transfer variable
debug info on alloc_box and alloc_stack instructions. In order to make
these mistakes easier to find I added an assertion to SILBuilder and
fixed all issues uncovered by that assertion, too.

The result is a moderate increase in debug info coverage in optimized code.

On stdlib/public/core/OSX/x86_64/Swift.o "variables with location"
increases from 60134 to 60299.
2019-09-24 14:10:25 -07:00
swift-ci
c1846c8cd7 Merge remote-tracking branch 'origin/master' into master-next 2019-09-24 12:50:34 -07:00
Doug Gregor
ab5d161c05 [SILGen] Separate the initialization of a wrapped property from a wrapped value
Teach SILGen to emit a separate SIL function to capture the
initialization of the backing storage type for a wrapped property
based on the wrapped value. This eliminates manual code expansion at
every use site.
2019-09-24 09:11:53 -07:00
Michael Gottesman
12aa95ac1e [ownership] Only allow BranchPropagatedUser to be constructed from Operands.
This commit only changes how BranchPropagatedUser is constructed and does not
change the internal representation. This is a result of my noticing that
BranchPropagatedUser could also use an operand internally to represent its
state. To simplify how I am making the change, I am splitting the change into
two PRs that should be easy to validate:

1. A commit that maps how the various users of BranchPropagatedUser have been
constructing BPUs to a single routine that takes an Operand. This leaves
BranchPropagatedUser's internal state alone as well as its user the Linear
Lifetime Checker.

2. A second commit that changes the internal bits of the BranchPropagatedUser to
store an Operand instead of a PointerUnion.

This will allow me to use the first commit to validate the second.
2019-09-23 17:24:55 -07:00
Michael Gottesman
39c202d487 [sil] Add a new helper method CondBranchInst::isConditionOperand.
I am doing some refactoring on BranchPropagatedUser that is requiring me to work
a lot more with arguments and I found a need for this to avoid trafficing in
operand indices.

As part of this I also needed to write the helper getConditionOperand() to get
the underlying operand. I refactored the already preset getCondition() to use
this helper instead since it was just semantically that method + get operand's
value.
2019-09-23 17:24:55 -07:00
Michael Gottesman
860192b90c [sil] Add a new helper method ApplySite::getCalleeOperand().
I need this for some refactorings I am doing around BranchPropagatedUser.

We already had ApplySite::getCallee() which just returned the value of the
operand. I refactored it to call this instead.
2019-09-23 17:24:55 -07:00
swift-ci
756ec9e826 Merge remote-tracking branch 'origin/master' into master-next 2019-09-23 13:50:41 -07:00
Michael Gottesman
6f5e5e61f5 Fix no-asserts build. 2019-09-23 11:42:57 -07:00
swift-ci
5343bef360 Merge remote-tracking branch 'origin/master' into master-next 2019-09-21 02:29:31 -07:00
Michael Gottesman
e90a68fa17 [polymorphic-builtins] Teach dataflow diagnostics how to emit an error if it sees an unspecialized polymorphic builtin.
This will ensure that if an expert user is using this feature and makes a
mistake as a result of tweaking their code, they get an error. This will ensure
they do not ship and look into why this is happening.

This is not intended to be used by anyone except for expert stdlib users.
2019-09-20 17:25:56 -07:00
Nate Chandler
851d9f44d0 [Gardening] Minor cleanup to Projection.h.
Replaced some namespace qualified references to ArrayRef and Optional
with the unqualified type.  Reordered the includes per clang-format.

Excerpted from @gottesm's https://github.com/apple/swift/pull/16756.
2019-09-20 10:02:04 -07:00
Nate Chandler
9bd6fec697 [SILOptimizer] Projection tree can vend users.
Added getUsers to ProjectionTree.  The new method vands, via an out
parameter, a set of all the users of all of the nodes in the projection
tree that are themselves not in the projection tree by way of
getNonProjUsers.  Took this opportunity to tweak getNonProjUsers to vend
a const ArrayRef rather than a SmallVector.

Excerpted from @gottesm's https://github.com/apple/swift/pull/16756.
2019-09-20 09:32:16 -07:00
Nate Chandler
70ad47332e [SILOptimizer] ProjectionTree can vend leaf types.
Added getAllLeafTypes to ProjectionTree.  The new method vends, via an
out paramter, a vector containing the types of all the leaves in a
projection tree in the order that they appear.  The method relies uses a
new convenience on ProjectionTreeNode, isLeaf to include only the types
of those nodes which are leaves.

Excerpted from @gottesm's https://github.com/apple/swift/pull/16756.
2019-09-20 09:23:21 -07:00
swift-ci
c8bcda3c9a Merge remote-tracking branch 'origin/master' into master-next 2019-09-19 19:09:06 -07:00
Michael Gottesman
9864cb9c06 [polymorphic-builtins] Teach constant folding how to fold a polymorphic builtin to its static overload if the passed in type is a concrete builtin type
Specifically, this transforms:

builtin "generic_add"<Builtin.Vec4xInt32>(

  ->

builtin "add_Vec4xInt32"(

If we do not have a static overload for the type, we just leave the generic call
alone. If the generic builtin takes addresses as its arguments (i.e. 2x
in_guaranteed + 1x out), we load the arguments, evaluate the static overloaded
builtin and then store the result into the out parameter.
2019-09-19 17:10:14 -07:00
swift-ci
1155f033a4 Merge remote-tracking branch 'origin/master' into master-next 2019-09-19 13:29:07 -07:00
Michael Gottesman
20c5dff4b5 [builtin] Implement polymorphic builtins for all BUILTIN_BINARY_OPERATIONs.
TLDR: This patch introduces a new kind of builtin, "a polymorphic builtin". One
calls it like any other builtin, e.x.:

```
Builtin.generic_add(x, y)
```

but it has a contract: it must be specialized to a concrete builtin by the time
we hit Lowered SIL. In this commit, I add support for the following generic
operations:

Type           | Op
------------------------
FloatOrVector  |FAdd
FloatOrVector  |FDiv
FloatOrVector  |FMul
FloatOrVector  |FRem
FloatOrVector  |FSub
IntegerOrVector|AShr
IntegerOrVector|Add
IntegerOrVector|And
IntegerOrVector|ExactSDiv
IntegerOrVector|ExactUDiv
IntegerOrVector|LShr
IntegerOrVector|Mul
IntegerOrVector|Or
IntegerOrVector|SDiv
IntegerOrVector|SRem
IntegerOrVector|Shl
IntegerOrVector|Sub
IntegerOrVector|UDiv
IntegerOrVector|Xor
Integer        |URem

NOTE: I only implemented support for the builtins in SIL and in SILGen. I am
going to implement the optimizer parts of this in a separate series of commits.

DISCUSSION
----------

Today there are polymorphic like instructions in LLVM-IR. Yet, at the
swift and SIL level we represent these operations instead as Builtins whose
names are resolved by splatting the builtin into the name. For example, adding
two things in LLVM:

```
  %2 = add i64 %0, %1
  %2 = add <2 x i64> %0, %1
  %2 = add <4 x i64> %0, %1
  %2 = add <8 x i64> %0, %1
```

Each of the add operations are done by the same polymorphic instruction. In
constrast, we splat out these Builtins in swift today, i.e.:

```
let x, y: Builtin.Int32
Builtin.add_Int32(x, y)
let x, y: Builtin.Vec4xInt32
Builtin.add_Vec4xInt32(x, y)
...
```

In SIL, we translate these verbatim and then IRGen just lowers them to the
appropriate polymorphic instruction. Beyond being verbose, these prevent these
Builtins (which need static types) from being used in polymorphic contexts where
we can guarantee that eventually a static type will be provided.

In contrast, the polymorphic builtins introduced in this commit can be passed
any type, with the proviso that the expert user using this feature can guarantee
that before we reach Lowered SIL, the generic_add has been eliminated. This is
enforced by IRGen asserting if passed such a builtin and by the SILVerifier
checking that the underlying builtin is never called once the module is in
Lowered SIL.

In forthcoming commits, I am going to add two optimizations that give the stdlib
tool writer the tools needed to use this builtin:

1. I am going to add an optimization to constant propagation that changes a
"generic_*" op to the type of its argument if the argument is a type that is
valid for the builtin (i.e. integer or vector).

2. I am going to teach the SILCloner how to specialize these as it inlines. This
ensures that when we transparent inline, we specialize the builtin automatically
and can then form SSA at -Onone using predictable memory access operations.

The main implication around these polymorphic builtins are that if an author is
not able to specialize the builtin, they need to ensure that after constant
propagation, the generic builtin has been DCEed. The general rules are that the
-Onone optimizer will constant fold branches with constant integer operands. So
if one can use a bool of some sort to trigger the operation, one can be
guaranteed that the code will not codegen. I am considering putting in some sort
of diagnostic to ensure that the stdlib writer has a good experience (e.x. get
an error instead of crashing the compiler).
2019-09-19 11:42:10 -07:00
swift-ci
b76e9ec111 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 19:49:09 -07:00
Ravi Kandhadai
22861ec0fd [Constant Evaluator] Pass assert configuartion option to the
evaluator to precisely evaluate Builtin.assert_configuration.

Unify UnknownReason::Trap and UnknownReason::AssertionFailure error
values in the constant evaluator, now that we have 'condfail_message'
SIL instruction, which provides an error message for the traps.
2019-09-18 17:35:46 -07:00
swift-ci
8ce5b01307 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 15:09:47 -07:00
Slava Pestov
533d41d0db SIL: Compute lowered local captures of SILDeclRefs and not AnyFunctionRefs
Unfortuantely this commit is bigger than I would like but I couldn't think
of any reasonable ways to split it up.

The general idea here is that capture computation is now done for a
SILDeclRef and not an AnyFunctionRef. This allows SIL to represent the
captures of a default argument generator.
2019-09-18 14:26:01 -04:00
Slava Pestov
e1e6f0e7ba SIL: Refactor type lowering computation of the effective generic signature
This also fixes a long-standing bug with default argument expressions
capturing generic parameters.
2019-09-18 14:26:01 -04:00
swift-ci
1fdda8eaa8 Merge remote-tracking branch 'origin/master' into master-next 2019-09-17 19:09:48 -07:00
ravikandhadai
fa5b0f30a9 Merge pull request #27205 from ravikandhadai/constexpr-debug-stdlib
[Constant Evaluator] Support debug-stdlib, improve diagnostics and support `assertionFailure`
2019-09-17 18:55:04 -07:00
swift-ci
8a00ff3c21 Merge remote-tracking branch 'origin/master' into master-next 2019-09-17 16:10:10 -07:00
Michael Gottesman
7e3608e007 [ownership] Add a new checkValue overload to LinearLifetimeChecker that validates the linear lifetime of the passed in value and returns bool to indicate success/failure.
This is the first in a series of patches that begin to hide the underlying
linear lifetime implementation underneath the facade of the linear lifetime
checker. I only updated the users that this applies to.
2019-09-17 14:41:30 -07:00
swift-ci
80a02d598c Merge remote-tracking branch 'origin/master' into master-next 2019-09-17 08:51:03 -07:00
Michael Gottesman
4230cf7958 Merge pull request #27211 from gottesmm/pr-9566688fe160ddaa5cdb741e119f513579ad8c4d
[ownership] Create a context structure for the linear lifetime checker.
2019-09-17 08:38:45 -07:00
swift-ci
c3837a3fb8 Merge remote-tracking branch 'origin/master' into master-next 2019-09-16 21:49:52 -07:00
swift-ci
3ab346ba6b Merge pull request #27197 from gottesmm/pr-32d08675e348d877f8935092770eccd63eb67427 2019-09-16 21:44:05 -07:00
Michael Gottesman
dceca2bc3b [ownership] Create a context structure for the linear lifetime checker.
This is just a simple refactoring commit in preparation for hiding more of the
details of the linear lifetime checker. This is NFC, just moving around code.
2019-09-16 20:13:56 -07:00