Commit Graph

655 Commits

Author SHA1 Message Date
Yuta Saito
620609076d [IRGen] Emit mod summary for full LTO to enable hermetic seal with lld
LTO pipeline requires consistent `EnableSplitLTOUnit` and module summary
in regular full LTO bitcode, and clang enables `EnableSplitLTOUnit` and
emit regular lto module summary on non-ld64 platforms.
Therefore, swiftc has to emit them for the consistency with clang.
2022-04-14 15:53:46 +00:00
John McCall
6385934d7e Metadata emission for extended existential type shapes 2022-04-12 14:52:47 -04:00
Michael Gottesman
a553b874ce [move-function] Rather than breaking block at the SIL level after moved dbg_value, do it late as an LLVM pass on llvm.dbg.addr
This has a few nice benefits:

1. The splitting happens after LLVM optimizations have run. This ensures that
LLVM will not join these blocks no matter what! The author of this commit has
found that in certain cases LLVM does this even at -Onone. By running this late,
we get the benefit we are looking for: working around the bad SelectionDAG
behavior.

2. This block splitting is just a workaround for the above mentioned unfortunate
SelectionDAG behavior. By doing this when we remove the workaround, we will not
have to update SIL level tests... instead we will just remove a small LLVM pass.

Some additional notes:

1. Only moved values will ever have llvm.dbg.addr emitted today, so we do not
have to worry about this impacting the rest of the language.

2. The pass's behavior is tested at the IR level by move_function_dbginfo.swift.
2022-03-07 19:55:21 -08:00
Michael Gottesman
6dde338a11 [sil-opt] Actually pass down IRGenOptions to irgen::createIRGenModule().
Otherwise the options from our invocation that we specialized in sil-opt's main
function will not take effect.
2022-02-18 12:56:36 -08:00
Erik Eckstein
fb8ee0edff extract the MD5Stream utility from IRGen to its own header file. 2022-02-01 08:13:27 +01:00
swift-ci
a7f9d15c2e Merge remote-tracking branch 'origin/main' into rebranch 2021-12-20 06:35:32 -08:00
Erik Eckstein
c55f040308 Add a mechanism to let cross-module-optimization add additional TBD symbols.
PublicCMOSymbols stores symbols which are made public by cross-module-optimizations.
Those symbols are primarily stored in SILModule and eventually used by TBD generation and validation.
2021-12-20 11:33:02 +01:00
swift-ci
134e17c8ec Merge remote-tracking branch 'origin/main' into rebranch 2021-12-17 16:54:09 -08:00
Pavel Yaskevich
a83101787d [IRGen] Implement accessible function section/record emission
Uses a dedicated section in the binary to emit records about
functions that can be looked up by name at the runtime, and
then called through a fully-abstracted entry point whose
arguments can be constructed in code.
2021-12-17 10:52:56 -08:00
Ben Barham
5343c72d10 [rebranch] Fix missing includes 2021-11-13 17:04:29 +10:00
Kuba (Brecka) Mracek
afe116b1d4 Also disable SwiftMergeFunctionsPass on top of LLVM MergeFunctions when VFE/WME is on (#40016) 2021-11-02 17:57:01 -07:00
Erik Eckstein
5321a7cae8 SIL: Only enable instruction leaks checking in the frontend's and SILOpt's modules.
Leaks checking is not thread safe and e.g. lldb creates multiple SILModules in multiple threads, which would result in false alarms.
Ideally we would make it thread safe, e.g. by putting the instruction counters in the SILModule, but this would be a big effort and it's not worth doing it. Leaks checking in the frontend's and SILOpt's SILModule (not including SILModules created for module interface building) is a good enough test.

rdar://84688015
2021-11-02 10:23:46 +01:00
Kuba (Brecka) Mracek
d682049d25 Under VFE/WME, disable mangled accessors and disable LLVM MergeFunctions (#39969) 2021-11-01 15:34:53 -07:00
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
swift-ci
3f8fea8508 Merge remote-tracking branch 'origin/main' into rebranch 2021-10-06 10:17:29 -07:00
Doug Gregor
2551a04621 Back-deploy @objc actor types.
@objc actors implicitly inherit from the new, hidden
`SwiftNativeNSObject` class that inherits from `NSObject` yet provides
Swift-native reference counting, which is important for the actor
runtime's handling of zombies. However, `SwiftNativeNSObject` is only
available in the Swift runtime in newer OS versions (e.g., macOS
12.0/iOS 15.0), and is available in the back-deployed _Concurrency
library, but there is no stable place to link against for
back-deployed code. Tricky, tricky.

When back-deploying @objc actors, record `NSObject` as the superclass
in the metadata in the binary, because we cannot reference
`SwiftNativeNSObject`. Then, emit a static initializer to
dynamically look up `SwiftNativeNSObject` by name (which will find it
in either the back-deployment library, on older systems, or in the
runtime for newer systems), then swizzle that in as the superclass of
the @objc actor.

Fixes rdar://83919973.
2021-10-05 23:04:57 -07:00
Kuba Mracek
2dfd232d90 Implement conditional stripping of type descriptors, protocols and protocol conformances via !llvm.used.conditional
A new LLVM IR affordance that allows expressing conditions under which globals
can be removed/dropped (even when marked with @llvm.used) is being discussed at:

- <https://reviews.llvm.org/D104496>
- <https://lists.llvm.org/pipermail/llvm-dev/2021-September/152656.html>

This is a preliminary implementation that marks runtime lookup records (namely
protocol records, type descriptors records and protocol conformance records)
with the !llvm.used.conditional descriptors. That allows link-time / LTO-time
removal of these records (by GlobalDCE) based on whether they're actually used
within the linkage unit. Effectively, this allows libraries that have a limited
and known set of clients, to be optimized against the client at LTO time, and
significantly reduce the code size of that library.

Parts of the implementation:
- New -conditional-runtime-records frontend flag to enable using !llvm.used.conditional
- IRGen code that emits these records can now emit these either as a single contiguous
  array (asContiguousArray = true, the old way), which is used for JIT mode, or
  as indivial globals (asContiguousArray = false), which is necessary for the
  !llvm.used.conditional stripping to work.
- When records are emitted as individual globals, they have new names of
  "\01l_protocol_" + mangled name of the protocol descriptor, and similarly for
  other records.
- Fixed existing tests to account for individual records instead of a single array
- Added an IR level test, and an end-to-end execution test to demonstrate that
  the !llvm.used.conditional-based stripping actually works.
2021-09-29 13:15:02 -07:00
swift-ci
64e7db3a76 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-21 07:13:27 -07:00
Kuba (Brecka) Mracek
46eb8d5db5 Implement LLVM IR Witness Method Elimination for Swift witness tables. (#39287)
- Witness method calls are done via @llvm.type.checked.load instrinsic call with a type identifier
- Type id of a witness method is the requirement's mangled name
- Witness tables get !type markers that list offsets and type ids of all methods in the wtable
- Added -enable-llvm-wme to enable Witness Method Elimination
- Added IR test and execution test
2021-09-21 06:57:44 -07:00
Nate Chandler
b4291916f2 Merge branch 'main' into rebranch
Conflicts:
        include/swift/SIL/SILBuilder.h
2021-09-15 13:30:12 -07:00
Arnold Schwaighofer
2381233ac1 Add flag -swift-async-framepointer=auto,never,always to
control swift extended frame information emission

On linux we default to disable the extended frame info (since the system
libraries don't support it).

On darwin the default is to automatically choose based on the deployment target.

The Concurrency library explicitly forces extended frame information and the
back deployment library explicitly disables it.
2021-09-14 12:47:16 -07:00
swift-ci
1d5a202148 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-14 07:14:26 -07:00
Kuba (Brecka) Mracek
5412ed1936 Implement LLVM IR Virtual Function Elimination for Swift classes. (#39128)
- Virtual calls are done via a @llvm.type.checked.load instrinsic call with a type identifier
- Type identifier of a vfunc is the base method's mangling
- Type descriptors and class metadata get !type markers that list offsets and type identifiers of all vfuncs
- The -enable-llvm-vfe frontend flag enables VFE
- Two added tests verify the behavior on IR and by executing a program
2021-09-14 06:59:07 -07:00
swift-ci
5ffe0c5401 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-19 09:13:25 -07:00
Arnold Schwaighofer
bf7d9108fb Disable GlobalISelAbort
When using GlobalISel instead of SelectionDAG lowering allow for
fall-back to SelectionDAG instead of aborting.
2021-08-18 13:08:18 -07:00
swift-ci
e30edb92c3 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-17 17:53:24 -07:00
Arnold Schwaighofer
71f64ac348 Add option to enable global-isel on arm64 archs
LLVM will eventually switch over to using global-isel on arm64 archs.
Setting this option (SWIFT_ENABLE_GLOBAL_ISEL_ARM64) can be used to experiment
with that in Swift before the switch happens.
2021-08-17 13:41:46 -07:00
Evan Wilde
b1ea839b1d Merge branches 'ewilde/rebranch/printHelp', 'ewilde/rebranch/vkrvalue', 'ewilde/rebranch/datalayout', 'ewilde/rebranch/withNullAsEmpty', 'ewilde/rebranch/format', 'ewilde/rebranch/collectUsedGlobals' and 'ewilde/rebranch/SILSerialization' into ewilde/swift-rebranch 2021-07-08 17:48:06 -07:00
Evan Wilde
5a1b0f82e1 Fix call to collectUsedGlobalVariables
LLVM commit 3adb89bb9f8e73c82787babb2f877fece7394770 updated the API of
this function to take a reference to a `SmallVectorImpl` instead of a
set to ensure that it behaves deterministically.
2021-07-08 17:38:52 -07:00
Evan Wilde
1e6787925f Fix IRGen datalayout
Same issue as with TBDGen. Clang doesn't hold onto the Datalayout object
anymore, but instead keeps the description string that is constructed on
the fly. This patch updates IRGen to behave the same way.
2021-07-08 16:59:11 -07:00
Evan Wilde
0aafd09835 F_None was renamed OF_None
This patch updates usages of F_None to OF_None, as LLVM changed that in
commit 3302af9d4c39642bebe64dd60a3aa162fefc44b2.
2021-06-23 10:36:39 -07:00
Nate Chandler
d765434e2b [IRGen] Restored non-constant async function calls in PAFs.
Previously, because partial apply forwarders for async functions were
not themselves fully-fledged async functions, they were not able to
handle dynamic functions.  Specifically, the reason was that it was not
possible to produce an async function pointer for the partial apply
forwarder because the size to be used was not knowable.

Thanks to https://github.com/apple/swift/pull/36700, that cause has been
eliminated.  With it, partial apply forwarders are fully-fledged async
functions and in particular have their own async function pointers.
Consequently, it is again possible for these partial apply forwarders to
handle non-constant function pointers.

Here, that behavior is restored, by way of reverting part of
ee63777332 while preserving the ABI it
introduced.

rdar://76122027
2021-04-06 15:51:32 -07:00
Nate Chandler
d3e0e7af07 [ptrauth] Signed AsyncFunctionPointers as data.
Previously, AsyncFunctionPointer constants were signed as code.  That
was incorrect considering that these constants are in fact data.  Here,
that is fixed.

rdar://76118522
2021-04-05 18:24:41 -07:00
Varun Gandhi
cc14992281 [Frontend] Add -emit-irgen option to driver and frontend.
Fixes SR-14389, fixes rdar://75715690.
2021-03-31 11:56:36 -07:00
Nate Chandler
c31cb54d35 [IRGen] Sign TaskResumeContext. 2021-02-03 17:50:50 -08:00
swift-ci
9d0d1fff60 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-26 06:12:31 -08:00
Arnold Schwaighofer
daa72d3cc5 Add llvm::Attribute::SwiftAsync to the context parameter
* Adds support for generating code that uses swiftasync parameter lowering.

* Currently only arm64's llvm lowering supports the swift_async_context_addr intrinsic.

* Add arm64e pointer signing of updated swift_async_context_addr.

This commit needs the PR llvm-project#2291.

* [runtime] unittests should use just-built compiler if the runtime did

This will start to matter with the introduction of usage of swiftasync parameters which only very recent compilers support.

rdar://71499498
2021-01-22 10:01:55 -08:00
swift_jenkins
de9e56fb12 Merge remote-tracking branch 'origin/main' into next 2020-12-16 19:43:18 -08:00
Dan Liew
8e95189d24 Merge pull request #35074 from apple/dliew/rdar-69335186
Disable "UseOdrIndicator" ASan instrumentation mode by default.
2020-12-16 19:19:40 -08:00
swift_jenkins
167386c104 Merge remote-tracking branch 'origin/main' into next 2020-12-15 12:42:57 -08:00
Dan Liew
9208b52de1 Disable "UseOdrIndicator" ASan instrumentation mode by default.
Previously Swift enabled the "UseOdrIndicator" ASan instrumentation mode
and gave no option to disable this. This probably wasn't intentional but
happened due to the fact the
`createModuleAddressSanitizerLegacyPassPass()` function has a default
value for the `UseOdrIndicator` parameter of `true` and in Swift we
never specified this parameter explicitly.

Clang disables the "UseOdrIndicator" mode by default but allows it to be
enabled using the `-fsanitize-address-use-odr-indicator` flag.
Having "UseOdrIndicator" off by default is probably the right
default choice because it bloats the binary. So this patch changes the
Swift compiler to match Clang's behavior.

This patch disables the "UseOdrIndicator" mode by default but adds a
hidden driver and frontend flag (`-sanitize-address-use-odr-indicator`)
to enable it. The flag is hidden so that we can remove it in the future
if needed.

A side effect  of disabling "UseOdrIndicator" is that by we will no
longer use private aliases for poisoning globals. Private aliases were
introduced to avoid crashes
(https://github.com/google/sanitizers/issues/398) due to ODR violations
with non-instrumented binaries. On Apple platforms the use of two-level
namespaces probably means that using private aliases wasn't ever really
necessary to avoid crashes. On platforms with a flat linking namespace
(e.g. Linux) using private aliases might matter more but should users
actually run into problems they can either:

* Fix their environment to remove the ODR, thus avoiding the crash.
* Instrument the previously non-instrumented code to avoid the crash.
* Use the new `-sanitize-address-use-odr-indicator` flag

rdar://problem/69335186
2020-12-15 11:09:30 -08:00
Erik Eckstein
e697e49582 [concurrency] IRGen:: do ptrauth for hop_to_executor
Sign the resume-function pointer which is stored in AsyncTask.ResumeTask
2020-12-15 15:23:20 +01:00
swift_jenkins
eade12ccaa Merge remote-tracking branch 'origin/main' into next 2020-12-07 08:50:18 -08:00
Nate Chandler
b0913fd829 [PtrAuth] Corrected AsyncContextParent schema.
Previously, the schema used a key intended for pointers to code.  An
AsyncContextParent is actually a pointer to data, so that key was
incorrect.  Here, that error is corrected and the schema now uses the
key for pointers to data.
2020-12-04 16:36:37 -08:00
Nate Chandler
d4be3e88e4 [PtrAuth] Adopt AsyncContextResume schema. 2020-12-04 16:36:36 -08:00
swift_jenkins
3e5db601d7 Merge remote-tracking branch 'origin/main' into next 2020-11-02 10:06:47 -08:00
Nate Chandler
c502e97a25 [Async CC] Auth'd parent context pointer. 2020-10-28 12:48:54 -07:00
Erik Eckstein
69edd5020a Merge remote-tracking branch 'origin/main' into next 2020-10-03 21:10:11 +02:00
John McCall
e1004499c4 [NFC] Split ProtocolDispatchStrategy out of MetadataValues.h.
This allows us to avoid rebuilding most of the compiler
whenever we add a new ABI constant.
2020-10-03 02:26:17 -04:00
swift_jenkins
b1fa15fe87 Merge remote-tracking branch 'origin/main' into next 2020-09-29 23:14:40 -07:00