Commit Graph

1020 Commits

Author SHA1 Message Date
Carl Peto
b914464712 Remove apparently obsolete builtin functions (#20947)
* Remove apparently obsolete builtin functions.

- Remove s_to_u_checked_conversion and u_to_s_checked_conversion functions from builtin AST parsing, SIL/IR generation and from SIL optimisations.

* Remove apparently obsolete builtin functions - unit tests.

- Remove unit tests for SIL transformations relating to s_to_u_checked_conversion and u_to_s_checked_conversion builtin functions.
2018-12-03 07:07:34 -05:00
John McCall
91a7c7635e Merge pull request #20415 from rjmccall/stdlib-borrowed-storage
Use @_borrowed on a few declarations in the stdlib and overlays
2018-11-28 21:29:27 -05:00
Michael Gottesman
c65c540d71 Merge pull request #20819 from gottesmm/pr-f46c6ad2fee1ea70f7b25a8f6a89ab7af28c1404
[ownership] Ban ValueOwnershipKind::Any in preparation for eliminated ValueOwnershipKind::Trivial
2018-11-28 13:55:10 -08:00
Michael Gottesman
c9bb5161a1 [ownership] Change SILUndef to return Any ownership for trivial values and owned for non-trivial values.
This is in preparation for verifying that when ownership verification is enabled
that only enums and trivial values can have any ownership. I am doing this in
preparation for eliminating ValueOwnershipKind::Trivial.

rdar://46294760
2018-11-27 17:31:08 -08:00
Andrew Trick
9c46b2a053 Fix block merging after inlining to help avoid quadratic inlining.
A recent SILCloner rewrite removed a special case hack for single
basic block callee functions:

commit c6865c0dff
Merge: 76e6c4157e 9e440d13a6
Author: Andrew Trick <atrick@apple.com>
Date:   Thu Oct 11 14:23:32 2018

    Merge pull request #19786 from atrick/silcloner-cleanup

    SILCloner and SILInliner rewrite.

Instead, the new inliner simply merges trivial unconditional branches
after inlining the return block. This way, the CFG is always in
canonical state after inlining. This is more robust, and avoids
interfering with subsequent SIL passes when non-single-block callees
are inlined.

The problem is that inlining a series of calls within a large block
could result in interleaved block splitting and merging operations,
which is quadratic in the block size. This showed up when inlining the
tens of thousands of array subscript calls emitted for a large array
initialization.

The first half of the fix is to simply defer block merging until all
calls are inlined. We can't expect SimplifyCFG to run immediately
after inlining, nor would we want to do that, *especially* for
mandatory inlining. This fix instead exposes block merging as a
trivial utility.

Note: by eliminating some unconditional branches, this change could
reduce the number of debug locations emitted. This does not
fundamentally change any debug information guarantee, and I was unable
to observe any behavior difference in the debugger.
2018-11-26 09:41:28 -08:00
David Zarzycki
fef48a52e7 Merge pull request #20649 from davezarzycki/fix_Wdefaulted-function-deleted-warnings
[Misc] NFC: Fix -Wdefaulted-function-deleted warnings
2018-11-18 11:40:00 -05:00
David Zarzycki
bf7f91b834 [Misc] NFC: Fix -Wdefaulted-function-deleted warnings 2018-11-17 08:30:59 -05:00
Michael Gottesman
6decec6c90 [inliner] Treat inline_always as meaning truly inline_always even in situations where we have large caller CFGs.
Currently if a caller is > 400 blocks, the inliner bails out of finding
inlinable targets. This is incorrect behavior for inline always functions. In
such cases, we should continue inlining inline always functions and skip any
functions that are not inline always.

rdar://45976860
2018-11-14 18:17:06 -08:00
Joe Shajrawi
93dcb9bddd [Exclusivity] Support exclusivity checks originating from block arguments
This includes:
1) Not crashing in AccessEnforcementOpts in case we have an Unidentified storage access - rdar://problem/45956642 and rdar://problem/45956777
2) Actually supporting finding the storage locations if we do begin_access <block argument>
3) Test case for said support
2018-11-13 11:25:11 -08:00
Joe Shajrawi
0ccc525269 Merge pull request #20483 from shajrawi/in_scope_distinct
[Exclusivity] Fix a bug wherein we miss detected a non conflicting in-scope access as conflicting
2018-11-09 16:15:51 -08:00
Joe Shajrawi
be9d290ef9 [Exclusivity] Fix a bug wherein we miss detected a non conflicting in-scope access as conflicting 2018-11-09 14:57:25 -08:00
John McCall
d339eab30c Don't apply the -Osize heuristic when inlining coroutines.
This is a performance hack: inlining a coroutine can promote heap
allocations of the frame to stack allocations, which is valuable
out of proportion to the normal weight.  There are surely more
principled ways of getting this effect, though.
2018-11-08 12:19:24 -05:00
Marc Rasi
bf18697b4f parsing, typechecking, and SILGen for #assert
`#assert` is a new static assertion statement that will let us write
tests for the new constant evaluation infrastructure that we are working
on. `#assert` works by lowering to a `Builtin.poundAssert` SIL
instruction. The constant evaluation infrastructure will look for these
SIL instructions, const-evaluate their conditions, and emit errors if
the conditions are non-constant or false.

