Commit Graph

80 Commits

Author SHA1 Message Date
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +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
50367ecfa6 [Profiler] Don't walk into property initializer closures
These don't have a parent, but still shouldn't be
walked into. Be sure to check that the SILDeclRef
is for a closure.

rdar://99963912
2022-09-15 17:01:44 +01:00
Hamish Knight
9bb87a5f50 [Profiler] NFC: Invert isUnmapped
IMO it's clearer this way.
2022-09-15 17:01:43 +01:00
Hamish Knight
b7d3f502fe [Profiler] Limit decl walking behavior
Unify the mapped behavior with the unmapped
behavior and only ever walk into a pattern binding
decls, top-level code decls, and non-nested
functions. This avoids walking into e.g nested
types, leading to duplicate coverage.

We don't need to handle the unmapped behavior
separately, as top-level code decls are always
explicit, and non-nested functions are always
checked when we create the profiler.

rdar://99963912
2022-09-15 17:01:43 +01:00
Hamish Knight
30568a60a8 [Profiler] Don't run PGO on unmapped decls
This avoids an unnecessary walk, as we don't have
any interesting profile data for such decls.
2022-09-15 17:01:42 +01:00
Hamish Knight
bf9b4b92fc [Profiler] Only map implicit getters for lazy vars
This is the only implicit getter case we care
about, the rest do not contain user-written code.
This means that we now otherwise only ever map
explicit decls, which we need to SILGen anyway. As
such I believe this should fix rdar://39332957.

We do still potentially map implicit expressions,
but should only do so for explicit property
initializers. There is one remaining bug where we
can map an implicit property wrapper backing
initalizer, which I'm tracking in rdar://99931619.
2022-09-14 20:51:52 +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
Hamish Knight
b582dbfa26 [Profiler] Clean up walking code a little
Use the new explicit ASTWalker actions to factor
out the skipping logic, ensuring to apply it in
post-visitation too, which fixes a PCMacro crash
(though I don't believe this is a configuration
that ever actually comes up). Also tighten up
invariants such that an `IfExpr` must appear
within an existing region.
2022-09-13 15:41:36 +01:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00
Hamish Knight
7e141f4b1c [Profiler] Emit coverage for literal initializers
It's not clear why these should be excluded when
other initializers receive coverage.
2022-09-01 19:29:17 +01:00
Hamish Knight
05e2309788 [Profiler] Fix coverage mapping for switches
Previously we assumed the exit counter was the
same as the entry counter. Update the logic such
that we track break statements (including
implicitly at the end of a case), as well as
early returns and jumps to parent statements. This
follows a similar logic to what we do for if
statements.

rdar://99141044
2022-08-25 17:30:34 +01:00
Hamish Knight
40bb60822f [Profiler] NFC: Add some comments 2022-08-25 17:30:33 +01:00
Hamish Knight
caf597212c Merge pull request #60645 from hamishknight/simon-says 2022-08-19 19:58:04 +01:00
Hamish Knight
d8bab13469 [Profiler] Fix counters following DoStmts
Previously we weren't compensating for label
jumps and returns, i.e we assumed the exit count
is the same as the entry count. Ensure we follow
the same logic that other labeled statements
follow such that control flow is accounted for.

rdar://98881045
2022-08-19 15:06:11 +01:00
Hamish Knight
92a8fbd3a7 [Profiler] Assert that counters are present 2022-08-19 15:06:11 +01:00
Hamish Knight
64fcbd9412 [Profiler] Support lazy variable initializers
Start visiting LazyInitializerExpr for profiling,
such that we emit a profile counter when
initializing the initial value for the first time.

rdar://43393937
2022-08-19 14:03:40 +01:00
Hamish Knight
a1d3884b6a Merge pull request #60579 from hamishknight/never-say-never 2022-08-19 13:46:04 +01:00
Hamish Knight
68c80c57cf [Profiler] Simplify PGOMapping a bit
Rather than re-computing the counter indices as we
walk, use the indices that we've already computed
as a part of MapRegionCounters. This should be
NFC.

Eventually we should also stop duplicating the
counter arithmetic, and instead rely on the
CounterExprs computed by CoverageMapping. For now
I'm leaving that as follow-up work.
2022-08-17 17:27:36 +01:00
Hamish Knight
3a3a98e06f [Profiler] NFC: Constify LoadedCounts 2022-08-17 17:27:24 +01:00
Hamish Knight
d1eb6f9465 [Profiler] Avoid introducing empty unreachable regions
When computing the counter for the region
following a labeled statement such as `if`, avoid
adding a new empty region if the counter for such
a region is known to be zero, i.e unreachable.
This avoids adding spurious unreachable regions
after an if statements where each branch returns,
throws, or otherwise jumps to a parent statement.

We will however still add the region if any code
follows such a statement, making it non-empty.

rdar://29390569
2022-08-16 20:27:30 +01:00
Hamish Knight
c1ae4ed6bf [Profiler] Introduce CounterExpr::isSemanticallyZero
Refactor `CounterExpr::expand` to accept a function
lookup for the counter indices, and add
`isSemanticallyZero` to allow for checking whether
a simplified counter is 0.
2022-08-16 20:27:29 +01:00
Vedant Kumar
cfd38c42a1 [Profiler] Assign counter to IfStmt condition
Push a region to cover any expressions within an IfStmt condition.

rdar://67280997
2020-08-18 14:05:24 -07:00
Owen Voorhees
8b4d9ef3eb [Profiler] Don't use presumed line numbers for profiling 2020-05-26 11:19:30 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Saleem Abdulrasool
fa46f7131c sprinkle some llvm_unreachable for MSVC (NFC)
MSVC does not realize that the switch is exhaustive and requires that
the path is explicitly marked as unreachable.  This silences the C4715
warning ("not all control paths return a value").
2020-04-24 18:59:07 -07:00
Doug Gregor
78880ffc1a Merge pull request #27776 from owenv/catch_revamp_take_4
[SE-0276] Support multiple patterns in catch clauses
2020-04-07 12:31:33 -07:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00
Slava Pestov
5f51546480 Sema: Fix source range for curry thunks
Fixes <rdar://problem/61117301> / <https://bugs.swift.org/browse/SR-12496>.
2020-04-03 23:26:04 -04:00
Michael Gottesman
e1a19e4173 [sil] Split library into subfolders, while still building as a single library still.
Specifically, I split it into 3 initial categories: IR, Utils, Verifier. I just
did this quickly, we can always split it more later if we want.

I followed the model that we use in SILOptimizer: ./lib/SIL/CMakeLists.txt vends
 a macro (sil_register_sources) to the sub-folders that register the sources of
 the subdirectory with a global state variable that ./lib/SIL/CMakeLists.txt
 defines. Then after including those subdirs, the parent cmake declares the SIL
 library. So the output is the same, but we have the flexibility of having
 subdirectories to categorize source files.
2020-03-30 11:01:00 -07:00