Commit Graph

2053 Commits

Author SHA1 Message Date
practicalswift
9185c052a9 [gardening] Fix inconsistent headers 2016-09-14 20:48:28 +02:00
Slava Pestov
185921f6ab AST: Remove slow version of Substitution::subst()
When applying substitutions to substitution lists in SIL, we would
unpack the ArrayRef<Substitution> into a SubstitutionMap on each
iteration over the original ArrayRef<Substitution>. Discourage
this sort of thing by removing the API in question and refactoring
surrounding code.
2016-09-13 22:58:58 -07:00
Roman Levenstein
7d594fb60d [sil-devirtualizer] Use a more advanced algorithm to figure out the exact types of instances
- Look through BB arguments with multiple predecessors.
- Provide a new helper function to figure out the exact type of the underlying object. It will be used by subsequent commits to improve the escape analysis.
2016-09-13 20:38:19 -07:00
Xin Tong
bfc7924995 Merge pull request #4748 from trentxintong/wireup-FSO
Wire up new epilogue release matcher with DSE and RLE
2016-09-13 11:32:30 -07:00
Xin Tong
65ba367beb Wire up new epilogue release matcher with DSE and RLE
rdar://26446587
2016-09-13 10:58:28 -07:00
Xin Tong
166e876f62 Merge pull request #4744 from trentxintong/wireup-FSO
Turn epilogue retain/release matcher to an Analysis
2016-09-13 08:41:33 -07:00
Xin Tong
5ab532d429 Turn epilogue retain/release matcher to an Analysis
It makes sense to turn the new epilogue retain/release matcher to an Analysis.
Its currently a data flow with an entry API point.  This saves on compilation time,
even though it does not seem to be very expensive right now. But it is a iterative
data flow which could be expensive with large CFGs.

rdar://28178736
2016-09-13 06:39:46 -07:00
Slava Pestov
a993e36c06 AST: Add a new SubstitutionMap data structure
This replaces the TypeSubstitutionMap / ConformanceMap pair that
has been appearing more and more lately.
2016-09-08 21:59:11 -07:00
Xin Tong
9b338e7f00 Replace SmallVector with SmallSetVector in the new epilogue ARC matcher 2016-09-06 09:53:17 -07:00
Xin Tong
23f8eef616 Two small improvements on epilogue retain/release matcher.
1. Make sure to abort the data flow as soon as we know we cant find the epilogue retain/release.
2. Ignore retain in the throw block, because we do not use the result or insert retain for it
in the throw block on caller side. This is a bug really, we have a test case for it in the
functionsigopts.sil. It will be tested once this new epilogue retain matcher is wired up.
2016-08-29 22:12:09 -07:00
Erik Eckstein
5bfb9b2cfd Improve comment and function name. NFC. 2016-08-24 11:29:48 -07:00
Erik Eckstein
959e19d7bc Add an optimization to eliminate a partial_apply if all applied arguments are dead in the applied function.
This consists of 3 parts:
1) Extend CallerAnalysis to also provide information if a function is partially applied
2) A new DeadArgSignatureOpt pass, similar to FunctionSignatureOpts, which just specializes for dead arguments of partially applied functions.
3) Let CapturePropagation eliminate such partial_apply instructions and replace them with a thin_to_thick conversion of the specialized functions.

This optimzation improves benchmarks where static struct or class functions are passed as a closure (e.g. -20% for SortStrings).
Such functions have a additional metatype parameter. We used to create a partial_apply in this case, which allocates a context, etc.
But this is not necessary as the metatype parameter is not used in most cases.

rdar://problem/27513085
2016-08-23 07:32:41 -07:00
Xin Tong
7842e5ccf0 Small comment fix in FSO 2016-08-20 13:33:45 -07:00
Erik Eckstein
a75a7f25f9 Re-instate: "SILPassManager: After a new function is pushed on the stack don't restart the pipeline on the old function."
This re-instates commit de9622654d

