[llvm] [profcheck] Add indirect call metadata (PR #154657)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 20 21:04:25 PDT 2025
================
@@ -92,12 +97,21 @@ bool ProfileInjector::inject() {
return false;
bool Changed = false;
for (auto &BB : F) {
- if (AnnotateSelect) {
- for (auto &I : BB) {
- if (isa<SelectInst>(I) && !I.getMetadata(LLVMContext::MD_prof))
- setBranchWeights(I, {SelectTrueWeight, SelectFalseWeight},
- /*IsExpected=*/false);
- }
+ for (auto &I : BB) {
+ // Annotate instructions that support MD_prof metadata, such as `select`
+ // and indirect calls - *if* they don't already have that metadata (i.e.
+ // if the unit test was authored with that metadata, don't replace it)
+ if (AnnotateSelect && isa<SelectInst>(I) &&
+ !I.getMetadata(LLVMContext::MD_prof))
+ setBranchWeights(I, {SelectTrueWeight, SelectFalseWeight},
+ /*IsExpected=*/false);
+ if (AnnotateIndirectCalls)
+ if (auto *CB = dyn_cast<CallBase>(&I))
+ if (CB->isIndirectCall() && !CB->getMetadata(LLVMContext::MD_prof))
+ // add a valid-format but bogus indirect call profile. Neither the
+ // GUIDs nor the counts are meant to matter.
+ annotateValueSite(*F.getParent(), *CB, {{2345, 10}, {5678, 20}}, 30,
----------------
mingmingl-llvm wrote:
nit picky: An in-line C-style comment makes the intent obvious (https://llvm.org/docs/CodingStandards.html#comment-formatting), something like /* Sum= */ 30.
https://github.com/llvm/llvm-project/pull/154657
More information about the llvm-commits
mailing list