Commit Graph

2601 Commits

Author SHA1 Message Date
Doug Gregor
911ed60a98 Eliminate dead code making use of SubstitutionList. 2018-05-11 17:37:27 -07:00
Doug Gregor
d457f1c752 [IRGen/SIL] More widespread use of SubstitutionMap. 2018-05-11 13:18:06 -07:00
Doug Gregor
09446defef Eliminate yet more SubstitutionLists from SIL in search of a steady-state 2018-05-11 13:18:06 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
Michael Gottesman
1d29fcad5f [function-sig-opts] Extract FunctionSignatureTransform into FunctionSignatureTransform.h in preparation for exploding out function-sig-opts.
I am also going to use this to implement Guaranteed -> Owned in its own file.
The exploding of the other parts of function-sig-opts will happen later.

rdar://38196046
2018-05-08 12:52:13 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Doug Gregor
408aaa5332 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 08:48:55 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
ed1983d9d0 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 00:05:21 -07:00
Arnold Schwaighofer
4525722395 SIL: Add getSingleDealloc to AllocStack and remove two copies of it
I am going to introduce a third use in a follow-up
2018-05-01 07:24:19 -07:00
Michael Gottesman
53c065a25b Merge pull request #16266 from gottesmm/pr-862698ff9224afe2ccafc3fa43c3016dd857c75d
[perf] Change a pass by value of a SmallPtrSet<Ptr, 8> to by ref.
2018-04-30 17:05:02 -07:00
Michael Gottesman
8a7e0fb743 [gardening] Change 3x SmallPtrSet in comments to be SmallPtrSetImpl while I am in the neighborhood. 2018-04-30 15:43:19 -07:00
Michael Gottesman
7b7c3ec9b5 [perf] Change a pass by value of a SmallPtrSet<Ptr, 8> to by ref.
Just noticed on inspection.
2018-04-30 15:43:19 -07:00
David Zarzycki
95473a10d7 [Misc] NFC: Fix random build warnings
Unused variables/methods, language extensions, extra semicolons, intentional
self assignment, platform specific quirks, etc.
2018-04-30 12:52:43 -04:00
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Michael Gottesman
1a66f4cbea [gardening] Change some c style for loops to for-each loops. 2018-04-26 17:32:59 -07:00
Michael Gottesman
74fd0a4017 [gardening] Eliminate whitespace around ++/-- and be consistent about using pre-increment. 2018-04-26 17:32:59 -07:00
Michael Gottesman
cbebc9bfd7 [func-sig-opts] Run DeadArgument elimination before ArgumentExplosion.
This ensures that we perform analysis and transformation in the same order. This
is the last missing piece before I can split function signature opts (a task for
another time).

rdar://38196046
2018-04-26 16:08:12 -07:00
Michael Gottesman
3603b5b38e [func-sig-opts] Add some options to disable individual parts of FSO.
This is just a quick way to write tests for FSO given that it is not split yet.

rdar://38196046
2018-04-26 13:50:11 -07:00
Michael Gottesman
1fdb6ca4ab [func-sig-opts] Make FunctionSignatureOptUtils a library specific header and merge some of it into FunctionSignatureOpts.
This functionality is really specific to FunctionSignatureOpts. It really
doesn't make sense to have it as a utils until it becomes more general or we
need it in multiple places.

NFC.

rdar://38196046
2018-04-25 18:10:30 -07:00
Michael Gottesman
b05094fbed Merge pull request #15973 from gottesmm/pr-6a0bf75d9fc53d10ccd9de4251fb9b080f22a6b5
SILCleanup => IRGenPrepare.
2018-04-17 10:45:17 -07:00
Andrew Trick
497920eed3 Merge pull request #15934 from atrick/sideeffect-refactor
[NFC] SideEffectAnalysis refactoring and cleanup.
2018-04-17 06:44:13 -07:00
Michael Gottesman
5baa90ca4c [irgen-prepare] Move SILCleanup to ./lib/SILOptimizer/Mandatory and rename it to IRGenPrepare.
I am going to be adding logic here to enable apple/swift#1550 to be completed.
The rename makes sense due to precedent from LLVM's codegen prepare and also
since I am going to be expanding what the pass is doing beyond just "cleaning
up". It is really a grab bag pass for performing simple transformations that we
do not want to pollute IRGen's logic with.

