Commit Graph

402 Commits

Author SHA1 Message Date
Michael Gottesman
93ed95847a [ownership] When deserializing a SILFunction, match the ownership of the deserialized function.
Ownership is truly a property not of a declaration, but of a function body. So
it makes sense to just match what we deserialize.

This also helps us to avoid mismatches if we lower ownership from a function,
delete it, and then relink it.

I also used this as an opportunity to clean up where we set that flag in
deserialization to only happen in one place for both declarations/definitions.
2019-08-11 15:05:54 -07:00
Joe Groff
77b012af1d SIL: Add an [exact_self_class] function attribute.
This indicates that the "self" argument to the current function is always dynamically of the exact
static base class type, allowing metadata accesses in IRGen to use the local self metadata to answer
metadata requests for the class type. Set this attribute on allocating entry points of designated
inits, which is one of the most common places where we emit redundant metadata accesses.
2019-08-08 14:03:07 -07:00
Joe Groff
3e2965f452 IRGen: Omit frame pointers from metadata accessors. 2019-08-07 14:16:41 -07:00
Vedant Kumar
569c8afc54 [Profiler] Separate profiler instances for property inits and constructors (#25247)
Assign separate SILProfiler instances to stored property initializers
and constructors.

Starting with rdar://39460313, coverage reporting for these constructs
was bundled up into a single SILProfiler uniqued by the NominalTypeDecl.
There are two problems with doing this.

First, the shared SILProfiler is given a fake name that can't be
demangled. That breaks Xcode's reports.  Second, the relationship
between SILProfiler and SILFunction is supposed to be 1:1. Having a
shared SILProfiler muddies things a bit and requires extra bookkeeping.

rdar://47467864
2019-06-05 10:38:10 -07:00
Andrew Trick
a3de97bb87 Add SILParser support for [dynamically_replaceable]. 2019-05-20 21:33:01 -07:00
Slava Pestov
980fb7c437 SIL: Remove default resilience expansion from isTypeABIAccessible() 2019-03-06 02:26:26 -05:00
Slava Pestov
d1cf8c9cf6 SIL: Add type lowering APIs to SILFunction
For now these just forward to methods on the module's TypeLowering,
but soon they will use the SILFunction's resilience expansion.
2019-02-28 23:12:08 -05:00
Michael Gottesman
23378cc16f [sil] Rename QualifiedOwnership => Ownership.
Done using Xcode's refactoring engine.
2018-12-16 15:21:52 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Arnold Schwaighofer
52c1903e54 Add SIL support for [dynamic_replacement_for: ] functions 2018-11-06 09:58:28 -08:00
Arnold Schwaighofer
5f4e183302 Add [dynamically_replacable] to SILFunctions
'dynamic' functions are marked as [dynamically_replaceable].
2018-11-06 09:53:21 -08:00
Andrew Trick
1e88e44ce8 Add critical edge verification and fix SIL passes.
SIL passes were violating the existing invariant on non-cond-br
critical edges in several places. I fixed the places that I could
find.  Wherever there was a post-pass to "clean up" critical edges, I
replaced it with a a call to verification that the critical edges
aren't broken in the first place.

We still need to eliminate critical edges entirely before enabling
ownership SIL.
2018-08-30 13:01:39 -07:00
John McCall
512e55683e Make it easy to create a SILBasicBlock immediately before a target block.
Also, make "after" requests explicit in the API.
2018-08-18 12:36:36 -04:00
Andrew Trick
c9033ed938 Add a SIL attribute [without_actually_escaping].
ConvertFunction and reabstraction thunks need this attribute. Otherwise,
there is no way to identify that withoutActuallyEscaping was used
to explicitly perform a conversion.

The destination of a [without_actually_escaping] conversion always has
an escaping function type. The source may have either an escaping or
@noescape function type. The conversion itself may be a nop, and there
is nothing distinctive about it. The thing that is special about these
conversions is that the source function type may have unboxed
captures. i.e. they have @inout_aliasable parameters. Exclusivity
requires that the compiler enforce a SIL data flow invariant that
nonescaping closures with unboxed captures can never be stored or
passed as an @escaping function argument. Adding this attribute allows
the compiler to enforce the invariant in general with an escape hatch
for withoutActuallyEscaping.
2018-08-14 17:14:25 -07:00
swift-ci
100bec92a7 Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 11:09:58 -07:00
Michael Gottesman
11b24415c1 [sil-module] Create SILFunctionBuilder and hide creation/erasing functions on SILModule.
This commit does not modify those APIs or their usage. It just:

1. Moves the APIs onto SILFunctionBuilder and makes SILFunctionBuilder a friend
   of SILModule.
2. Hides the APIs on SILModule so all users need to use SILFunctionBuilder to
   create/destroy functions.

I am doing this in order to allow for adding/removing function notifications to
be enforced via the type system in the SILOptimizer. In the process of finishing
off CallerAnalysis for FSO, I discovered that we were not doing this everywhere
we need to. After considering various other options such as:

1. Verifying after all passes that the notifications were sent correctly and
   asserting. Turned out to be expensive.
2. Putting a callback in SILModule. This would add an unnecessary virtual call.

I realized that by using a builder we can:

1. Enforce that users of SILFunctionBuilder can only construct composed function
   builders by making the composed function builder's friends of
   SILFunctionBuilder (notice I did not use the word subclass, I am talking
   about a pure composition).
2. Refactor a huge amount of code in SILOpt/SILGen that involve function
   creation onto a SILGenFunctionBuilder/SILOptFunctionBuilder struct. Many of
   the SILFunction creation code in question are straight up copies of each
   other with small variations. A builder would be a great way to simplify that
   code.
3. Reduce the size of SILModule.cpp by 25% from ~30k -> ~23k making the whole
   file easier to read.

NOTE: In this commit, I do not hide the constructor of SILFunctionBuilder since
I have not created the derived builder structs yet. Once I have created those in
a subsequent commit, I will hide that constructor.

rdar://42301529
2018-07-31 10:04:03 -07:00
swift-ci
691e92eb8b Merge remote-tracking branch 'origin/master' into master-next 2018-07-11 16:29:41 -07:00
Gogul Balakrishnan
9e26f0a8cb Made the helper into static function and addressed cosmetic changes. 2018-07-10 22:37:05 -07:00
Gogul Balakrishnan
f48091745c Add a viewCFGOnly function for debugging purposes. 2018-07-10 14:27:45 -07:00
swift-ci
adcaa7eafc Merge remote-tracking branch 'origin/master' into master-next 2018-06-26 06:09:27 -07:00
Huon Wilson
ed64fadb28 [SIL]/[SILOpt] Thunks and specializations shouldn't be connected to their parent class.
The "subclass scope" is meant to represent a connection to a vtable (and how
public something needs to be), for things that end up in class
vtables. Specializations and thunks are mostly internal implementation details
and do not end up there, so subclass scope is not applicable to them. This stops
the thunks and specializations being incorrectly public.

(Note, there are some thunks that _are_ public facing: if a function has its
signature optimized, the original entry point becomes a thunk, and this entry
point is what ends up in vtables etc., so needs to remain around, which means
keeping the same hacks for `private` members of an `open` class.)

Fixes rdar://problem/40738913.
2018-06-26 16:25:42 +10:00
Huon Wilson
413501b34a [SIL] Separate thunks from signature optimization from other thunks.
Signature optimization is slightly different to (most) other thunks, in that
it's taking an existing function and turning that into a thunk, rather than
creating a thunk that calls an existing function. These symbols can be public,
etc. and so need to be handled a bit different to other types of thunks.
2018-06-26 14:53:58 +10:00
swift-ci
b87ea23124 Merge remote-tracking branch 'origin/master' into master-next 2018-06-06 17:29:44 -07:00
Erik Little
863f3a19ff Rename @effects to @_effects
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00
swift-ci
7b7c4d7469 Merge remote-tracking branch 'origin/master' into master-next 2018-05-11 21:10:05 -07:00
Doug Gregor
049c56dde6 Eliminate getForwardingSubstitutions().
Use the SubstitutionMap version everywhere.
2018-05-11 17:37:27 -07:00
swift-ci
2ea33a93e9 Merge remote-tracking branch 'origin/master' into master-next 2018-05-03 00:09:35 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
swift-ci
b87673dc82 Merge remote-tracking branch 'origin/master' into master-next 2018-04-27 00:29:08 -07:00
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Bob Wilson
9dc02e67a2 master-next: Stop using ilist_default_traits
LLVM r330736 removed ilist_default_traits. Apparently it is not needed
and ilist_node_traits works just as well.
2018-04-25 22:44:58 -07:00
Doug Gregor
703f8dbb75 Merge pull request #15759 from ikesyo/sil-using-over-typedef
[gardening][SIL] Replace `typedef` with `using`
2018-04-05 22:42:49 -07:00
Vedant Kumar
daa094e5e0 [Coverage] Only instrument functions which are definitions
The ASTs for functions which aren't definitions may not be fully
typechecked or well-formed, so: avoid looking at them.

This fixes at least one assertion failure seen while building a project
with coverage, and is probably good for some substantial compile-time
improvements with coverage enabled.

rdar://39069115
2018-04-05 13:33:43 -07:00
Sho Ikeda
03fbd4a6de [gardening][SIL] Replace typedef with using 2018-04-05 13:53:20 +09:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Andrew Trick
3992a8c94f Print and parse the [canonical] function attribute. 2018-02-27 09:53:13 -08:00
Jordan Rose
bb339778b4 Add @_weakLinked and a corresponding SIL attribute
This is mostly intended to be used for testing at this point; in the
long run, we want to be using availability information to decide
whether to weak-link something or not. You'll notice a bunch of FIXMEs
in the test case that we may not need now, but will probably need to
handle in the future.

Groundwork for doing backward-deployment execution tests.
2018-02-20 17:55:31 -08:00
Andrew Trick
287ccece75 Add SILFunction::WasDeserializedCanonical flag.
We need to be able to detect function definitions that have been
deserialized. There's no need to rerun diagnostics on those functions,
and in some cases it's actually incorrect to do so. With exclusivity,
we could even miscompile in theory (debug assert) because the fully
optimized SIL does adhere to rules requires by the
diagnostic. Hopefully that specific issue can be fixed soon, but the
point is that we need control over the order that passes are run
because we play these games all the time. Not to mention the wasted
compilation time.

It would probably be sufficient to check isAvailableExternally. However, using
an explicit flag is, well, more explicit. It also generalizes to serializing IR
at any stage.

Note: I would strongly prefer not to rely on this flag for correctness. In
principle, serialized SIL should be compatible with all SIL stages prior to the
serialization point. However, it is necessary to fix bugs in the short term, and
useful for bootstrapping SIL changes in general. Also, it formalizes some
assumptions about the way the pass pipeline is expected to work making it easier
to reason about and avoid pass ordering bugs. In particular, we should not be
relying on a second round of the mandatory pass pipeline to catch important
performance opportunities.
2018-02-09 09:55:47 -08:00
Slava Pestov
48d0407f43 SIL: Remove SILFunction::{is,set}KeepAsPublic() 2018-01-12 22:08:00 -08:00
Vedant Kumar
c6bd848489 [Coverage] Assign profilers to closures without an inherited profiler
This is a step towards being able to report coverage for closures in
member initializer expressions. These closures do not inherit a
profiler, so they need a fresh one.

We currently treat initializer expressions which aren't closures as a
part of the constructor. This doesn't work for closures because the
constructor's profiler may not be available at the time the closure is
created.
2018-01-05 17:20:20 -08:00
Vedant Kumar
dd560d2aa6 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-05 17:20:20 -08:00
Vedant Kumar
cccee1df03 Revert "[Coverage] Refactor SIL generation for profiling" 2018-01-03 21:57:49 -08:00
Vedant Kumar
aba9d53736 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-03 11:18:40 -08: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
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
Slava Pestov
773e6bff56 SIL: Add SILFunction::getResilienceExpansion() 2017-11-10 16:20:09 -08: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
Joe Shajrawi
75939510cd PGO: Use ProfileCounter instead of Optional<uint64_t> to hold profile counts 2017-09-26 13:34:46 -07:00
Joe Shajrawi
2c03144436 Add support for function_entry_count Profile counter 2017-09-26 11:10:52 -07:00