-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #75416 - richkadel:llvm-coverage-map-gen-5.3, r=richkadel
LLVM IR coverage encoding aligns closer to Clang's I found some areas for improvement while attempting to debug the SegFault issue when running rust programs compiled using MSVC, with coverage instrumentation. I discovered that LLVM's coverage writer was generating incomplete function name variable names (that's not a typo: the name of the variable that holds a function name). The existing implementation used one-up numbers to distinguish variables, and correcting the names did not fix the MSVC coverage bug, but the fix in this PR makes the names and resulting LLVM IR easier to follow and more consistent with Clang's implementation. I also changed the way the `-Zinstrument-coverage` option is supported in symbol_export.rs. The original implementation was incorrect, and the corrected version matches the handling for `-Zprofile-generate`, as it turns out. (An argument could be made that maybe `-Zinstrument-coverage` should automatically enable `-Cprofile-generate`. In fact, if `-Cprofile-generate` is analagous to Clang's `-fprofile-generate`, as some documentation implies, Clang always requires this flag for its implementation of source-based code coverage. This would require a little more validation, and if implemented, would probably require updating some of the user-facing messages related to `-Cprofile-generate` to not be so specific to the PGO use case.) None of these changes fixed the MSVC coverage problems, but they should still be welcome improvements. Lastly, I added some additional FIXME comments in instrument_coverage.rs describing issues I found with the generated LLVM IR that would be resolved if the coverage instrumentation is injected with a `Statement` instead of as a new `BasicBlock`. I describe seven advantages of this change, but it requires some discussion before making a change like this. r? @tmandry
- Loading branch information
Showing
12 changed files
with
161 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/test/run-make-fulldeps/instrument-coverage/filecheck-patterns.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Check for metadata, variables, declarations, and function definitions injected | ||
# into LLVM IR when compiling with -Zinstrument-coverage. | ||
|
||
WIN32: $__llvm_profile_runtime_user = comdat any | ||
|
||
CHECK: @__llvm_coverage_mapping = internal constant | ||
CHECK-SAME: section "[[INSTR_PROF_COVMAP]]", align 8 | ||
|
||
WIN32: @__llvm_profile_runtime = external global i32 | ||
|
||
CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = [[PRIVATE_GLOBAL]] | ||
CHECK-SAME: section "[[INSTR_PROF_CNTS]]", align 8 | ||
|
||
CHECK: @__profd__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = [[PRIVATE_GLOBAL]] | ||
CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called, | ||
CHECK-SAME: ()* @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called to i8*), | ||
CHECK-SAME: section "[[INSTR_PROF_DATA]]", align 8 | ||
|
||
CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog4main = [[PRIVATE_GLOBAL]] | ||
CHECK-SAME: section "[[INSTR_PROF_CNTS]]", align 8 | ||
|
||
CHECK: @__profd__R{{[a-zA-Z0-9_]+}}testprog4main = [[PRIVATE_GLOBAL]] | ||
CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog4main, | ||
CHECK-SAME: ()* @_R{{[a-zA-Z0-9_]+}}testprog4main to i8*), | ||
CHECK-SAME: section "[[INSTR_PROF_DATA]]", align 8 | ||
|
||
CHECK: @__llvm_prf_nm = private constant | ||
CHECK-SAME: section "[[INSTR_PROF_NAME]]", align 1 | ||
|
||
CHECK: @llvm.used = appending global | ||
CHECK-SAME: i8* bitcast ({ {{.*}} }* @__llvm_coverage_mapping to i8*) | ||
WIN32-SAME: i8* bitcast (i32 ()* @__llvm_profile_runtime_user to i8*) | ||
CHECK-SAME: i8* bitcast ({ {{.*}} }* @__profd__R{{[a-zA-Z0-9_]*}}testprog4main to i8*) | ||
CHECK-SAME: i8* getelementptr inbounds ({{.*}}* @__llvm_prf_nm, i32 0, i32 0) | ||
CHECK-SAME: section "llvm.metadata" | ||
|
||
CHECK: define hidden { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}} { | ||
CHECK-NEXT: start: | ||
CHECK-NOT: bb{{[0-9]+}}: | ||
CHECK: %pgocount = load i64, i64* getelementptr inbounds | ||
CHECK-SAME: * @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called, | ||
|
||
CHECK: declare void @llvm.instrprof.increment(i8*, i64, i32, i32) #[[LLVM_INSTRPROF_INCREMENT_ATTR:[0-9]+]] | ||
|
||
WIN32: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() #[[LLVM_PROFILE_RUNTIME_USER_ATTR:[0-9]+]] comdat { | ||
WIN32-NEXT: %1 = load i32, i32* @__llvm_profile_runtime | ||
WIN32-NEXT: ret i32 %1 | ||
WIN32-NEXT: } | ||
|
||
CHECK: attributes #[[LLVM_INSTRPROF_INCREMENT_ATTR]] = { nounwind } | ||
WIN32: attributes #[[LLVM_PROFILE_RUNTIME_USER_ATTR]] = { noinline } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters