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

David Li via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 14:30:04 PDT 2023


================
@@ -12,27 +12,96 @@
 #ifndef LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
 #define LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
 
+#include "llvm/ADT/SetVector.h"
 #include "llvm/IR/InstVisitor.h"
 #include <vector>
 
 namespace llvm {
-// Visitor class that finds all indirect call.
+// Visitor class that finds indirect calls or instructions that gives vtable
+// value, depending on Type.
 struct PGOIndirectCallVisitor : public InstVisitor<PGOIndirectCallVisitor> {
+  enum class InstructionType {
+    kIndirectCall = 0,
+    kVTableVal = 1,
+  };
   std::vector<CallBase *> IndirectCalls;
-  PGOIndirectCallVisitor() = default;
+  SetVector<Instruction *, std::vector<Instruction *>> VTableAddrs;
+  PGOIndirectCallVisitor(InstructionType Type) : Type(Type) {}
 
   void visitCallBase(CallBase &Call) {
-    if (Call.isIndirectCall())
+    const CallInst *CI = dyn_cast<CallInst>(&Call);
----------------
david-xl wrote:

Suggest restructure the code a little more for better reading:


```
if (Call.isIndirectCall())
   IndirectCalls.push_back(&Call);

if (Type != kVTableVal) 
   return;

// Handle VTable type below
```



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


More information about the cfe-commits mailing list