Commit Graph

328 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
f664b16010 SIL: Add an on stack version of partial_apply
It does not take ownership of its non-trivial arguments, is a trivial
function type and therefore must not be destroyed. The compiler must
make sure to extend the lifetime of non-trivial arguments beyond the
last use of the closure.

  %objc = copy_value %0 : $AnObject
  %closure = partial_apply [stack] [callee_guaranteed] %16(%obj) : $@convention(thin) (@guaranteed AnObject) -> ()
  %closure2 = mark_dependence %closure : $@noescape @callee_guaranteed () -> () on %obj : $AnObject
  %user = function_ref @useClosure : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %user(%closure2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  dealloc_stack %closure : $() ->()
  destroy_value %obj : $AnObject // noescape closure does not take ownership

SR-904
rdar://35590578
2019-01-15 11:20:33 -08:00
Davide Italiano
2472f2b365 Merge pull request #21584 from dcci/setdebug2
[SILInstruction] Remove unused arg in setDebugScope()
2019-01-02 09:01:01 +01:00
Davide Italiano
d3d7342d9e [SILInstruction] Remove unused arg in setDebugScope() 2019-01-01 10:18:35 -08:00
Arnold Schwaighofer
74736d8ee2 Don't duplicate basic blocks ending in dynamic_method_br
IRGen does not support objc methods thunks.

rdar://46531828
2018-12-11 10:26:52 -08:00
Andrew Trick
8de89c392a Add a scale-test validation test for quadratic behavior during inlining.
Adds a stat to SILInstruction's transferNodesFromList to record the
number of times an instruction is transfered to another block. This is
the only way I can think of to detect quadratic behavior of passes
that split basic blocks.
2018-11-26 15:24:41 -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
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
Michael Gottesman
3cd1b7bedc [sil] Extract out ApplySite/FullApplySite into their own header.
I believe that these were in SILInstruction for historic reasons. This is a
separate API on top of SILInstruction so it makes sense to pull it out into its
own header.
2018-09-25 13:32:59 -07:00
Arnold Schwaighofer
73df12c09f Remove dead constant_string_literal
constant_string_literal was added to support a one word representation
of String that never materialized.
2018-09-05 12:13:57 -07:00
John McCall
3a044683b0 Update SILLoop::canDuplicate to correctly handle begin_apply.
Leave a warning in isTriviallyDuplicatable so that future updates
there will know to also update this code.
2018-08-26 04:10:07 -04:00
John McCall
6cc5a27c09 begin_apply is not a trivially-duplicable instruction.
The test case here did not actually previously fail, but it
seems worth including.
2018-08-26 01:18:37 -04:00
Erik Eckstein
99a9ed5535 SIL: remove the pinning instructions: strong_pin, strong_unpin, is_unique_or_pinned
They are not used anymore after removing the pinning addressors.
2018-08-23 12:47:56 -07:00
Jordan Rose
886475b51a Make SILInstructionResultArray::begin() and end() inlinable (#18612)
These are trivial functions and should be inlined away; the only
tricky bit is they need to be defined after the iterator type.
This gives a slight speedup of stdlib compilation time (about 5%
of the time spent generating the swiftmodule).
2018-08-10 10:25:31 -07:00
David Zarzycki
476d869e55 [SIL] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
Doug Gregor
d457f1c752 [IRGen/SIL] More widespread use of SubstitutionMap. 2018-05-11 13:18:06 -07:00
Andrew Trick
6a48b2d02d Merge pull request #16491 from atrick/enforce-keypath-exclusivity-as-error
Enforce keypath exclusivity as an error.
2018-05-10 16:03:01 -07:00
Andrew Trick
fe326266cc [exclusivity] Add a [builtin] flag to begin_[unpaired_]access.
This flag supports promoting KeyPath access violations to an error in
Swift 4+, while building the standard library in Swift 3 mode. This is
only necessary as long as the standard library continues to build in
Swift 3 mode. Once the standard library build migrates, it can all be
ripped out.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 21:42:37 -07:00
Slava Pestov
b44946d227 SIL: Fix an assertion 2018-05-09 22:50:50 -04:00
Jordan Rose
f6e85d1d64 [SIL] Simplify SILInstructionResultArray::iterator
No major change in execution time, but why make things more
complicated than they need to be? It does make
SILInstructionResultArray::begin drop out of the top ten functions in
the inverted call stack (not counting performLLVM).
2018-05-04 17:48:52 -07:00
Jordan Rose
5bf9b9ac76 [SIL] Avoid std::function in transform-iterators
In a non-rigorous test, this change shaves off 20% of the time spent
in SIL optimizations for the standard library in a +Asserts build.
(Admittedly the wins for a no-asserts build will be much lower because
SILInstructionResultArray has a bunch of assertions in its
constructor.)
2018-05-04 17:48:52 -07:00
Andrew Trick
ed8a604c27 Merge branch 'master' into add-access-tracking-flag 2018-03-29 18:26:22 -07:00
Davide Italiano
dfaf133d27 [LoadableByAddress] Fix debug info holes when expanding alloc_stack.
<rdar://problem/36876376>
2018-03-28 11:54:03 -07:00
Andrew Trick
e50faa5125 [exclusivity] Add 'no_nested_conflict' flag to begin_access.
This statically guarantees that the access has no inner conflict within
its own scope.

IRGen will turn this into a "nontracking" access in which an
exclusivity check is performed for conflicts on an outer scope. However,
unlike normal accesses the runtime does not record the access, and the
access will not be checked for subsequent conflicts.

end_unpaired_access [no_nested_conflict] is not currently
supported. Making a begin_unpaired_access [no_nested_conflict] requires
deleting the corresponding end_unpaired_access. Future runtimes
could support this for verification by storing inline data in the
valud buffer. However, the runtime can never assume that a
[no_nested_conflict] begin_unpaired_access will have a corresponding
end_unpaired_access call without adding a new ExclusivityFlag for
that purpose.
2018-03-27 10:50:07 -07:00
Arnold Schwaighofer
5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08:00
Andrew Trick
1d08be56a3 Mark begin_access is non-clonable (!isTriviallyDuplicatable()).
In one shot, this prevents multiple CFG transforms from breaking the simple
begin/end access marker pattern for access scopes.
2018-03-01 00:05:34 -08:00
Joe Shajrawi
102b6f0b61 Merge pull request #14587 from shajrawi/newinstr
Optimizer peephole for tagged BridgeObjects
2018-02-13 07:38:53 -08:00
Joe Shajrawi
f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
Arnold Schwaighofer
d51053b003 Add convert_escape_to_noescape instruction for converting escaping to noescape functions
@noescape function types will eventually be trivial. A
convert_escape_to_noescape instruction does not take ownership of its
operand. It is a projection to the trivial value carried by the closure
-- both context and implementation function viewed as a trivial value.

A safe SIL program must ensure that the object that the project value is based
on is live beyond the last use of the trivial value. This will be
achieve by means of making the lifetimes dependent.

For example:

  %e = partial_apply [callee_guaranteed] %f(%z) : $@convention(thin) (Builtin.Int64) -> ()
  %n = convert_escape_to_noescape %e : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
  %n2 = mark_dependence %n : $@noescape @callee_guaranteed () -> () on %e : $@callee_guaranteed () -> ()
  %f2 = function_ref @use : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %f2(%n2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  release_value %e : $@callee_guaranteed () -> ()

Note: This is not yet actually used.

Part of:
SR-5441
rdar://36116691
2018-02-06 18:01:23 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Chris Lattner
415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
David Zarzycki
54ea315586 [Basic] NFC: Stop using transparent unions 2017-12-16 10:43:49 -05:00
David Zarzycki
7368cc9a8b [SIL] NFC: Convert SILNode to new inline bitfield macros 2017-12-16 09:31:21 -05:00
Slava Pestov
1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov
1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Michael Gottesman
3226921b70 [sil] Add reverse iterator and reverse range support to SILInstructionResultArray.
I also used this as an opportunity to make SILInstructionResultArray::iterator
not inherit from std::iterator given that std::iterator is now deprecated.

Just slicing code off a larger commit.

rdar://31521023
2017-11-14 09:55:12 -08:00
Michael Gottesman
fa4873ae74 [ome] Teach the eliminator how to lower destructure_{struct,tuple}.
I am doing this to ensure that parts of the optimizer that have not yet been
updated for such operations do not see said instructions. This will ensure no
surprise perf regressions from this work.

rdar://31521023
2017-10-25 19:21:24 -07:00
Michael Gottesman
4c80c4d66f Address John's feedback.
Specifically to commits:

36a8d0d5c0
6df5462ee2

rdar://31521023
2017-10-25 13:48:51 -07:00
Michael Gottesman
6df5462ee2 [sil] Add support for multiple value instructions by adding MultipleValueInstruction{,Result}.
rdar://31521023
2017-10-24 18:36:37 -07:00
swift-ci
3d53e7baa2 Merge pull request #12451 from lattner/SILValue-getLoc 2017-10-15 16:14:45 -07:00
Chris Lattner
cd99f859e3 NFC code cleanup changes:
- Hoist a duplicated static function with a fixme out to SILValue::getLoc()
 - Fix a whitespace issue.
2017-10-15 15:31:41 -07:00
Slava Pestov
0acf3ac8d9 SIL: Remove is_nonnull instruction 2017-10-13 17:38:32 -07:00
Michael Gottesman
267d63e085 [sil] Instead of returning an ArrayRef<SILValue> for SILInstruction::getResults(), use SILInstructionResultArray.
The reason that I am doing this is in preparation for adding support for
MultipleValueInstruction. This enables us to avoid type issues and also ensures
that we do not increase the size of SingleValueInstruction while we are doing
it.

The MultipleValueInstruction commit will come soon.

rdar://31521023
2017-10-12 18:30:05 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Andrew Trick
c5f226f9ff [sil-opaque-values] Add UnconditionalCheckedCastValue to SILInstruction::mayRelease. 2017-09-15 14:08:58 -07:00
Roman Levenstein
74908ce818 Create utility functions for mapping between the numeric opcode of a SILValue/SILInstruction and its mnemonic name
Use it for the stats collection, but also for SIL printing.
2017-09-10 21:47:55 -07:00
Roman Levenstein
f0a39e9e14 Add support for collecting various SIL optimizer counters
This patch implements collection and dumping of statistics about SILModules, SILFunctions and memory consumption during the execution of SIL optimization pipelines.

The following statistics can be collected:
  *  For SILFunctions: the number of SIL basic blocks, the number of SIL instructions, the number of SIL instructions of a specific kind, duration of a pass
  *  For SILModules: the number of SIL basic blocks, the number of SIL instructions, the number of SIL instructions of a specific kind, the number of SILFunctions, the amount of memory used by the compiler, duration of a pass

By default, any collection of statistics is disabled to avoid affecting compile times.

One can enable the collection of statistics and dumping of these statistics for the whole SILModule and/or for SILFunctions.

To reduce the amount of produced data, one can set thresholds in such a way that changes in the statistics are only reported if the delta between the old and the new values are at least X%. The deltas are computed as using the following formula:

   Delta = (NewValue - OldValue) / OldValue

Thresholds provide a simple way to perform a simple filtering of the collected statistics during the compilation. But if there is a need for a more complex analysis of collected data (e.g. aggregation by a pipeline stage or by the type of a transformation), it is often better to dump as much data as possible into a file using e.g. -sil-stats-dump-all -sil-stats-modules -sil-stats-functions and then e.g. use the helper scripts to store the collected data into a database and then perform complex queries on it. Many kinds of analysis can be then formulated pretty easily as SQL queries.
2017-09-10 21:47:55 -07:00
Andrew Trick
5aac427ee0 SIL Ownership: Remove consumptionKind from SIL unconditional cast and related logic.
Remove the cast consumption kind from all unconditional casts. It
doesn't make sense for unconditional casts, complicates SIL ownership,
and wasn't fully supported for all variants. Copies should be
explicit.
2017-08-18 20:44:54 -07:00