This commit implements parsing, typechecking and SILGen for `#assert`.
2018-11-07 16:34:17 -08:00
Arnold Schwaighofer
44b3a47e56 Merge pull request #20333 from aschwaighofer/dynamic_function_replacement
Dynamic function replacement
2018-11-07 13:08:46 -08:00
Andrew Trick
2cc250c9ab Make AccessEnforcementOpts more conservative for builtins.
Avoid sinking releases arbitrarily below "miscelaneous" builtins.
Instead, explicitly define the behavior of each one.
2018-11-06 17:53:59 -08:00
Andrew Trick
5983aae176 Fix AccessEnforcementReleaseSinking. Check for illegal cases.
In the included, test case, the optimization was sinking
releases past is_escaping_closure.

Rewrite the isBarrier logic to be conservative and define the
mayCheckRefCount property in SIL/InstructionUtils. Properties that may
need to be updated when SIL changes belong there.

Note that it is particularly bad behavior if the presence of access
markers in the code cause miscompiles unrelated to access enforcement.

Fixes <rdar://problem/45846920> TestFoundation, TestProcess, closure
argument passed as @noescape to Objective-C has escaped.
2018-11-06 13:52:03 -08:00
Arnold Schwaighofer
7e32c68e1d Add new SIL instruction for calling dynamically_replaceable funtions
%0 = dynamic_function_ref @dynamically_replaceable_function
  apply %0()
  Calls a [dynamically_replaceable] function.

  %0 = prev_dynamic_function_ref @dynamic_replacement_function
  apply %0
  Calls the previous implementation that dynamic_replacement_function
  replaced.
2018-11-06 09:53:22 -08:00
Arnold Schwaighofer
5f4e183302 Add [dynamically_replacable] to SILFunctions
'dynamic' functions are marked as [dynamically_replaceable].
2018-11-06 09:53:21 -08:00
Joe Shajrawi
2e237f4838 [Exclusivity] Add new dominating access checks in loop pre-headers
General case:
<loop preheader>
A = ref_element_addr
<loop>
begin_access A [dynamic] [no_nested_conflict]

Adding an empty begin_access A in the preheader would allow us to turn the loop's access to [static]
2018-11-02 11:53:15 -07:00
Joe Shajrawi
e3cd69b926 Merge pull request #20201 from shajrawi/release-sink
[Exclusivity] Sink may release release instructions out of access scopes
2018-10-31 19:14:25 -07:00
Joe Shajrawi
32da4f9f45 [Exclusivity] Sink may release release instructions out of access scopes
General case:
begin_access A
...
strong_release / release_value / destroy
end_access

The release instruction can be sunk below the end_access instruction,
This extends the lifetime of the released value, but, might allow us to
Mark the access scope as no nested conflict.
2018-10-31 15:48:08 -07:00
Andrew Trick
063bbfcf7d Merge pull request #20136 from atrick/silcloner-cleanup
[NFC] SILCloner rewrite stage 2: "threading" cloners.
2018-10-30 16:33:50 -07:00
Andrew Trick
1446952521 Merge pull request #20111 from atrick/critedge-util
NFC: SILBasicBlock utilties for handling critical edges.
2018-10-29 15:42:07 -07:00
Andrew Trick
903a9821ab SILCloner rewrite stage 2: "threading" cloners.
Rewrite the SILCLoners used in SimplifyCFG. For convenience, there is
now simply a BasicBlockCloner and a SILFunctionCloner. It's pretty
obvious what they do and almost impossible to use incorrectly.

