Commit Graph

8213 Commits

Author SHA1 Message Date
Joe Groff
bac64f3a11 More macro namespace qualification hygiene
NFC
2015-11-30 15:16:43 -08:00
Slava Pestov
9ee10e7d39 IRGen: destructiveProjectEnumData() value witness doesn't need a return value
The rest of the runtime assumes the payload starts at the beginning
of the enum, so simplify some code by removing the return value here.
2015-11-30 13:32:55 -08:00
Erik Eckstein
c5c3b176b0 EscapeAnalysis: improve the ConnectionGraph ABI.
Now only those functions are public which are callable from a client.
+ a few other changes.
2015-11-30 13:11:00 -08:00
Erik Eckstein
34bea2c440 EscapeAnalysis: change the handling of use-points.
We can now query if a specific instruction is a use-point.
2015-11-30 13:11:00 -08:00
Erik Eckstein
bd70851769 SIL: Fix mayRelease() for BuiltinInst 2015-11-30 13:11:00 -08:00
Erik Eckstein
966033ac9a EscapeAnalysis: make a separate state for "escapes with return" 2015-11-30 13:11:00 -08:00
Joe Groff
6605b596f3 Absolute-qualify name refs in macro expansion 2015-11-30 12:23:41 -08:00
Joe Groff
5e5cdc6be3 Runtime: Use 'once' instead of static local variable initialization.
The C++ ABI for static locals is a bit heavy compared to dispatch_once; doing this saves more than 1KB in runtime code size. Dispatch_once/call_once is also more likely to be hot because it's also used by Swift and ObjC code.

Alas, llvm::get_execution_seed() from llvm/ADT/Hashing.h still inflicts one static local initialization on us we can't override (without forking Hashing.h, anyway).
2015-11-30 12:08:12 -08:00
Nadav Rotem
f63492f3fa Fix a the description of the CSE pass. 2015-11-29 23:08:45 -08:00
Chris Lattner
2379928d07 Fix <rdar://22774938> QoI: "never used" in an "if let" should rewrite expression to use != nil
When we see an unused variable in a simple-enough "if/let" (also guard and
while of course), fixit it into a comparison against nil instead of replacing
the name of the variable with "_".  Also special case initialization with an
as? expression, since we can transform that into an "is" boolean test.
2015-11-29 21:49:36 -08:00
Chris Lattner
714dcd5ba5 Fix <rdar://problem/23202128> QoI: Poor diagnostic with let vs. var passed to C function
This improves the error message when attempting an array to UnsafeMutablePointer
conversion but where the element type of the array is incorrect or where the array itself
is immutable.

As a bonus fix, this dramatically improves the diagnostic when you pass "&array" to
a function that takes an UnsafePointer.  We decided to not require & in this case, so
we can just provide a nice fixit to rip it off when this common error happens.
2015-11-28 22:13:49 -08:00
Nadav Rotem
5542bc3792 [Serialization] Fix a bug in the serialization of resilient functions
The SIL serializer can decide not to serialize the body of functions in the SIL
module, and only emit a declaration.  If we keep the original linkage kind
(public, private, etc) then the deserialized module won't pass verification
because we do not allow internal functions to have external declarations. This
commit changes the linkage kind for the functions that the serializer decides to
emit as a declaration (without a body).

rdar://21989088
2015-11-28 03:04:56 -08:00
Michael Gottesman
14002274ff [loop-arc] Add a simple Loop visitor that visits loops bottom up in the loop tree. 2015-11-26 20:29:13 -06:00
Nadav Rotem
300ab4df05 [PM] Add a small verification method to ensure that analysis run on funcs with bodies.
Add a small verification method that checks that we run our function analysis
only on functions with bodies (not on external definitions). I ran into this bug
when working on the pass manager.
2015-11-25 14:26:44 -08:00
Nadav Rotem
e8bbace5e1 [SideEffectsAnalysis] Cleanups some code.
Abbreviate SILInstruction::MemoryBehavior and rewrite one of the loops.
2015-11-24 15:52:51 -08:00
Mark Lacey
54ceaf230f Tweak access-modifier formatting. 2015-11-24 13:10:04 -08:00
Mark Lacey
ea5ebb7fc0 Fix up includes in PassManager.h. 2015-11-24 10:44:58 -08:00
Nadav Rotem
a07da67d6f [AliasAnalysis] Cache the results of TBAA.
Add a cache for calls to typesMayAlias. We never invalidate this cache
because type aliasing relations never change.

