Commit Graph

4277 Commits

Author SHA1 Message Date
zoecarver
eb39989f10 Remove debug dump call 2019-12-07 17:22:08 -08:00
zoecarver
97f1b4e28e Check that the only uses of a global addrs are stores 2019-12-07 17:19:46 -08:00
zoecarver
42a7b653ab Add extra safety check before removing globals and add accessors even in the global accessor function 2019-12-07 17:19:07 -08:00
Michael Gottesman
dce8b6a3da Revert "Revert "[semantic-arc-opts] Teach load [copy] -> load_borrow about forwarding…""
This reverts commit a50796e07a.
This recommits commit df6ff7fea9.

Conflicts:
	lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp
2019-12-07 13:19:17 -08:00
zoecarver
b366e9b5ad Fix invalid global addr being collected 2019-12-07 12:55:00 -08:00
zoecarver
179652ccae stash 2019-12-06 22:02:31 -08:00
zoecarver
6819c28de2 Merge branch 'master' into optimize/dead-global-vars 2019-12-06 22:01:06 -08:00
Michael Gottesman
67ff2ae69e [semantic-arc-opts] Change to always use the worklist.
Previously we were:

1. Doing a linear scan, performing certain optimizations, and setting up a
worklist for future processing.

2. Draining the worklist of changed instructions until we reached a fix point.

The key thing here is that for (1) to be safe, we would need to not perform any
optimizations on block arguments since there was an ssumption that we would only
perform SSA-like optimizations.

I am going to be adding such optimizations soon, so it makes sense to just
convert the initial traversal to non-destructively seed the worklist and
eliminate that initial optimization pass.

This should be NFC.
2019-12-06 11:50:17 -08:00
Michael Gottesman
d6e30b5aa8 [outliner] Add support for passing bridging args as guaranteed if we do not find a release. 2019-12-06 11:50:17 -08:00
zoecarver
c11a9715d4 Remove duplicate test and fix formatting 2019-12-06 11:18:34 -08:00
zoecarver
95afdd0207 Check size of element, not if the element exists 2019-12-06 11:15:53 -08:00
zoecarver
798eea831c add helper function: canBeUsedOrChangedExternally 2019-12-06 10:45:04 -08:00
zoecarver
a8ad156142 Resolve build failure 2019-12-06 10:39:20 -08:00
Erik Eckstein
9b16a3567b Cross-module-optimization: make sure that witness tables, which are used by serialized functions, get public linkage
Fixes an undefined-symbol error.
2019-12-06 09:37:03 +01:00
zoecarver
e713ead777 Rename GlobalAccess to GlobalAccesses 2019-12-05 12:53:29 -08:00
zoecarver
73af502d2d Create list of instructions to delete 2019-12-05 12:51:35 -08:00
Erik Eckstein
a7910d7ed4 Cross-module-optimization: fix a use-after-free ASAN crash
rdar://problem/57642102
2019-12-05 14:10:54 +01:00
swift-ci
cb4d0fa9b8 Merge pull request #28560 from eeckstein/fix-cmo2 2019-12-04 09:38:24 -08:00
Varun Gandhi
e7be41d0cb Merge pull request #27479 from varungandhi-apple/vg-track-clang-function-types
Track Clang function types in the AST
2019-12-04 08:47:35 -08:00
Erik Eckstein
1b20134d4f Cross-module-optimization: Mark stored class properties as usableFromInline if they are used in a ref_element_addr instruction.
Fixes a wrong linkage for direct field offset variables.
2019-12-04 17:02:56 +01:00
Erik Eckstein
356a388d05 Cross-module-optimization: no need to add AST-attributes to make functions always-emit-into-client.
This is less hacky and possible now, as we de-serialize the linkage from SIL (and not just derive it from the AST attributes).
2019-12-04 09:16:28 +01:00
Erik Eckstein
d224031efc SpeculativeDevirtualizer: Make sure to link SILFunctions after speculative de-virtualization.
This makes sure that the pass de-serializes all always-emit-into-client functions.
2019-12-04 09:16:28 +01:00
swift-ci
7388b6c0a5 Merge pull request #28556 from atrick/escape-valueescapes 2019-12-03 23:23:33 -08:00
Andrew Trick
b8d901be63 EscapeAnalysis: minor cleanup to prepare for alias analysis rewrite.
Create a Predecessor abstraction for readability. Eliminates frequent
occurence of inscrutable getInt() and getPointer() calls.