This is worthwhile on its own just to make the usage clear, but the
real reason is that after this cleanup, it will be possible to remove
many extraneous calls to global critical edge splitting related to
cloning.
2018-10-29 08:57:19 -07:00
Andrew Trick
2aa8427dc6 SILCloner: rename 'remapValue' to 'getMappedValue' to avoid confusion.
A follow up commit adds an API for SILCloner clients to set mapped
values. Calling the map lookup "remap" would be unacceptably misleading.
2018-10-27 16:30:37 -07:00
Joe Shajrawi
b5508f5488 [Exclusivity] Remove dominated access checks with no nested conflict:
Simplification of the code (bail on unpaired accesses) + change the implementation so we can avoid quadratic behavior
2018-10-26 11:19:21 -07:00
Joe Shajrawi
63b50f65a4 [Exclusivity] Remove dominated access checks with no nested conflict.
General case:

—
begin_access A (may or may not have no_nested_conflict)
load/store
end_access

apply // may have a scoped access that conflicts with A

begin_access A [no_nested_conflict]
load/store
end_access A
—

The second access scope does not need to be emitted.

NOTE: KeyPath access must be identified at the top-level, non-inlinable stdlib entry point.
As such, The sodlib entry pointed is annotated by a new @_semantics that is equivalent to inline(never)
2018-10-25 15:21:06 -07:00
Andrew Trick
12bb49f57a Expose SIL/BasicBlockUtils for critical edge splitting.
The primary interfaces for CFG manipulation belong in SIL. This is
just what's necessary to fix SILCloner.
2018-10-22 08:34:57 -07:00
swift-ci
b0389af92e Merge pull request #19894 from shajrawi/inline_exclusivity 2018-10-16 14:08:19 -07:00
Joe Shajrawi
2dc1015279 [Exclusivity] Make the performance inliner aware of exclusivity checks 2018-10-16 13:06:36 -07:00
Erik Eckstein
7b16f7f196 SILOptimizer: fix a phase ordering problem, which prevented array optimizations to work in some cases
Introduce an "early redundant load elimination", which does not optimize loads from arrays.
Later array optimizations, like ABCOpt, get confused if an array load in a loop is converted to a pattern with a phi argument.

This problem was introduced with accessors.

rdar://problem/44184763
2018-10-12 09:32:50 -07:00
Andrew Trick
c6865c0dff Merge pull request #19786 from atrick/silcloner-cleanup
SILCloner and SILInliner rewrite.
2018-10-11 14:23:32 -07:00
Andrew Trick
9e440d13a6 Rename SILCloner doPostProcess and foldValue to recordClonedInstruction and recordFoldedValue. 2018-10-10 18:01:12 -07:00
Harlan
00cc011621 [SILOptimizer] Don't diagnose infinite recursion if a branch terminates the program (#19781)
* [SILOptimizer] Don't diagnose infinite recursion if a branch terminates the program

This patch augments the infinite recursion checker to not warn if a
branch terminates, but still warns if a branch calls into something with
@_semantics("programtermination_point"). This way, calling fatalError
doesn't disqualify you for the diagnostic, but calling exit does.

This also removes the warning workaround in the standard library, and
annotates the internal _assertionFailure functions as
programtermination_points, so they get this treatment too.

* Fix formatting in SILInstructions.cpp

* Re-add missing test
2018-10-09 09:46:37 -07:00
Andrew Trick
bd28b0ea1b SILCloner and SILInliner rewrite.
Mostly functionally neutral:
- may fix latent bugs.
- may reduce useless basic blocks after inlining.

This rewrite encapsulates the cloner's internal state, providing a
clean API for the CRTP subclasses. The subclasses are rewritten to use
the exposed API and extension points. This makes it much easier to
understand, work with, and extend SIL cloners, which are central to
many optimization passes. Basic SIL invariants are now clearly
expressed and enforced. There is no longer a intricate dance between
multiple levels of subclasses operating on underlying low-level data
structures. All of the logic needed to keep the original SIL in a
consistent state is contained within the SILCloner itself. Subclasses
only need to be responsible for their own modifications.

