Commit Graph

55 Commits

Author SHA1 Message Date
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
Michael Gottesman
49bf82245b [mandatory-inlining] Make fixupReferenceCounts not delete instructions.
The main loop of mandatory inlining is spending a lot of time managing complex
iterator invalidation issues. This is the first in a series of commits that move
the main inlining loop to only delete the callee and to do all cleanups after we
have finished inlining.

This specific optimization (the quick retain/release peephole), I am not going
to do in MandatoryInlining, we already have guaranteed arc opts afterwards that
will be able to hit such a peephole so no perf should be lost.

*NOTE* The reason why I had to touch some of the code motion tests is that the
routine I am using to ensure that strong_retain/release_value is emitted as
appropriate is also used by codemotion. Code motion tests had cargo culted some
code from previous tests that retained Builtin.Int32. I changed the routines
though so that when a retain/release is inserted, if it is trivial, nothing is
inserted. No routine was relying on the actual usage of the inserted
retain/releases, so everything will be safe. This addition to the relevant code
caused me to need to change the tests in code motion to use actual non-trivial
values. The same code paths are being tested in terms of blocking code
motion/etc.

rdar://31521023
2017-09-10 13:23:48 -07:00
Joe Shajrawi
570a82aea5 Reduce expansion of large types in the optimizer 2017-08-25 13:56:26 -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
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
Erik Eckstein
3b54966ff2 SILOptimizer: Add a utility to find dead-end blocks. 2017-07-21 10:37:54 -07:00
Erik Eckstein
805960b0ac ValueLifetimeAnalysis: fix the lifetime computation in case the value definition is in a single-block loop.
This caused DeadObjectElimination to generate a memory leak in case a dead array is in a single-block loop.
rdar://problem/31420889
2017-04-04 10:43:53 -07:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Slava Pestov
4ed09b4a73 SILOptimizer: Remove some workarounds for old problems
It looks like the devirtualizer used to have problems computing
method types in the presence of generic substitutions, covariant
returns and other things, so it would bail if a perticular set
of pre-conditions was not met on the types of original method call
and the devirtualized method call.

I don't think any of this is necessary anymore. If this patch
introduces any regressions, we need to fix the root cause instead
of re-introducing this logic.
2017-02-27 00:03:46 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
b22f9ea487 AST: Remove SubstitutionMap::getMap()
We don't want to expose the fact that SubstitutionMaps are
backed by a DenseMap, since that's going to change soon.
2017-02-06 19:43:33 -08:00
Slava Pestov
844765b2fc SILOptimizer: Clean up hasDynamicSelfTypes() and hasUnboundGenericTypes() 2017-01-08 21:01:13 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
4e8ff35df5 [semantic-sil] Add ValueOwnershipKind field to SILPHIArgument and split Argument creation methods into one for SILPHIArgument and another for SILFunctionArgument.
We preserve the current behavior of assuming Any ownership always and use
default arguments to hide this change most of the time. There are asserts now in
the SILBasicBlock::{create,replace,insert}{PHI,Function}Argument to ensure that
the people can only create SILFunctionArguments in entry blocks and
SILPHIArguments in non-entry blocks. This will ensure that the code in tree
maintains the API distinction even if we are not using the full distinction in
between the two.

Once the verifier is finished being upstreamed, I am going to audit the
createPHIArgument cases for the proper ownership. This is b/c I will be able to
use the verifier to properly debug the code. At that point, I will also start
serializing/printing/parsing the ownershipkind of SILPHIArguments, but lets take
things one step at a time and move incrementally.

In the process, I also discovered a CSE bug. I am not sure how it ever worked.
Basically we replace an argument with a new argument type but return the uses of
the old argument to refer to the old argument instead of a new argument.

rdar://29671437
2016-12-18 14:48:35 -08:00
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -06:00
Michael Gottesman
bf6920650c [gardening] Drop BB from all argument related code in SILBasicBlock.
Before this commit all code relating to handling arguments in SILBasicBlock had
somewhere in the name BB. This is redundant given that the class's name is
already SILBasicBlock. This commit drops those names.

Some examples:

getBBArg() => getArgument()
BBArgList => ArgumentList
bbarg_begin() => args_begin()
2016-11-25 01:14:36 -06:00
Michael Gottesman
e42bf07af4 [gardening] Always create SILBasicBlocks via SILFunction::createBasicBlock.
This eliminates all inline creation of SILBasicBlock via placement new.

There are a few reasons to do this:

1. A SILBasicBlock is always created with a parent function. This commit
formalizes this into the SILBasicBlock API by only allowing for SILFunctions to
create SILBasicBlocks. This is implemented via the type system by making all
SILBasicBlock constructors private. Since SILFunction is a friend of
SILBasicBlock, SILFunction can still create a SILBasicBlock without issue.

2. Since all SILBasicBlocks will be created in only a few functions, it becomes
very easy to determine using instruments the amount of memory being allocated
for SILBasicBlocks by simply inverting the call tree in Allocations.

