Commit Graph

786 Commits

Author SHA1 Message Date
Saleem Abdulrasool
7352392830 IRGen: add support for DLL Storage semantics
Add initial support for modelling DLL Storage semantics for global values.  This
is needed to support the indirect addressing mechanism used on Windows.
2016-07-06 18:03:57 -07:00
Adrian Prantl
6b1263bf5a [Driver] Add a -gdwarf-types option and set it up as an alias for -g (NFC-ish)
Background
----------

Now that Swift AST type support in LLDB has matured, we can stop emitting DWARF
type information by default to reduce compile time and ibject file size.
A future commit will change -g to emit only AST type references.

The full set of debug options will be
-gnone
-gline-tables-only
-g                 // AST types (= everything that LLDB needs)
-gdwarf-types      // AST types + DWARF types (for legacy debuggers)
2016-07-05 12:06:23 -07:00
Michael Gottesman
3c603ab18b Merge remote-tracking branch 'origin/master' into master-next 2016-07-01 18:44:21 -07:00
Saleem Abdulrasool
83901998c9 Port for PS4
Add support for the PS4 OS.  Update the standard library and add a target unit
test.
2016-06-30 20:14:50 -07:00
Saleem Abdulrasool
97d97cbf1f IRGen: address a TODO in the autolinking
Use the target specific directive generation.  This addresses a TODO to use the
same logic as clang.  Unfortunately, the logic in clang is not accessible
outside of it, so replicate the behaviour.
2016-06-28 18:42:51 -07:00
Vedant Kumar
1409a445d9 [stable-merge] Adopt new setUnnamedAddr API 2016-06-27 11:12:28 -07:00
Joe Groff
22c4e08b96 IRGen: Fix TypeInfo for witness_method SIL values.
@convention(witness_method) values were changed to carry a pointer to their source witness table, but the type info wasn't changed to match. Fixing this fixes rdar://problem/26268544.
2016-06-14 10:22:37 -07:00
Dmitri Gribenko
1d666d1950 Merge pull request #2897 from compnerd/autolink-coff
Native autolinking on COFF
2016-06-04 22:18:48 -07:00
Saleem Abdulrasool
7837db48d2 IRGen: dont use autolink-extract for COFF targets
COFF supports the `.drectve` section for embedding linker directives.  LLVM has
long supported emitting this section.  With this move, ELF shall become the only
target needing the autolink-extract functionality.
2016-06-04 17:37:27 -07:00
Saleem Abdulrasool
89bebf897f IRGen: change switch to be covered
Rather than adding a default case, add the missing case and rely on covered
switches providing indications of future additions.  NFC.
2016-06-04 15:04:13 -07:00
Saleem Abdulrasool
6023745e42 IRGen: clean up some debug code
Seems that there was some accidental debug code checked in.  Remove it.  NFC.
2016-06-04 14:53:44 -07:00
John McCall
838b12e41d Adjust for API changes in Clang. 2016-05-17 22:44:14 -07:00
John McCall
06c65464cf Don't crash if an error is emitted by Clang IR-generation.
Clang IR-generation can fail.  When it does this, it destroys the
module. Previously, we were blithely assuming this couldn't happen,
and so we would crash on the deallocated module.  Delay the
finalization of the Clang code generator until our own module
finalization, which is a more appropriate place for it anyway,
and then just bail out of the last few steps if Clang fails.
2016-05-17 12:38:53 -07:00
Michael Gottesman
bdac088e0a [upstream-update] Rename of namespace clang::CodeGenOptions => clang::codegenoptions. NFC.
(cherry picked from commit 57b0c35375fae8d7186862ddc41d6a8a5fdfe135)
(cherry picked from commit 45c518df0b4e0939b98f2f16fc3b45bf05780030)
2016-05-13 22:03:21 -07:00
John McCall
8e3151f451 Switch the TargetMachine back to being IGM-specific instead of global to the IRGenerator.
My understanding is that this *should* be read-only, but there
are test cases that are failing that suggest it might not be.
2016-04-27 10:38:10 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
John McCall
822f6d0729 Remove redundant llvm::DataLayout argument from IRGenModule constructor. 2016-04-26 17:24:48 -07:00
John McCall
b340e439c8 Remove redundant llvm::Triple argument from IRGenModule constructor. 2016-04-26 17:19:09 -07:00
David Farler
09d0cfee8d Hang closure capture descriptors from their heap metadata
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.

A closure capture descriptor has the following:

- The number of captures.
- The number of sources of metadata reachable from the closure.
  This is important for substituting generics at runtime since we
  can't know precisely what will get captured until we observe a
  closure.
- The number of types in the NecessaryBindings structure.
  This is a holding tank in a closure for sources of metadata that
  can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
  source of metadata for every generic argument needed to perform
  substitution at runtime.
  Key: The typeref for the generic parameter visible from the closure
  in the Swift source.
  Value: The metadata source, which describes how to crawl the heap from
  the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.

Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.

rdar://problem/24989531
2016-04-22 19:09:06 -07:00
David Farler
263af75590 Revert "Stamp Swift binaries with the reflection version"
This reverts commit 437d3f2043.
2016-04-15 12:26:27 -07:00
Slava Pestov
824bd7544d IRGen: Emit typerefs for all builtin types referenced from reflection metadata sections
In order to perform layout, the remote mirrors library needs to know
about the size, alignment and extra inhabitants of builtin types.

Ideally we would emit a reflection info section in libswiftRuntime.o,
but in the meantime just duplicate builtin type metadata for all
builtin types referenced from the current module instead.

In practice only the stdlib and a handful of overlays like the SIMD
overlay use builtin types, and only a few at a time.

Tested manually by running swift-reflection-tool on the standard
library -- I'll add automated tests by using -parse-stdlib to
reference Builtin types in a subsequent patch that adds more layout
logic.

NFC if -enable-reflection-metadata is off.
2016-04-15 00:12:11 -07:00
David Farler
437d3f2043 Stamp Swift binaries with the reflection version
This will be cross-checked with SwiftRemoteMirror's version
compatibility.

rdar://problem/25559468
2016-04-07 20:16:13 -07:00
Roman Levenstein
b985794992 Prepare IRGen and LLVM passes to use the new preserve_most calling convention, but do not enable it yet.
The convention should be enabled once we can properly build the runtime library using Siwft's own clang/llvm binaries.
2016-04-01 14:19:47 -07:00
Roman Levenstein
5eca6e4df4 Get rid of a workaround for the JIT symbol lookup.
The underlying LLVM JIT problem is solved now and there is no need for any workarounds.
2016-03-03 16:03:50 -08:00
Slava Pestov
b3103ac7b7 Runtime: Fix alignment issue in default witness tables
The size of a protocol's metadata was not a multiple of 8 bytes, so
on 64-bit platforms, the runtime would copy default witnesses from
the wrong address, because IRGen metadata does not add alignment padding,
whereas the in-memory structure does.

Fix this by adding a 32-bit padding field at the end of the protocol
descriptor. Technically this is not necessary on 32-bit, but this keeps
things simpler for now.

The test case for this is a library evolution test exercising resilient
default protocol requirements, but it is not quite ready to go in yet.
2016-03-03 07:36:59 -08:00
practicalswift
795b86004b [gardening] When using C style comments, stick to the one line form.
In the rare cases where C style comments are needed sticking with the
one line form is preferred to allow for quick comment analysis by
simple methods such as:

$ git grep -E '(//|/\*.*\*/)'

When using the single line form the command above is guaranteed to
include all comment content (+ some non-comment content), which
greatly simplifies quick comment analysis.
2016-03-02 10:06:55 +01:00
swiftix
2573782c8b Merge pull request #1357 from swiftix/wip-runtime-calling-convention
Prepare the ground for using a new calling convention for functions from the runtime library
2016-03-01 16:22:37 -08:00
John McCall
3ce1ba3e65 Only store the minimal requirements in generic metadata, where
"minimal" is defined as the set of requirements that would be
passed to a function with the type's generic signature that
takes the thick metadata of the parent type as its only argument.
2016-02-25 10:33:33 -08:00
Roman Levenstein
f9d0609d16 Fix a dynamic symbol lookup issue in interpreter mode.
This was a very subtle bug, which occurred only in interpreter mode under Linux.
The actual name of the symbol should be artificially prefixed by an underscore,
because this underscore is stripped during a symbol lookup in interpreter mode.
If this is not done, then a reference to variable "_x" is being resolved as a reference
to the function "x"!
2016-02-25 09:11:15 -08:00
Roman Levenstein
2ff5755dc3 Use the "rt_" prefix for all generated wrappers to distinguish them from the actual runtime functions. 2016-02-25 06:00:30 -08:00
Roman Levenstein
99fd8b6080 Rename some macros based on the PR review comments.
- use  the SWIFT prefix for all macros
- make names of some macros shorter
2016-02-25 05:31:00 -08:00
Roman Levenstein
de3b850ce8 Use more descriptive names for calling conventions.
Rename RuntimeCC into DefaultCC
Rename RuntimeCC1 into RegisterPreservingCC
Remove RuntimeCC0 because it was identical to DefaultCC.
2016-02-25 05:31:00 -08:00
Roman Levenstein
2956e5675f Update x-macro metaprogramming support in IRGenModule.
Teach IRGen how to handle runtime functions definitions in RuntimeFunctions.def
depending on their calling convention and on their need for global symbols referring
to their internal implementations.

