Commit Graph

77 Commits

Author SHA1 Message Date
Arnold Schwaighofer
a71dff2c06 PerformanceInlinerUtils: Support convert_escape_to_noescape instructions 2018-02-13 04:19:59 -08:00
Erik Eckstein
44aafd950c Tuning the inliner heuristics:
* allow small class methods to be inlined with -Osize
* inline pure calls: references to objects, which are initialized with constants, are considered as constant arguments
2018-01-19 11:32:37 -08:00
eeckstein
b126b62256 Revert "Optimization changes to completely fold OptionSet literals" 2018-01-18 22:05:07 -08:00
Erik Eckstein
8fb523e776 Tuning the inliner heuristics:
* allow small class methods to be inlined with -Osize
* inline pure calls: references to objects, which are initialized with constants, are considered as constant arguments
2018-01-18 18:27:17 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -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
Roman Levenstein
ac73a650cf Do not allow for inlining of a callee with layout constraints unless the substitutions have the same layout constraints. 2017-09-20 16:39:40 -07:00
Roman Levenstein
038dc3bd6a metatype_inst with a concrete, non-generic type can be considered a constant for the purposes of the pure invocations checks 2017-08-22 15:16:19 -07:00
Arnold Schwaighofer
a440302088 Inliner: Add @_semantics("inline_late")
@_semantics(inline_late) for inlining only outside the standard library in the
late performance inliner.

It can be beneficial to run the inliner only outside the standard library when
code size has been reduced far enough that inlining can take place based on the
inliner's heuristics.

rdar://33099675
SR-5360
2017-07-11 15:21:05 -07:00
Roman Levenstein
abdee7fb43 [sil-inliner] Do not perform early performance inlining for functions with certain @_semantics attributes
Specifically, do not perform the early inlining for functions annotated with @_semantics("pair_no_escaping_closure") and @_semantics("self_no_escaping_closure")

Add new tests and cleanup some tests.

It recovers from the performance regression that was recently introduced.

Fixes rdar://32555803
2017-06-05 11:59:37 -07:00
Roman Levenstein
00d663d172 [sil-generic-specializer] Add @_semantics("optimize.sil.specialize.generic.partial.never") to disable partial specialization on functions
This new @_semantics is used to annotate some very big functions in the standard library. It reduced the code size of the stdlib by 2%.
2017-06-01 16:33:18 -07:00
Roman Levenstein
ef41353877 [sil-inliner] Skip only array @_semantics during early inlining
The inliner was skipping even non-array related @_semantics by mistake.
2017-06-01 14:09:22 -07:00
Roman Levenstein
341b5c506d [sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled
If some functions are explicitly annotated by developers as @inline(__always) or @_transparent, they should always be a subject for the inlining of generics, even if this kind of inlining is not enabled currently for all functions.
2017-05-19 15:08:18 -07:00
Roman Levenstein
5b4691d901 Revert "[sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled" 2017-05-19 08:20:55 -07:00
Roman Levenstein
3fcd6f40c8 [sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled
If some functions are explicitly annotated by developers as @inline(__always) or @_transparent, they should always be a subject for the inlining of generics, even if this kind of inlining is not enabled currently for all functions.
2017-05-18 21:54:45 -07:00
practicalswift
fbad9fc6b8 [gardening] Remove unused variable 2017-05-16 23:23:41 +02:00
Roman Levenstein
dd93027a0e Always inline pure functions with constant arguments
A function is pure if it has no side-effects.
If there is a call of a pure function with constant arguments, it always makes sense to inline it, because we know that the whole computation will be constant folded.
2017-05-15 11:52:36 -07:00
Roman Levenstein
d66924b01e [sil-inliner] Move some functionality from PerformanceInliner into PerformanceInlinerUtils. NFC.
It does not change any functionality. The only purpose it to make some functions reusable by other passes.
2017-05-15 09:03:53 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
38ec08f45f [gardening] Standardize SILBasicBlock successor/predecessor methods that deal with blocks rather than the full successor data structure to have the suffix 'Block'.
This was already done for getSuccessorBlocks() to distinguish getting successor
blocks from getting the full list of SILSuccessors via getSuccessors(). This
commit just makes all of the successor/predecessor code follow that naming
convention.

Some examples:

getSingleSuccessor() => getSingleSuccessorBlock().
isSuccessor() => isSuccessorBlock().
getPreds() => getPredecessorBlocks().

Really, IMO, we should consider renaming SILSuccessor to a more verbose name so
that it is clear that it is more of an internal detail of SILBasicBlock's
implementation rather than something that one should consider as apart of one's
mental model of the IR when one really wants to be thinking about predecessor
and successor blocks. But that is not what this commit is trying to change, it
is just trying to eliminate a bit of technical debt by making the naming
conventions here consistent.
2016-11-27 12:32:51 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
265a4605a0 [gardening] Fix typos. 2016-10-16 12:53:49 +02:00
practicalswift
5d7bf22381 [gardening] Improve header consistency 2016-10-16 12:41:09 +02:00
practicalswift
0e26aed692 [gardening] Fix inconsistent header. 2016-10-15 11:39:12 +02:00
Roman Levenstein
0cc7043599 [sil-performance-inliner] Re-factoring: Split the performance inliner into a main driver and a set of utility files. NFC.
- Move the common performance inliner functionality into PerformanceInlinerUtils.cpp.
- Move the functionality specific to non-generic inlining into NonGenericPerformanceInliner.cpp
- Temporarily disable the inlining of generics. It will be enabled in the subsequent commit.
2016-10-12 16:48:06 -07:00