Commit Graph

1020 Commits

Author SHA1 Message Date
Michael Gottesman
c54c903272 [func-sig-opts] Move addThunkArgument from FunctionSignatureTransform => FunctionSignatureTransformDescriptor.
More thinning of FunctionSignatureTransform.

rdar://38196046
2018-04-05 10:18:59 -07:00
Slava Pestov
e401304421 SILOptimizer: Clean up devirtualizer to use replaceDeadApply() 2018-04-05 08:53:33 -07:00
Michael Gottesman
3217987f4b [func-sig-opts] Extract out creation of function names/types onto the transform descriptor.
The two methods on FunctionSignatureTransform in question:

    createOptimizedSILFunctionName()
    createOptimizedSILFunctionType()

are pure computation on the transform descriptor on the
FunctionSignatureTransform. So there really isn't a reason not to make it a
getter method on FunctionSignatureTransformDescriptor. This helps me to thin out
FunctionSignatureTransform even further in prepration for splitting it.
2018-04-04 18:24:18 -07:00
Huon Wilson
50dc0c7c1f Remove artefact of bad merge. 2018-04-05 11:06:45 +10:00
Michael Gottesman
a1a6b86ad0 Merge pull request #15681 from gottesmm/pr-17835777497d609fe7736e8fa069a797e16fd153
[func-sig-opts] Add some missing anonymous namespaces.
2018-04-04 17:39:29 -07:00
Michael Gottesman
870d94bd68 [func-sig-opts] Reduce indentation by inverting a condition.
NFC.
2018-04-04 15:22:13 -07:00
Michael Gottesman
4a0a2c15eb Merge pull request #15728 from gottesmm/pr-0526c20d5d982f0b8125feae69de2dcc04ac60a9
[func-sig-opts] Extract out rest of helper functions from FunctionSig…
2018-04-03 20:52:42 -07:00
Michael Gottesman
ee79f06562 [func-sig-opts] Extract out rest of helper functions from FunctionSignatureTransform in preparation for splitting FunctionSignatureTransform into multiple sub-transforms.
This is something that has been talked about for some time. By splitting up
function signature optimization into several smaller "transforms" that can be
composed, we are able to test each transform individually as well as make it
easier to add more optimizations. Hopefully, other function signature
optimizations we currently perform with separate passes can be combined into
this framework.

NFC.
2018-04-03 19:35:04 -07:00
Michael Gottesman
ee94a8a723 [gardening] Add some missing anonymous namespaces. 2018-04-03 19:29:00 -07:00
swift-ci
9be60dd7b2 Merge pull request #15684 from gottesmm/blotmapvector_cleanups 2018-04-02 15:58:52 -07:00
Michael Gottesman
2007badf6b [blot-map-vector] Merge blot/erase => erase.
They do the same thing.
2018-04-02 11:29:49 -07:00
Michael Gottesman
7336534cfb [func-sig-opts][gardening] Standardize code section banners to look the same. 2018-04-02 08:53:24 -07:00
Michael Gottesman
eb6fd29fad [func-sig-opts] Add some missing anonymous namespaces.
No point in injecting anything into the global namespace.
2018-04-02 08:53:14 -07:00
Michael Gottesman
248d9db03c [func-sig-opts] Extract out the state shared in between various subtransforms in preparation for splitting the pass into separate testable chunks. 2018-03-31 13:27:35 -07:00
Michael Gottesman
5d400dc5d5 [func-sig-opts] Use MutableArrayRef instead of llvm::SmallVector to store Argument/Result descriptors.
We never push_back additional such items onto the descriptor lists once the
transform is constructed. We do on the other hand, potentially modify those
items in the vector. That suggests that this property is better represented by
the "simpler" MutableArrayRef.
2018-03-31 12:59:48 -07:00
Andrew Trick
1416739a64 Suppress NRVO in copy forwarding unless the copy is just a move.
Fixes <rdar://problem/39059402> CopyForwarding + Guaranteed Bug
2018-03-30 18:09:35 -07:00
Erik Eckstein
2b4132be23 SILOptimizer: adapt Outliner pass to guaranteed-by-default calling convention
Also did some refactoring to share common code.