IRGen would now generate wrappers for runtime functions invocations if at least one
of the following conditions is met:
- The runtime function is defined using FUNCTION_WITH_GLOBAL_SYMBOL_AND_IMPL,
  which explicitly states that it has a global symbol referring to its implementation. In this case,
  the generated wrapper will perform an indirect call using the specified global symbol.
  This results in some performance improvements, because doing so removes one level of
  indirection during a call of the runtime function.
  The invocation sequence before looked like:
    Swift code -> dynamic linker stub -> runtime_function -> indirect call of runtime_function's implementation through a global function pointer
  And using a wrapper it becomes:
    Swift code -> wrapper -> indirect call of runtime_function's implementation through a global function pointer

- The runtime function is defined using the usual FUNCTION x-macro but it uses a calling convention
   that requires that wrappers should be used instead of dynamic linker stubs to avoid the situations
   where the dynamic linker would clobber some of the callee-saved registers when it performs a lazy
   binding of the runtime function, which may lead to an undefined behaviour during the program execution.

   In this case, the behaviour is similar to the first case, except that the name of the global symbol for
   the  runtime function f is assumed to be _f, i.e. it has an underscore as a prefix. This symbol
   will be auto-generated and properly initialized by an x-macro based metaprogramming machinery
   in the runtime library.
2016-02-25 05:31:00 -08:00
Roman Levenstein
4941f51388 Add a new RuntimeCC1 calling convention in IRGen.
This calling convention can be now used in RuntimeFunctions.def.
2016-02-25 05:30:59 -08:00
Roman Levenstein
850dde984d Set the C_CC calling convention dynamically in IRGen.
It makes it look more uniform with other calling convention members of IRGen, e.g. with RuntimeCC.
2016-02-25 05:30:59 -08:00
Roman Levenstein
634579aae2 Move RuntimeFunctions.def into a shared location.
RuntimeFunctions.def was used only by IRGen so far. But it is going to be used by the runtime library as well.
2016-02-25 05:30:59 -08:00
Roman Levenstein
8f5e525d2d Add function to generate an llvm wrapper for performing a runtime function call.
The generated wrapper simply invokes a corresponding entry point by means of
an indirect call via a global the symbol, which is a function pointer referring
to the implementation of a runtime function.

Using such wrappers allows for invocations of runtime functions from dynamic
libraries without the usual indirections via dynamic linker stubs.

If the calling convention and the current target require a wrapper, it will be
generated. Each wrapper gets a hidden linkage and is marked as ODR, so that
a linker can merge all wrappers with the same name.
2016-02-25 05:30:58 -08:00
Roman Levenstein
420d6deda8 Make the functions generating LLVM IR declarations of runtime entry points available outside of IRGen.
This functionality could be re-used by e.g. LLVMPasses, which currently create LLVM IR declarations of runtime entry points on their own.

To make the function re-usable, slightly change the API of the function:
- use llvm::Module instead of IRGenModule.
- use llvm::ArrayRef instead of std::initializer_list, which allows the clients of this API to dynamically form the lists of return types and arguments.
2016-02-25 05:30:58 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Slava Pestov
e0e2d9bf24 IRGen: Emit default witness tables in protocol metadata
IRGen now uses a ConstantBuilder to build protocol metadata, which may
now have additional fields at the end for default witnesses.

For now, the default implementations in the test have to external
because IRGen cannot emit a witness_method body where Self is
abstract. I will fix this by passing in the witness table as part
of the witness_method calling convention.

On the IRGen side, other than the calling convention change, the only
remaining piece here is emitting GenericWitnessTables and accessor
functions for conformances where the conformance is defined in
a different module than the protocol, and the protocol is resilient.

Sema still needs to infer default witnesses and store them in the
ProtocolDecl, so that SILGen can emit default witness thunks for
them.
2016-02-08 00:48:55 -08:00
David Farler
a6a5ece206 IRGen: Emit type references for remote reflection
- Implement emission of type references for nominal type field
  reflection, using a small custom encoder resulting in packed
  structs, not strings. This will let us embed 7-bit encoded
  32-bit relative offsets directly in the structure (not yet
  hooked in).
- Use the AST Mangler for encoding type references
  Archetypes and internal references were complicating this before, so we
  can take the opportunity to reuse this machinery and avoid unique code
  and new ABI.

Next up: Tests for reading the reflection sections and converting the
demangle tree into a tree of type references.

Todo: For concrete types, serialize the types for associated types of
their conformances to bootstrap the typeref substitution process.

rdar://problem/15617914
2016-02-03 13:52:26 -08:00
Erik Eckstein
aaaf36e835 Incremental compilation for the llvm part of the compiler.
Only re-generate an object file if the llvm IR (after IRGen) changed.
The check is done based on a MD5 hash of the llvm IR which is stored in a special section in the object file.

This reduces compilation time for multi-threaded whole module compilation if only a small number of files are changed.
The incremental compilation also works for compilations with a single output file. In this case it's all-or-nothing.
2016-01-29 13:16:30 -08:00
Slava Pestov
d887d823ef Re-apply "Protocol conformances can now reference resilient value types"
This comes with a fix for a null pointer dereference in _typeByName()
that would pop with foreign classes that do not have a
NominalTypeDescriptor.

Also, I decided to back out part of the change for now, where the
NominalTypeDescriptor references an accessor function instead of a
pattern, since this broke LLDB, which reaches into the pattern to
get the generic cache.

Soon we will split off the generic cache from the pattern, and at
that time we can change the NominalTypeDescriptor to point at the
cache. But for now, let's avoid needless churn in LLDB by keeping
that part of the setup unchanged.
2016-01-29 00:49:00 -08:00
Slava Pestov
4fd1387b3a Revert "Protocol conformances can now reference resilient value types"
This apparently broke Foundation and LLDB tests. I need to investigate further.

This reverts commit 65dd0e7b93.
2016-01-28 01:03:39 -08:00
Slava Pestov
65dd0e7b93 Protocol conformances can now reference resilient value types
Change conformance records to reference NominalTypeDescriptors instead of
metadata patterns for resilient or generic types.

For a resilient type, we don't know if the metadata is constant or not,
so we can't directly reference either constant metadata or the metadata
template.

Also, whereas previously NominalTypeDescriptors would point to the
metadata pattern, they now point to the metadata accessor function.
This allows the recently-added logic for instantiating concrete types
by name to continue working.

In turn, swift_initClassMetadata_UniversalStrategy() would reach into
the NominalTypeDescriptor to get the pattern out, so that its bump
allocator could be used to allocate ivar tables. Since the pattern is
no longer available this way, we have to pass it in as a parameter.

In the future, we will split off the read-write metadata cache entry
from the pattern; then swift_initClassMetadata_UniversalStrategy() can
just take a pointer to that, since it doesn't actually need anything
else from the pattern.

Since Clang doesn't guarantee alignment for function pointers, I had
to kill the cute trick that packed the NominalTypeKind into the low
bits of the relative pointer to the pattern; instead the kind is now
stored out of line. We could fix this by packing it with some other
field, or keep it this way in case we add new flags later.

Now that generic metadata is instantiated by calling accessor functions,
this change removes the last remaining place that metadata patterns were
referenced from outside the module they were defined in. Now, the layout
of the metadata pattern and the behavior of swift_getGenericMetadata()
is purely an implementation detail of generic metadata accessors.

This patch allows two previously-XFAIL'd tests to pass.
2016-01-28 00:33:10 -08:00
David Farler
ca1804f455 IRGen: Add helper methods to get field metadata and field name sections 2016-01-26 09:33:54 -08:00
David Farler
aa57b7402d Stub out FieldDescriptor LLVM type 2016-01-26 09:33:54 -08:00
David Farler
0b8a74800f Define the FieldRecord LLVM type
An individual field record for a nominal type consists of:

- 32-bit general purpose flags,
- 32-bit relative offset to the encoded type reference string, or
  32-bit relative offset to the mangled name of the type defined
  in another image, and
- 32-bit relative offset to the field name string.
2016-01-21 11:24:28 -08:00
Luke Howard
70c5755adb [SR-381]: runtime resolution of type metadata from a name
replace ProtocolConformanceTypeKind with TypeMetadataRecordKind

metadata reference does not need to be indirectable

more efficient check for protocol conformances

remove swift_getMangledTypeName(), not needed yet

kill off Remangle.cpp for non-ObjC builds

cleanup

cleanup

cleanup comments
2016-01-15 17:48:42 +11:00
John McCall
f1682cd9a8 Use real types instead of "Self" for the IR value names of local type data.
Since that's somewhat expensive, allow the generation of meaningful
IR value names to be efficiently controlled in IRGen.  By default,
enable meaningful value names only when generating .ll output.

I considered giving protocol witness tables the name T:Protocol
instead of T.Protocol, but decided that I didn't want to update that
many test cases.
2016-01-13 19:26:18 -08:00