Commit Graph

587 Commits

Author SHA1 Message Date
Arnold Schwaighofer
d75e4c2bd2 IRGen: get/await_async_continuation support.
rdar://71124933
2020-11-19 08:43:26 -08:00
Arnold Schwaighofer
74419d0885 Lower asynchronous functions to LLVM async coroutine intrinsics
rdar://70097093
2020-11-13 10:41:42 -08:00
Nate Chandler
2d21932672 [Async CC] Add constant "pointer" for async func.
An AsyncFunctionPointer, defined in Task.h, is a struct consisting of
two i32s: (1) the relative address of the async function and (2) the
size of the async context to be allocated when calling that function.

Here, such structs are emitted for every async SILFunction that is
emitted.
2020-11-12 18:20:10 -08:00
Varun Gandhi
0484f3a3e7 [NFC] Reuse AST/ClangTypeConverter in IRGen.
Also remove the original implementation from GenClangType.cpp
since it isn't used anymore.
2020-11-12 10:31:40 -08:00
Doug Gregor
4c2c2f32e9 [Concurrency] Implement a builtin createAsyncTask() to create a new task.
`Builtin.createAsyncTask` takes flags, an optional parent task, and an
async/throwing function to execute, and passes it along to the
`swift_task_create_f` entry point to create a new (potentially child)
task, returning the new task and its initial context.
2020-11-07 23:05:04 -08:00
nate-chandler
5c59babfeb Merge pull request #34490 from nate-chandler/generic-metadata-prespecialization-components/special-entry
[metadata prespecialization] Add canonical records to cache.
2020-11-04 19:35:40 -08:00
Nate Chandler
cda11b90a1 [Runtime] Add prespecialized-caching getGenericMetadata variant.
Add a new entry point for getting generic metadata which adds the
canonical metadata records attached to the nominal type descriptor to
the metadata cache.

Change the implementation of the primary entry-point
swift_getGenericMetadata to stop looking through canonical
prespecialized records.

Change the implementation of swift_getCanonicalSpecializedMetadata to
use the caching token attached to the nominal type descriptor to add
canonical prespecialized metadata records to the metadata cache only
once rather than using the cache variables to limit the number of times
the attempt was made.
2020-11-01 13:35:03 -08:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Nate Chandler
a085fdbadc [IRGen] Defined TaskContinuationFunction.
Added the llvm::StructType and a pointer to it.
2020-10-27 11:28:01 -07:00
Nate Chandler
b74052cdd2 [Async CC] Added task and executor args.
The previous stage of bringup only had async functions taking a single
argument: the async context.  The next stage will involve the task and
executor.  Here, arguments are added for those values.  To begin with,
null is always passed for these values.
2020-10-26 14:27:16 -07:00
Azoy
e60ef84bd2 Implement Tuple Equatable Conformance 2020-10-22 18:24:28 -04:00
Nate Chandler
607772aaa2 [Runtime] Stubbed entry points for task de/alloc. 2020-09-30 18:57:48 -07:00
John McCall
03d94b44a6 Add default IR attributes to helper functions and convert
several more places to use getOrCreateHelperFunction.

This means that several of these places are now emitting
shared functions rather than private ones, which I've
verified is okay.  There are some other places where
privacy is still unfortunately necessary.

