Commit Graph

55 Commits

Author SHA1 Message Date
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
1bb7448a94 [Coverage] Bump coverage version to match clang 2024-04-08 08:58:59 -07:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Hamish Knight
d31f76853a [SIL] Introduce skipped coverage ranges
Introduce a skipped region kind, printed using
a `skipped` keyword.
2023-11-14 20:41:35 +00:00
Hamish Knight
d428721ac4 [Profiler] Avoid quadratic search for coverage filename in WMO
Previously we were doing a `std::find` over the
files for each coverage mapping, which would be
quadratic for WMO. Switch to using a DenseMap
instead.
2023-05-22 17:54:17 +01:00
Hamish Knight
b55f97250d [IRGen] Update coverage mapping for version 6
The coverage format version we use is automatically
set to whatever the latest version LLVM has. This
resulting in us outputting version 6 as our
format without having made the changes necessary
to reflect the new format. Update the emission
logic to take account for [the new changes in
version 6][1] (we need to include the current
working directory as the first element of the list
of files we output). Additionally, add a
`static_assert` so we don't get caught out by
version bumps in the future. Note we can't pin our
version, as it must stay in sync with the version
Clang is using.

[1]: https://llvm.org/docs/CoverageMappingFormat.html#llvm-ir-representation
2023-05-20 00:32:21 +01:00
Hamish Knight
6d3545f4d5 [IRGen] Don't emit multiple copies of coverage maps
Iterating over the IRGenModules and emitting every
SILCoverageMap in the SILModule meant that we
were emitting N copies of the coverage maps for
parallel IRGen, where N is the number of output
object files.

This has always been wrong, but was previously
saved by the fact that we would drop the coverage
map on the floor if we didn't have the name data
available. This would only be the case for the
IRGenModule that had the emitted entity to
profile, in addition to any IRGenModules that
had inlined the body of a profiled enitity. As
such, this prevented the duplication from being
too egregious. However with the recent change to
emit unused name data in the case where we don't
already have name data available, we're now fully
duplicating every coverage mapping, and emitting a
ton of redundant name data.

Fix things such that we only emit coverage mapping
records for the IRGenModule that corresponds to
the entity being profiled.

rdar://102905496
2022-12-06 14:28:35 +00:00
Hamish Knight
d59ff45468 [Profiler] Track the parent SourceFile for a SILCoverageMap
This tracks the source file that the profiled
entity was defined in.
2022-12-06 14:28:34 +00:00
Hamish Knight
01c7c16c18 [IRGen] Allow lazy emission of coverage mapped functions
We previously eagerly emitted such functions to
ensure that their name data is emitted through the
profiler increment. Now that are able to emit the
profile name data separately, this is unnecessary,
and we can avoid emitting their definitions.
2022-09-16 15:47:17 +01:00
Hamish Knight
cc465937a2 [IRGen] Emit name data for unused coverage counters
Previously, if all the coverage counters for a
given SIL function were optimized out, we would
have dropped the coverage map on the floor,
leading to inaccurate coverage reports in `-O`.
However LLVM allows us to emit the name data for
the coverage maps separately by defining an
`__llvm_coverage_names` global with the name data,
which is picked up by its instrumentation lowering
pass. Use this to continue to emit coverage maps
for functions that do not get emitted.

rdar://99813754
2022-09-16 15:47:16 +01:00
Ben Barham
381d053156 [rebranch] Fix up a incorrect main -> next merge
`CoverageFilenamesSectionWriter` now takes an `ArrayRef<std::string>`
rather than `ArrayRef<StringRef>`. stable/20210726 reverted that change
so that the coverage formats were the same. stable/20211026 doesn't have
that revert though.
2021-11-13 17:04:29 +10:00
Evan Wilde
a5f11c4851 Fix the main->next merge conflicts
This cleans up all of the merge conflicts from main into next after the
rebranch merge.
2021-10-15 15:57:55 -07:00
Robert Widmann
40e4206410 Fixup Coverage Mapping
Adapt to https://reviews.llvm.org/D95753
2021-03-03 21:30:03 -08:00
swift_jenkins
90dd9dbae8 Merge remote-tracking branch 'origin/master' into master-next 2020-06-16 14:18:53 -07:00
Keith Smiley
1b77448d37 Add path remapping with -coverage-prefix-map to coverage data
Previously the path to covered files in the __LLVM_COV / __llvm_covmap
section were absolute. This made remote builds with coverage information
difficult because all machines would have to have the same build root.
This change uses the values for `-coverage-prefix-map` to remap files in
the coverage info to relative paths. These paths work correctly with
llvm-cov when it is run from the same source directory as the
compilation, or from a different directory using the `-path-equivalence`
argument.

This is analogous to this change in clang https://reviews.llvm.org/D81122
2020-06-15 17:38:34 -07:00
Karoy Lorentey
68351d2110 Revert "Merge remote-tracking branch 'origin/master-next'"
This reverts commit 1c9b0908e6, reversing
changes made to 3eb82c1836.
2020-06-08 16:48:38 -07:00
Robert Widmann
993c35dcd6 Merge remote-tracking branch 'upstream/master' into contextual-clues 2020-04-17 11:52:53 -07:00
Robert Widmann
40d9cd8d3f [NFC] Give IRGenModule Exclusive Ownership of an LLVMContext Object 2020-04-16 11:57:44 -07:00
Vedant Kumar
61f4c32bc8 [Coverage] Port GenCoverage to the new format
Totally untested, as tests are not really close to building on
master-next at the moment.
2020-03-03 14:59:01 -08:00
Alex Langford
a489c40fd7 Adjust for LLVM commit dd1ea9de2e3e3 2020-03-03 12:44:55 -08:00
Dan Zheng
1779632a6f [IRGen] NFC: silence llvm::MaybeAlign warnings.
Use `llvm::MaybeAlign` instead of `unsigned` to silence slew of warnings.
2020-02-20 08:49:28 +00:00
Vedant Kumar
9606717bae [Coverage] Drop records for functions DCE'd after builtin lowering
A function may be eliminated as dead code after initial builtin lowering
occurs. When this happens, an entry in the profile symbol table for the
function is not guaranteed. Its coverage record should be dropped.

