Commit Graph

2424 Commits

Author SHA1 Message Date
David Zarzycki
82e08ed3b7 [AST] NFC: Repack misc AbstractFunctionDecl bits 2017-12-10 20:38:01 -05:00
Michael Gottesman
5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08:00
Slava Pestov
1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov
1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Arnold Schwaighofer
3e04f21a41 SIL: Remove EnableGuaranteedClosureContext now that it is the default 2017-11-27 07:25:03 -08:00
Michael Gottesman
8f5a4859f2 [sil] Add some more utilities for working with destructure operations.
Just slicing off some code from my pred-memopts patch since Slava needs this
functionality for some other work he is doing.
2017-11-19 17:24:33 -08:00
Michael Gottesman
a8b1917512 [all-+0] Add a new convention for setters: DefaultSetterConventions.
In a situation where normal arguments are +0, we want setters to still take
normal parameters at +1 since in most cases setters will be taking a parameter
that is being forwarded into to be store into a field.

Since this doesn't actually change the current ParameterConvention for setter
normal arguments, this is NFC.

rdar://34222540
2017-11-19 12:35:18 -08:00
Adam Nemet
fb008462a5 Fix no-assert build after PR12933 2017-11-17 12:22:12 -08:00
swift-ci
012cc4a6e7 Merge pull request #12933 from anemet/opt-remark-generic-specialization 2017-11-17 10:05:22 -08:00
Adam Nemet
bd8764caaa Add opt remarks to Generic Specializer pass
Adds a combined API to output both debug message and optimization remarks.

The previously added test partial_specialization_debug.sil ensures that it's an
NFC for debug output.
2017-11-16 10:10:24 -08:00
Slava Pestov
cce30cc9bb SIL: Remove SILFunction::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Erik Eckstein
90c21be191 Unify the implementation of optimization mode in various option classes.
This commit is mostly refactoring.

*) Introduce a new OptimizationMode enum and use that in SILOptions and IRGenOptions
*) Allow the optimization mode also be specified for specific SILFunctions. This is not used in this commit yet and thus still a NFC.

Also, fixes a minor bug: we didn’t run mandatory IRGen passes for functions with @_semantics("optimize.sil.never")
2017-11-14 11:25:02 -08:00
swift-ci
d1f6107bbc Merge pull request #12924 from gottesmm/pr-2103183ed8106e85e0948acf6949f64bf51946b2 2017-11-14 11:16:50 -08:00
swift-ci
1af18d84c1 Merge pull request #12923 from gottesmm/pr-6c446d1f42da1561151e296c5d3510a68baad584 2017-11-14 11:05:14 -08:00
Michael Gottesman
3226921b70 [sil] Add reverse iterator and reverse range support to SILInstructionResultArray.
I also used this as an opportunity to make SILInstructionResultArray::iterator
not inherit from std::iterator given that std::iterator is now deprecated.

Just slicing code off a larger commit.

rdar://31521023
2017-11-14 09:55:12 -08:00
Michael Gottesman
ac8aa12486 [sil-builder] Add utility method emitDestructureValueOperation.
This just abstracts the creation of a destructure_store or destructure_tuple
without the caller needing to know.

Just slicing simple code off of a larger commit.

rdar://31521023
2017-11-14 09:54:34 -08:00
Michael Gottesman
4a263cfcc8 Clean up TypeLowering a bit. I did this while doing some exploratory work. No point in just losing it. 2017-11-14 09:49:05 -08:00
John McCall
045998544f Add begin_apply, abort_apply, and end_apply instructions to allow
yield_once coroutines to be executed.
2017-11-13 04:03:54 -05:00
John McCall
aff457381c Change ApplyInstBase to not try to handle trailing objects itself. NFC.
The goal is to make it more composable to add trailing-objects fields in
a subclass.

While I was doing this, I noticed that the apply instructions provided
redundant getNumArguments() and getNumCallArguments() accessors, so I
went ahead and unified them.
2017-11-13 04:03:21 -05:00
John McCall
7743be30f6 Add a "token" type to SIL to allow dependencies to be expressed without
allowing abstraction.
2017-11-13 04:03:21 -05:00
Arnold Schwaighofer
fe4d4df508 Merge pull request #12863 from aschwaighofer/sil_and_siloptimizer_callee_guaranteed_fix
SILCombine and SIL adjustFunctionType fix for @callee_guaranteed
2017-11-12 07:05:20 -08:00
Slava Pestov
78ad6c4577 AST: New mangling for method dispatch thunks 2017-11-11 16:31:53 -08:00
Slava Pestov
55e8ac23e2 Merge pull request #12874 from slavapestov/dynamic-required-inits-still-have-allocating-entry-point-in-vtable
SILGen: Fix bug with vtable entries for allocating initializers
2017-11-11 16:09:30 -08:00
swift-ci
dc40ef17af Merge pull request #12877 from gottesmm/pr-2825f88a344991e66817bd6fda9868fee5b09a15 2017-11-11 12:03:42 -08:00
Michael Gottesman
2f1ebf3c51 [pred-memopt] Provide normal succ manipulation methods on TermInst instead of SILBasicBlock.
I am doing this for a few different reasons:

1. The code for manipulating successors was partially in TermInst (with
SILBasicBlock delegating to TermInst) and partly in SILBasicBlock itself. It
makes more sense to just be consistent and move all said functionality into
TermInst and just always delegate to SILBasicBlock.

2. I am preparing an API around gathering all critical edges. All of the
critical edge breaking APIs to take a TermInst. I wanted to use some of the
successor APIs, only to discover that we were not delegating to TermInst.  By
moving said functionality onto TermInst itself and delegating, we have it in
both places.

rdar://31521023
2017-11-11 11:27:42 -08:00
Slava Pestov
ce2a434587 SILGen: Fix bug with vtable entries for allocating initializers
Some changes I was working on uncovered a latent bug where we would
emit a class_method instruction to call an allocating initializer
that did not have a vtable entry.

Previously this wasn't caught because the only example of this in
our test suite was in test/SILGen/objc_bridging_any.swift, which
did not test with IRGen; if it did, an IRGen crash would have been
observed.

Factor out some code duplication to prevent this from happening
again, and add a SILGen test that we emit a vtable entry in this
case, and that the test case passes IRGen also.
2017-11-11 02:01:50 -08:00
Slava Pestov
773e6bff56 SIL: Add SILFunction::getResilienceExpansion() 2017-11-10 16:20:09 -08:00
Arnold Schwaighofer
68d0a8774a SIL: Make adjustFunction type of closures parameterized on whether we use
guaranteed closures

This is going to go away once we change the default to guaranteed
closures.

SR-5441
rdar://33255593
2017-11-10 15:18:01 -08:00
Jordan Rose
1598a21e43 DI: Warn on non-delegating cross-module struct initializers
...as detected by initializing an individual field without having
initialized the whole object (via `self = value`).

This only applies in pre-Swift-5 mode because the next commit will
treat all cross-module struct initializers as delegating in Swift 5.
2017-11-09 11:24:28 -08:00
Huon Wilson
99c4cddfca [SILGen] Store conditional conformances in SILWitnessTables. 2017-11-08 17:02:50 -08:00
Michael Gottesman
b17935aff2 [pred-memopt] Rather than extracting values at the load site, extract at the store site.
Previously in PredMemOpts, we would insert any extracts at the load site, i.e.:

  store %foo to %0
  ...
  %1 = struct_element_addr %0, $Type, $Type.field
  %2 = load %1
  ...
  apply %use(%2)

would transform to:

  store %foo to %0
  ...
  %2 = struct_extract %foo
  apply %use(%2)

This framework will not work with Ownership enabled since the value stored is
considered consumed by the store. This change fixes the issue by moving such
non-destructive extracts to occur while %foo is considered live, i.e. before the
store:

  %2 = struct_extract %foo
  store %foo to %0
  ...
  apply %use(%2)

This means that we have to store insertion points for each store that provides
us with available values and insert the extracts at those points. This creates
some complications in the case where we have multiple stores since we need to
deal with phi nodes. Rather than dealing with it by hand, we just insert the
extracts at each point and then use the SSA updater to insert the relevant phi
nodes.

rdar://31521023
2017-11-08 10:40:39 -08:00
swift-ci
69a6e5e260 Merge pull request #12789 from rjmccall/sil-coroutines 2017-11-07 03:22:22 -08:00
John McCall
14d6390352 Add "yield" and "unwind" instructions to SIL. 2017-11-07 03:51:54 -05:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Slava Pestov
ced25fb0d7 SILGen: Remove more references to the 'uncurry level' concept 2017-11-06 18:48:20 -08:00
Michael Gottesman
b4bfd2f9d3 [pred-memopt] Add convenience begin/end borrow operation on SILBuilder.
These APIs make it easy to create borrow/end_borrow operations in a pass that
has to handle both ownership and non-ownership SIL.

