[llvm-branch-commits] [llvm] [compiler-rt] [ThinLTO][TypeProf] Implement vtable def import (PR #79381)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 25 16:50:28 PST 2024


================
@@ -1285,46 +1285,44 @@ void annotateValueSite(Module &M, Instruction &Inst,
   Inst.setMetadata(LLVMContext::MD_prof, MDNode::get(Ctx, Vals));
 }
 
-bool getValueProfDataFromInst(const Instruction &Inst,
-                              InstrProfValueKind ValueKind,
-                              uint32_t MaxNumValueData,
-                              InstrProfValueData ValueData[],
-                              uint32_t &ActualNumValueData, uint64_t &TotalC,
-                              bool GetNoICPValue) {
+MDNode *mayHaveValueProfileOfKind(const Instruction &Inst,
+                                  InstrProfValueKind ValueKind) {
   MDNode *MD = Inst.getMetadata(LLVMContext::MD_prof);
   if (!MD)
-    return false;
+    return nullptr;
 
-  unsigned NOps = MD->getNumOperands();
+  if (MD->getNumOperands() < 5)
+    return nullptr;
 
-  if (NOps < 5)
-    return false;
-
-  // Operand 0 is a string tag "VP":
   MDString *Tag = cast<MDString>(MD->getOperand(0));
-  if (!Tag)
-    return false;
-
-  if (!Tag->getString().equals("VP"))
-    return false;
+  if (!Tag || !Tag->getString().equals("VP"))
+    return nullptr;
 
   // Now check kind:
   ConstantInt *KindInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
   if (!KindInt)
-    return false;
+    return nullptr;
   if (KindInt->getZExtValue() != ValueKind)
-    return false;
+    return nullptr;
+
+  return MD;
+}
 
+static bool getValueProfDataFromInst(const MDNode *const MD,
----------------
modiking wrote:

>I could do the refactoring this before major implementation changes are in, so this pr picks up unique_ptr<Array> interface soon. Will leave this PR as it is for now, and update it after refactoring one is in the main branch.

Definitely don't need to change this PR, just making sure it's something that's on your radar so we can keep the code clean.

>There are two bool version in this pr, one is this static function and the other one is non-static function (called by existing callers of bool version). The non-static bool version gets the checking from mayHaveValueProfileOfKind.

I see, or rather I see now that you told me 😆. Given that consider renaming the static function (`getValueProfDataFromInstImpl`?) to make it easier to distinguish.

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


More information about the llvm-branch-commits mailing list