The hit rate of this cache is really high.
2015-11-23 22:20:37 -08:00
Nadav Rotem
a3020a82fe [AliasAnalysis] Make the dependence on SideEffectsAnalysis internal.
This commit removes the public method for fetching SideEffectsAnalysis. The
dependency on SEA is now an implementation detail of AliasAnalysis and
computeMemoryBehavior.
2015-11-23 19:31:05 -08:00
Nadav Rotem
651edbff73 Revert "[AliasAnalysis] Document and roll the alias() family of methods. NFC."
@atrick commented that he preferred the non-macro unrolled version.

This reverts commit c1dce5c75c.
2015-11-23 14:49:33 -08:00
Nadav Rotem
971aa239e4 [AliasAnalysis] Remove the AliasAnalysis Cache.
The AliasAnalysis is unsafe. When we delete instructions we don't have a good
mechanism for invalidating the cache and we don't want instructions to
explicitly invalidate AliasAnalysis after every deletion of an instruction.

Morever, the alias analysis cache _always_ misses. Removing the cache did not
change the build time of the standard library at all.
2015-11-22 19:38:37 -08:00
Nadav Rotem
c7a4637bd5 [AliasAnalysis] Rename getMemoryBehavior.
getMemoryBehavior is also used by SILInstruction. This commit renames
    getMemoryBehavior to computeMemoryBehavior and cleans some of the code
    that touches it.

// I forgot to add this file in my previous commit.
2015-11-22 19:38:19 -08:00
Nadav Rotem
2276a93917 [AliasAnalysis] Clean some of the docs.
Move some comments from the definition to the decleration and tidy
some of the comments.
2015-11-22 19:37:59 -08:00
Nadav Rotem
4b2da0a4a0 [AliasAnalysis] Remove the default argument from getMemoryBehavior.
ObserveRetains is not an obvious default and it does not make sense to have it
as a default argument.
2015-11-22 19:37:28 -08:00
Nadav Rotem
c1dce5c75c [AliasAnalysis] Document and roll the alias() family of methods. NFC.
Document alias() and roll the mayAlias() family of methods into a single
function.
2015-11-22 19:37:19 -08:00
Nadav Rotem
f6d6f31c94 [AliasAnalysis] Document the AliasResult enum. NFC. 2015-11-22 19:37:10 -08:00
Slava Pestov
d432286980 Re-apply "Sema: Targeted fix for LLDB REPL issue"
Now with a change to the AST printer to never print @_fixed_layout.
Once some more groundwork is in place, we will be able to only print
this attribute when its needed, but this is good enough for now.
2015-11-20 20:01:46 -08:00
Ted Kremenek
3e779dbc66 Revert "Revert "Safely implement strict TBAA rules.""
We believe the failure now may be in the setup of the test harness.
Re-applying this change, since the tests passed in our other
configurations.
2015-11-20 15:08:58 -08:00
Ted Kremenek
ddc9c52d5a Revert "Safely implement strict TBAA rules."
This reverts commit 3d5c4969a0.

This is breaking the iOS device tests.
2015-11-20 14:51:25 -08:00
Andrew Trick
3d5c4969a0 Safely implement strict TBAA rules.
This fixes type punning issues with unsafeBitCast.