With LTO+PGO, normal inlining can occur if profitable so there shouldn't be
overhead that we care about in shipping compilers.
2016-11-25 01:12:49 -06: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
Joe Groff
e4c67e2d5a SIL: Give project_box a field index operand.
Allow project_box to get the address of any field in a multi-field box.
2016-10-24 13:10:41 -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
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
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
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
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
Xin Tong
c758848c92 Share a few createIncrement/createDecrement functions 2016-05-26 12:55:25 -07:00
swift-ci
48e0aac9a6 Merge pull request #2234 from trentxintong/IP 2016-04-18 16:41:10 -07:00
Xin Tong
bfc9683b49 Use a SmallPtrSet instead of a DenseSet. More memory efficient 2016-04-18 14:54:39 -07:00
practicalswift
0c89048988 [gardening] Fix recently introduced typo: "transistive" → "transitive" 2016-04-14 22:26:44 +02:00
Xin Tong
31b6c65039 Fix a logic error in eraseUseOfValue.
I failed to create a test case. And we hav existing tests in FSO that will
exercise this.

rdar://25559780
2016-04-13 20:53:28 -07:00
Erik Eckstein
3e52d24853 add a debug dump function for ValueLifetimeAnalysis 2016-04-13 13:22:30 -07:00
Mark Lacey
99d4485713 Fix double delete in generic specialization.
We ended up adding the same instruction twice to a SmallVector of
instructions to be deleted. To avoid this, we'll track these
to-be-deleted instructions in a SmallSetVector instead.

We were also failing to add an instruction that we can delete to the set
of instructions to be deleted, so I fixed that as well.

I've added a test case, but it's currently disabled because fixing this
turned up another issue in the same code which I still need to take a
look at.

Fixes rdar://problem/25369617.
2016-03-30 13:10:00 -07:00
Slava Pestov
a9ad760b78 SIL: Clean up duplicated "can be referenced from a fragile function" checks 2016-03-25 22:46:50 -07:00
practicalswift
d00a5ef814 [gardening] Weekly gardening: typos, duplicate includes, header formatting, etc. 2016-03-24 22:41:10 +01:00
Xin Tong
524ed34583 Make sure epilogue releases do not kill redundant loads
I did not measure a performance improvements with this.
2016-03-23 23:59:54 -07:00
Arnold Schwaighofer
7405512dcb Fix the cast optimizer to remove instructions after inserting unreachable
Also insert the store and dealloc_stack instructions before the trap the cast
optimizer inserts.

rdar://24761530
2016-03-09 20:05:59 -08:00
practicalswift
9b1d73fcac [gardening] Fix recently introduced typo: "exit exit" → "exit" 2016-03-02 09:34:21 +01:00
Erik Eckstein
115c50a5c7 DeadObjectElimination: Fix a problem with dead array elimination.
With the new ValueLifetimeAnalysis DOE did not handle case where a dead array is not released on a path at all (because it leads to an unreachable).
2016-03-01 12:30:52 -08:00
Erik Eckstein
1730b90ae4 Reinstate "Rewrite the ValueLifetimeAnalysis."
Reinstates commit 0c2ca94ef7

With two bug fixes:
*) use after free asan crash
*) wrong check in ValueLifetimeAnalysis::isWithinLifetime
And some refactoring
2016-02-29 07:42:59 -08:00
Xin Tong
d0dc008fc1 Revert GenericSpecializer code.
This reverts commit

ed8126d050
ac0e7fd183
a11042eb05
b2d6e8ce6e
3a83cee006
0c2ca94ef7

First 4 commits are @practicalswift typo fixes which are implicated. Last 2 are
the culprits.

This causes an asan build crash.
2016-02-28 11:13:44 -08:00
practicalswift
b2d6e8ce6e [gardening] Fix recently introduced typo: "corrseponding" → "corresponding" 2016-02-27 12:16:52 +01:00
Erik Eckstein
0c2ca94ef7 Rewrite the ValueLifetimeAnalysis.
It fixes a problem with lifetime regions having "exit-edges". This crashed the ClosureSpecializer.
2016-02-26 14:05:48 -08:00
Erik Eckstein
682c1cb5a1 refactoring: move static function isPartialApplyOfReabstractionThunk from SILCombiner to Local.
Because it will be needed by the generic specializer, too.
NFC
2016-02-22 13:58:10 -08:00
Xin Tong
a48584ccbc Create a fast path for not-final release instruction.
For a release on a guaranteed function paramater, we know right away
that its not the final release and therefore does not call deinit.

Therefore we know it does not read or write memory other than the reference
count.

This reduces the compilation time of dead store and redundant load elim. As
we need to go over alias analysis to make sure tracked locations do not alias
with it.
2016-02-20 22:00:36 -08:00
Erik Eckstein
8520120121 SimplifyCFG: don't recalculate the dominator tree for each jump threaded checked_cast_br instruction.
This is done by splitting the transformation into an analysis phase and a transformation phase (which does not use the dominator tree anymore).
The domintator tree is recalucated once after the whole function is processed.

This change eventually solves the compile time problem of rdar://problem/24410167.
2016-02-02 17:46:32 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Erik Eckstein
5a53b31f57 SIL: remove use-iteration functions from SILValue.
They are not needed anymore. NFC.
2016-01-25 15:00:49 -08:00
Erik Eckstein
b745691a38 SIL refactoring: Move some functions out of SILValue and Operand
SILValue.h/.cpp just defines the SIL base classes. Referring to specific instructions is a (small) kind of layering violation.
Also I want to keep SILValue small so that it is really just a type alias of ValueBase*.
NFC.
2016-01-25 10:37:03 -08:00
practicalswift
73b1d082ba [gardening] Fix typos: "word word" (three spaces) → "word word" (one space) 2016-01-24 21:38:03 +01:00