Create an escapesInsideFunction() API that only uses mapped
values. This prevents bugs where a content node's value would be
mistakenly used to check for escapes.
2019-12-03 21:50:48 -08:00
Robert Widmann
2b1c1a2d23 Merge pull request #28455 from kitaisreal/willthrow-only-on-throw
[SILGEN] Inject "willThrow" hooks after foreign error propagation.
2019-12-03 19:38:58 -08:00
zoecarver
e73f027bf0 Merge branch 'master' into optimize/dead-global-vars 2019-12-03 18:25:18 -08:00
zoecarver
e470ed00f1 Merge branch 'master' into optimize/dead-global-vars 2019-12-03 11:58:46 -08:00
swift-ci
f0157b0f87 Merge pull request #28473 from atrick/arrayproperty-opt 2019-12-03 10:32:49 -08:00
Joe Groff
e544d367ac Merge pull request #28424 from jckarter/subst-function-type-reabstraction
SIL: Plumb abstraction patterns through type lowering.
2019-12-03 10:11:34 -08:00
Erik Eckstein
a5397b434c Cross module optimization
This is a first version of cross module optimization (CMO).

The basic idea for CMO is to use the existing library evolution compiler features, but in an automated way. A new SIL module pass "annotates" functions and types with @inlinable and @usableFromInline. This results in functions being serialized into the swiftmodule file and thus available for optimizations in client modules.
The annotation is done with a worklist-algorithm, starting from public functions and continuing with entities which are used from already selected functions. A heuristic performs a preselection on which functions to consider - currently just generic functions are selected.

The serializer then writes annotated functions (including function bodies) into the swiftmodule file of the compiled module. Client modules are able to de-serialize such functions from their imported modules and use them for optimiations, like generic specialization.

The optimization is gated by a new compiler option -cross-module-optimization (also available in the swift driver).
By default this option is off. Without turning the option on, this change is (almost) a NFC.

