paulkirth updated this revision to Diff 215938.
paulkirth edited the summary of this revision.
paulkirth added a comment.
- Update CodeGenOptions to remove -fmisexpect
- Access the LLVMContext directly
- Add -line-tables-only for more accurate diagnostics
Fixes various issues with tests and cleans up some residual code from the
original frontend implementation
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66324/new/
https://reviews.llvm.org/D66324
Files:
clang/include/clang/Basic/CodeGenOptions.def
clang/test/Profile/Inputs/misexpect-switch-default.proftext
clang/test/Profile/misexpect-branch.c
clang/test/Profile/misexpect-switch-default.c
clang/test/Profile/misexpect-switch-only-default-case.c
clang/test/Profile/misexpect-switch.c
llvm/lib/Transforms/Utils/MisExpect.cpp
Index: llvm/lib/Transforms/Utils/MisExpect.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MisExpect.cpp
+++ llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -114,7 +114,7 @@
mdconst::dyn_extract<ConstantInt>(MD->getOperand(i));
RealWeights[i - 1] = Value->getZExtValue();
}
- misexpect::verifyMisExpect(&I, RealWeights, I.getParent()->getParent()->getContext());
+ misexpect::verifyMisExpect(&I, RealWeights, I.getContext());
}
}
}
Index: clang/test/Profile/misexpect-switch.c
===================================================================
--- clang/test/Profile/misexpect-switch.c
+++ clang/test/Profile/misexpect-switch.c
@@ -1,7 +1,7 @@
// Test that misexpect detects mis-annotated switch statements
// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
-// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect
+// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect -debug-info-kind=line-tables-only
int sum(int *buff, int size);
int random_sample(int *buff, int size);
Index: clang/test/Profile/misexpect-switch-only-default-case.c
===================================================================
--- clang/test/Profile/misexpect-switch-only-default-case.c
+++ clang/test/Profile/misexpect-switch-only-default-case.c
@@ -1,7 +1,7 @@
// Test that misexpect emits no warning when there is only one switch case
// RUN: llvm-profdata merge %S/Inputs/misexpect-switch-default-only.proftext -o %t.profdata
-// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -fmisexpect
+// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect -debug-info-kind=line-tables-only
// expected-no-diagnostics
int sum(int *buff, int size);
Index: clang/test/Profile/misexpect-switch-default.c
===================================================================
--- clang/test/Profile/misexpect-switch-default.c
+++ clang/test/Profile/misexpect-switch-default.c
@@ -1,7 +1,7 @@
// Test that misexpect detects mis-annotated switch statements for default case
-// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata
-// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect
+// RUN: llvm-profdata merge %S/Inputs/misexpect-switch-default.proftext -o %t.profdata
+// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect -debug-info-kind=line-tables-only
int sum(int *buff, int size);
int random_sample(int *buff, int size);
@@ -17,26 +17,24 @@
int main() {
init_arry();
int val = 0;
-
- int j, k;
- for (j = 0; j < outer_loop; ++j) {
- for (k = 0; k < inner_loop; ++k) {
- unsigned condition = rand() % 5;
- switch (__builtin_expect(condition, 6)) { // expected-warning-re {{Potential performance regression from use of __builtin_expect(): Annotation was correct on {{.+}}% of profiled executions.}}
- case 0:
- val += sum(arry, arry_size);
- break;
- case 1:
- case 2:
- case 3:
- case 4:
- val += random_sample(arry, arry_size);
- break;
- default:
- __builtin_unreachable();
- } // end switch
- } // end inner_loop
- } // end outer_loop
+ int j;
+ for (j = 0; j < outer_loop * inner_loop; ++j) {
+ unsigned condition = rand() % 5;
+ switch (__builtin_expect(condition, 6)) { // expected-warning-re {{Potential performance regression from use of __builtin_expect(): Annotation was correct on {{.+}}% of profiled executions.}}
+ case 0:
+ val += sum(arry, arry_size);
+ break;
+ case 1:
+ case 2:
+ case 3:
+ break;
+ case 4:
+ val += random_sample(arry, arry_size);
+ break;
+ default:
+ __builtin_unreachable();
+ } // end switch
+ } // end outer_loop
return 0;
}
Index: clang/test/Profile/misexpect-branch.c
===================================================================
--- clang/test/Profile/misexpect-branch.c
+++ clang/test/Profile/misexpect-branch.c
@@ -1,7 +1,7 @@
// Test that misexpect detects mis-annotated branches
// RUN: llvm-profdata merge %S/Inputs/misexpect-branch.proftext -o %t.profdata
-// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect
+// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect -debug-info-kind=line-tables-only
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
@@ -16,7 +16,7 @@
int bar() {
int rando = buzz();
int x = 0;
- if (likely(rando % (outer_loop * inner_loop) == 0)) { // expected-warning-re {{Potential performance regression from use of __builtin_expect(): Annotation was correct on {{.+}}% of profiled executions.}} expected-remark-re {{Potential performance regression from use of __builtin_expect(): Annotation was correct on {{.+}}% of profiled executions.}}
+ if (likely(rando % (outer_loop * inner_loop) == 0)) { // expected-warning-re {{Potential performance regression from use of __builtin_expect(): Annotation was correct on {{.+}}% of profiled executions.}}
x = baz(rando);
} else {
x = foo(50);
Index: clang/test/Profile/Inputs/misexpect-switch-default.proftext
===================================================================
--- /dev/null
+++ clang/test/Profile/Inputs/misexpect-switch-default.proftext
@@ -0,0 +1,17 @@
+main
+# Func Hash:
+8712453512413296413
+# Num Counters:
+9
+# Counter Values:
+1
+20000
+20000
+4066
+11889
+0
+0
+4045
+0
+
+
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -169,7 +169,6 @@
///< enable code coverage analysis.
CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
///< regions.
-CODEGENOPT(MisExpect , 1, 0) ///< Validate __builtin_expect with PGO counters
/// If -fpcc-struct-return or -freg-struct-return is specified.
ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, SRCK_Default)
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits