Commit Graph

206 Commits

Author SHA1 Message Date
Joe Groff
77dd9b2992 Split exact-subclass and bindable-to-subclass queries.
In many places, we're interested in whether a type with archetypes *might be* a superclass of another type with the right bindings, particularly in the optimizer. Provide a separate Type::isBindableToSuperclassOf method that performs this check. Use it in the devirtualizer to fix rdar://problem/24993618. Using it might unblock other places where the optimizer is conservative, but we can fix those separately.
2016-03-09 11:14:45 -08:00
Michael Gottesman
bb15808554 Convert some trivial std::count_if invocations on ranges to use the provided range adaptor. 2016-03-08 14:58:13 -08:00
Michael Gottesman
5f72810ad3 Add a range adaptor for std::count and update various trivial usages in the compiler to use this API instead. 2016-03-08 14:58:13 -08:00
Mark Lacey
4f2f993c68 Fix use-after-free in SimplifyCFG's block argument splitter.
We were creating new uses of an argument just prior to erasing it from
the block argument list.

We need to replace references to that value in the side structure we
generate with references to the new value that we're replacing it with.

Fixes SR-884 / rdar://problem/25008398.
2016-03-07 23:22:34 -08:00
Xin Tong
64e2710102 Move LSBase.x to SILOptimizer/Utils/. NFC. 2016-03-07 22:07:13 -05:00
Xin Tong
ba0249c924 Rename SILValueProjection.x to LSBase.x. NFC 2016-03-07 21:26:56 -05:00
Xin Tong
55377e727a Move createExtract to ProjectionPath::createExtract. NFC. 2016-03-07 21:26:56 -05:00
Xin Tong
bfc258f628 Simplify LSValue::reduce for redundant load elimination
LSValue::reduce reduces a set of LSValues (mapped to a set of LSLocations) to
a single LSValue.

It can then be used as the forwarding value for the location.

Previously, we expand into intermediate nodes and leaf nodes and then go bottom
up, trying to create a single LSValue out of the given LSValues.

Instead, we now use a recursion to go top down. This simplifies the code. And this
is fine as we do not expect to run into type tree that are too deep.

Existing test cases ensure correctness.
2016-03-07 21:26:56 -05:00
Kevin Yu
8f193c856e [gardening] Fix typos "cant" -> "can't", "dont" -> "don't" 2016-03-06 00:25:14 +00: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
Xin Tong
ddb9bba50e Improve the compilation time of redundant load elimination
For forwarding on allocstacks, we can invalidate the forwable bit when we
hit the deallocate stack.

This helps compilation time as we do not need to propagate these bits down
to subsequent basic blocks.
2016-02-29 10:11:40 -08:00
Erik Eckstein
68f0d5c202 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

It was reverted because of a bug in ValueLifetimeAnalysis which is now fixed.
2016-02-29 07:42:59 -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
eeckstein
718e9e6f72 Merge pull request #1462 from eeckstein/specializer_new_attempt
Specializer new attempt
2016-02-26 17:02:29 -08:00
Xin Tong
19c528e59d Make more passes respect no.optimize 2016-02-26 16:03:17 -08:00
Erik Eckstein
3a83cee006 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

The exposed crash in the ClosureSpecializer is fixed.
2016-02-26 14:05:48 -08: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
f70b53b015 Revert "Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."""
This reverts commit c556d5cd39.

Hitting a new assert.
2016-02-25 09:50:11 -08:00
Erik Eckstein
c556d5cd39 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

After Xin's recent fix in ARC (6a9a430f68) the crash on i386 should be resolved.
2016-02-25 08:48:15 -08:00
Mark Lacey
0a893c1f88 Fix typo in comment. 2016-02-24 14:17:32 -08:00
Michael Gottesman
a5be2fff01 [sil] Use FullApplySite instead of ApplyInst in SILInstruction::getMemoryBehavior().
We were giving special handling to ApplyInst when we were attempting to use
getMemoryBehavior(). This commit changes the special handling to work on all
full apply sites instead of just AI. Additionally, we look through partial
applies and thin to thick functions.

I also added a dumper called BasicInstructionPropertyDumper that just dumps the
results of SILInstruction::get{Memory,Releasing}Behavior() for all instructions
in order to verify this behavior.
2016-02-23 15:00:43 -08:00
Erik Eckstein
5b4c73ed3b Revert "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."
This reverts commit 4187959e66.

There is a crash in StdlibUnittests on i386 (Release-Assert build)
2016-02-23 08:29:41 -08:00
Erik Eckstein
4187959e66 GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.
With this re-abstraction a specialized function has the same calling convention as if it would have been written with the specialized types in the first place.
In general this results in less alloc_stacks and load/stores.
It also can eliminate some re-abstraction thunks, e.g. if a generic closure is used in a non-generic context.
It some (hopefully rare) cases it may require to add re-abstraction thunks.

In case a function has multiple indirect results, only the first is converted to a direct result. This is an open TODO.
2016-02-22 13:58:10 -08:00
Erik Eckstein
666e20381f Refactor some ArraySemanticsCall code. NFC. 2016-02-22 13:58:10 -08:00
Mark Lacey
bc36b2a601 Improve handling of unreachable blocks in mem2reg.
We were handling regular uses, but not handling promotions in things
like debug_value_addr.

