Commit Graph

3736 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
84a68e11e0 Merge pull request #25014 from aschwaighofer/fix_combine_dynamic_function_ref
SILCombine: We are not guaranteed to get a function_ref instruction here
2019-05-23 11:41:46 -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
372046cc04 [diagnose-unreachable] Ignore/eliminate end_borrows after noreturn functions.
This seems to happen more often when we strip ownership after diagnose
unreachable.
2019-05-22 20:06:18 -07:00
Andrew Trick
df2afaa5c2 Merge pull request #24936 from atrick/comment-closure-scope
Add a comment in ClosureScopeAnalysis.
2019-05-22 10:36:19 -07:00
Andrew Trick
bdf7b2ade6 Merge pull request #24947 from atrick/fix-dynamic-exclusivity
Fix exclusivity diagnostics to be aware of [dynamically_replaceable].
2019-05-22 10:36:01 -07:00
swift-ci
a96890c7ae Merge pull request #24929 from eeckstein/optimize-keypath 2019-05-21 11:20:29 -07:00
swift-ci
b170ad72a8 Merge pull request #24953 from gottesmm/pr-71990c28f613fe44d9bf454eeb0b89a4356c8f91 2019-05-21 10:40:51 -07:00
Erik Eckstein
da38e3ac81 SILCombine: optimize keypath instructions.
If the keypath argument of a keypath access function is a keypath literal instruction, generate the projection inline and remove the access function.
For example, replaces (simplified SIL):
   %kp = keypath ... stored_property #Foo.bar
   apply %keypath_runtime_function(%root_object, %kp, %addr)
with:
   %addr = struct_element_addr %root_object, #Foo.bar
   load/store %addr

Currently this only handles stored property patterns.

rdar://problem/36244734
2019-05-21 09:44:59 -07:00
Erik Eckstein
5f8a5054c3 DeadObjectElimination: remove dead keypath instructions 2019-05-21 09:44:59 -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
Arnold Schwaighofer
528fe42bfb Merge pull request #24923 from aschwaighofer/dynamically_replaceable_closure_fixes
Fix capture promotion and closure scope analysis' handling of dynamically_replaceable functions
2019-05-21 05:56:41 -07:00
Andrew Trick
6e3f56fa92 Fix exclusivity diagnostics to be aware of [dynamically_replaceable].
Previously, any function marked [dynamically_replaceable] that was
partially applied and captured by address would not be diagnosed.

This is a rare thing. For example:

struct S {
  var x = 0
  public mutating func testCallDynamic() {
    dynamic func bar(_ i: inout Int) {
      i = 1
      x = 2
    }
    bar(&x)
  }
}

Fixes <rdar://problem/50972786> Fix exclusivity diagnostics to be
aware of [dynamically_replaceable].
2019-05-20 21:46:30 -07:00
Andrew Trick
4e00cad71e Add a comment in ClosureScopeAnalysis.
As a follow-up to reviewing the dynamically replaceable
implementation, document the place where this analysis will likely
crash in the future once we start optimizing non-escaping closure
captures.
2019-05-20 17:12: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
1db75d6430 Merge pull request #24920 from gottesmm/pr-1ce3bba234b68150bc0675d364f95465bb26344d
[mandatory-inlining] When using the linear lifetime checker to insert…
2019-05-20 14:53:41 -07:00
Arnold Schwaighofer
eb609d0420 Address review comment 2019-05-20 14:10:59 -07:00
Arnold Schwaighofer
6c0baaee85 Fix closurescope analysis
rdar://50949761
2019-05-20 13:20:23 -07:00
Arnold Schwaighofer
4912e6aa85 CapturePromotion: Disable for dynamically_replaceable sil functions
rdar://50949761
2019-05-20 13:20:10 -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
3b029010b9 [mandatory-inlining] When using the linear lifetime checker to insert compensating releases, if we find a double use due to a loop, do not insert an apply at that call site.
Otherwise, one will get use after frees. I added an interpreter test as wlel as
an end to end test.