rdar://31521023
2017-11-06 11:27:21 -08:00
Michael Gottesman
6c10f911c0 [di] When scalarizing tuples in DI use destructure_tuple.
Bug noticed on inspection.

rdar://31521023
2017-11-05 00:10:15 -05:00
Arnold Schwaighofer
b5fab6145f SILCombiner: Fix partial_apply optimization of @callee_guaranteed
closures

@callee_guaranteed closure contexts must not be released when replacing
a closure application.

SR-5441
rdar://33255593
2017-11-04 14:03:56 -07:00
Michael Gottesman
ec573ba213 [sil] Allow createTrivial{Store,Load}Or to optionally handle non-ownership sil functions.
This is just convenient if you want to have a pass work transparently with both
ownership and non-ownership SIL.

Chopped off from the larger pred-memopt update commit to ease review.

rdar://31521023
2017-11-03 23:07:22 -05:00
Slava Pestov
6fbf8b81a3 SIL: Kill completely bogus getTypeLinkage() function
- The overload of operator^ on FormalLinkage, while cute, was only used
  in this one place, and does not behave like an XOR.

- The structural type walk was totally unnecessary in the first place,
  because we were only ever calling getTypeLinkage() with builtin types
  and nominal types.

- Furthermore, the structural type walk was doing the wrong thing with
  nested nominal types, because the linkage of a nested type A.B
  should not be the intersection of the linkage of A and A.B. If A is an
  imported type and A.B is defined in an extension of A, we would give
  the metadata of A.B shared linkage, which is wrong.
2017-11-03 16:03:00 -07:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Greg Parker
d6e1866344 [SIL] Make @_silgen_name and @_cdecl functions immune to some optimizations (#12696)
@_silgen_name and @_cdecl functions are assumed to be referenced from
C code. Public and internal functions marked as such must not be deleted
by the optimizer, and their C symbols must be public or hidden respectively.

rdar://33924873, SR-6209
2017-11-01 01:41:05 -07:00
Michael Gottesman
333f231bea [sil] Change some methods on SingleValueInstruction to use redeclarations instead of using directives.
lldb is not aware of using directives currently so if you try to invoke the
given methods you will get an ambiguous name lookup error from lldb. These are
important methods for debugging in lldb, so instead in this commit we just
redeclare them and delegate to the appropriate parent class.
2017-10-29 12:19:25 -07:00
Joe Groff
f599c1a67f Merge pull request #12660 from jckarter/sil-constant-info-rehashing
SIL: Keep stable pointer identities for cached SILConstantInfos.
2017-10-29 02:10:34 +02:00
Slava Pestov
da6d960c9b Merge pull request #12652 from slavapestov/fix-resilient-stdlib
Fix resilient stdlib
2017-10-27 12:21:23 -07:00
Joe Groff
c564790701 SIL: Keep stable pointer identities for cached SILConstantInfos.
TypeConverter::getConstantInfo was changed to return its found records by reference, but by reference into the inline storage of a DenseMap, which is a bad idea if someone else makes a getConstantInfo call that causes the cache to rehash before we're done with the reference from a previous call. Change it so that the cached SILConstantInfos get allocated out of the SILModule's arena, and so that we store the pointers in the hashtable, so that the references remain stable. Should fix rdar://problem/35132592.
2017-10-27 11:26:50 -07:00
swift-ci
dfbcccfb75 Merge pull request #12585 from anemet/save-opt-record 2017-10-27 11:09:50 -07:00
Adam Nemet
66085a8aef Save optimization remarks in an external YAML file
This brings the capability from clang to save remarks in an external YAML files.
YAML files can be viewed with tools like the opt-viewer.

Saving the remarks is activated with the new option -save-optimization-record.

Similarly to -emit-tbd, I've only added support for single-compile mode for now.
In this case the default filename is determined by
getOutputFilenameFromPathArgOrAsTopLevel, i.e. unless explicitly specified
with -save-optimization-record-path, the file is placed in the directory of the
main output file as <modulename>.opt.yaml.
2017-10-27 10:14:27 -07:00