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

Mingming Liu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 25 16:42:30 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,
----------------
minglotus-6 wrote:

> Is there a plan to consolidate this function so that it's no longer a stub for existing callsites?

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.

> Also, existing callers of the bool version no longer get the checking from mayHaveValueProfileOfKind which seems to be an unintended change of functionality

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`.

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


More information about the llvm-branch-commits mailing list