[llvm] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 14:49:39 PDT 2023


================
@@ -19,20 +19,38 @@ namespace llvm {
 // Visitor class that finds all indirect call.
 struct PGOIndirectCallVisitor : public InstVisitor<PGOIndirectCallVisitor> {
   std::vector<CallBase *> IndirectCalls;
+  std::vector<Instruction *> VTableAddrs;
   PGOIndirectCallVisitor() = default;
 
   void visitCallBase(CallBase &Call) {
     if (Call.isIndirectCall())
-      IndirectCalls.push_back(&Call);
+      if (Call.isIndirectCall()) {
+        IndirectCalls.push_back(&Call);
+
+        LoadInst *LI = dyn_cast<LoadInst>(Call.getCalledOperand());
----------------
modiking wrote:

Looking for vtables this way seems like it'll also capture cases where function pointers are stored/passed around which would have the same pattern: https://godbolt.org/z/sMve8fhPa.

With `-fwhole-program-vtables` each virtual callsite is tagged from the front end (https://godbolt.org/z/KvY4dW1qa) which would make correctly identifying vtables easier.

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


More information about the llvm-commits mailing list