[llvm] a1062d9 - [profcheck] Print the function name in the error (#177264)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 10:09:58 PST 2026
Author: Alan Zhao
Date: 2026-01-22T10:09:52-08:00
New Revision: a1062d98bbce2af9f6ef8f85837f40b523ee1f3f
URL: https://github.com/llvm/llvm-project/commit/a1062d98bbce2af9f6ef8f85837f40b523ee1f3f
DIFF: https://github.com/llvm/llvm-project/commit/a1062d98bbce2af9f6ef8f85837f40b523ee1f3f.diff
LOG: [profcheck] Print the function name in the error (#177264)
This is helpful for tests with a lot of test cases and grepping for
instructions with missing profile data isn't feasible because it doesn't
account for things like vectors which are exempt.
Tracking issue: #147390
Added:
Modified:
llvm/lib/Transforms/Utils/ProfileVerify.cpp
llvm/test/Transforms/PGOProfile/prof-verify-no-entrycount.ll
llvm/test/Transforms/PGOProfile/prof-verify.ll
llvm/test/Transforms/PGOProfile/profcheck-llvm.global_ctors.ll
llvm/test/Transforms/PGOProfile/profcheck-select.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/ProfileVerify.cpp b/llvm/lib/Transforms/Utils/ProfileVerify.cpp
index 69e03f01245db..ce7bcff9c4e0b 100644
--- a/llvm/lib/Transforms/Utils/ProfileVerify.cpp
+++ b/llvm/lib/Transforms/Utils/ProfileVerify.cpp
@@ -9,6 +9,7 @@
#include "llvm/Transforms/Utils/ProfileVerify.h"
#include "llvm/ADT/DynamicAPInt.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/IR/Analysis.h"
#include "llvm/IR/Constants.h"
@@ -83,6 +84,12 @@ bool isAsmOnly(const Function &F) {
}
return true;
}
+
+void emitProfileError(StringRef Msg, Function &F) {
+ F.getContext().emitError("Profile verification failed for function '" +
+ F.getName() + "': " + Msg);
+}
+
} // namespace
// FIXME: currently this injects only for terminators. Select isn't yet
@@ -237,8 +244,7 @@ PreservedAnalyses ProfileVerifierPass::run(Function &F,
if (!EntryCount) {
auto *MD = F.getMetadata(LLVMContext::MD_prof);
if (!MD || !isExplicitlyUnknownProfileMetadata(*MD)) {
- F.getContext().emitError("Profile verification failed: function entry "
- "count missing (set to 0 if cold)");
+ emitProfileError("function entry count missing (set to 0 if cold)", F);
return PreservedAnalyses::all();
}
} else if (EntryCount->getCount() == 0) {
@@ -252,15 +258,13 @@ PreservedAnalyses ProfileVerifierPass::run(Function &F,
continue;
if (I.getMetadata(LLVMContext::MD_prof))
continue;
- F.getContext().emitError(
- "Profile verification failed: select annotation missing");
+ emitProfileError("select annotation missing", F);
}
}
if (const auto *Term =
ProfileInjector::getTerminatorBenefitingFromMDProf(BB))
if (!Term->getMetadata(LLVMContext::MD_prof))
- F.getContext().emitError(
- "Profile verification failed: branch annotation missing");
+ emitProfileError("branch annotation missing", F);
}
return PreservedAnalyses::all();
}
diff --git a/llvm/test/Transforms/PGOProfile/prof-verify-no-entrycount.ll b/llvm/test/Transforms/PGOProfile/prof-verify-no-entrycount.ll
index 9c5f046af47af..4ef5b03bded35 100644
--- a/llvm/test/Transforms/PGOProfile/prof-verify-no-entrycount.ll
+++ b/llvm/test/Transforms/PGOProfile/prof-verify-no-entrycount.ll
@@ -15,4 +15,4 @@ no:
ret void
}
-; CHECK: Profile verification failed: function entry count missing (set to 0 if cold)
+; CHECK: Profile verification failed for function 'foo': function entry count missing (set to 0 if cold)
diff --git a/llvm/test/Transforms/PGOProfile/prof-verify.ll b/llvm/test/Transforms/PGOProfile/prof-verify.ll
index a967378dc652c..c1e3e4760d60d 100644
--- a/llvm/test/Transforms/PGOProfile/prof-verify.ll
+++ b/llvm/test/Transforms/PGOProfile/prof-verify.ll
@@ -22,4 +22,5 @@ no:
; INJECT: br i1 %c, label %yes, label %no, !prof !1
; INJECT: !1 = !{!"branch_weights", i32 3, i32 5}
-; VERIFY: Profile verification failed: branch annotation missing
\ No newline at end of file
+; VERIFY: Profile verification failed for function 'foo': branch annotation missing
+
diff --git a/llvm/test/Transforms/PGOProfile/profcheck-llvm.global_ctors.ll b/llvm/test/Transforms/PGOProfile/profcheck-llvm.global_ctors.ll
index 84c680fc158ac..9fd6ec786f190 100644
--- a/llvm/test/Transforms/PGOProfile/profcheck-llvm.global_ctors.ll
+++ b/llvm/test/Transforms/PGOProfile/profcheck-llvm.global_ctors.ll
@@ -10,4 +10,4 @@ define internal void @dtor() {
ret void
}
-; CHECK-NOT: Profile verification failed: function entry count missing
+; CHECK-NOT: Profile verification failed for function {{.+}}: function entry count missing
diff --git a/llvm/test/Transforms/PGOProfile/profcheck-select.ll b/llvm/test/Transforms/PGOProfile/profcheck-select.ll
index e6b3ddd42fcb0..620ae7ba36f78 100644
--- a/llvm/test/Transforms/PGOProfile/profcheck-select.ll
+++ b/llvm/test/Transforms/PGOProfile/profcheck-select.ll
@@ -66,7 +66,7 @@ define void @bar(i1 %c) !prof !0 {
}
!0 = !{!"function_entry_count", i64 1000}
!1 = !{!"branch_weights", i32 1, i32 7}
-; CHECK-NOT: Profile verification failed: select annotation missing
+; CHECK-NOT: Profile verification failed for function 'bar': select annotation missing
;--- verify-missing.ll
declare void @foo(i32 %a);
@@ -76,7 +76,7 @@ define void @bar(i1 %c) !prof !0 {
ret void
}
!0 = !{!"function_entry_count", i64 1000}
-; CHECK: Profile verification failed: select annotation missing
+; CHECK: Profile verification failed for function 'bar': select annotation missing
;--- verify-vec.ll
define <2 x i32> @vec(<2 x i1> %c, <2 x i32> %v1, <2 x i32> %v2) !prof !{!"function_entry_count", i32 10} {
More information about the llvm-commits
mailing list