Commit Graph

587 Commits

Author SHA1 Message Date
Tim Kientzle
adb456270d Forcibly disable static constant array emission for now
This code currently uses the "empty array" metadata for static arrays (because
the "empty array" can never be freed and the metadata on the array storage is
not actually used in Swift).

But that doesn't work if the array is passed to Objective-C,
which does rely on the metadata.  So Objective-C code would
see bridged arrays of this type as empty.

Workaround for: rdar://101126543
2022-10-31 14:12:34 -07:00
Arnold Schwaighofer
92edb70e37 Transfer code gen option OpaquePointers to LLVMContext 2022-10-07 08:29:18 -07:00
Arnold Schwaighofer
3905955589 Merge pull request #61232 from aschwaighofer/wip_opaque_ptr_2
IRGen: Pass the elementType of pointers through to operations
2022-10-04 10:56:41 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Hamish Knight
0431bb2d1c [IRGen] Don't emit coverage maps for synthesized Clang decls
We don't need to perform coverage mapping for any
Clang decls we've synthesized, as they have no
user-written code. This is also needed to avoid a
Clang crash when attempting to emit coverage for
decls without source locations (rdar://100172217).

rdar://82820628
2022-09-20 15:58:07 +01:00
Erik Eckstein
1ae1c51022 IRGen: add sppreq instead of sspstrong for functions which need stack protection.
Now that Swift decides whether or not we need stack protection we should force LLVM to emit stack protection when we request it.
2022-09-08 08:42:25 +02:00
Argyrios Kyrtzidis
5c058d9c48 [IRGen] Update for upstream clang::CreateLLVMCodeGen() API change 2022-08-10 09:07:17 -07:00
Ben Barham
22d62bb4e0 Merge remote-tracking branch 'origin/main' into rebranch
Trivial conflict caused by the line above the
`IGM.constructInitialFnAttributes` change in `lib/IRGen/GenDecl.cpp`
having an extra argument passed in rebranch (due to the new LLVM API).
2022-08-03 19:12:06 -07:00
Arnold Schwaighofer
0379719052 IRGen: Add option to enable stack protector
Adds frontend option -enable-stack-protector to enable emission of a
stack protector.

Disabled by default.

When enabled enables LLVM's strong stack protection mode.

rdar://93677524
2022-08-02 09:05:37 -07:00
Arnold Schwaighofer
10ec81edf0 IRGen: Add force import thunk to used globals on windows
LLVM's new pass pipeline will otherwise remove the internal symbol.
2022-07-26 17:07:50 -07:00
swift-ci
7382a9c41e Merge remote-tracking branch 'origin/main' into rebranch 2022-07-11 07:53:46 -07:00
Nate Chandler
34c08b8344 [TaskToThread] Add Task.runInline.
The new intrinsic, exposed via static functions on Task<T, Never> and
Task<T, Error> (rethrowing), begins an asynchronous context within a
synchronous caller's context.  This is only available for use under the
task-to-thread concurrency model, and even then only under SPI.
2022-07-08 08:44:18 -07:00
swift-ci
bc8cecbd9a Merge remote-tracking branch 'origin/main' into rebranch 2022-06-22 22:13:18 -07:00
Erik Eckstein
24d077e78b IRGen: re-enable generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998

This reverts the revert commit df353ff3c0.
Also, I added a frontend option to disable this optimization: `-disable-readonly-static-objects`
2022-06-21 18:30:42 +02:00
swift-ci
743cd8cb76 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 13:55:02 -07:00
Erik Eckstein
df353ff3c0 Revert "IRGen: generate static arrays in read-only data sections."
This reverts commit aca0d8358b.

I need to fix a problem before this can actually land.
2022-06-17 20:32:32 +02:00
swift-ci
0c25b6259b Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 06:34:50 -07:00
Erik Eckstein
aca0d8358b IRGen: generate static arrays in read-only data sections.
So far, static arrays had to be put into a writable section, because the isa pointer and the (immortal) ref count field were initialized dynamically at the first use of such an array.

But with a new runtime library, which exports the symbols for the (immortal) ref count field and the isa pointer, it's possible to put the whole array into a read-only section. I.e. make it a constant global.

rdar://94185998
2022-06-17 11:21:29 +02:00
swift-ci
7cb90dc351 Merge remote-tracking branch 'origin/main' into rebranch 2022-06-10 15:33:41 -07:00
Arnold Schwaighofer
821ba47079 IRGen: Add a frontend option to force single LLVM module emission in multithreaded mode
This allows to experiment with single module LLVM emission without
having to change drivers that expect multiple output files.

rdar://94744623
2022-06-10 09:46:07 -07:00
swift-ci
26cf6542ba Merge remote-tracking branch 'origin/main' into rebranch 2022-05-28 07:14:52 -07:00
Max Desiatov
950792a260 IRGen: fix swifterror attribute mismatch for WebAssembly 2022-05-28 17:31:44 +09:00
Ben Barham
caa5003c7c [next] Pass LLVM context to AttrBuilder constructor
The `AttrBuilder` API was changed in llvm/llvm-project
d2cc6c2d0c2f8a6e272110416a3fd579ed5a3ac1 to now take a `LLVMContext &`
as part of its constructor. Update uses to pass one in.
2022-05-05 16:25:10 -07:00
Ben Barham
04035b43b7 [next] Temporarily use getPointerElementType
`PointerType::getElementType` has been removed entirely as part of the
opaque pointers migration. Update to `getPointerElementType` for now
until we've also migrated.
2022-05-05 16:25:10 -07:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Saleem Abdulrasool
82d3df9211 stdlib: enable prespecialization of generic metadata on Windows
Enable support for pre-speciailization of generic metadata on Windows.
2022-03-02 14:02:49 -08:00
John McCall
aca744b211 Remove the Flags field from AsyncContext.
Generated code has never actually initialized this field, so we
might as well remove it.  Doing so mostly doesn't impact the ABI
since we don't store anything for arguments or results in the
context as part of the normal call sequence.  We do need to adjust
some of the hard-coded contexts, however, such as continuation
contexts and the statically-sized context for special runtime
async functions.
2022-02-25 16:57:49 -05:00
Karoy Lorentey
e24bb55abf Merge pull request #41449 from lorentey/custom-traps
[IRGen] Allow configuring a panic function to call instead of trapping
2022-02-21 12:46:33 -08:00
Saleem Abdulrasool
98bd2dba57 IRGen: internalize symbols with -static
This pipes the `-static` flag when building a static library into IRGen.
This should have no impact on non-Windows targets as the usage of the
information simply removes the `dllexport` attribute on the generated
interfaces.  This ensures that a library built with `-static` will not
re-export its interfaces from the consumer.  This is important to ensure
that the consumer does not vend the API surface when it statically links
a library.  In conjunction with the removal of the force load symbol,
this allows the generation of static libraries which may be linked
against on Windows.  However, a subsequent change is needed to ensure
that the consumer does not mark the symbol as being imported from a
foreign module (i.e. `dllimport`).
2022-02-18 19:42:08 +00:00
Karoy Lorentey
2966dce3d9 [IRGen] Allow configuring a panic function to call instead of trapping
Add a new frontend option (called `-trap-function <name>`, similar to Clang’s existing `-ftrap-function`) that specifies a function to call instead of trapping.

When the option is used, the compiler will emit a call to the specified function every time it would have otherwise emitted a trap instruction. The function must have no parameters and it must never return.

rdar://89125883
2022-02-17 23:19:08 -08:00
Pavel Yaskevich
2bd7a49d75 [IRGen] Record generic environment associated with accessible function
Without this piece of information it wouldn't be possible to form
a call to the recorded function at runtime if it's generic.
2022-01-24 10:17:59 -08:00
swift-ci
574959ebcb Merge remote-tracking branch 'origin/main' into rebranch 2022-01-04 19:34:06 -08:00
Kuba (Brecka) Mracek
243141e8b5 [IRGen] When emitting llvm.used.conditional list, strip all pointer casts in dependencies (#40678) 2022-01-04 19:32:45 -08:00
Adrian Prantl
f0b7065169 Consistently initialize clang CodeGenOptions.DebugTypeExtRefs
on all code paths. This flag is part of the Clang module hash. Setting it on all
paths makes it easier to reason about the permutations of Clang modules that are
being built on behalf of Swift.
2021-12-20 16:48:11 -08:00
swift-ci
134e17c8ec Merge remote-tracking branch 'origin/main' into rebranch 2021-12-17 16:54:09 -08:00
Pavel Yaskevich
ef4e94ef23 [Distributed] IRGen: Define a runtime record for accessible functions
A "accessible" function that can be looked up based on a string key,
and then called through a fully-abstracted entry point whose arguments
can be constructed in code.
2021-12-17 10:52:56 -08:00
swift-ci
be79aeb3bc Merge remote-tracking branch 'origin/main' into rebranch 2021-12-14 09:34:56 -08:00
Kuba Mracek
4271edde6b Add an end-to-end test for ThinLTO (-lto=llvm-thin flag), fix compiler crashes, fix tests 2021-12-13 16:59:32 -08:00
swift-ci
ee96d2798c Merge remote-tracking branch 'origin/main' into rebranch 2021-11-30 08:33:02 -08:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Ben Barham
11f28196bc Merge pull request #40168 from bnbarham/rebranch-failures
[rebranch] Fix compilation failures
2021-11-17 08:50:11 +10:00
Ben Barham
30be5117d2 [rebranch][IRGen] Update uses of AttributeList functions
The functions in llvm-project `AttributeList` have been
renamed/refactored to help remove uses of `AttributeList::*Index`.

Update to use these new functions where possible. There's one use of
`AttrIndex` remaining as `replaceAttributeTypeAtIndex` still takes the
index and there is no `param` equivalent. We could add one locally, but
presumably that will be added eventually.
2021-11-13 17:04:29 +10:00
Ben Barham
e139a2f2ea [rebranch] Rename various functions to match new names in LLVM
llvm-project 601102d282d5e9a1429fea52ee17303aec8a7c10 renamed various
functions in `CharInfo.h` and `Lexer.h`. Rename uses in Swift.
2021-11-13 15:33:09 +10:00
Arnold Schwaighofer
2e4a86986c IRGen: Annotate runtime calls with willreturn attribute
`willreturn`
This function attribute indicates that a call of this function will
either exhibit undefined behavior or comes back and continues execution
at a point in the existing call stack that includes the current
invocation. Annotated functions may still raise an exception, i.a.,
`nounwind` is not implied. If an invocation of an annotated function does
not return control back to a point in the call stack, the behavior is
undefined.

I conservatively did not assume that the deinit is willreturn therefore
release like operations are not marked `willreturn`.

rdar://73574236
2021-11-12 07:58:11 -08:00
Evan Wilde
3e2c5a6af5 Make it LinkOnceODRLinkage
Make the little variable LinkOnceODRLinkage so that it doesn't take up
as much space.
2021-11-04 09:03:27 -07:00
Evan Wilde
1e7ce90361 Fixing the strong imported async frame pointer flags
The weakly-imported symbol was getting optimized out, then put back in
as a strongly-imported symbol. This is no good. The symbol is a
declaration though, so it can't be "used" directly. Instead, we assign
it to another global and "use" it. That avoids the optimizations and
should be fine. Even if that symbol is a nullptr because it doesn't
exist, we are taking the pointer to it, which should be fine for all
situations.
2021-11-04 09:02:17 -07:00
Erik Eckstein
ff2db93922 SIL/IRGen: analysis of runtime effects for an instruction
Define the possible runtime effects of an instruction in an enum `RuntimeEffect`.
Add a new utility `swift:getRuntimeEffect` to estimate the runtime effects of an instruction.

Also, add a mechanism to validate the correctness of the analysis in IRGen: annotate all runtime functions in RuntimeFunctions.def with the actual effect what the runtime function has or can have. Then check if the effects of emitted runtime functions for an instruction match what `getRuntimeEffect` predicts.
This check is only enabled on demand by defining the CHECK_RUNTIME_EFFECT_ANALYSIS macro in RuntimeEffect.h
2021-10-28 18:43:14 +02: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
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
swift-ci
b736faa703 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-23 14:53:57 -07:00