This was exposed by some pass ordering changes I have in an upcoming
commit.
2016-02-22 12:11:00 -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
Nadav Rotem
b4d836880f [Doc] Rename a function and change 'auto' to an explicit type as suggested by @slavapestov in code review. 2016-02-19 21:54:07 -08:00
Xin Tong
95f3280461 Remove a double negative. NFC 2016-02-19 20:45:23 -08:00
Xin Tong
e42bd372eb Skip processing block without loads.
After collected enough information in the first iteration of the
data flow. We do not do second iteration (last iteration) for blocks
without loads as we will not forward any load there.

This improves compilation time of redundant load elimination.
2016-02-19 20:45:23 -08:00
Nadav Rotem
2d20eb6c54 Update the pass to use the destructured result types that John introduced a few days ago. 2016-02-19 16:48:29 -08:00
Nadav Rotem
30927d3459 Implement CSE of the trio open_ext + witness_method + apply.
When we emit calls to existential methods silgen produces a sequence of the
three instructions below:

open_existential_addr %0 : $*Pingable to $*@opened("1E467EB8-...") Pingable
witness_method $@opened("1E467EB8-...") Pingable, #Pingable.ping!1
apply %3<@opened("1E467EB8-...") Pingable>(%2)

This commit adds a new CSE-like pass that finds sequences of calls to protocol
methods and reuses the first two instructions open_existential_addr and
witness_method. The optimization finds arguments that must not alias and may not
escape and combines all of the existential method calls to use the same method
lookup. The optimization handles control flow by finding the top dominating
open_existential instruction, and uses that instruction.

related to rdar://22704464.
2016-02-19 16:48:29 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Arnold Schwaighofer
31e01a5dd9 CopyForwarding: More places to check whether we have a function arg 2016-02-17 15:08:43 -08:00
Arnold Schwaighofer
2f81e4eaf8 CopyForwarding: We need to check whether an argument is a function argument before checking its convention 2016-02-17 14:38:44 -08:00
Xin Tong
e2c0990851 Rename hasNoUsesExceptDebug to onlyHaveDebugUses. The double negation logic is
harder to understand. NFC.
2016-02-10 14:46:09 -08:00
Xin Tong
84a6ff1d98 And lastly rename NewProjection to Projection. This is a NFC. rdar://24520269 2016-02-09 22:20:10 -08:00
Xin Tong
6fb741bbca Migrate dead object elimination to new projection. This should be a NFC 2016-02-09 22:20:09 -08:00
Xin Tong
0258e8e816 Migrate to use new projection for SimplifyCFG. This should be a NFC.
This is part of rdar://24520269
2016-02-06 08:27:05 -08:00
Xin Tong
338a2d0af5 Migrate to use new projection for SILmem2reg. This should be a NFC.
This is part of rdar://24520269
2016-02-05 23:16:35 -08:00
Xin Tong
8318b83016 Remove unnecessary header. NFC 2016-02-05 22:49:24 -08:00
Mark Lacey
82fd057eaf Remove devirtualization and specialization from the inliner.
Now that we process functions in bottom-up order in the pass manager and
have a mechanism to restart the pass pipeline on the current
function (or on a newly created callee function), we can split these
passes back out from the inliner and end up with the same benefits we
had from initially integrating them. We get the further benefit of fully
optimizing newly created callee functions before continuing with the
function that resulted in the creation of those callee
functions (e.g. as a result of a specialization pass running).
2016-02-04 08:52:01 -08:00
Adrian Prantl
0854b3ce6d SILDebugScope: Add accessors for the parent SIL functions and use them in
assertions. (NFC)
2016-02-03 14:48:06 -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
Arnold Schwaighofer
ac423ebe97 A generic class can inherit from objc and so the devirtualizer needs to emit a default case
rdar://23228386
2016-02-01 20:33:40 -08:00
Arnold Schwaighofer
f6866b4ae7 Perform a dynamic method call if a class has objc ancestry in speculative devirt as fallback.
If a class has an @objc ancestry this class can be dynamically overridden and
therefore we don't know the default case even if we see the full class
hierarchy.

rdar://23228386
2016-02-01 18:16:37 -08:00
Dmitri Gribenko
1f6fe29e49 Merge pull request #1155 from practicalswift/typo-fixes-20160201
[gardening] Fix typos: "specalized" → "specialized", "uniqueing" → "uniquing"
2016-02-01 14:57:18 -08:00
practicalswift
397bda1624 [gardening] Fix recently introduced typo: "uniqueing" → "uniquing" 2016-02-01 23:07:39 +01:00
Erik Eckstein
3c6c48c4bf SimplifyCFG: simplify the switch_enum -> select_enum conversion.
The main intention for this change is to eliminate the use of the post/dominator trees in this transformation.
These were re-calculated on every conversion which caused long compile times for functions with lot of switch_enum instructions: rdar://problem/24410167

Beside that, the code for collecting the target-block's predecessors is now simpler. It's not necessary to handle arbitrary control flow pathes because jump threading is simplifying the CFG anyway.

Now SimplifyCFG does not use the PostDominanceAnalysis anymore.
2016-02-01 13:32:55 -08:00
Slava Pestov
587a11ebb5 Merge pull request #1144 from Saisi/niggling_typos
Fixed more niggling typos
2016-01-29 23:55:21 -08:00