[llvm] [Inline][PGO] After inline, update InvokeInst profile counts in caller and cloned callee (PR #83809)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 17:03:38 PDT 2024


================
@@ -77,11 +80,25 @@ bool isBranchWeightMD(const MDNode *ProfileData) {
   return isTargetMD(ProfileData, "branch_weights", MinBWOps);
 }
 
+bool isValueProfileMD(const MDNode *ProfileData) {
+  return isTargetMD(ProfileData, "VP", MinVPOps);
+}
+
 bool hasBranchWeightMD(const Instruction &I) {
   auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
   return isBranchWeightMD(ProfileData);
 }
 
+bool hasCountTypeMD(const Instruction &I) {
+  auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
+  // Value profiles record count-type information.
+  if (isValueProfileMD(ProfileData))
+    return true;
+  // Conservatively assume non CallBase instruction only get taken/not-taken
+  // branch probability, so not interpret them as count.
+  return isa<CallBase>(I) && !isBranchWeightMD(ProfileData);
----------------
minglotus-6 wrote:

Non-CallBase instructions (e.g., [SwitchInst](https://llvm.org/docs/BranchWeightMetadata.html#switchinst)) could have branch weights with two ops (i.e., one `branch_weight` string and one int), and the helper function `hasCountTypeMD` would be more self-contained to return `false` (tell caller it's not count-type profile) since we know only CallInst or InvokeInst carry count-type values in `branch_weights`. 

https://github.com/llvm/llvm-project/pull/83809


More information about the llvm-commits mailing list