Commit Graph

2768 Commits

Author SHA1 Message Date
Davide Italiano
c4adb9bd16 Merge pull request #25490 from dcci/rdar48887384
[CastOptimizer] Set the correct debug scope for the SILBuilder.
2019-06-14 18:58:34 -07:00
Davide Italiano
af541470f5 Merge pull request #25472 from dcci/silbuilder-inherit
[SILInliner] Inherit SILBuilderContext when creating a new one.
2019-06-14 18:24:25 -07:00
Davide Italiano
9575a6e05c [CastOptimizer] Set the correct debug scope for the SILBuilder.
<rdar://problem/48887384>
2019-06-14 15:58:13 -07:00
Davide Italiano
36b917b048 [SILInliner] Inherit SILBuilderContext when creating a new one.
Addresses Michael's feedback on my last commit.
2019-06-14 10:49:02 -07:00
Michael Gottesman
c5e9fc286a [cast-optimizer] Fix a leak in the cast optimizer when we perform load promotion and fail.
Specifically, in this part of the cast optimizer we are trying to optimize casts
that can be done in two parts. As an example consider: NSObject ->
Array<Any>. In this case, we first cast from NSObject -> NSArray and then try to
conditionally bridge to Array<Any> from NSArray.

The problem is we did not destroy the NSObject correctly if the first cast
failed. I couldn't figure out how to create an actual swift test case that
produces this problem since we are pretty conservative about triggering this
code path. But in SIL it is pretty easy and in ossa, we trigger the ownership
verifier.

This is another victory for the ownership verifier!

rdar://51753580
2019-06-14 10:33:24 -07:00
Davide Italiano
7c1ab3384c Merge pull request #25407 from dcci/rdar51512044
[SILInliner] Set the correct scope for {begin,end}_borrow.
2019-06-13 16:54:08 -07:00
Davide Italiano
0f1837c1fc [SILInliner] Also pass a SILBuilderContext.
Pointed out by Michael Gottesman.
2019-06-13 14:30:24 -07:00
Davide Italiano
15dd4fe4d1 [SILInliner] Set the correct scope for {begin,end}_borrow.
<rdar://problem/51512044>
2019-06-12 16:05:33 -07:00
Michael Gottesman
2e9c904e16 [mandatory-inlining] Teach mandatory inlining how to handle begin_borrow instructions.
This was exposed by test/SILOptimizer/diagnostic_constant_propagation.swift. It
isn't a pattern in the mandatory inlining tests. I added some tests for it.
2019-06-12 13:13:52 -07:00
John Holdsworth
fe32ba1a86 Add missing newlines 2019-06-10 22:12:24 +01:00
Saleem Abdulrasool
731c31f9a5 MSVC: litter the code with llvm_unreachable (NFC)
Add `llvm_unreachable` to mark covered switches which MSVC does not
analyze correctly and believes that there exists a path through the
function without a return value.
2019-06-01 19:02:46 -07:00
ravikandhadai
29a8dbf3a0 Merge pull request #25133 from ravikandhadai/constexpr-ownership
[Constant evaluator] Add support for destructure_tuple and destructure_struct instructions to the constant evaluator.
2019-05-30 15:03:20 -07:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Ravi Kandhadai
2c97b72651 [Constant evaluator] Add support for destructure_tuple and
destructure_struct instructions to the constant evaluator.
2019-05-29 18:24:27 -07:00
Arnold Schwaighofer
8d1fabd859 Merge pull request #25073 from aschwaighofer/sil_getReferencedFunctionOrNull_getInitialReferencedFunction
SIL: Replace uses of getReferencedFunction() by getReferencedFunction…
2019-05-28 10:27:32 -07:00
Michael Gottesman
39dbf54e19 [cast-opt] Update checked_cast_addr_br objc -> swift bridged cast optimization for ownership.
These fix assertions that we hit by even performing the optimization, some
making sure the test doesn't hit those is sufficient.
2019-05-26 18:30:21 -07:00
Arnold Schwaighofer
c187c8ac13 SIL: Replace uses of getReferencedFunction() by getReferencedFunctionOrNull() and getInitialReferencedFunction()
With the advent of dynamic_function_ref the actual callee of such a ref
my vary. Optimizations should not assume to know the content of a
function referenced by dynamic_function_ref. Introduce
getReferencedFunctionOrNull which will return null for such function
refs. And getInitialReferencedFunction to return the referenced
function.
Use as appropriate.

rdar://50959798
2019-05-26 08:58:14 -07:00
Michael Gottesman
ad676857ea [cast-opt] Fix miscompile when we tried to optimize take_on_success that resulted in invalid IR being emitted.
The specific problem here is that we are setting the insertion point of a
SILBuilder and not unsetting it. I fixed the problem by creating a separate
builder so the original builder stays put.

