Commit Graph

1537 Commits

Author SHA1 Message Date
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Robert Widmann
a9e11e3130 [NFC] Separate Taking Redundant Conformance Diagnostics From The Lookup Table 2020-03-24 12:40:11 -07:00
Saleem Abdulrasool
29c00f6969 IRGen: improve DLLStorage computation for Windows
This slightly regresses the standard library build (intentionally) while
generally improving the build of dispatch, foundation, xctest.

Rather than continuing to rely on the short-term hack of special casing
the standard library, identify the module where the decl originates
from.  If the module is the current module, then assume that the symbol
need not be imported (static linking does not currently work on Windows
anyways).  This allows for properly identifying the module where the
symbol will be homed.

Because we no longer special case the standard library here, a few known
metadata types will be incorrectly marked as being imported rather than
local.

Since linked entities which have `Shared` SILLinkage should be module
local, special case them to always be local.  Without this the metadata
access function is still marked incorrectly.

With this computation we now get nearly all the cases correct.  Dispatch
no longer has to rely on the linker relaxing the import to a local
binding.  XCTest is also clean.  Foundation misses the following case:
- `$sSS10FoundationE19_bridgeToObjectiveCAA8NSStringCyF`

The regressed cases in swiftCore are:
- `$sBi64_WV`
- `$sBi8_WV`
- `$sBi16_WV`
- `$sBi32_WV`
- `$sBpWV`
- `$syycWV`
- `$sBoWV`
- `$sBOWV`
- `$sBbWV`
- `$sytWV`
2020-03-08 19:24:29 -07:00
Kuba Mracek
8a4a226cd6 Undo unintentional llvm::MaybeAlign changes 2020-03-07 13:44:16 -08:00
Kuba (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Arnold Schwaighofer
335be17562 IRGen: Reinstate JIT workaround removed in PR #28704
The usage of private vars that seemingly are accessed accross object
files confuses the JIT.

rdar://59782487
2020-02-26 08:00:05 -08:00
Dan Zheng
1779632a6f [IRGen] NFC: silence llvm::MaybeAlign warnings.
Use `llvm::MaybeAlign` instead of `unsigned` to silence slew of warnings.
2020-02-20 08:49:28 +00:00
Slava Pestov
836a0b9722 IRGen: Remove IRGenModule::CurSourceFile 2020-02-11 18:59:21 -05:00
Slava Pestov
e6dc10accd IRGen: More accurate getAddrOfLLVMVariableOrGOTEquivalent()
The logic here used to consist of a couple of ad-hoc checks,
followed by a general assumption that if something had already
been emitted, it could be referenced directly, whereas everything
else had to go through a GOT entry.

This is way too conservative. Instead, let's try to correctly
calculate what translation unit an entity is going to end up in.
2020-02-11 18:59:21 -05:00
Slava Pestov
8bdabe81ad IRGen: Add LinkEntity::getDeclContextForEmission()
This replaces getSourceFileForEmission().
2020-02-11 18:59:21 -05:00
Slava Pestov
7fb62337a6 IRGen: Remove old workaround to force emitting GOT entries
The logic in getAddrOfLLVMVariableOrGOTEquivalent() should be
sufficient to decide if a GOT entry is needed.
2020-02-11 18:59:21 -05:00
Slava Pestov
762ab4fc6a IRGen: Add a counter for GOT entries emitted 2020-02-11 18:59:21 -05:00
swift-ci
fda8e977e1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-07 14:24:32 -08:00
Dan Zheng
a174243159 [AutoDiff upstream] Add SIL differentiability witness IRGen. (#29704)
SIL differentiability witnesses are a new top-level SIL construct mapping
an "original" SIL function and derivative configuration to derivative SIL
functions.

This patch adds `SILDifferentiabilityWitness` IRGen.

`SILDifferentiabilityWitness` has a fixed `{ i8*, i8* }` layout:
JVP and VJP derivative function pointers.

Resolves TF-1146.
2020-02-07 14:10:34 -08:00
swift-ci
7c76036449 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 09:03:21 -08:00
Erik Eckstein
cabcecc97e IRGen: in multi-threaded compilation, create all specializations of a function in the same LLVM module.
This increases the chances that multiple specializations from the same function can be merged with LLVM's function merge pass.
2020-01-21 15:33:29 +01:00
swift-ci
7ca13a93e4 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-12 21:23:29 -08:00
Doug Gregor
def86ce402 Revert "[irgen] Force emission of objc class refs for non-foreign clang objc classes whose metadata we use."
This reverts commit 8247525471. While
correct, it has uncovered several issues in existing code bases that
need to be sorted out before we can land it again.
Fixes rdar://problem/57846390.
2020-01-11 21:46:42 -08:00
swift-ci
5dcb80b599 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 15:24:32 -08:00
Nate Chandler
d78dc038c4 [metadata prespecialization] Specialize VWTs.
Prespecialized metadata records must refer to value witness tables that
have correct values for size and stride.  In order to do that, a
prespecialized value witness table must emitted and referred to.  Here,
a fully specialized value witness table is emitted.

For the moment, the value witness table is fully specialized.  Having it
be specialized, though, will likely cause serious code size problems,
since it results in specialized value witness functions being generated.

rdar://problem/58088270
2020-01-09 17:25:34 -08:00
Nate Chandler
686c49aec3 [IRGen] Don't add prespecialized metadata to ABI.
The usages of a type that happen to be made in a module are
implementation details of that module and should not be exported.
2020-01-09 17:25:34 -08:00
Nate Chandler
9e2e090623 [IRGen] Emit metadata accessors last.
Metadata accessors are dependent on prespecializations of the metadata
of generic, in-module types.  Those prespecializations are themselves
dependent on usages of the types in functions.  Consequently, the
accessors must be emitted after all the functions are emitted.
2020-01-09 17:25:34 -08:00
Nate Chandler
c4d13e4b4b [IRGen] Directly reference prespecializations.
When possible, directly reference metadata prespecializations.  Doing so
is possible when the type is defined in the same module, because in
those cases the metadata accessor can be modified to ensure that the
prespecialized metadata is canonical.

rdar://problem/56994171
2020-01-09 17:25:33 -08:00
Nate Chandler
d9205fafd3 [IRGen] Prepare to emit prespecializations. 2020-01-09 17:25:33 -08:00
Nate Chandler
c2d5d60d65 [IRGen] Prepare to lazily emit prespecializations.
Added worklist of prespecializations awaiting lazy emission to
IRGenModule.  Added map from type decl to list of bound types for which
prespecializations will be emitted.

For now, no specializations are emitted.
2020-01-09 17:25:33 -08:00
Nate Chandler
cdf3817c04 [gardening] Extracted common expression to value. 2020-01-09 17:25:30 -08:00
Arnold Schwaighofer
43c24be5cd Merge remote-tracking branch 'upstream/master' into master-next 2020-01-08 06:41:34 -08:00
Robert Widmann
19f0d52eca Merge pull request #28995 from CodaFi/absolutely-path-ological
[NFC] Hide SourceFile::Decls
2020-01-06 18:48:55 -08:00
Robert Widmann
96b3b9f0f4 [NFC] Hide SourceFile::Decls
In preparation for installing some stable paths infrastructure here,
hide access to the array of top-level decls.
2020-01-03 14:14:00 -08:00
Kita, Maksim
b7cb3b67bf SR-11889: Using Located<T> instead of std::pair<SourceLoc, T> 2019-12-20 17:18:58 +03:00
swift_jenkins
a812971ee5 Merge remote-tracking branch 'origin/master' into master-next 2019-12-17 15:00:16 -08:00
Xi Ge
1ebc78b22b [RemoteAST] Using module names specified by @_originallyDefinedIn for top-level decls marked as so
This should allow runtime de-mangling of those moved symbols.
2019-12-16 17:57:32 -08:00
Xi Ge
03fab30ee0 Merge branch 'master' into tbdgen-ld-hide 2019-12-14 20:57:05 -08:00
Xi Ge
93a83d3f14 IRGen: reuse linker directives collected from tbd gen to emit these symbols to IR 2019-12-12 22:22:28 -08:00
Xi Ge
fdcd50628c IRGen: add a function suitable for emitting linker directive as global variable 2019-12-12 22:22:28 -08:00
swift_jenkins
7de866d584 Merge remote-tracking branch 'origin/master' into master-next 2019-12-11 13:20:24 -08:00
Arnold Schwaighofer
71bb9a9d73 Remove workaround for unnamed_addr constants for LLVM JIT
The JIT has been fixed in llvm r362139.

rdar://51809210
2019-12-11 08:26:16 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Saleem Abdulrasool
636564e2cd IRGen: collocate WASM/ELF handling
WASM currently is treated identically to the ELF paths.  Collocate the
types to make it easier to ensure that all the paths are correctly
handling the emission.  This adds the missed case for the module hash.
2019-12-09 09:21:04 -08:00
Varun Gandhi
13b0fa9baa [NFC] Reduce some duplication in IRGen code for method descriptors. (#28475) 2019-12-04 16:32:56 -08:00
Robert Widmann
72e80c21f1 Bump the module format version
We've changed *what* is serialized by changing the way
@_dynamicReplacement is type checked, but not *how* it's
serialized.  Bump the format so there aren't strange incompatibilities
because of this.
2019-12-03 15:30:05 -08:00
Robert Widmann
4e36fc0bd5 Replace semantic usages of DynamicReplacementAttr with the request
Complete the refactoring by splitting the semantic callers for the original decl of a dynamically replaced declaration.

There's also a change to the way this attribute is validated and placed.  The old model visited the attribute on any functions and variable declarations it encountered in the primary.  Once there, it would strip the attribute off of variables and attach the corresponding attribute to each parsed accessor, then perform some additional ObjC-related validation.

The new approach instead leaves the attribute alone.  The request exists specifically to perform the lookups and type matching required to find replaced decls, and the attribute visitor no longer needs to worry about revisiting decls it has just grafted attributes onto.  This also means that a bunch of parts of IRGen and SILGen that needed to fan out to the accessors to ask for the @_dynamicReplacement attribute to undo the work the type checker had done can just look at the storage itself.  Further, syntactic requests for the attribute will now consistently succeed, where before they would fail dependending on whether or not the type checker had run - which was generally not an issue by the time we hit SIL.
2019-12-03 15:30:04 -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
Michael Gottesman
8247525471 [irgen] Force emission of objc class refs for non-foreign clang objc classes whose metadata we use.
Today in far more cases we are using mangled strings to look up metadata at
runtime. If we do this for an objc class but for whatever reason we do not have
any other references to the class, the static linker will fail to link in the
relevant framework. The reason why this happens is that autolinking is treated
by the static linker as a hint that a framework may be needed rather than as a
"one must link against the framework". If there aren't any undefined symbols
needed by the app from that framework, the linker just will ignore the hint. Of
course this then causes the class lookup to fail at runtime when we use our
mangled name to try to lookup the class.

I included an Interpreter test as well as IRGen tests to make sure that we do
not regress here in the future.

NOTE: The test modifications here are due to my moving the ObjCClasses framework
out of ./test/Interpreters/Inputs => test/Inputs since I am using it in the
IRGen test along side the interpreter test.

rdar://56136123
2019-11-21 16:03:54 -08:00
swift-ci
73912924cc Merge remote-tracking branch 'origin/master' into master-next 2019-11-11 13:30:12 -08:00
Arnold Schwaighofer
7acabfe1cf IRGen: We need to emit metadata for types that are emitted with shared linkage
Otherwise one TU could only require the type descriptor without metadata
and another TU could require metadata and type descriptor. Whether the
metadata access function is available would then depend on the linking
order of the two TUs.

rdar://56929811
2019-11-11 10:00:17 -08:00
Adrian Prantl
20e2cc6046 Adapt to upstream changes. 2019-10-29 16:11:38 -07:00
swift-ci
d410fb848d Merge remote-tracking branch 'origin/master' into master-next 2019-10-07 22:09:16 -07:00