The problem of the infinite loop should be fixed by the previous fix in FunctionSignatureOpts.
In addition this new commit implements a safety check to void such cases, even if buggy optimizations try to keep pushing new functions onto the work list.
2016-08-19 14:04:49 -07:00
Erik Eckstein
759a05ee25 Prevent FunctionSignatureOpts to explode arguments if its type only has a single field.
This could happen in case the argument type is an enum and if one of the enum payloads has multiple non-trivial fields and only one of the values is released before the return.
2016-08-19 14:04:49 -07:00
Greg Parker
19e0eb8537 Revert "SILPassManager: After a new function is pushed on the stack don't res…" 2016-08-18 14:48:12 -07:00
Erik Eckstein
de9622654d SILPassManager: After a new function is pushed on the stack don't restart the pipeline on the old function.
Instead the pipeline is continued on the old function. This happens when a pass pushes a new, e.g. specialized function, on the function stack.
There is no need to repeat passes which already did run on a function.
It saves a little of compile time and I didn't see any significant impact on code size or performance.
It also simplifies the pass manager.
2016-08-17 11:48:05 -07:00
Erik Eckstein
3581173a61 SIL: add the self-parameter to the list of type-dependent operands if an instruction uses the dynamic-self type.
This establishes a real def-use relation from the self-parameter to any instruction which uses the dynamic-self type.
This is an addition to what was already done for opened archetypes.
The biggest part of this commit is to rename "OpenedArchetypeOperands" to "TypeDependentOperands" as this name is now more appropriate.

Other than that the change includes:
*) type-dependent operands are now printed after a SIL instruction in a comment as "type-defs:" (for debugging)
*) FuncationSignatureOpts doesn't need to explicitly check if a function doesn't bind dynamic self to remove a dead self metadata argument
*) the check if a function binds dynamic self (used in the inliner) is much simpler now
*) also collect type-dependent operands for ApplyInstBase::SubstCalleeType and not only in the substitution list
*) with this SILInstruction::mayHaveOpenedArchetypeOperands (used in CSE) is not needed anymore and removed
*) add type dependent operands to dynamic_method instruction

Regarding the generated code it should be a NFC.
2016-08-12 16:55:27 -07:00
Xin Tong
34eadd43ee Small refactoring in RRCM. 2016-08-09 21:44:53 -07:00
Erik Eckstein
84565932c6 SILOptimizer: fixed bugs which cause memory leaks.
*) cast optimizer: when a bridging cast is replaced with a function call and the owning convention of the instruction and the call parameter do not match, compensating retain/release instructions must be inserted.
*) cast optimizer: when a consuming dead cast instruction is removed a compensating release instruction must be inserted
*) mem2reg: An alloc_stack location which contains a destroy_addr must not be considered as a write-only location. The destroy_addr must be preserved.

rdar://problem/27601057
2016-08-04 15:39:14 -07:00
practicalswift
dbc6ec55b8 [gardening] Fix recently introduced "a" vs. "an" typos 2016-07-25 10:09:57 +02:00
Dmitri Gribenko
d82682ec6c Merge pull request #3733 from practicalswift/typo-fixes-20160724
[gardening] Fix recently introduced typos.
2016-07-24 15:43:03 -07:00
practicalswift
7e89679404 [gardening] Fix recently introduced typos. 2016-07-24 22:32:40 +02:00
practicalswift
5c916c0e71 [gardening] "a" vs. "an"-fixes 2016-07-24 21:39:51 +02:00
Michael Gottesman
ac3024292b [simplify-cfg] When moving cond_fail to preds, do not bail early.
This commit fixes a bug where we were not checking that all predecessors had the
cond_fail block as its only successor. This occured since we were bailing early
when we saw a constant. So if we saw a predecessor with a constant before a
predecessor that had multiple successors, we would optimize even though we would
be introducing an extra cond_fail along a path.

I added a new utility pass to test this code since so much is going on in
SimplifyCFG that it is difficult to construct a test case running the full
pass.

Really this code should be in a different pass (properly SIL Code Motion TBH).
But for now, this commit just fixes the bug.