rdar://42564768
2019-08-23 18:55:31 -07:00
Vedant Kumar
c597ad1775 [Coverage] Use a MapVector to store coverage maps in a module, NFC (#15858)
Using a MapVector allows coverage maps to be printed in a deterministic
order, and to be queried by function name. This makes an assertion
cheaper.
2018-04-10 17:24:59 -07:00
Vedant Kumar
6debe84674 [Coverage] Record PGO function name in SILCoverageMap
This simplifies the lowering of instrprof_increment by getting rid of a
call to llvm::getPGOFuncName().
2018-01-05 17:20:20 -08:00
Vedant Kumar
31bd4c7249 [Coverage] Defensively drop malformed coverage mappings
The compiler shouldn't emit coverage mappings for functions which don't
contain profiling instrumentation. However, due to bugs in the profiling
code, this sometimes happens. In this case, it's better to defensively
drop just the malformed coverage mappings instead of allowing corrupted
profiles to be 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
Vedant Kumar
451faec864 [Coverage] Fix use-after-scope bug
Found by ASAN:
<rdar://problem/31670782>

Introduced while integrating an API update for getInstrProfSectionName.
2017-04-17 17:35:32 -07:00
Bob Wilson
29f870952c Update to use new getInstrProfSectionName API from LLVM r300381 2017-04-16 23:27:04 -07:00
Bob Wilson
360da92c7d [master-next] Adjust for LLVM r300277
llvm::getInstrProfCoverageSectionName was changed to take the LLVM module
as an argument.
2017-04-14 13:00:44 -07:00
Vedant Kumar
757125ab10 [Coverage] Pass each prof name var to the lowering pass just once
While invoking the instrprof_increment intrinsic, we used to pass the
profile name variable by using a GEP instruction to get to the string
constant. That prevented llvm from uniquing the names. Use a constexpr
GEP to fix the issue.
2017-02-15 13:57:47 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Vedant Kumar
a064157d99 [Coverage] Fix UB in use of the CoverageMappingWriter API
Passing {FileID} into the CoverageMappingWriter constructor causes UB.
The ArrayRef constructed from the initializer list becomes invalid once
the constructor returns, because the lifetime of the initializer list
expires. Use an alternate ArrayRef constructor which outlives the
CoverageMappingWriter instance.

This commit also re-reenables coverage_smoke.swift.

rdar://problem/29591622
2016-12-20 16:51:38 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Vedant Kumar
0049ba998b Revert "[stable-merge] [IRGen] Adopt new coverage encoding API"
This reverts commit 4a7ba9c580. I reverted
this API out of llvm to investigate failures in our stage2 instrumented
builds.
2016-06-29 14:55:19 -07:00
Vedant Kumar
4a7ba9c580 [stable-merge] [IRGen] Adopt new coverage encoding API 2016-06-27 11:09:30 -07:00
Mark Lacey
4dbf8d70dd Fixes for moved LLVM header files
The latest merge brought in changes that move some LLVM header
files.
2016-05-03 17:00:22 -07:00
Mark Lacey
182b6dfb18 Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	tools/driver/CMakeLists.txt
	tools/swift-reflection-dump/swift-reflection-dump.cpp
2016-05-03 14:23:20 -07:00
John McCall
6c92c324f6 Rename IRGenModuleDispatcher to just IRGenerator and transfer
ownership of some of the basic structures to it.
2016-04-27 09:42:03 -07:00
Vedant Kumar
668d81f1f3 [Coverage] Do not move PGO name pointers into __llvm_prf_names
Instead, pass name pointers to InstrProfiling::lowerCoverageData() using
the new API (via getCoverageUnusedNamesVarName). This ensures that we
don't emit an uncompressed *and* a compressed version of all function
names into the module, fixing rdar://problem/25493310.
2016-04-22 14:46:57 -07:00
Vedant Kumar
dc11f8bf01 [Coverage] Re-apply "Respect function linkage in PGO name variables"
Fix a crash in emitBuiltinCall() which occurs because we drop function
linkage information when creating SILCoverageMaps.

This re-applies 45c7e4e86 with the MachO-specific checks in the test
case removed.
2016-03-17 22:44:35 -07:00
Vedant Kumar
c59b266f93 Revert "[Coverage] Respect function linkage in PGO name variables"
This reverts commit 45c7e4e861.

The IR CHECK lines in coverage.swift are flaky.
2016-03-17 18:21:32 -07:00
Vedant Kumar
45c7e4e861 [Coverage] Respect function linkage in PGO name variables
Fix a crash in emitBuiltinCall() which occurs because we drop function
linkage information when creating SILCoverageMaps.
2016-03-17 18:06:39 -07:00
Vedant Kumar
992d3aae15 [IRGen] Fix lowering of int_instrprof_increment
Update our usage of llvm's coverage API and fix the way we lower
instrprof_increment intrinsics.

This keeps us up-to-date with llvm/stable and makes instrumented IR
easier to read.
2016-02-15 15:49:38 -08:00
Chris Lattner
7f0caa2223 silience some unused code warnings. 2016-02-08 11:21:41 -08:00
practicalswift
a764144ff5 [gardening] llvm/ProfileData/InstrProf.h included twice. 2016-02-07 21:40:30 +01:00
Michael Gottesman
68ac0fd0d1 Temporarily disable Coverage generation until I can get someone to look at it. It seems that the coverage code in LLVM is completely changed. 2016-02-06 11:22:27 -08:00
Vedant Kumar
efb8135f36 [Coverage] Use new definitions from InstrProf.h
Changes to the coverage mapping API in upstream llvm have caused merge
conflicts and breakage in swift. This commit phases in bits of the new
API in a way that can be safely cherry-picked to swift-{2.2,3.0}-branch.

This commit is NFC for master-next and swift-2.2-branch, but constitutes
an actual bugfix for 3.0. That's because 3.0 is paired with a version of
llvm that takes advantage of the new coverage API to reduce the size of
instrumented binaries.

This effectively closes Swift PR-1053.

(cherry picked from commit a079d313fe)
2016-02-01 12:29:42 -08:00