Commit Graph

200 Commits

Author SHA1 Message Date
Arnold Schwaighofer
67e3d27fd9 Copy-on-write existential performance work (#8369)
* IRGen: Change c-o-w existential implementation functions

* initialzeBufferWith(Copy|Take)OfBuffer value witness implementation for cow existentials

Implement and use initialzeBufferWith(Copy|Take)OfBuffer value witnesses for
copy-on-write existentials.

Before we used a free standing function but the overhead of doing so was
noticable (~20-30%) on micro benchmarks.

* IRGen: Use common getCopyOutOfLineBoxPointerFunction

* Add a runtime function to conditionally make a box unique

* Fix compilation of HeapObject.cpp on i386

* Fix IRGen test case

* Fix test case for i386
2017-03-27 20:51:02 -07:00
Saleem Abdulrasool
15565c116a Adjust for SVN r298393 2017-03-22 07:44:03 -07:00
Devin Coughlin
6ac36df1e7 SIL: Add SIL builtin for Thread Sanitizer inout accesses
...and IRGen it into a call to __tsan_write1 in compiler-rt. This is
preparatory work for a later patch that will add an experimental
option to treat Swift inout accesses as TSan writes.
2017-03-06 19:13:50 -08:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
AnnaZaks
1122ebd731 Merge pull request #6453 from apple/asan
[tsan] Do not report races coming from deinitializers and _Block_release
2017-01-06 11:50:28 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Anna Zaks
18c10c566f [tsan] Do not report races coming from deinitializers and _Block_release
TSan does not observe the guaranteed syncronization between the ref
count drop to zero and object destruction. This can lead to false positive
reports.

This patch adds an attribute to deinitializers to ignore memory accesses
at run time. It also moves the logic to add sanitizer attributes from
IRGenFunction to IRGenSILFunction, which means that the automatically
generated code such as _Block_release handler will not be instrumented
and the accesses made in them will be invisible to TSan.

Solves a problem similar to what's addressed in clang commit:
https://reviews.llvm.org/D25857
2017-01-05 10:26:25 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Adrian Prantl
75e10a66cc This fixes a bot failure in the LLDB testsuite.
This removes an assertion that no longer serves its purpose and
relaxes the IRBuilder checks for debug info when generating code
inside the debugger.

When LLDB is JIT-compiling expressions, it will not generate a
SWIFT_ENTRY_POINT_FUNCTION (there will be one per expression)
but it will still generate the equivalent of top level code.

rdar://problem/26955467
2016-06-28 10:33:40 -07:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -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
practicalswift
66183cdbf7 [gardening] Fix unjustified spacing 2016-04-07 10:10:24 +02:00
Anna Zaks
92fae2e9a4 Add experimental support for Thread Sanitizer.
This patch threads the TSan option through the front end.
2016-04-06 11:53:43 -07:00
John McCall
0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
John McCall
abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
John McCall
41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07: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
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
ec04b22145 Properly propagate the calling convention into LLVM's call instructions.
Each runtime function definition in RuntimeFunctions.def states which calling convention
should be used for this runtime function.  But IRGen and LLVMPasses were not always
properly propagating this declared calling convention all the way down to llvm's Call instructions.
In many cases, the standard C convention was set for the call irrespective of the actual calling
convention defined for a given runtime function. As a result, incorrect code was generated.

This commit tries to fix all those places, where such a mismatch was found. In many cases this is
achieved by defining a helper function CreateCall in such a way that makes sure that the call instruction
gets the same calling convention as the one used by its callee operand.
2016-02-25 05:30:59 -08:00
zaks
ef925f8fb3 [asan] Add basic support for Address Sanitizer function instrumentation
ASan allows to catch and diagnose memory corruption errors, which are possible
when using unsafe pointers.

This patch introduces a new driver/frontend option -sanitize=address to enable
ASan. When option is passed in, the ASan llvm passes will be turned on and
all functions will gain SanitizeAddress llvm attribute.
2016-02-24 09:45:38 -08:00
John McCall
7dd9f5f037 Improve IRGen's infrastructure for caching local type data.
There are several interesting new features here.

The first is that, when emitting a SILFunction, we're now able to
cache type data according to the full dominance structure of the
original function.  For example, if we ask for type metadata, and
we've already computed it in a dominating position, we're now able
to re-use that value; previously, we were limited to only doing this
if the value was from the entry block or the LLVM basic block
matched exactly.  Since this tracks the SIL dominance relationship,
things in IRGen which add their own control flow must be careful
to suppress caching within blocks that may not dominate the
fallthrough; this mechanism is currently very crude, but could be
made to allow a limited amount of caching within the
conditionally-executed blocks.

This query is done using a proper dominator tree analysis, even at -O0.
I do not expect that we will frequently need to actually build the
tree, and I expect that the code-size benefits of doing a real
analysis will be significant, especially as we move towards making
more metadata lazily computed.

The second feature is that this adds support for "abstract"
cache entries, which indicate that we know how to derive the metadata
but haven't actually done so.  This code isn't yet tested, but
it's going to be the basis of making a lot of things much lazier.
2016-01-05 17:55:51 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fd70b26033 Fix typos in comments. 2015-12-28 02:15:34 +01:00
Adrian Prantl
8ab1e2dd50 Unify debug scope and location handling in SILInstruction and SILBuilder.
The drivers for this change are providing a simpler API to SIL pass
authors, having a more efficient of the in-memory representation,
and ruling out an entire class of common bugs that usually result
in hard-to-debug backend crashes.

Summary
-------

SILInstruction

Old                   New
+---------------+     +------------------+    +-----------------+
|SILInstruction |     |SILInstruction    |    |SILDebugLocation |
+---------------+     +------------------+    +-----------------+
| ...           |     | ...              |    | ...             |
|SILLocation    |     |SILDebugLocation *| -> |SILLocation      |
|SILDebugScope *|     +------------------+    |SILDebugScope *  |
+---------------+                             +-----------------+

We’re introducing a new class SILDebugLocation which represents the
combination of a SILLocation and a SILDebugScope.
Instead of storing an inline SILLocation and a SILDebugScope pointer,
SILInstruction now only has one SILDebugLocation pointer. The APIs of
SILBuilder and SILDebugLocation guarantees that every SILInstruction
has a nonempty SILDebugScope.

Developer-visible changes include:

SILBuilder
----------

In the old design SILBuilder populated the InsertedInstrs list to
allow setting the debug scopes of all built instructions in bulk
at the very end (as the responsibility of the user). In the new design,
SILBuilder now carries a "current debug scope" state and immediately
sets the debug scope when an instruction is inserted.
This fixes a use-after-free issue with with SIL passes that delete
instructions before destroying the SILBuilder that created them.

Because of this, SILBuilderWithScopes no longer needs to be a template,
which simplifies its call sites.

SILInstruction
--------------

It is neither possible or necessary to manually call setDebugScope()
on a SILInstruction any more. The function still exists as a private
method, but is only used when splicing instructions from one function
to another.

Efficiency
----------

In addition to dropping 20 bytes from each SILInstruction,
SILDebugLocations are now allocated in the SILModule's bump pointer
allocator and are uniqued by SILBuilder. Unfortunately repeat compiles
of the standard library already vary by about 5% so I couldn’t yet
produce reliable numbers for how much this saves overall.

rdar://problem/22017421
2015-11-19 09:31:26 -08:00
Erik Eckstein
68fa1c2c34 Support for stack promotion in IRGen.
This means: handling of alloc_ref [stack].
It can be configured with two new options. See Option/FrontendOptions.td.

As the [stack] attribute is not generated yet, there should be NFC.




Swift SVN r32929
2015-10-28 00:44:25 +00:00
Joe Groff
2630dba793 Runtime: Rename Box2 functions to Box.
Swift SVN r29763
2015-06-27 18:10:17 +00:00
Joe Groff
8a04d67408 IRGen: Strip out dead code for untyped boxes.
Swift SVN r29761
2015-06-27 17:50:13 +00:00
Joe Groff
8ec59e5c11 Runtime: Implementation for generic typed boxes.
Provide new swift_{alloc,dealloc,project}Box2 entry points that allocate, project, and deallocate typed boxes using runtime-instantiated metadata. Give these a new metadata kind, so that external tools recognize the difference and can interpret the metadata appropriately.

Swift SVN r29714
2015-06-26 00:06:17 +00:00
Dmitri Hrybenko
2fc1cbe8c1 Adjust to the new IRBuilder APIs
Swift SVN r29692
2015-06-25 22:01:24 +00:00
Joe Groff
3c2ee54d43 IRGen: Implementation of typed box operations.
When producing TypeInfo for a box, try to reuse instantiations for common type structures:

- any POD type with the same stride and alignment can share a fixed HeapLayout;
- any single-refcounted-pointer type can share a fixed HeapLayout with types that have the same ReferenceCounting;
- dynamically-sized types can share a runtime-based box implementation.

For the runtime implementation, use new to-be-implemented variants of allocBox/deallocBox that will produce polymorphically-projectable boxes using instantiated metadata.

Swift SVN r29612
2015-06-24 19:43:24 +00:00
Joe Groff
2d3eba9e0d IRGen: Reuse value witness table projections.
Don't project every value witness from the metadata every time we need one; this wastes code size in a way LLVM can't really optimize since it doesn't know the metadata is immutable. The code size wins on the standard library are disappointingly small (stdlib only shrinks by 4KB), but this makes generic IR a lot more compact and easier to read.

Swift SVN r28095
2015-05-03 05:00:40 +00:00
John McCall
dc5a03a7bc Add IRGen support for error results from functions.
As part of this, re-arrange the argument order so that
generic arguments come before the context, which comes
before the error result.  Be more consistent about always
adding a context parameter on thick functions, even
when it's unused.  Pull out the witness-method Self
argument so that it appears last after the error
argument.

Swift SVN r26667
2015-03-28 02:00:17 +00:00
Erik Eckstein
650714b430 IRGen: cache alloc function attributes in IRGenModule instead of a static variable.
Swift SVN r25425
2015-02-20 14:39:49 +00:00
Erik Eckstein
9544893104 IRGen: Use a different cache for layout-metadata.
Metadata used for layout is (or may be) different than the "regular" metadata.
Therefore we need a separate cache for it.



Swift SVN r25238
2015-02-12 13:44:23 +00:00
Erik Eckstein
a5b8e05ea6 Reuse type metadata in the most obvious cases.
This avoids redundant calls of swift_get*Metadata() if the metadata is reused in the same basic block
or if it is already availabe in the function entry block.
There is still room for improvement, e.g. by not limiting the reuse to a single block.

This change reduces the dylib codesize by about 11%, mostly in protocoll witnesses (-34%).

It also results in some improvements for the -Onone performance:
RangeAssignment: +31%
StdlibSort: +20%




Swift SVN r25123
2015-02-10 14:42:39 +00:00
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
Joe Groff
6cb2bf96b8 IRGen: Implement the dealloc_box instruction.
Failable initializers will need to clean up an uninitialized 'self' box in the case where a class initializer calls out to a 'super.init' or 'self.init' fails. Because some framework classes assume that they have a refcount of exactly one during initialization, we have to take 'self' from the box during the delegation, and reinitialize the box with the result of the delegation on success. This means we actually have to implement lowering for dealloc_box.

Swift SVN r21493
2014-08-27 22:44:53 +00:00
Greg Parker
fe8618a3d2 Scrap the custom allocator until we have time to fix it.
The allocator's crimes include:
* It uses OS SPI that must not be used by non-OS apps.
* It does not play well with memory debugging tools like Instruments.
* It does not return memory to the OS in response to memory pressure.
* It is less tested than we would like because many configurations 
  inadvertently turn it off (such as running from Xcode).
* Its per-thread magazine implementation does not actually work.
* Its "try alloc" flag is incompletely implemented and never used.
* Its "zero fill" flag is unimplemented and inconsistently used.



Swift SVN r20757
2014-07-30 14:11:40 +00:00
John McCall
059ed4cd10 Propagate alignment arguments around through the
slow allocation/deallocation APIs.

Swift SVN r18160
2014-05-16 01:40:36 +00:00
Dave Zarzycki
2f4d679fd0 Runtime: Drop the "raw" label on normal memory. NFC.
DI defined away the need for zeroed memory.

Swift SVN r15293
2014-03-20 20:42:27 +00:00
John McCall
9cc98c6f52 Move the assorted routines out of GenExpr.cpp.
Swift SVN r12426
2014-01-16 22:32:33 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Adrian Prantl
5bbe0afb9f Debug info: Properly handle the function prologue in the line table.
Introduces a new flag in SILLocation: InPrologue to mark instructions
that setup the stack and allocate storage for local variables/arguments.

Fixes rdar://problem/15290023: Breakpoint set on prologue - crash ensues.

Swift SVN r9686
2013-10-26 00:12:20 +00:00
Anna Zaks
e36839ca8a [IRGen] Eliminate calls to SILLocation() from IRGen.
Here, the location information does not have to always be available. Use Optional instead of creating an empty location.

Swift SVN r8055
2013-09-09 22:34:01 +00:00
Adrian Prantl
ed9f734731 update comment.
Swift SVN r7233
2013-08-14 17:27:46 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Adrian Prantl
2c2ec20b3a Debug Info: Push the current location before we create a new function,
because we often emit functions while in the middle of another function.

Swift SVN r6744
2013-07-30 18:21:06 +00:00
Adrian Prantl
511ddc46fd Debug Info: Set the debug location for the function prologue to the decl of the function.
rdar://problem/14536357

Swift SVN r6576
2013-07-25 01:03:46 +00:00
Adrian Prantl
ceb32c281c Debug Info: Attach (some of the) functions without sources to their scopes.
Various cleanups.

Swift SVN r5863
2013-06-28 00:52:07 +00:00
Joe Groff
197c3e6d02 IRGen: Strip unneeded parameters from IRGenFunction constructor.
Swift SVN r5146
2013-05-10 18:18:14 +00:00