rdar://50884462
2019-05-20 12:12:13 -07:00
ravikandhadai
d744ab0e86 Merge pull request #24908 from apple/rxwei-patch-5
Update OSLogOptimization.cpp to fix warning.
2019-05-20 11:05:05 -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
Richard Wei
c718126be1 Update OSLogOptimizationc.cpp to fix warning.
Fixes the following warning:
```console
third_party/unsupported_toolchains/swift/src/swift/lib/SILOptimizer/Mandatory/OSLogOptimization.cpp:396:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
```
2019-05-19 20:42:52 -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
Slava Pestov
d832fb9823 SILOptimizer: Fix crash on invalid in invalid escaping captures pass
An inout capture of 'self' is not lowered as a SIL argument inside
an initializer, so add a new check to handle this case.

Fixes <rdar://problem/50412872>.
2019-05-18 00:24:13 -04:00
Erik Eckstein
71b8c5617e SILCombine: fix a miscompile in dead alloc_existential_box removal
The miscompile results in a use-after-free crash.

rdar://problem/50759056
2019-05-16 15:05:44 -07:00
Andrew Trick
868156c069 Merge pull request #24773 from atrick/fix-accessopt-slow
Add AccessEnforcementOpts fast paths.
2019-05-16 10:59:02 -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
Andrew Trick
1120617b64 Remove a stray llvm::dbgs() from compile time debugging. 2019-05-14 15:09:40 -07:00
Andrew Trick
a9070cf6d4 Add AccessEnforcementOpts fast paths.
1. During identifyAccess, determine if there are either any
identical accesses or an accesses that aren't already marked
no_nested_storage. If there are neither, then skip the subsequent
data flow analysis.

2. In the new StorageSet, indicate whether identical storage was
seen elsewhere in the function. During dataflow, only add an access
to the out-of-scope access set if was marked as having identical
storage with another access.

3. During data flow, don't track in scope conflicts for
instructions already marked [no_nested_conflict].
2019-05-14 15:09:40 -07:00
Andrew Trick
c08e4396ab In AccessEnforcementOpts, skip SCC analysis.
When there is nothing that can be merged, there's no point doing an
extra CFG analysis.
2019-05-14 14:44:21 -07:00
Andrew Trick
cd88cedd86 Slightly reword a comment in AccessEnforcementOpts. 2019-05-14 14:44:20 -07:00
Andrew Trick
c1bda8f090 Replace AccessedStorage projection with an index.
Further simplify AccessedStorage. Shrink it to two words. Remove the
Projection abstraction and streamline the projection logic.
2019-05-14 12:44:46 -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
swift-ci
05808b93fb Merge pull request #24728 from atrick/simplify-accessed-storage-no-rea 2019-05-14 12:01:23 -07:00
Andrew Trick
0d3c6144ed Remove RefElementAddr field from AccessedStorage.
- code simplification critical for comprehension
- substantially improves the overhead of AccessedStorage comparison
- as a side effect improves precision of analysis in some cases

AccessedStorage is meant to be an immutable value type that identifies
a storage location with minimal representation. It is used in many global
interprocedural data structures.

The RefElementAddress instruction that it was derived from does not
contribute to the uniqueness of the storage location. It doesn't
belong here. It was being used to create a ProjectionPath, which is an
extremely inneficient way to compare access paths.

Just delete all the code related to that extra field.
2019-05-14 10:45:54 -07:00
Andrew Trick
8cc013ed3f Fix LICM debug output typo. 2019-05-14 10:45:53 -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
Michael Gottesman
2ae51ca0aa Merge pull request #24610 from gottesmm/pr-2df2f80b348fecaae23a17b6aa3272de096fd075
[sil] Expand immutable address use verification to in_guaranteed parameters.
2019-05-10 09:55:10 -07:00
Michael Gottesman
179251d167 [sil-combine] Do not perform existential type propagation on @in parameters when we have a copy of the underlying value.
Otherwise, we may get use-after-frees as in the added test.

rdar://50609145
2019-05-09 23:01:43 -07:00
Davide Italiano
dc6b2e2f5c Merge pull request #24657 from dcci/alias-ubsan
[AliasAnalysis] Check for nullptr before dereferencing.
2019-05-09 17:08:48 -07:00
Jordan Rose
e8773b5e4d Add a PrettyStackTrace for SILInliner::inlineFunction (#24658) 2019-05-09 16:46:55 -07:00
Davide Italiano
642f64f2f8 [AliasAnalysis] Check for nullptr before dereferencing.
Fixes an undefined behaviour sanitizer bug.

<rdar://problem/50641097>
2019-05-09 15:47:19 -07:00