I originally came across this in my work on moving ownership stripping after the
diagnostic passes. This patch fixes it without my other changes to ease
cherry-picking to 5.1.

I also added more test coverage by expanding the test case to also handle
copy_on_success and take_always.

rdar://51093557
2019-05-24 09:58:24 -07:00
Arnold Schwaighofer
4985e0f818 SILCombine: We are not guaranteed to get a function_ref instruction here
Also fix an issue in that cast optimizer and objc bridging thunks that
are marked dynamic.

Same test case tests both issues.

rdar://51068786
2019-05-23 08:39:31 -07:00
Michael Gottesman
748bf88bbe [ownership] Convert SILOptimizer/cast_folding.swift to work with ownership and fix all issues exposed. 2019-05-21 09:07:13 -07:00
Michael Gottesman
ef1ad0613c Merge pull request #24102 from gottesmm/pr-cdde379c40f94a6fd49361a2b347388665705682
[constant-prop] When replacing uses of destructure_tuple, only RAUW i…
2019-05-20 15:15:20 -07:00
Michael Gottesman
0fce7059a2 Merge pull request #24906 from gottesmm/pr-086b5df86583874c4bef884b5a495e2a1d16845c
Teach ConstExpr how to look through begin_borrow, copy_value and to i…
2019-05-20 12:15:30 -07:00
Michael Gottesman
08c25da322 [cast-opt] Fix another code path in the cast optimizer for ownership and add an additional run of cast_folding_objc.swift with stripping ownership after serialization. 2019-05-20 00:51:26 -07:00
Michael Gottesman
86a7ce67b9 Teach ConstExpr how to look through begin_borrow, copy_value and to ignore destroy_value, end_borrow.
This is needed now that const expr handles string operations/etc. There aren't
tests for this now since I would need to stub out the stdlib. But these are
pretty simple changes overall, I do not expect any problems, and I plan on
enabling this relatively soon.
2019-05-19 17:33:42 -07:00
Michael Gottesman
35c3a0fce3 [cast-opt] Change one pathway through the cast-optimizer to use higher level constructs that are both ossa and non-ossa compatible 2019-05-18 18:32:31 -07:00
Michael Gottesman
5910829830 [constant-prop] When replacing uses of destructure_tuple, only RAUW if we actually have uses since we may not delete the actual destructure.
The specific case where this happened here is:

```
  // Worklist = [
  %0 = struct $Int (...)
  %1 = $Klass
  %2 = tuple (%0, %1)
  (%3, %4) = destructure_tuple %2
  store %3 to [trivial] %3stack
  store %4 to [init] %4stack
```

What would happen is we would visit the destructure_tuple, replace %3 with %0
but fail to propagate %4:

```
  %0 = struct $Int (...)
  %1 = $Klass
  %2 = tuple (%0, %1)
  (%3, %4) = destructure_tuple %2
  store %0 to [trivial] %3stack
  store %4 to [init] %4stack
```

This then causes the tuple to be added to the worklist. When we visit the tuple,
we see that we have a destructure_tuple that is a user of the tuple, we see that
it still has that Struct as a user despite us having constant propagated that
component of the tuple. This then causes us to add the struct back to the
worklist despite that tuple component having no uses. Then when we visit the
struct. Which causes us to visit the tuple, etc.

