Commit Graph

1051 Commits

Author SHA1 Message Date
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
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
Slava Pestov
16d5716e71 SIL: Use the best resilience expansion when lowering types
This is a large patch; I couldn't split it up further while still
keeping things working. There are four things being changed at
once here:

- Places that call SILType::isAddressOnly()/isLoadable() now call
  the SILFunction overload and not the SILModule one.

- SILFunction's overloads of getTypeLowering() and getLoweredType()
  now pass the function's resilience expansion down, instead of
  hardcoding ResilienceExpansion::Minimal.

- Various other places with '// FIXME: Expansion' now use a better
  resilience expansion.

- A few tests were updated to reflect SILGen's improved code
  generation, and some new tests are added to cover more code paths
  that previously were uncovered and only manifested themselves as
  standard library build failures while I was working on this change.
2019-04-26 22:47:59 -04:00
Slava Pestov
472787bab7 SIL: isNonThrowing parameter of SILBuilder::create{Begin,}Apply() defaults to false
Also remove the overload of createApply() that does not take a SubstitutionMap.
It accomplishes nothing except creating ambiguity.
2019-04-25 22:27:38 -04:00
swift-ci
d24bc38797 Merge pull request #23701 from DougGregor/property-delegates-as-custom-attributes 2019-04-24 22:51:18 -07:00
Erik Eckstein
2e01b0edeb SIL: add assign_by_delegate instruction
Used for property delegates.
2019-04-23 11:32:28 -07:00
Ravi Kandhadai
d9a3f9c1b8 [const evaluator] Improving diagnostics generation for
unknown symbolic values by renaming some diagnostics and
creating new unknown reasons for each type of failure that
can happen during constant evaluation.
2019-04-18 13:17:17 -07:00
Ravi Kandhadai
55e82004a2 [const evaluator] Expose the step-wise constant evaluation mode
(also referred to as flow-sensitive mode) so that the evaluator
can be used by clients to constant evaluate instructions in a
SILFunction body one by one following the flow of control.
2019-04-17 18:12:17 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -04:00
swift-ci
4dc763aa4b Merge pull request #23964 from atrick/fix-prespecialize 2019-04-16 16:57:57 -07:00
Andrew Trick
60ee010e13 Force-link the prespecialized body. Remove extraneous linkage logic.
A prespecialized function may reference a non-public stdlib
symbols. Force link the function body when it is
specialized. Normally, the SILLinker does this, but it cannot see
through the prespecialize proxy function.

All symbols that must be prespecialized are now explicitly
requested. There's no accidental prespecialization, so there's no need
for special logic to adjust the specialized function linkage. Remove
all of that.
2019-04-15 20:51:35 -07:00
Michael Gottesman
1983368057 [cast-opt] Create an ownership version of bridged_cast_folding.sil and fix the cast optimizer so we can optimize it correctly. 2019-04-14 01:06:03 -07:00
Michael Gottesman
4304732553 Merge pull request #24020 from gottesmm/pr-435183b51ab766a85b8b66a35286dbc6f1d0e6fa
[cast-opt] Eliminate a leak along the cast failure path when bridging…
2019-04-14 00:28:02 -07:00
Michael Gottesman
de021aa32b [cast-opt] Eliminate a leak along the cast failure path when bridging from a swift to ns object derived class.
I added an interpreter test that exercises this code path using LifetimeTracked
to make sure we do not regress again.

rdar://49882071
2019-04-13 20:10:24 -07:00
ravikandhadai
10a7229bd6 Merge pull request #23877 from ravikandhadai/constexpr-refactoring
[const evaluator] Refactoring: exposing functions to look up symbolic values and to flow-sensitively evaluate possibly branching instructions.
2019-04-13 19:28:29 -07:00
Michael Gottesman
13a3dbbba0 [cast-opt] Simplify some code by hoisting some code/early exiting.
Importantly this lets us know further on in the function that as an invariant we
only can have checked_cast_addr_br.
2019-04-13 17:45:45 -07:00
Michael Gottesman
9caeaafd80 [cast-optimizer] Add some file level flags to section out the file into chunks. 2019-04-13 14:57:28 -07:00
Ravi Kandhadai
6d373750ef [const evaluator] Refactoring: exposing functions to look up the
symbolic value bound to a SIL value from the state, and to
flow-sensitively evaluate a single instruction regardless of
whether or not it is a branch.
2019-04-12 15:39:02 -07:00