rdar://problem/22591518
2019-12-03 14:37:01 +01:00
Erik Eckstein
0b6e3bf6f6 DeadFunctionElimination: factor out function/method visiting of keypath components into a general utility.
This is a NFC
2019-12-03 14:37:01 +01:00
Erik Eckstein
402e228b39 SIL: add a table in SILModule to mark method declarations as externally visible.
This is needed for cross-module-optimization: CMO marks functions as inlinable. If a private or internal method is referenced from such an inlinable function, it must not be eliminated by dead function elimination after serialization (a method is basically an AbstractFunctionDecl).
For SILFunctions we can do this by simply setting the linkage, but for methods we need another mechanism.
2019-12-03 14:37:01 +01:00
Erik Eckstein
db815521d3 GlobalOpt: Prevent calling a non-resilient (or not usable from inline) function from inlinable code.
This problem can show up with cross module optimization.
2019-12-03 14:37:01 +01:00
Michael Gottesman
a31d550348 [allocbox-to-stack] Add a new semantics attribute that says vars of a nominal type marked with _semantics("boxtostack.mustbeonstack") must be on the stack. 2019-12-02 20:29:52 -08:00
Slava Pestov
0e0e4efebe Merge pull request #28401 from slavapestov/fix-cast-to-self
Fix casts involving the 'Self' type
2019-12-02 19:56:51 -05:00
Michael Gottesman
df47eb2c1f [sil] Use SILNodes.def to define ARGKIND##ArrayRef instead of hard coding names.
I also changed all of the places that vended these to use SILNodes.def as well
so that when new argument kinds are added, things just work.
2019-12-02 14:39:02 -08:00
Joe Groff
0926d2380b SIL: Sink GenericContextScope into IRGen.
All the context dependencies in SIL type lowering have been eradicated, but IRGen's
type info lowering is still context-dependent and doesn't systemically pass generic
contexts around. Sink GenericContextScope bookkeeping entirely into IRGen for now.
2019-12-02 12:20:05 -08:00
Joe Groff
5140174eb5 SIL: Plumb abstraction patterns through type lowering.
Lowering a SIL type should be a pure function of the formal type of a value and the
abstraction pattern it's being lowered against, but we historically did not carry
enough information in abstraction patterns to lower generic parameter types, so we
relied on a generic context signature that would be pushed and popped before lowering
interface types. This patch largely eliminates the necessity for that, by making it
so that `TypeClassifierBase` and its subclasses now take an `AbstractionPattern`
all the way down, and fixing up the visitor logic so that it derives appropriate
abstraction patterns for tuple elements, function arguments, and aggregate fields too.
This makes it so that type lowering is independent of the current generic context.
(Unfortunately, there are still places scattered across the code where we use the
current generic context in order to build abstraction patterns that we then feed
into type lowering, so we can't yet completely eliminate the concept.)

This then enables us to integrate substituted function type construction into type
lowering as well, since we can now lower a generic parameter type against an
abstraction pattern without that generic parameter having to be tied to the same
generic signature (or any generic signature at all, which in the case of a
substituted function type hasn't necessarily even been finalized yet.)
2019-12-02 12:15:56 -08:00
Yuta Saito
e5331919db Add possibility of public class 2019-12-02 11:04:15 -08:00
Erik Eckstein
66ccfd78ed Inliner: fix condition to prevent inlining of functions with dynamic-self.
Now the condition matches exactly what's checked in asserts in SILBuilder.

fixes an assert in the PerformanceInliner
https://bugs.swift.org/browse/SR-11817
rdar://problem/57369847
2019-11-26 12:53:40 +01:00
Andrew Trick
4da33e15ad Cleanup: move ArrayPropertyOpt out of COWArrayOpt.cpp.
These are separate, mostly unrelated passes. Putting them in their own
files makes it easier to read the code, understand how to control the
passes, and makes it possible to independently trace, and debug them.
2019-11-25 11:53:49 -08:00
Joe Groff
70031d3d2f SILGen: Don't inject "willThrow" hooks before rethrow propagation branches.
The hook is intended to be used by debuggers to catch the point a `throw` happened in user source. It's unnecessary and undesirable to hook in places where an already-thrown error is just being implicitly propagated.
2019-11-23 16:16:32 +03:00
Slava Pestov
efe4883eef SILOptimizer: Fix to deal with casts involving dynamic Self
The cast optimizer was too eager to fold casts where the source and
target lowered types were the same, even though the formal types
might be different. Move the classifyFeasibility() check to deal
with this case.

Also in dead code elimination we have to mark all operands of a
cast branch instruction as live, not just the first operand,
otherwise we miss the special 'type dependent' self metadata
operand and replace it with 'undef'.
2019-11-22 16:39:17 -05:00
Varun Gandhi
8021795672 [AST] Setup AST and SIL to accomodate Clang function types.
We still don't store compute or store the type anywhere; we will do so in
later commits.
2019-11-22 12:42:08 -08:00
Andrew Trick
8052a61a56 Merge pull request #28430 from atrick/fix-existential-conformance
Fix ExistentialSpecializer: inherited conformance
2019-11-22 09:13:21 -08:00
Andrew Trick
7d0a772542 Fix ExistentialSpecializer: inherited conformance
The ExistentialSpecializer incorrectly assumed that an existential's conformances match an opened archetype. They don't. Opened archetypes strip inherited conformances per the ABI for generic argument passing. Existential values retain those inherited conformances (for some inexplicable reason).

- Rename ASTContext::getExistentialSignature() to
  getOpenedArchetypeSiganture() because it was doing exactly the wrong
  thing for existentials.

- Fix ConcreteExistentialInfo to produce the correct SubstitutionMap.

- Fix ExistentialSpecializer to generate the correct conformances for
  init_existential by adding a collectExistentialConformances() helper.

Fixes <rdar://problem/57025861> "Assertion failed: (conformances.size() == numConformanceRequirements)" in ExistentialSpecializer on inlined code
2019-11-22 01:56:20 -08:00
eeckstein
f5665dfc8f Merge pull request #28382 from eeckstein/fix_aeic
Optimizer: Don't keep alwaysEmitIntoClient-functions alive after serialization
2019-11-22 07:25:24 +01:00
Andrew Trick
9c04d33cdf Merge pull request #28404 from atrick/fix-escape-ispointer
EscapeAnalysis: eliminate dangling pointers.
2019-11-21 11:50:49 -08:00
Michael Gottesman
f240867732 Merge pull request #28371 from gottesmm/move-semantic-arc-opts-and-destroy-hoisting-later
[ownership] Move semantic-arc-opts and destroy hoisting right before eliminating ownership from non-transparent functions.
2019-11-21 10:02:15 -08:00
Erik Eckstein
932d468945 Optimizer: Don't keep alwaysEmitIntoClient-functions alive after serialization
This enables dead-function elimination if such functions are not referenced with the module.
2019-11-21 18:01:00 +01:00