https://github.com/apple/swift/pull/15502

rdar://39335800
2018-04-17 00:07:16 -07:00
Slava Pestov
bb244b2812 SIL Optimizer: Update outdated comment concerning transparent functions 2018-04-16 19:32:02 -07:00
Andrew Trick
cdcb7c7a2c [NFC] SideEffectAnalysis refactoring and cleanup.
Make this a generic analysis so that it can be used to analyze any
kind of function effect.

FunctionSideEffect becomes a trivial specialization of the analysis.

The immediate need for this is to introduce an new
AccessedStorageAnalysis, although I foresee it as a generally very
useful utility. This way, new kinds of function effects can be
computed without adding any complexity or compile time to
FunctionSideEffects. We have the flexibility of computing different
kinds of function effects at different points in the pipeline.

In the case of AccessedStorageAnalysis, it will compute both
FunctionSideEffects and FunctionAccessedStorage in the same pass by
implementing a simple wrapper on top of FunctionEffects.

This cleanup reflects my feeling that nested classes make the code
extremely unreadable unless they are very small and either private or
only used directly via its parent class. It's easier to see how these
classes compose with a flat type system.

In addition to enabling new kinds of function effects analyses, I
think this makes the implementation of side effect analysis easier to
understand by separating concerns.
2018-04-16 17:05:04 -07:00
Arnold Schwaighofer
49ba28a9ac Outliner: Clear IsBridgedArgument state in between matching
Otherwise, when we mangle a signature of bridged/not_bridged arguments
we can see the state from the previous match of another instruction.

SR-7426
rdar://39414272
2018-04-13 11:10:22 -07:00
swift-ci
a16c423518 Merge pull request #15875 from dcci/di-member 2018-04-12 11:35:31 -07:00
Davide Italiano
b4d563802b [SILInstruction] Introduce isDebugInstruction().
This is a property of an instruction and should be a member
function of `SILInstruction` and not a free function in
`DebugUtils`. Discussed with Adrian.
2018-04-11 10:14:21 -07:00
Andrew Trick
8ab8ca4efa Make CopyForwarding more conservative about shrinking lifetimes.
Fixes <rdar://problem/39209102> [SR-7354]: Swift 4.1 Regression: EXC_BAD_ACCESS for Optimized Builds in Xcode 9.3

Commentary:

The underlying problem is that CopyForwarding is an inherently
dangerous pass by design that has been waiting for the SIL
representation to evolve to the point where it can be rewritten.

The regressions was caused by PredictableMemOps failing to preserve
normal patterns of ownership. When it forwards loads, it implicitly
extends the lifetime of stored value

store %val to %addr
...
retain %val
...
destroy_addr %addr

CopyForwarding already tried to detect such violations of ownership
rules and normally bypasses destroy hoisting in those cases. In this
case, it fails to detect the problem because PredictableMemOps has
already erased the load, so there's no evidence of the value's
lifetime being extended.

It might have been nice if PredictableMemOps had transformed the
retain %val into a retain %addr. However, for the immediate fix, we
don't want to change any existing behavior other than suppressing
optimization. In the long term, CopyForwarding does not really make
sense without SemanticSIL+SILOwnership and should be totally rewritten
and greatly simplified at that point.
2018-04-10 22:08:54 -07:00
Michael Gottesman
88bc490380 [func-sig-opts] hasNonTrivialNonDebugUse => hasNonTrivialNonDebugTransitiveUsers and move to DebugUtils.
I am getting rid of FunctionSignatureOptUtils. It is only used by
FunctionSignatureOpts, so it should either be a local utility file whose header
lives in ./lib or integrated into FunctionSignatureOpts. Beyond this utility
function (which seems like a generally useful thing that should be in
DebugUtils), the only other thing left in FunctionSignatureOptUtils is part of
the heuristic of FunctionSignatureOpts. It should really be in that file.

rdar://38196046
2018-04-07 10:06:48 -07:00
swift-ci
25d9e5ffd6 Merge pull request #15768 from gottesmm/pr-eb8a7dc34368b86cdaa62ae93666d70cfcb26acb 2018-04-05 11:14:38 -07:00
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