The immediate motiviation is to make CFG updates self-contained so
that SIL remains in a valid state. This will allow the removal of
critical edge splitting hacks and will allow general SIL utilities to
take advantage of the fact that we don't allow critical edges.

This rewrite establishes a simple principal that should be followed
everywhere: aside from the primitive mutation APIs on SIL data types,
each SIL utility is responsibile for leaving SIL in a valid state and
the logic for doing so should exist in one central location.

This includes, for example:
- Generating a valid CFG, splitting edges if needed.
- Returning a valid instruction iterator if any instructions are removed.
- Updating dominance.
- Updating SSA (block arguments).

(Dominance info and SSA properties are fundamental to SIL verification).

LoopInfo is also somewhat fundamental to SIL, and should generally be
updated, but it isn't required.

This also fixes some latent bugs related to iterator invalidation in
recursivelyDeleteTriviallyDeadInstructions and SILInliner. Note that
the SILModule deletion callback should be avoided. It can be useful as
a simple cache invalidation mechanism, but it is otherwise bug prone,
too limited to be very useful, and basically bad design. Utilities
that mutate should return a valid instruction iterator and provide
their own deletion callbacks.
2018-10-08 19:30:09 -07:00
Graydon Hoare
cc16ddfd13 Revert "[SILOptimizer] Don't diagnose infinite recursion if a branch terminates (#19724)"
This reverts commit e94450e840.

rdar://45080912
2018-10-07 23:54:33 -07:00
Harlan
e94450e840 [SILOptimizer] Don't diagnose infinite recursion if a branch terminates (#19724)
This patch augments the infinite recursion checker to not warn if a
branch terminates, but still warns if a branch calls into something with
`@_semantics("arc.programtermination_point")`. This way, calling `fatalError`
doesn't disqualify you for the diagnostic, but calling `exit` does.

This also removes the warning workaround in the standard library, and
annotates the internal _assertionFailure functions as
`programtermination_point`s, so they get this treatment too.
2018-10-05 19:15:26 -07:00
Erik Eckstein
643f98fdb3 SILOptimizer: fix non-deterministic behavior in RedundantLoadElimination and DeadStoreElimination.
Replace some DenseSets, which are used for iteration, with vectors.

SR-8844
rdar://problem/44762620
2018-10-01 15:32:37 -07:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -07:00
Michael Gottesman
c62f31f5dc Inject llvm::SmallBitVector into namespace swift;
I also eliminated all llvm:: before SmallBitVector in the code base.
2018-09-21 09:49:25 -07:00
swift-ci
02b872efe6 Merge pull request #19372 from shajrawi/arrayinclass 2018-09-20 18:28:56 -07:00
Joe Shajrawi
43efed3337 [Exclusivity] Merge scopes with nested conflicts
We can merge out-of-scope regardless of having a conflict within a scope
i.e.
  begin_access %x

  end_access %x

  begin_access %x

  conflict

  end_access %x

can be merged (same for the same scopes in reverse order)
We can always do so unless there's a conflict between the first end_access and the second begin_access
2018-09-20 17:01:28 -07:00
Jordan Rose
de7b8ff071 Replace 'delete's with std::unique_ptr throughout SILOptimizer 2018-09-18 09:44:01 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Jordan Rose
737a405596 Add ModuleDecl::isOnoneSupportModule, and use it
A few places around the compiler were checking for this module by its
name. The implementation still checks by name, but at least that only
has to occur in one place.

(Unfortunately I can't eliminate the string constant altogether,
because the implicit import for SwiftOnoneSupport happens by name.)

No functionality change.
2018-09-06 16:05:16 -07:00
Erik Eckstein
b702f996a2 SILMem2Reg: fix a crash which was uncovered by the change in SROA
It's basically fixing two over-conservative asserts.

rdar://problem/44143761
2018-09-05 14:06:01 -07:00
swift-ci
be693bba82 Merge pull request #19140 from shajrawi/mayrelease2 2018-09-05 12:11:32 -07:00
Joe Shajrawi
e7eb78e2a7 AccessEnforcementOpts continued refactoring 2018-09-05 11:04:38 -07:00
swift-ci
6f3b6182bc Merge pull request #15665 from graydon/everybody-gets-a-tracer 2018-09-05 00:46:20 -07:00