rdar://26904047
2016-07-17 23:31:53 -07:00
Xin Tong
e61fc669e3 Merge pull request #3244 from trentxintong/ReleaseCM
Implement an iterative data flow to find epilogue retains or releases
2016-07-11 15:11:28 -07:00
Xin Tong
eaaf825032 Implement an iterative data flow to find epilogue retains or releases.
We have a few places this analysis can be used. e.g. FSO, ASO, etc.
I will wire them up one by one later.

rdar://problem/26446587
2016-07-11 14:06:06 -07:00
Han Sangjin
cccfbf4d3c [swiftc/msvc] Compiling with MSVC (#1516)
Some modifications for the ms-extension option of the clang.exe in the Visual Studio 2015 development environment

This patch is only for swiftc.exe. I used the library set of Visual Studio 2015 Update 1 and recent version of swift-clang as the compiler. If you are using the real MSVC compiler, more patch might be required.
2016-07-08 19:06:10 -07:00
swiftix
a4b23b7970 Merge pull request #3241 from swiftix/wip-opened-archetypes-v3
Track dependencies of SIL instructions on opened archetypes which they use.

This time all bugs discovered by buildbots are supposed to be fixed.
2016-06-28 12:39:13 -07:00
Roman Levenstein
8f85b3d345 Print a pass number of the current SIL pass when a compiler crashes
It makes it easier to perform a bisection and finding out the reason of the crash.
2016-06-28 09:24:58 -07:00
Roman Levenstein
794d72e923 Track dependencies of SIL instructions on opened archetypes which they use
Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype.

This patch does the following:
- Map opened archetypes to the instructions defining them, i.e. to open_existential instructions.
- Introduce a helper class SILOpenedArchetypesTracker for creating and maintaining such mappings.
- Introduce a helper class SILOpenedArchetypesState for providing a read-only API for looking up available opened archetypes.
- Each SIL instruction which uses an opened archetype as a type gets an additional opened archetype operand representing a dependency of the instruction on this archetype. These opened archetypes operands are an in-memory representation. They are not serialized. Instead, they are re-constructed when reading binary or textual SIL files.
- SILVerifier was extended to conduct more thorough checks related to the usage of opened archetypes.
2016-06-28 08:43:01 -07:00
swiftix
be27850aa2 Revert "Track dependencies of SIL instructions on opened archetypes which they use" 2016-06-24 21:25:08 -07:00
Roman Levenstein
9d4fc913d9 Track dependencies of SIL instructions on opened archetypes which they use
Till now there was no way in SIL to explicitly express a dependency of an instruction on any opened archetypes used by it. This was a cause of many errors and correctness issues. In many cases the code was moved around without taking into account these dependencies, which resulted in breaking the invariant that any uses of an opened archetype should be dominated by the definition of this archetype.

This patch does the following:
- Map opened archetypes to the instructions defining them, i.e. to open_existential instructions.
- Introduce a helper class SILOpenedArchetypesTracker for creating and maintaining such mappings.
- Introduce a helper class SILOpenedArchetypesState for providing a read-only API for looking up available opened archetypes.
- Each SIL instruction which uses an opened archetype as a type gets an additional opened archetype operand representing a dependency of the instruction on this archetype. These opened archetypes operands are an in-memory representation. They are not serialized. Instead, they are re-constructed when reading binary or textual SIL files.
- SILVerifier was extended to conduct more thorough checks related to the usage of opened archetypes.
2016-06-24 10:36:52 -07:00
Mark Lacey
f47cd8afd0 Fix leak in BasicCalleeAnalysis.
Each time we delete the pass manager, we delete the analyses it
holds. In this analysis we were holding onto memory that wasn't getting
released when the analysis was deleted.

Fixes rdar://problem/26245872.
2016-06-23 07:49:06 -07:00
Xin Tong
e06e1be1ad Merge pull request #2950 from trentxintong/SCM
Remove last bit of retain release code motion in SILCodeMotion.
2016-06-08 13:41:20 -07:00
practicalswift
46cbb98049 [gardening] Fix incorrect file name in header. 2016-06-08 22:00:05 +02:00
swift-ci
41177fa12c Merge pull request #2952 from trentxintong/MISC 2016-06-08 12:08:32 -07:00
Xin Tong
500acb98e0 Rename LSBase.h to LoadStoreOptUtils.h 2016-06-08 10:57:27 -07:00
Xin Tong
be793d26eb Remove last bit of retain release code motion in SILCodeMotion. All these code are
replaced by retain release code motion. This code has been disabled for sometime now.

This should bring the retain release code motion into a close. The retain release
code motion pipeline looks like this. There could be some minor cleanups after this though.

1. We perform a global data flow for retain release code motion in RRCM (RetainReleaseCodeMotion)
2. We perform a local form of retain release code motion in SILCodeMotion. This is more
for cases which can not be handled in RRCM. e.g. sinking into a switch is more efficiently
done in a local form, the retain is not needed on the None block. Release on SILArgument needs
to be split to incoming values, this can not be done in RRCM and other cases.
3. We do not perform code motion in ASO, only elimination which are very important.

Some modifications to test cases, they look different, but functionally the same.
RRCM has this canonicalization effect, i.e. it uses the rc root, instead of
the SSA value the retain/release is currently using. As a result some test cases need
to be modified.

I also removed some test cases that do not make sense anymore and lot of duplicate test
cases between earlycodemotion.sil and latecodemotion.sil. These tests cases only have retains
and should be used to test early code motion.
2016-06-08 10:49:33 -07:00
practicalswift
8df3859ce7 [gardening] Fix recently introduced typos. 2016-06-05 11:11:44 +02:00
practicalswift
57bccc8b06 [gardening] Fix inconsistent formatting. 2016-06-04 00:37:15 +02:00
Xin Tong
f2954f9235 Merge pull request #2725 from trentxintong/SFSO
Share a few createIncrement/createDecrement functions
2016-05-26 13:58:02 -07:00
Xin Tong
c758848c92 Share a few createIncrement/createDecrement functions 2016-05-26 12:55:25 -07:00
Xin Tong
a752b443d9 Merge pull request #2712 from trentxintong/SFSO
Change FSO explosion heurisitics.
2016-05-26 12:22:55 -07:00
Xin Tong
d8e11f59e1 Change FSO explosion heurisitics. We explode when we can not find all the
epilogue releases for an argument.

I did not measure performance difference with this change.

rdar://25451364
2016-05-26 10:17:14 -07:00
Xin Tong
35471ab345 Merge pull request #2310 from trentxintong/SFSO
Simplify function signature optimzation and fix a memory leak in function signature.
2016-05-25 15:11:12 -07:00
Xin Tong
db9ee7c614 Fix a memory leak in FSO
Make sure the destructor of the SmallVector in ProjectionTreeNode gets
called when the BumpPtrAllocator is destroy'ed.
2016-05-25 15:08:18 -07:00
Xin Tong
fb3eb0b646 Simplify function signature optimzation.
Several functionalities have been added to FSO over time and the logic has become
muddled.

We were always looking at a static image of the SIL and try to reason about what kind of
function signature related optimizations we can do.

This can easily lead to muddled logic. e.g. we need to consider 2 different function
signature optimizations together instead of independently.

Split 1 single function to do all sorts of different analyses in FSO into several
small transformations, each of which does a specific job. After every analysis, we produce
a new function and eventually we collapse all intermediate thunks to in a single thunk.

With this change, it will be easier to implement function signature optimization as now
we can do them independently now.

Small modifications to the test cases.
2016-05-25 11:12:27 -07:00
Xin Tong
b5b905e3cc Bring back rc identity cache.
This takes off 0.7% of the 27.7% of the time we spent in SILoptimizer when building
Stdlib.
2016-05-25 09:25:27 -07:00
swiftix
4eaed25a5e Merge pull request #2491 from swiftix/devirtualizer-fixes
Small fixes for the sil-devirtualizer
2016-05-11 21:35:46 -07:00