Commit Graph

1020 Commits

Author SHA1 Message Date
Erik Eckstein
6c93798acc SILOptimizer: Add a new TempRValue optimization pass
This is a separate optimization that detects short-lived temporaries that can be eliminated.
This is necessary now that SILGen no longer performs basic RValue forwarding in some cases.

SR-5508: Performance regression in benchmarks caused by removing SILGen peephole for LoadExpr in +0 context
2017-08-05 17:23:51 -07:00
swift-ci
e5b6bc1276 Merge remote-tracking branch 'origin/master' into master-next 2017-08-02 15:49:58 -07:00
Roman Levenstein
b83faa0109 [sil-devirtualizer] Fix a bug in devirtualization of methods that never return
This bug was caught by the SIL verifier. Any invocation of a NoReturn function should be followed by an `unreachable` instruction.

Fixes rdar://problem/33591235
2017-08-02 15:14:03 -07:00
swift-ci
0c1ec5f4ed Merge remote-tracking branch 'origin/master' into master-next 2017-08-01 16:48:57 -07:00
Roman Levenstein
5a22424607 [dead-store-elimination] Add support for handling stores to stack promoted objects
Essentially, treat `alloc_ref [stack]` allocated objects in the same way as we treat `alloc_stack` allocated objects.
2017-08-01 15:39:46 -07:00
swift-ci
0a5ee4200a Merge remote-tracking branch 'origin/master' into master-next 2017-07-24 12:48:50 -07:00
Erik Eckstein
6377cc095a SIL: Replace TransitivelyUnreachableBlocks with DeadEndBlocks
We had both utilities doing the same thing.
NFC
2017-07-24 09:50:42 -07:00
Bob Wilson
7ae35833de Merge remote-tracking branch 'origin/master' into master-next 2017-07-21 16:18:54 -07:00
Erik Eckstein
f59c1e4438 StackPromotion: a big simplification of the algorithm
Instead of having the complicated logic of finding the end of an object's lifetime we now use the existing ValueLifetimeAnalysis and StackNesting tools.
This simplifies the implementation a lot and does not use dominator and post-dominator trees anymore.

It's not a NFC because the way how to ensure proper nesting of stack allocations is now different.
To correct the stack nesting, the deallocations are moved down (instead of moving the allocations up).
Also it's now required that there is a final release for the allocation on all paths (which was not the case in some hand-written SIL tests).

Computation of dead-end blocks and escape analysis are now only done on demand. This saves compile time in case a function has no alloc_refs at all.
2017-07-21 13:24:58 -07:00
Erik Eckstein
a0e6082d25 SILOptimizer: change the way how ValueLifetimeAnalysis handles dead-end (unreachable) CFG paths.
In dead-array elimination we assume that the array allocation is post-dominated by all its final releases.
The only exception are branches to dead-end ("unreachable") blocks. So we just ignored all paths which didn't end up in a final release.
Now we explicitly pass the set of dead-end blocks and just ignore those blocks.
This is safer and it's also needed in the upcoming re-write of StackPromotion.
2017-07-21 10:46:03 -07:00
Bob Wilson
62c84a5461 [master-next] Update to work with recent dominator tree changes.
This patch started with a suggestion from Adrian Prantl to adapt to
LLVM r307953. The code has changed more since then so I modified it
to get it to build and I also fixed up StackPromotion to deal with related
changes. (I did not search back very far but it looks like the StackPromotion
change may have been a latent bug that did not matter much until recent
changes started using the function parameter.)
2017-07-19 22:52:21 -07:00
John McCall
4d3e44f98d Update SIL's dominance analysis for the template changes in LLVM.
StackPromotion is still busted.
2017-07-18 17:03:28 -04:00
swift-ci
b1384e5ca1 Merge remote-tracking branch 'origin/master' into master-next 2017-07-18 11:08:50 -07:00
Huon Wilson
994121e3d2 Merge pull request #10861 from huonw/symbol-list-10
TBD: includes all symbols from a full build and test
2017-07-18 10:54:17 -07:00
Huon Wilson
7d843f723c [SILOptimizer] A signature optimized function should have specialized linkage.
Previously this would mean that specialization of a public function are public,
which is incorrect.
2017-07-17 17:33:02 -07:00
Bob Wilson
2fb4f0cae0 master-next: move DEBUG_TYPE macro definition after #includes
LLVM r307950 added a definition of DEBUG_TYPE, followed by an #undef,
in the GenericDomTreeConstruction.h header.
2017-07-14 13:29:42 -07:00
Arnold Schwaighofer
e09abf1341 SimplifyCFG: JumpThread to facilitate ARC removal
It is beneficial to jump thread if we can remove a retain/release pair.

rdar://33099675
SR-5360
2017-07-11 13:43:57 -07:00
Erik Eckstein
c422461527 ArrayElementValuePropagation: Don’t create wrong SIL when trying to optimize ContiguousArray
Instead just bail on ContiguousArray.

https://bugs.swift.org/browse/SR-5293
rdar://problem/32983212
2017-06-28 11:36:39 -07:00
Erik Eckstein
8193b084e4 ARCCodeMotion: fix two problems in release hoisting:
1) PostOrderAnalysis is not invalidated after splitting critical edges. This let the data flow solver omit new inserted blocks.

2) Handle infinite loops in the CFG correctly. So that we don’t insert random release instructions into such CFG pathes.

