Commit Graph

2777 Commits

Author SHA1 Message Date
Michael Gottesman
591482114d [gardening] Re-flow a small comment. NFC. 2019-07-01 13:12:57 -07:00
Joe Groff
acee7c2a18 Merge pull request #25856 from jckarter/demangler-reentrance
Demangler: Save state to allow reentrant demangling.
2019-06-28 13:23:11 -07:00
Joe Groff
df46a144b5 Demangler: Save state to allow reentrant demangling.
If somebody called `demangleType` or `demangleSymbol` using a demangler that was already
in the middle of demangling a string, then the state for the new demangler would clobber the old
demangler. This manifested in rdar://problem/50380275 because, as part of demangling a
string with a symbolic reference to a private type's context, we would demangle the debug string
for the referenced context using the same demangler. If there were additional operators in the
original string after the symbolic reference, these never got demangled because the demangler
was now in the state of having completed demangling the other string, so we would drop nesting,
and incorrectly report field types of, for instance, `Array<PrivateStruct>` or
`(PrivateStruct, OtherStruct)` as just being `PrivateStruct`.

This is a likely situation to be in, especially now that `Demangler` objects also serve as
arena allocators for their demangled nodes, so change the top-level demangler entry points
to use an RAII object to push and pop the existing state instead of unilaterally clobbering
the existing state.
2019-06-28 10:00:16 -07:00
Michael Gottesman
5d9675392e [cast-opt] Improve handling of arguments when optimizing Swift -> ObjC bridging casts.
Specifically:

1. I removed an extra defensive copy that we put in place some time ago that
isn't really warranted. We know that we have an @owned value, so can safely just
pass the value as a @guaranteed parameter. This also eliminates an ownership
error that would occur due to my not having updated this code for ownership in
tree.

2. I also ensured that if we are performing a loadable address bridging cast ->
value bridging cast that we store the loadable value back into memory after we
perform the cast. Otherwise, it appears to leak to the ownership verifier.

I also centralized the non-ownership tests for this into one place
(const_fold_objc_bridge.sil => constant_propagation_objc.sil).
2019-06-23 13:17:10 -07:00
ravikandhadai
bcdd46cdfe Merge pull request #25677 from ravikandhadai/constexpr-intliteral-trunc
[Const Evaluator] Make compile-time constant evaluator correctly handle s_to_s_checked_trunc_IntLiteral_IntNN where the bit width of the source symbolic value (an APInt) could be smaller than the destination bits
2019-06-23 10:45:01 -07:00
Michael Gottesman
4b31d37307 [cast-opt] Rename misnamed variable.
This is actually an out parameter of the apply that we are then switching upon.
2019-06-22 22:12:00 -07:00
Ravi Kandhadai
11efa58a6c [Const Evaluator] Make compile-time constant evaluator correctly handle
s_to_s_checked_trunc_IntLiteral_IntNN where the bit width of the source
symbolic value (an APInt) could be smaller than the destination bits.
2019-06-21 19:35:06 -07:00
Davidino Italiano
12ee5d3b48 [CastOptimizer] Set the correct debug scope for the SILBuilder.
This is a recommit with a change to only run the test for
optimized stdlib [as the bug reproduces only there [as the bug reproduces only there]
2019-06-17 08:33:29 -07:00
Ben Langmuir
3ac3ff0a6b Revert " [CastOptimizer] Set the correct debug scope for the SILBuilder. " 2019-06-17 07:18:06 -07:00
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