I've also fixed the name of the store-extra-inhabitants
helper function to say "store" instead of "get", which
is longstanding (but harmless because it's private).

Fixes rdar://66707994.
2020-08-08 16:57:02 -04:00
nate-chandler
5141219a69 Merge pull request #32506 from nate-chandler/runtime/add-swift_getCanonicalSpecializedMetadata
[Runtime] Add entry point to canonicalize metadata.
2020-07-16 12:18:58 -07:00
Hamish Knight
949d400b0f [IRGen] Store target machine on GeneratedModule
This will avoid needing to recreate it when we
come to perform LLVM passes.
2020-07-15 16:46:40 -07:00
Nate Chandler
b0fc8daa83 [Runtime] Add entry point to canonicalize metadata.
The new function swift_getCanonicalSpecializedMetadata takes a metadata
request, a prespecialized non-canonical metadata, and a cache as its
arguments.  The idea of the function is either to bless the provided
prespecialized metadata as canonical if there is not currently a
canonical metadata record for the type it describes or else to return
the actual canonical metadata.

When called, the metadata cache checks for a preexisting entry for this
metadata.  If none is found, the passed-in prespecialized metadata is
added to the cache.  Otherwise, the metadata record found in the cache
is returned.

rdar://problem/56995359
2020-07-15 15:27:36 -07:00
Yuta Saito
20bc0af42b [LTO] Support LLVM LTO for IRGen and frontend
This commit adds -lto flag for frontend to enable LTO at LLVM level.
When -lto=llvm given, compiler emits LLVM bitcode file instead of object
file and adds index summary for LTO.
In addition for ELF format, emit llvm.dependent-libraries section to
embed auto linking information
2020-07-01 23:30:58 +00:00
Nate Chandler
6d0c34caf3 [Runtime] Add entry point to compare conformance descriptors.
The new function swift_compareProtocolConformanceDescriptors calls
through to the preexisting code in MetadataCacheKey which has been
extracted out from MetadataCacheKey::compareWitnessTables into a new
public static function
MetadataCacheKey::compareProtocolConformanceDescriptors.

The new function's availability is "future" for now.
2020-06-22 15:01:28 -07:00
Nate Chandler
2c6d7d78df [Runtime] Add entry point to compare type context descriptors.
The new function `swift_compareTypeContextDescriptors` is equivalent to
a call through to swift::equalContexts.  The implementation it the same
as that of swift::equalContexts with the following removals:
- Handling of context descriptors of kind other outside of
  ContextDescriptorKind::Type_First...ContextDescriptorKind::Type_Last.
  Because the arguments are both TypeContextDescriptors, the kinds are
  known to fall within that range.
- Casting to TypeContextDescriptor.  The arguments are already of that
  type.

For now, the new function has "future" availability.
2020-06-22 12:07:02 -07:00
Saleem Abdulrasool
71309a8fa9 Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows" 2020-06-07 11:25:48 -07:00
Saleem Abdulrasool
d0131ba6be Merge pull request #31146 from kateinoigakukun/katei/enable-lang-agnostic-lto
[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows
2020-06-05 11:38:09 -07:00
Yuta Saito
915c4a6997 [LTO] Support LLVM level link time optimization
This commit adds -lto flag for driver to enable LTO at LLVM level.
When -lto=llvm given, compiler emits LLVM bitcode file instead of object
file and perform thin LTO using libLTO.dylib plugin.
When -lto=llvm-full given, perform full LTO instead of thin LTO.
2020-05-31 08:12:52 +09:00
Arnold Schwaighofer
20f4ef93de IRGen: Default to clang's frame pointer elimination settings
Clang provides options to override that default value.
These options are accessible via the -Xcc flag.

Some Swift functions explicitly disable the frame pointer.

The clang options will not override those.
2020-05-28 12:21:42 -07:00
Arnold Schwaighofer
617f1c3ac9 Only use omit the frame pointer on arm64, x86_64 darwin needs it for some its tools 2020-05-22 12:24:23 -07:00
Arnold Schwaighofer
35dceab8a0 Set clang code generation's frame pointer kind. 2020-05-22 05:34:54 -07:00
Arnold Schwaighofer
109813ffe5 Add option to disable leaf frame pointer elimination 2020-05-21 13:19:24 -07:00
Arnold Schwaighofer
e155f03e0d IRGen: Always eliminate frame pointers of leaf functions
rdar://20933449
2020-05-21 13:18:57 -07:00
John McCall
4f54c75dc8 Use Clang's logic for adding the default IR attributes to a function.
A lot of attributes are essentially default target configuration, and we should only differ when there's a good reason to.

For the attributes we were already setting:
- the ptrauth and target CPU/feature attributes are taken care of by Clang
- I've updated the optsize/minsize attributes to the apparent intent
- I've left the frame-pointer override in place for now

Fixes rdar://63289339, which was caused by Swift's ptrauth IR attributes getting out of sync with Clang's.
2020-05-21 02:24:20 -04:00
David Zarzycki
36257d6a62 [IRGen] NFC: Add static_assert cross references
The metadata visitors note the address start of the metadata, but that
is not actually the way the offsets are calculated.
2020-05-14 09:03:03 -04:00
Hamish Knight
2d9b63ed11 A SILModule Always Has An Associated Context
Now that the integrated REPL has been removed,
there is always an associated decl context, and
we can assert as such.
2020-05-10 19:56:12 -07:00
nate-chandler
7ae3d38435 Merge pull request #31262 from nate-chandler/generic-metadata-prespecialization-components/on-for-stdlib
[metadata prespecialization] Reenable for stdlib.
2020-04-27 09:29:47 -07:00
Nate Chandler
99009e044e [metadata prespecialization] Reenable for stdlib.
Whenever building the stdlib for a supported platform, enable metadata
prespecialization for it.
2020-04-20 17:16:32 -07:00
Robert Widmann
85fdc7a555 Merge pull request #31080 from CodaFi/why-I-R-ta
Give IRGenModule Ownership of its LLVMContext
2020-04-17 10:32:46 -07:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Robert Widmann
de304b5bee [NFC] Introduce GeneratedModule
swift::GeneratedModule encapsulates an llvm::Module, llvm::LLVMContext
pair that must live and die together. It has  convenient accessors for
projecting the module and context components. The meat of this type is
the two conversion functions, which transfer ownership of either the
module component to the caller or the module and context to ORCJIT.

This is because ORC enforces an ownership contract that is distinct from
LLVM's rather wild ownership story for modules and their associated
contexts. See http://llvm.org/docs/ORCv2.html#how-to-use-threadsafemodule-and-threadsafecontext
2020-04-16 11:57:44 -07:00
Robert Widmann
40d9cd8d3f [NFC] Give IRGenModule Exclusive Ownership of an LLVMContext Object 2020-04-16 11:57:44 -07:00
David Ungar
9dcd2b52b2 Allocate LLVMContext in IRGenModule. 2020-04-16 11:57:44 -07:00
Nate Chandler
240fd09364 [metadata prespecialization] Not always on for stdlib.
Prespecializing metadata in the stdlib looks to be exposing a bug in its
implementation.  Disabling for now.
2020-04-08 08:07:49 -07:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Arnold Schwaighofer
e8a7b1bd75 Merge pull request #29859 from aschwaighofer/irgen_typelayout_based_value_witness
IRGen: Type layout based value witness generation
2020-02-21 08:24:17 -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
Arnold Schwaighofer
7b65768167 IRGen: Add code to compute type layouts
rdar://51988441
2020-02-19 07:12:55 -08:00
Arnold Schwaighofer
91995c40d4 IRGen: Add code for recursive type layout based witness generation
This adds code that can be used to build recursive type layouts. And
code that generates value witness IR based on the recursive type
layouts.

Value witnesses generated based on type layouts will only refer to
archetypes when computing fields offsets for frozen generic types (vs
instantiated type medata).

rdar://51988441
2020-02-19 07:12:55 -08:00
Nate Chandler
4475f43ba0 [metadata prespecialization] Always on for stdlib.
Regardless of any flags, the stdlib will have its generic metadata
prespecialized.

Temporarily reintroduced the flag to enable the feature flag while
preserving the flag to disable it and changed the default back to off
for the moment.
2020-02-17 11:53:27 -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
Nate Chandler
ae1f41e1b2 [metadata prespecialization] Only Apple or linux.
Temporarily disable metadata prespecialization on platforms other than
MacOS, iOS, tvOS, watchOS, or Linux.  At the moment, tests are failing
on Windows with linker errors such as

  demangleToMetadata-558ea9.o : error LNK2001: unresolved external symbol $ss5Int64VN
  demangleToMetadata-558ea9.o : error LNK2001: unresolved external symbol $sSSSHsWP

Once the issue leading to those linker errors has been resolved, the
feature will be enabled on Windows.
2020-02-05 18:06:27 -08:00
Robert Widmann
bd57f14661 [NFC] Push const IRGenOptions and SILOptions everywhere 2020-01-13 22:01:41 -08:00
Robert Widmann
eb61931012 [NFC] Grab the private discriminator for a file in IRGenDebugInfo
This was being done at an odd point in the frontend presumably because by that point the private discriminator had been fully computed.  Instead, push the conditions for generating the prefix data down to debug info generation and stop mutating IRGenOptions::DebugFlag in the frontend.
2020-01-13 22:01:41 -08:00
Saleem Abdulrasool
bbcff82916 Merge pull request #29112 from compnerd/elf-autolink-sanitization
IRGen: handle ASAN better with importing on ELF
2020-01-10 16:05:12 -08:00
Saleem Abdulrasool
837e331f16 IRGen: handle ASAN better with importing on ELF
ELF's lack of linker directives is worked around by a custom section
(`.swift1_autolink_entries`).  This is metadata that is not intended to
be emitted into the linked binary.  A previous change introduced the use
of a module (global) assembly gadget to discard the section.  However,
this interacts poorly with ASAN which would instrument the section,
resulting in a strong reference.  This reference would persist to a
discarded symbol.  lld would object to this.  Blacklist the symbol to
ensure that ASAN + autolinking can co-exist.
2020-01-09 21:48:25 -08:00