Commit Graph

806 Commits

Author SHA1 Message Date
Erik Eckstein
f702be94b7 SIL: cleanup the GenericSpecializationMangler API
NFC
2020-12-07 17:23:46 +01:00
Michael Gottesman
c026e95cce [ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.
This makes it easier to understand conceptually why a ValueOwnershipKind with
Any ownership is invalid and also allowed me to explicitly document the lattice
that relates ownership constraints/value ownership kinds.
2020-11-10 14:29:11 -08:00
Andrew Trick
3128eae3f0 Add NestedSemanticFunctionCheck diagnostic
to check for improperly nested '@_semantic' functions.

Add a missing @_semantics("array.init") in ArraySlice found by the
diagnostic.

Distinguish between array.init and array.init.empty.

Categorize the types of semantic functions by how they affect the
inliner and pass pipeline, and centralize this logic in
PerformanceInlinerUtils. The ultimate goal is to prevent inlining of
"Fundamental" @_semantics calls and @_effects calls until the late
pipeline where we can safely discard semantics. However, that requires
significant pipeline changes.

In the meantime, this change prevents the situation from getting worse
and makes the intention clear. However, it has no significant effect
on the pass pipeline and inliner.
2020-10-26 17:02:33 -07:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Andrew Trick
5ae231eaab Rename getFieldNo() to getFieldIndex().
Do I really need to justify this?
2020-09-24 22:44:13 -07:00
Erik Eckstein
093c2140e6 SILBuilder: require an insertion point when creating instructions.
This helps to avoid instruction leaks.
It's a NFC.
2020-09-11 14:29:51 +02:00
swift_jenkins
fb86a758ff Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-28 08:47:16 -07:00
Joe Groff
f588f2f478 Merge pull request #33650 from jckarter/global_init_mangling
Remove hardcoded symbol name parsing from SILOptimizer passes
2020-08-28 08:34:35 -07:00
Joe Groff
66e2ce691a Remove apparently unnecessary filter for CMO serializing references to globalinit once variables 2020-08-26 11:38:16 -07:00
swift_jenkins
80f2475366 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-25 20:46:48 -07:00
Joe Groff
6d6165a9db SILOptimizer: Recognize globalinit once functions using an attribute instead of symbol name matching 2020-08-25 17:43:27 -07:00
Nate Chandler
94b5f76654 Revert "[SIL] Add SILFunctionType flag for async."
This reverts commit 9b8828848d.
2020-08-25 13:37:26 -07:00
swift_jenkins
8cfd9be2cb Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-19 15:06:17 -07:00
Nate Chandler
9b8828848d [SIL] Add SILFunctionType flag for async. 2020-08-19 11:29:58 -07:00
swift-ci
74a22bc619 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-03 06:03:55 -07:00
Erik Eckstein
ba7ecfb2c4 SIL: small refactoring of swift::findInitializer
NFC
2020-08-03 12:01:29 +02:00
swift-ci
930fe04f0e Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-28 15:43:48 -07:00
Arnold Schwaighofer
ecf9fbd5f1 Move the EagerSpecializer pass to the Transforms directory
It is no longer a module transform.
2020-07-28 10:25:36 -07:00
Arnold Schwaighofer
54c758f2a1 Convert the EagerSpecializer pass to a function pass
Should be NFC.
2020-07-27 13:55:59 -07:00
Nathan Hawes
9d4ed5f39c Manually merge remote-tracking branch 'upstream/master' into manually-merge-master-to-master-rebranch 2020-07-20 16:09:55 -07:00
Michael Gottesman
ac3109a21d [eager-specializer] Fix for ownership and add a bunch of missing code coverage for ossa.
Specifically, we were missing a bunch of coverage around specializing guaranteed
parameters and non-trivial values in general.
2020-07-09 21:46:19 -07:00
Michael Gottesman
fde1cd22aa [gardening] Remove using llvm::dbgs() from EagerSpecializer and fix file level doxygen comment. 2020-07-07 12:44:02 -07:00
Meghana Gupta
9c5c73370b [ownership] Enable GlobalOpt on ossa and add ossa tests (#32621)
GlobalOpt works mostly on trivial values (there are special cases for ObjectInst and ValueToBridgeObjectInst).
optimizeGlobalAccess is explicitly turned off for non-trivial values. optimizeInitializer calls SILGlobalVariable::isValidStaticInitializerInst which limits it to mostly trivial values except for special cases for ObjectInst and ValueToBridgeObjectInst.

This changes adds GlobalOpt tests for ossa and enables GlobalOpt on ossa
2020-07-06 22:59:43 -07:00
swift_jenkins
96364c5238 Merge remote-tracking branch 'origin/master' into master-next 2020-06-23 01:59:43 -07:00
Erik Eckstein
a7425c16ff Improvements for cross-module-optimization
* Include small non-generic functions for serializaion
* serialize initializer of global variables: so that global let variables can be constant propagated across modules

rdar://problem/60696510
2020-06-22 16:49:26 +02:00
Xi Ge
f8bef59209 Merge remote-tracking branch 'apple/master' into apple-master-next 2020-06-12 14:20:06 -07:00
David Zarzycki
e077b6ffd9 [SIL] NFC: Make SILVTable follow C++ and LLVM best practices
1) Convert the `Entry` type to a class with getters/setters
2) Use llvm::TrailingObjects
3) Use llvm::PointerIntPair
2020-06-11 07:51:42 -04:00
swift_jenkins
e0326ac2e3 Merge remote-tracking branch 'origin/master' into master-next 2020-06-10 07:39:27 -07:00
David Zarzycki
017ee7bf04 [SIL] NFC: Simplify SILVTable and save 8 bytes per SILVTable
We were not using the primary benefits of an intrusive list, namely the
ability to insert or remove from the middle of the list, so let's switch
to a plain vector. This also avoids linked-list pointer chasing.
2020-06-10 07:54:23 -04:00
Karoy Lorentey
57ea964f2c Merge commit '3eb82c183662945687f48e11c09828f551b34858' into master-next
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:58:37 -07:00
Karoy Lorentey
68351d2110 Revert "Merge remote-tracking branch 'origin/master-next'"
This reverts commit 1c9b0908e6, reversing
changes made to 3eb82c1836.
2020-06-08 16:48:38 -07:00
Karoy Lorentey
1c9b0908e6 Merge remote-tracking branch 'origin/master-next'
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:43:40 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
swift_jenkins
bba5c5a061 Merge remote-tracking branch 'origin/master' into master-next 2020-05-19 09:38:17 -07:00
Saleem Abdulrasool
cebe79d482 SIL: use object libraries instead of globbing
This simplifies the handling of the subdirectories in the SIL and
SILOptimizer paths.  Create individual libraries as object libraries
which allows the analysis of the source changes to be limited in scope.
Because these are object libraries, this has 0 overhead compared to the
previous implementation.  However, string operations over the filenames
are avoided.  The cost for this is that any new sub-library needs to be
added into the list rather than added with the special local function.
2020-05-18 18:56:34 +00:00
swift_jenkins
c60a485196 Merge remote-tracking branch 'origin/master' into master-next 2020-05-06 12:35:16 -07:00
Arnold Schwaighofer
970c27248f Merge pull request #31470 from aschwaighofer/fix_rdar62560867
SIL: Thread type expansion context through to function convention apis
2020-05-06 11:52:19 -07:00
swift_jenkins
2dc3bda3dc Merge remote-tracking branch 'origin/master' into master-next 2020-05-05 09:18:38 -07:00
Dan Zheng
bab23d8298 SILOptimizer: fix partial_apply optimization. (#31552)
`partial_apply` can be rewritten to `thin_to_thick_function` only if the
specialized callee is `@convention(thin)`.

This condition is newly exercised by the differentiation transform:
`{JVP,VJP}Emitter::visitApplyInst` generates argument-less `partial_apply`
with `@convention(method)` callees.

Resolves SR-12732.
2020-05-05 09:09:42 -07:00
Arnold Schwaighofer
147144baa6 SIL: Thread type expansion context through to function convention apis
This became necessary after recent function type changes that keep
substituted generic function types abstract even after substitution to
correctly handle automatic opaque result type substitution.

Instead of performing the opaque result type substitution as part of
substituting the generic args the underlying type will now be reified as
part of looking at the parameter/return types which happens as part of
the function convention apis.

rdar://62560867
2020-05-04 13:53:30 -07:00
swift_jenkins
aeae575444 Merge remote-tracking branch 'origin/master' into master-next 2020-04-29 07:19:06 -07:00
Erik Eckstein
318f988359 cross-module-optimiations: Fix an compiler crash and a wrong linkage
In case a property is more visible than its container, an assert was triggering in ValueDecl::isUsableFromInline().

rdar://problem/62403317
2020-04-29 13:25:33 +02:00
swift_jenkins
19c5f21713 Merge remote-tracking branch 'origin/master' into master-next 2020-04-11 19:40:50 -07:00
Dave Abrahams
e583f3a8c3 Add -sil-cross-module-serialize-all option. (#30816)
Thanks, Michael!
2020-04-11 19:35:41 -07:00
swift_jenkins
7108e8a071 Merge remote-tracking branch 'origin/master' into master-next 2020-04-10 19:05:21 -07:00
Xi Ge
435d13496e AST: making export: true in @_specialized attribute a no-operation
The client code doesn't actually call into these specialized functions even
though they have public linkage. This could lead to TBD verification failure
shown in rdar://44777994.

This patch also warns users' codebase when `export: true` is specified.
2020-04-10 16:52:22 -07:00
swift_jenkins
7289cd2659 Merge remote-tracking branch 'origin/master' into master-next 2020-04-02 21:21:13 -07:00
Dan Zheng
aa66cce808 [AutoDiff upstream] Add differentiation transform.
The differentiation transform does the following:
- Canonicalizes differentiability witnesses by filling in missing derivative
  function entries.
- Canonicalizes `differentiable_function` instructions by filling in missing
  derivative function operands.
- If necessary, performs automatic differentiation: generating derivative
  functions for original functions.
  - When encountering non-differentiability code, produces a diagnostic and
    errors out.

Partially resolves TF-1211: add the main canonicalization loop.

To incrementally stage changes, derivative functions are currently created
with empty bodies that fatal error with a nice message.

Derivative emitters will be upstreamed separately.
2020-04-02 15:43:57 -07:00
swift_jenkins
63f5052019 Merge remote-tracking branch 'origin/master' into master-next 2020-03-24 07:20:09 -07:00
Erik Eckstein
84e2a568ca GlobalOpt: don't speculatively execute global initializers
For example: hoist out of loops where the loop count could be 0.
We did this on purpose. But, if not wrong, it's at least very confusing if the initializer has observable side effects.
Instead let CSE and LICM do the job and handle initializer side-effects correctly.

rdar://problem/60292679
2020-03-23 15:53:22 +01:00