https://bugs.swift.org/browse/SR-5187
rdar://problem/32713742
2017-06-23 15:20:09 -07:00
Devin Coughlin
2896d5b93f [SIL Utils] Move IndexTrieNode into its own header in Utils. NFC.
Move IndexTrieNode from DeadObjectElimination into its own header. I plan to
use this data structure when diagnosing static violations of exclusive access.
2017-06-14 21:23:14 -07:00
Erik Eckstein
26642ec419 SIL optimizer: Don’t crash if the user illegally lets an address of a local variable escape with withUnsafePointer
rdar://problem/32307046
2017-05-22 11:39:49 -07:00
Robert Widmann
3b202c18d8 Use 'hasAssociatedValues'
Use 'hasAssociatedValues' instead of computing and discarding the
interface type of an enum element decl.  This change has specifically not
been made in conditions that use the presence or absence of the
interface type, only conditions that depend on the presence or absence
of associated values in the enum element decl.
2017-05-22 09:54:47 -07:00
Roman Levenstein
980a590708 [sil-inliner] Transparent functions should be inlined by the performance inliner as if they are always inline functions 2017-05-19 15:08:25 -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
116581f2c5 [sil-inliner] Transparent functions should be inlined by the performance inliner as if they are always inline functions 2017-05-18 21:54:45 -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
Erik Eckstein
74fa0bcc87 Disable generic inlining and partial specialization, except in libswiftCore
This avoids code size regressions in programs while still getting the performance improvements in generic code in the stdlib.

rdar://problem/32277313
2017-05-18 15:38:54 -07:00
Erik Eckstein
88c97d9436 Remove a hack to change linkage from public_external to shared.
The linkage change let the compiler generate code for public functions which are imported from the stdlib - and are also available in the swiftCore library.
This got worse since we use public linkage for @_versioned internal functions in the stdlib.

Getting rid of the linkage change reduces code size a lot: up to 40% for some projects.

I didn’t see any significant impact on benchmark performance.
2017-05-18 09:23:38 -07: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
Slava Pestov
9c210247f5 Remove unused variables 2017-05-10 22:12:26 -07:00
Roman Levenstein
6402d3d97d Remove even more dead code 2017-05-10 09:11:43 -07:00
Roman Levenstein
f909858f53 Remove dead code that became obsolete after re-factoring 2017-05-10 08:04:28 -07:00
Roman Levenstein
45c2c4af0e Re-factoring: Get rid of useless arguments in "create*Apply" functions
Till now createApply, createTryApply, createPartialApply were taking some arguments like SubstCalleeType or ResultType. But these arguments are redundant and can be easily derived from other arguments of these functions. There is no need to put the burden of their computation on the clients of these APIs.

The removal of these redundant parameters simplifies the APIs and reduces the possibility of providing mismatched types by clients, which often happened in the past.
2017-05-10 08:03:37 -07:00
practicalswift
8c40c65c80 [gardening] Fix typos. 2017-05-09 21:50:04 +02:00
practicalswift
437a186032 [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar) 2017-05-09 11:26:07 +02: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
Andrew Trick
2336a87866 [Exclusivity] Enable access markers for the entire -Onone pipeline.
Dynamic markers are still conditional on the command line option.
2017-04-28 21:33:09 -07:00
Erik Eckstein
76eca003bb ArrayElementValuePropagation: explicitly reserve space for new elements when doing the array-content-of optimization
When Array.append(contentOf:) is replaced by individual Array.append(element) calls, an explicit reserveCapacityForAppend is inserted.
2017-04-27 09:06:56 -07:00
Erik Eckstein
e3ae6f29b6 SimplifyCFG: improve jump threading for switch_enum
1) to find a threading candidate for a branch instruction, look through multiple successor blocks and not only in the immediate successor
2) handle SSA-cycles when getting the case for an enum value
2017-04-27 09:06:55 -07:00
Slava Pestov
0290c2d5d8 AST: Make GenericSignature and GenericEnvironment SubstitutionMaps interchangable
SubstitutionMap::lookupConformance() would map archetypes out
of context to compute a conformance path. Do the same thing
in SubstitutionMap::lookupSubstitution().

The DenseMap of replacement types in a SubstitutionMap now
always has GenericTypeParamTypes as keys.

This simplifies some code and brings us one step closer to
a more efficient representation of SubstitutionMaps.
2017-04-24 14:12:36 -07:00
Roman Levenstein
53745e61cf Merge pull request #8961 from swiftix/open-archtypes-tracker-fixes
[sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder
2017-04-24 13:52:51 -07:00
Huon Wilson
d08d0ffdb8 Merge pull request #8845 from huonw/private-func-sig-specializations
[SILOpt] Specialized functions are never public.
2017-04-24 10:41:41 -07:00
Roman Levenstein
202de40f05 [sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder
Fixes rdar://problem/31749245
2017-04-24 08:50:55 -07:00
Roman Levenstein
a60e037c48 Revert "[sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder" 2017-04-22 20:41:31 -07:00
Roman Levenstein
33c8bde859 [sil-opened-archetype-tracker] Improve tracking of archetypes in SILBuilder
Fixes rdar://problem/31749245
2017-04-22 10:03:37 -07:00
Huon Wilson
84035b8bbf [SILOpt] Specialized functions are never public.
Specializations are implementation details, and thus shouldn't be
public, even if they are specializing a public function. Without this
downgrade, the ABI of a module depends on random internal code
(could change inlining decisions etc.), as well as swiftc's optimiser.
2017-04-21 16:58:00 -07:00
Roman Levenstein
e1c3538ecb redundundant-overflow-check-removal improvements
- Code-refactoring
- Support for comparison followed by a cond_fail
- Correctness fixes for relation propagation
2017-04-20 15:28:23 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00