rdar://49947112
2019-05-18 15:26:25 -07:00
Ravi Kandhadai
9be4fef53a [SIL Optimization] Add a mandatory optimization pass for optimizing
the new os log APIs based on string interpolation.
2019-05-14 18:08:59 -07:00
swift-ci
7ef557e7c8 Merge pull request #24780 from ravikandhadai/constexpr-refactoring 2019-05-14 16:34:48 -07:00
ravikandhadai
f563212f03 Revert "[SIL Optimization] Add a mandatory pass for optimizing the new os log APIs based on string interpolation." 2019-05-14 15:11:05 -07:00
Ravi Kandhadai
8b217afcaf [Const Evaluator] Fix a minor bug in the copy constructor deletion of
`ConstExprStepEvaluator`.
2019-05-14 12:09:57 -07:00
Ravi Kandhadai
b7b46622aa [SIL Optimization] Add a mandatory optimization pass for optimizing
the new os log APIs based on string interpolation.
2019-05-13 19:40:39 -07:00
swift-ci
616ec93fa2 Merge pull request #24625 from atrick/canonicalize-stores 2019-05-11 19:32:29 -07:00
Jordan Rose
e8773b5e4d Add a PrettyStackTrace for SILInliner::inlineFunction (#24658) 2019-05-09 16:46:55 -07:00
Andrew Trick
320759227a Canonicalize stores in the CanonicalizeInstruction utility.
This is the complement to load canonicalization. Although store
canonicalization is not required before diagnostics, it should be
defined in the same utility.
2019-05-09 13:00:39 -07:00
Erik Eckstein
b058869656 SILOptimizer: replace the recursive CFG walk in the RemoveUnreachable utility with a worklist algorithm.
This avoids deep stack nesting for large CFGs. It also makes the code simpler.
2019-05-08 13:55:00 -07:00
Andrew Trick
aa6347c832 Merge pull request #24153 from atrick/fix-let-exclusivity
Add a SILGenCleanup pass and CanonicalizeInstruction utility.
2019-05-06 22:51:19 -07:00
Andrew Trick
52237aaaf7 Avoid else-return in splitAggregateLoad. 2019-05-06 17:23:08 -07:00
Andrew Trick
f151a96644 Add a comment on replaceUsesOfExtract per review feedback. 2019-05-06 17:23:08 -07:00
Andrew Trick
ece096d91e Fix eraseFromParentWithdebugInsts to call a callback.
The recursivelyDeleteTriviallyDeadInstructions utility takes a
callBack to be called for every deleted instruction. However, it
wasn't passing this callBack to eraseFromParentWithdebugInsts. The
callback was used to update an iterator in some cases, so not calling
it resulted in iterator invalidation.

Doing this also cleans up the both APIs:
recursivelyDeleteTriviallyDeadInstructions and eraseFromParentWithdebugInsts.
2019-05-06 17:23:08 -07:00
Andrew Trick
ca9ae0dda8 Canonicalize nontrivial loads.
This adds support to the load->struct_extract canonicalization for
nontrivial element types which look like:

load [copy]
borrow
struct_extract
...uses...
end_borrow
destroy
2019-05-06 17:23:08 -07:00
ravikandhadai
a282b4513d Merge pull request #24488 from ravikandhadai/inliner-refactoring
[SIL Inlining] Extract out a reusable code snippet in PerformanceInliner into a utility function in SILInliner.
2019-05-06 15:13:23 -07:00
Andrew Trick
f395f86039 Canonicalize loads in SILGenCleanup.
Reimplement load instruction canonicalization as part of the
CanonicalizeInstruction utility.
2019-05-06 13:31:35 -07:00
Andrew Trick
9aa2523393 Add a CanonicalizeInstruction utility.
CanonicalizeInstruction will be a superset of
simplifyInstruction (once all the transforms are fixed for ownership
SIL). Additionally, it will also include simple SSA-based
canonicalization that requires new instruction creation. It may not
perform any optimization that interferes with diagnostics or increases
compile time.

Canonicalization replaces simplifyInstruction in SILCombine so we can
easily factor some existing SILCombine transforms into canonicalization.
2019-05-06 09:36:07 -07:00
Ravi Kandhadai
bed34d65ad [SIL Inlining] Extract out a reusable code snippet in PerformanceInliner
into a utility function in SILInliner.
2019-05-03 15:00:41 -07:00
Arnold Schwaighofer
a5036a97df Fix generic specialization that can result in noreturn apply without unreachable
rdar://50393169
2019-05-02 16:12:21 -07:00
ravikandhadai
d912e3312e Merge pull request #24113 from ravikandhadai/constexpr-skip
[Const evaluator] Add support to "skip" instructions in step-wise evaluation
2019-05-02 15:52:05 -07:00
ravikandhadai
26dc0921ed Merge pull request #24410 from ravikandhadai/consteval_inject_enum_addr
[Const Evaluator] Add support for inject_enum_addr, select_enum and select_enum_addr
2019-05-01 16:53:11 -07:00
Ravi Kandhadai
cb9cb31f7a [Const Evaluator] Add support for inject_enum_addr, select_enum
and select_enum_addr instructions to the constant evaluator.
2019-05-01 11:06:00 -07:00
Ravi Kandhadai
b0e56f70f9 [Const evaluator] Enable stepwise constant evaluator to skip
instructions without evaluating them while conservatively accounting
for the effects of the skipped instructions on the interpreter state.
2019-04-30 15:36:29 -07:00
Ravi Kandhadai
a7b7db7854 [Constant Evaluator] Move "string.append" semantics attribute from
`String.+=` function to `String.append` function, and use a new
semantics attribute for String.+=.

Teach the constant evaluator about `String.Append` instead of `String.+=`.
2019-04-30 14:26:06 -07:00