rdar://problem/38152291
2018-03-29 10:49:36 -07:00
Joe Shajrawi
a232e1f358 [SILMem2Reg] add an assert when replacing debug_value_addr with debug_value: make sure it is not an address-only type 2018-03-23 15:29:37 -07:00
Andrew Trick
9703d56e03 [exclusivity] Remove dead access markers after optimization.
Generalized to handle scope markers which will become common with future
ownership and lifetime dependence markers.
2018-03-11 23:13:30 -07:00
Erik Eckstein
c408468210 ObjectOutliner: restrict object outlining to tail allocated arrays.
SR-7146, rdar://problem/38302248
2018-03-09 16:25:16 -08:00
Arnold Schwaighofer
1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Arnold Schwaighofer
89e972f5a8 SILGen: Implement withoutActuallyEscaping verification
Check that an ``withoutActuallyEscaping(noescape_closure) { // scope}`` closure
has not escaped in the scope using the ``is_escaping_closure %closure``
instruction.

rdar://35525730
2018-03-07 09:00:12 -08:00
Arnold Schwaighofer
5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
swift-ci
4df75e8cc5 Merge pull request #14816 from lattner/mem2reg-cleanup 2018-02-24 15:43:08 -08:00
Chris Lattner
47fbb0502e Refactor the body of the mem2reg transformation out to a helper function
to reduce indentation and simplify the logic, NFC.
2018-02-24 13:41:08 -08:00
Andrew Trick
a4c78dcf72 [NFC] Split up SimplifyCFG and JumpThreadSimplifyCFG transform.
A couple of lines of boilerplate simplies life. It's always nice when the
Transform class matches the formal pass definition. This way, the back trace
doesn't point you to the wrong transform.

There's no good reason to share Transform classes that I know of.
2018-02-22 20:16:44 -08:00
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Arnold Schwaighofer
a9fa8c9c2b Merge pull request #14514 from aschwaighofer/wip_closure_capture_abi_part2
WIP: Closure ABI - Make @noescape Swift closures trivial
2018-02-14 05:19:25 -08:00
Arnold Schwaighofer
d490c22bb4 SimplifyCFG: Skip convert_escape_to_noescape in try_apply -> apply optimization 2018-02-13 09:38:02 -08:00
Joe Shajrawi
102b6f0b61 Merge pull request #14587 from shajrawi/newinstr
Optimizer peephole for tagged BridgeObjects
2018-02-13 07:38:53 -08:00
Joe Shajrawi
f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
Andrew Trick
4734920222 Don't rerun diagnostic passes on deserialized SIL. 2018-02-09 09:55:47 -08:00
Andrew Trick
0dfce6c0f6 Don't rerun mandatory lowering passes on deserialized SIL. 2018-02-09 09:55:47 -08:00
Andrew Trick
0d937d1c15 Make MarkUninitialized a function pass. 2018-02-09 09:55:47 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Andrew Trick
5c4c6e2ed7 Fix AllocBoxToStack to notify the PassManager of cloned functions.
If the pass does not register a new function, that new function will never be
passed through the current function pipeline. We were getting lucky that enough
of the mandatory passes were module passes that it didn't seem to matter in
practice (until I convert them to function passes).

(after pass reorganization, a one line fix that doesn't rely on
outrageous changes to the pass' function signatures.)
2018-02-05 21:17:32 -08:00
Andrew Trick
ee42bdc446 [NFC] Reorganize the AllocBoxToStackPass.
In preparation for fixing a bug.
- Separate general SIL utilities, liveness, escape analysis,
  and promotion.
- Give promotion routines access to the current pass.

Ideally, the current pass would be accessible via TLS. In the meantime,
pass routines should always have access to a state object that
encapsulates the pass information corresponding to a single invocation
of the pass.

Access to the pass' state should be consistent and idiomatic; it should
not depend on the where we are in the call stack. This makes the code much easier to understand and refactor, and it enables exploratory changes.
2018-02-05 21:17:32 -08:00
Michael Gottesman
950e55d899 [sil][typelowering] Inline (i.e. eliminate) the confusing method TypeLowering::getLoweringStyle() and change it to properly use TypeExpansionKind::None instead of TypeExpansionKind::DirectChildren for the non-expansion case.
Now we will consistently expand destroy_addr/copy_addr into either
{retain,release}_value or into ARC operations on its most derived descendents.
This will improve code-size (by not expanding when we didn't intend to), but
more importantly preserve invariants that the ARC optimizer depends upon.

rdar://36509461
2018-01-25 14:09:57 -08:00
Michael Gottesman
d14024acd3 [sil][typelowering] Rename the enum LoweringStyle => TypeExpansionKind and add a None case to make its usage clearer.
This enum controls how certain routines in TypeLowering potentially expand types
when performing copy_value/destroy_value operations. Its previous form was
problematic because:

1. The name LoweringStyle does't suggest anything related to expansion really.
The new has the word expansion in it explicitly.
2. The cases of LoweringStyle used to be Shallow, Deep. This caused confusion
since Shallow (the base case) was not a no-op. It just caused us to expand into
children. Now TypeExpansionKind has 3 cases to make this clear: None,
DirectChildren, and MostDerivedDescendents.

Confusion around this API caused us to canonicalize ARC operations differently
for different operations (e.g. copy_value/destroy_value vs
copy_addr/destroy_addr). This caused us to misout on some code-size wins (since
we were splitting some operations onto DirectChildren of aggregates), but more
importantly also caused the optimizer to break an invariant that the ARC
optimizer relied upon: local semantic pairings being at the same level of
abstraction. In a subsequent commit, I am going to fix that bug.

rdar://36509461
2018-01-24 16:28:03 -08:00
Erik Eckstein
3afd9c8eb4 ObjectOutliner: fix for handling set_deallocating instruction correctly.
rdar://problem/36692828
2018-01-23 18:21:33 -08:00
Erik Eckstein
e081392672 ObjectOutliner: handle set_deallocating instruction correctly.
rdar://problem/36692828
2018-01-22 17:04:56 -08:00
Davide Italiano
3c9fa1627c [AllocBoxToStack] Use SILBUilderWithScope instead of SILBuilder.
It's the correct thing to do, as we immediately switch the current
debug scope. In this case, it's NFC as the code was already doing
the right thing, but this is more concise/harder to get wrong.
2018-01-21 13:18:34 -08:00
Erik Eckstein
80a734ab30 DeadObjectElimination: handle objects for which the destructor is de-virtualized and inlined
Also: add an additional DeadObjectElimination pass in the low level pipeline because
redundant load elimination (which runs before) can turn an object into a dead object.
2018-01-19 11:33:26 -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
Erik Eckstein
c3ef03fc37 ARCCodeMotion: add a small peephole optimization which removes adjacent retain/release pairs.
This reduces phase ordering problems, because it eliminates the need for a ARCSequenceOpt (which also does this optimization).
2018-01-19 11:32:36 -08:00
Erik Eckstein
bf87035a36 GlobalOpt: Move the object outlining from GlobalOpt into a separate pass "ObjectOutliner"
We run GlobalOpt multiple times in the pass pipeline but in some cases object outlining shouldn't be done too early.
Having it done in a separate pass enables to run it independently from GlobalOpt.
2018-01-19 11:32:36 -08:00
Erik Eckstein
4f8cccff68 SimplifyCFG: do constant folding also in SimplifyCFG.
This enables to optimize chains of constant-foldable terminal instructions, for which we would have needed multiple ConstantPropagaion-SimplifyCFG pass pairs in the pipeline otherwise.
See the test file for an example.
2018-01-19 11:32:33 -08:00
eeckstein
b126b62256 Revert "Optimization changes to completely fold OptionSet literals" 2018-01-18 22:05:07 -08:00