Commit Graph

23 Commits

Author SHA1 Message Date
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
1b8e475421 [Profiler] Avoid exposing the RegionCounterMap
Not sure why we ever did this, expose the counter
index via a lookup method instead.
2023-11-16 17:28:57 +00:00
Hamish Knight
e6d9f38dac [Profiler] Introduce error branch ProfileCounterRefs
These reference error branches for AST nodes that
can throw errors.
2023-11-16 17:28:57 +00:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Hamish Knight
350e28b4b7 [Profiler] Rework profiling of top-level code
Instead of creating and destroying a SILProfiler
per TopLevelCodeDecl, setup a single profiler
for the top-level entry point function, and visit
all the TopLevelCodeDecls when mapping regions.
2022-10-14 17:45:14 +01:00
Hamish Knight
b4d4137a5e [Profiler] NFC: Trim out unused imports
Also bump the copyright year.
2022-10-13 19:42:38 +01:00
Hamish Knight
809cfb7bf2 [Profiler] Introduce ProfileCounterRef
For now this just wraps an ASTNode, but in the
future it will allow us to model counters
that cannot simply hang off ASTNodes, e.g
error branch counters.
2022-10-13 19:42:37 +01:00
Hamish Knight
5b1ca3f0e0 [SILGen] Avoid forcing function bodies for profiling
This is no longer necessary now that we ensure we
always SILGen functions that contain user code.
2022-09-29 10:08:17 +01:00
Hamish Knight
20830cc2fb [Profiler] Avoid profiling unavailable decls
Such decls don't provide useful coverage info.

rdar://83253091
2022-09-19 10:06:36 +01:00
Hamish Knight
5039c1c3f1 [Profiler] NFC: Remove unnecessary parameter
`SILProfiler::create` is only ever called when
emitting a definition, so this check is redundant.
2022-09-14 20:51:51 +01: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
Vedant Kumar
bdfd220968 [Coverage] Mark symtab entries as guaranteed after intrinsic lowering
SIL optimizations may rewrite profiling intrinsics in a way that IRGen
can't lower (r://39146527). Don't claim that a coverage mapping has a
guaranteed associated symbol table entry when this happens.

I have not added a test, as this is a defensive workaround until we can
land add a SIL verifier check that prevents profiling intrinsics from
being rewritten.

rdar://40133800
2018-05-10 18:51:40 -07:00
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Vedant Kumar
bb567886d8 [Coverage] Disable forced emission for unmapped decls (#15909)
Disable forced SILGen for lazy functions which are not used for code
coverage reporting.

As a drive-by, fix the forced emission logic for functions profiled for
PGO.

This helps address a compile-time issue (r://39332957).
2018-04-12 19:34:34 -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
Slava Pestov
98d74bd555 SIL: Header gardening 2018-03-27 01:43:26 -07: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
54f3754337 [Coverage] Clean up a few classes, NFC
Run clang-format, delete some dead code, and fix a few naming
inconsistencies.
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
Mark Lacey
7c49bc9733 Revert "[Coverage] Clean up a few classes, NFC" 2018-01-03 18:51:28 -08:00
Vedant Kumar
e875efa4ae [Coverage] Clean up a few classes, NFC
Run clang-format, delete some dead code, and fix a few naming
inconsistencies.
2018-01-03 16:46:18 -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