Commit Graph

472 Commits

Author SHA1 Message Date
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
Nate Chandler
89278f8cbf [metadata prespecialization] Target only >=5.2.
Compatibility with earlier swift runtimes would require modifying the
runtime compatibility libraries to adjust the behavior of
checkMetadataState by way of typeForMangledNode or even
typeForMangledName.  For now, simply require that a version of swift
whose runtime knows about prespecialized metadata is being targeted.
2020-01-09 17:25:32 -08:00
Saleem Abdulrasool
e2d208d358 IRGen,Driver: extract tool usage into a variable (NFC)
autolink-extract is needed on ELF (and windows-cygnus).  However, WASM
also has gone down this path and did not actually indicate that it
needed the autolink extract handling.  Extract the handling check into a
variable which helps readability.
2019-12-09 21:46:25 -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
Arnold Schwaighofer
0d324d223f Add swift_getTypeByMangledNameInContextInMetadataState such that we can
use getTypeByMangledName when abstract metadata state is requested

This can significantly reduce the code size of apps constructing deeply
nested types with conditional conformances.

Requires a new runtime.

rdar://57157619
2019-11-18 14:41:35 -08:00
Arnold Schwaighofer
4cba76309f IRGen: Add TypeExpansionContext to IRGen 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
8fbe089ecc IRGen: Strip a bitcast that might be there because a runtime function was previously declared of a different type
rdar://55914836
2019-10-04 10:21:01 -07:00
Brent Royal-Gordon
051159f3b4 Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/TBDGen/TBDGen.cpp
2019-09-24 19:04:43 -07:00
Harlan Haskins
ccd534d139 [TBD] Ensure swift-abi-version is kept in sync with IRGen (#27347)
The TAPI_SWIFT_ABI_VERSION macro was never updated in sync with
IRGen::swiftVersion, so just expose that value through
irgen::getSwiftABIVersion() and use it in TBDGen.

Fixes rdar://55643763
2019-09-24 18:48:29 -07:00
Gwen Mittertreiner
697b29e875 Update for Removal of DisableFPElim
DisableFPElim was removed from CGO in cfe r366645. This change fixes the
build for master-next.
2019-08-23 17:02:34 -07:00
Puyan Lotfi
333ffb321e Fixing up IRGenModule to handle changes in CodeGenOptions.
DisableFPElim was removed from CGO in cfe r366645. This change fixes the build
for master-next.

(cherry picked from commit 5d0fec6e36)
2019-08-19 16:53:03 -07:00
swift-ci
558bb50560 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-12 19:23:26 -07:00
Saleem Abdulrasool
1d84cb60a8 Driver: loosen restrictions for -force-autolink-symbol
On targets which support COMDAT (PE/COFF, ELF), use that to relax the
constraints on the emission of `-force-autolink-symbol` so that it is
possible to use that with `-incremental`.
2019-08-12 10:54:07 -07:00
swift-ci
266f22fef1 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-09 22:44:18 -07:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
sameerasal
fa13be22ec Remove .swift1_autolink_entries from ther final linked binary
Mark the section .swift1_autolink_entries as SHF_EXCLUDE
  so the section will get dropped by the linker after linking the final
  binary.

  This section is used to save the flags needed for auto link and there
  is no reason it should stay in the final linked binary.Mark the
  section .swift1_autolink_entries as SHF_EXCLUDE
  so the section will get dropped by the linker after linking the final
  binary.

  This section is used to save the flags needed for auto link and there
  is no reason it should stay in the final linked binary.

  This solves issue SR-11247
2019-08-08 14:38:46 -07:00