The optimizer is still too aggressive with UnsafePointer. To fix that,
we first need an explicit API for circumventing type safety
(rdar://23406272).

I should be able to fix the following regressions by migrating the
stdlib away from unsafeBitCast to unsafeReferenceCast (~2 weeks).

Slowdowns:
|.Benchmark.................|..Before.|...After.|.Speedup|
|.ArrayInClass..............|...49.00.|...78.00.|.-37.2%.|
|.Sim2DArray................|..471.00.|..549.00.|.-14.2%.|
|.PrimeNum..................|.1876.00.|.1980.00.|..-5.3%.|

Speedups:
|.Benchmark.................|..Before.|...After.|.Speedup|
|.HeapSort..................|.2962.00.|.2663.00.|..11.2%.|
|.StdlibSort................|.2672.00.|.2537.00.|...5.3%.|
2015-11-20 09:59:56 -08:00
Andrew Trick
2016e3323b Revert today's changes to SIL AliasAnalysis.
This series of commits is reverted because it introduces risk. This type
of change requires design discussion and thorough unit testing.

Revert "Refactor in alias analysis. NFC"

This reverts commit 3390a584b8.

Revert "Update SILArgument alias analysis to make use of the new alias() interface"

This reverts commit 5940fcca78.

Revert "Clean up uneeded SIL in a LIT test"

This reverts commit 81ebb5667f.

Revert "Fix LIT test in basic-aa."

This reverts commit a55340394f.

Revert "Improve comments in alias analysis"

This reverts commit 44ddc5b4df.

Revert "Implement SILArgument and select_enum handling for alias analysis"

This reverts commit 23c257938f.
2015-11-19 16:53:24 -08:00
Adrian Prantl
de8faa0094 Update comments. 2015-11-19 13:59:11 -08:00
Adrian Prantl
83b44be215 Out-line the definition of ScopeCloner::getOrCreateClonedScope(). NFC 2015-11-19 13:59:11 -08:00
Xin Tong
44ddc5b4df Improve comments in alias analysis 2015-11-19 10:28:42 -08: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
Xin Tong
23c257938f Implement SILArgument and select_enum handling for alias analysis 2015-11-19 09:22:00 -08:00
Nadav Rotem
f8143bba82 Clean and document the PassManager's runFunctionPasses. 2015-11-19 08:56:55 -08:00
Roman Levenstein
5a4888236d Revert "Re-apply "Reduce memory footprint of the Swift compiler""
This reverts commit bf2fdb6764.

One of the build bots reported a malloc/free error, while other bots had successful builds. It could indicate a non-deterministic failure.
Preventively revert this patch as it is the most likely cause of these issues.

rdar://23611346
2015-11-19 07:56:57 -08:00
Mark Lacey
19b7554cf2 Use the new function order helper in side effect analysis.
Rather than using the call graph's bottom-up ordering, use the new helper.
2015-11-19 07:17:05 -08:00
Nadav Rotem
133fdde391 Rename the trait WholeFunction to FunctionBody. 2015-11-18 21:15:40 -08:00
Nadav Rotem
55e79aedbd Fix a bug in the invalidation of analysis in the inliner and ArrayOpt passes.
And add an assertion to make sure that invalidation messages invalidate some trait.
2015-11-18 21:15:40 -08:00
Roman Levenstein
bf2fdb6764 Re-apply "Reduce memory footprint of the Swift compiler"
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

The use-after-free issue reported by build bots is fixed now.

rdar://23303031
2015-11-18 18:14:29 -08:00
Roman Levenstein
46fda83a51 [AliasAnalysis] Don't cache the results between queries.
The cache is using SILValues as keys and such key would contain dangling pointers after the instruction corresponding to a given SILValue is erased.
Therefore, the cache needs to be invalidated between queries. It still makes sense to use the cache during queries, because sometimes queries may be recursive and pretty expensive to compute. It is safe to use  caching during the query, because no instructions are being erased while processing it.

The removal of the cache does not seem to affect compile times in a negative way.
2015-11-18 18:14:29 -08:00
Roman Levenstein
294282275d [RCIdentityAnalysis] Don't cache the results of analysis
The cache was using SILValue as a key and this key would contain a dangling pointer after the instruction corresponding to a given SILValue is erased.
The removal of the cache does not seem to affect compile times in a negative way.

rdar://23602657
2015-11-18 17:34:18 -08:00
Nadav Rotem
cc2ca083ee Change the bool that represents the property of observing or ignoring retains in Alias Analysis into an enum.
We had a true/false bug in this flag. Let's not have another bug with this flag.
2015-11-18 17:02:27 -08:00
Erik Eckstein
d2d6e0cbe8 Re-apply "Update SideEffectAnalysis to use BasicCalleeAnalysis.""
... and re-enable the cse_apply test.
The underlying problem is fixed in LICM in the previous commit.

Original commit: 02e08e23de.
2015-11-18 15:06:50 -08:00
Nadav Rotem
681171b11f [callgraph] The new invalidation trait 'function' needs to invalidate the call graph. 2015-11-18 13:23:06 -08:00
Joe Groff
9ea30d00fe Runtime: Remove custom operator new(InPlace).
C++ no longer imposes a null check requirement on placement 'new', and clang no longer emits the null check. This hack is no longer needed.
2015-11-18 12:31:24 -08:00
Joe Groff
7c68fc14c4 Add a comment for why Demangler::isDigit isn't just std::isdigit. 2015-11-18 12:01:00 -08:00
Nadav Rotem
7a5fe1dc0f Change the analysis invalidation message from "preserve" to "invalidate".
This commit changes the way passes invalidate analysis. Passes now report the
list of traits that they invalidate.  We went back and forth on this a few times
and we are now going back to the invalidation mode. In a few places in the
optimizer passes had to record the fact that they deleted a call or a branch and
had to construct the enum that will contain the preserve list. Now passes can
either use the new enum states that are the intersection of traits or even send
multiple invalidation message.

We are making this change now because Mark added a new kind of invalidation
trait ("function"). Adopting this new invalidation trait required that we
inspect all of the invalidation sites anyway. This commit includes a more
efficient use of the 'function' attribute, and our function passes don't
invalidate the 'function' attribute anymore.
2015-11-18 11:34:37 -08:00