-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Profile] Add binary profile correlation for code coverage. #69493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
3a394ce
7767844
c5cca07
44704f6
384ee6c
fb20012
61775c7
37f5fc4
9f76629
8fb0a77
1ee0053
f677688
023a4a6
a30427f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,10 @@ | |
// is textually included. | ||
#define COVMAP_V3 | ||
|
||
namespace llvm { | ||
extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate; | ||
} // namespace llvm | ||
|
||
static llvm::cl::opt<bool> EmptyLineCommentCoverage( | ||
"emptyline-comment-coverage", | ||
llvm::cl::desc("Emit emptylines and comment lines as skipped regions (only " | ||
|
@@ -1829,6 +1833,22 @@ void CoverageMappingModuleGen::emit() { | |
llvm::GlobalValue::InternalLinkage, NamesArrVal, | ||
llvm::getCoverageUnusedNamesVarName()); | ||
} | ||
const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some comments for this segment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already reverted changes in Clang because |
||
llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx); | ||
uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION; | ||
if (llvm::ProfileCorrelate == llvm::InstrProfCorrelator::BINARY) | ||
ProfileVersion |= VARIANT_MASK_BIN_CORRELATE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might overwrite other modifier bits set else where. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
auto *VersionVariable = new llvm::GlobalVariable( | ||
CGM.getModule(), llvm::Type::getInt64Ty(Ctx), true, | ||
llvm::GlobalValue::WeakAnyLinkage, | ||
llvm::Constant::getIntegerValue(IntTy64, llvm::APInt(64, ProfileVersion)), | ||
VarName); | ||
VersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility); | ||
llvm::Triple TT(CGM.getModule().getTargetTriple()); | ||
if (TT.supportsCOMDAT()) { | ||
ZequanWu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage); | ||
VersionVariable->setComdat(CGM.getModule().getOrInsertComdat(VarName)); | ||
} | ||
} | ||
|
||
unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -o - %s | FileCheck %s | ||
// RUN: %clang_cc1 -mllvm -profile-correlate=binary -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -o - %s | FileCheck %s --check-prefix=BIN-CORRELATE | ||
ZequanWu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// CHECK: @__llvm_profile_raw_version = {{.*}} i64 9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it 9? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
// BIN-CORRELATE: @__llvm_profile_raw_version = {{.*}} i64 4294967305 | ||
|
||
int main() { | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// REQUIRES: linux || windows | ||
ZequanWu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Default | ||
// RUN: %clang -o %t.normal -fprofile-instr-generate -fcoverage-mapping -fuse-ld=lld %S/Inputs/instrprof-debug-info-correlate-main.cpp %S/Inputs/instrprof-debug-info-correlate-foo.cpp | ||
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal | ||
// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw | ||
// RUN: llvm-cov report --instr-profile=%t.normal.profdata %t.normal > %t.normal.report | ||
// RUN: llvm-cov show --instr-profile=%t.normal.profdata %t.normal > %t.normal.show | ||
|
||
// With -profile-correlate=binary flag | ||
// RUN: %clang -o %t-1.exe -fprofile-instr-generate -fcoverage-mapping -mllvm -profile-correlate=binary -fuse-ld=lld %S/Inputs/instrprof-debug-info-correlate-main.cpp %S/Inputs/instrprof-debug-info-correlate-foo.cpp | ||
ZequanWu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// RUN: env LLVM_PROFILE_FILE=%t-1.profraw %run %t-1.exe | ||
// RUN: llvm-profdata merge -o %t-1.profdata --binary-file=%t-1.exe %t-1.profraw | ||
// RUN: llvm-cov report --instr-profile=%t-1.profdata %t-1.exe > %t-1.report | ||
// RUN: llvm-cov show --instr-profile=%t-1.profdata %t-1.exe > %t-1.show | ||
// RUN: diff %t.normal.profdata %t-1.profdata | ||
// RUN: diff %t.normal.report %t-1.report | ||
// RUN: diff %t.normal.show %t-1.show | ||
|
||
// Strip above binary and run | ||
// RUN: llvm-strip %t-1.exe -o %t-2.exe | ||
// RUN: env LLVM_PROFILE_FILE=%t-2.profraw %run %t-2.exe | ||
// RUN: llvm-profdata merge -o %t-2.profdata --binary-file=%t-1.exe %t-2.profraw | ||
// RUN: llvm-cov report --instr-profile=%t-2.profdata %t-1.exe > %t-2.report | ||
// RUN: llvm-cov show --instr-profile=%t-2.profdata %t-1.exe > %t-2.show | ||
// RUN: diff %t.normal.profdata %t-2.profdata | ||
// RUN: diff %t.normal.report %t-2.report | ||
// RUN: diff %t.normal.show %t-2.show | ||
|
||
// Online merging. | ||
// RUN: env LLVM_PROFILE_FILE=%t-3.profraw %run %t.normal | ||
// RUN: env LLVM_PROFILE_FILE=%t-4.profraw %run %t.normal | ||
// RUN: llvm-profdata merge -o %t.normal.merged.profdata %t-3.profraw %t-4.profraw | ||
// RUN: llvm-cov report --instr-profile=%t.normal.merged.profdata %t.normal > %t.normal.merged.report | ||
// RUN: llvm-cov show --instr-profile=%t.normal.merged.profdata %t.normal > %t.normal.merged.show | ||
|
||
// RUN: rm -rf %t.profdir && mkdir %t.profdir | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m-4.profraw %run %t-2.exe | ||
// RUN: env LLVM_PROFILE_FILE=%t.profdir/%m-4.profraw %run %t-2.exe | ||
// RUN: llvm-profdata merge -o %t-4.profdata --binary-file=%t-1.exe %t.profdir | ||
// RUN: llvm-cov report --instr-profile=%t-4.profdata %t-1.exe > %t-4.report | ||
// RUN: llvm-cov show --instr-profile=%t-4.profdata %t-1.exe > %t-4.show | ||
// RUN: diff %t.normal.merged.profdata %t-4.profdata | ||
// RUN: diff %t.normal.merged.report %t-4.report | ||
// RUN: diff %t.normal.merged.show %t-4.show | ||
|
||
// TODO: After adding support for binary ID, test binaries with different binary IDs. |
Uh oh!
There was an error while loading. Please reload this page.