1 //===-- IndirectCallVisitor.h - indirect call visitor ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements defines a visitor class and a helper function that find
11 // all indirect call-sites in a function.
13 #ifndef LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
14 #define LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
16 #include "llvm/IR/InstVisitor.h"
20 // Visitor class that finds all indirect call.
21 struct PGOIndirectCallVisitor : public InstVisitor<PGOIndirectCallVisitor> {
22 std::vector<Instruction *> IndirectCalls;
23 PGOIndirectCallVisitor() {}
25 void visitCallBase(CallBase &Call) {
26 if (Call.isIndirectCall())
27 IndirectCalls.push_back(&Call);
31 // Helper function that finds all indirect call sites.
32 inline std::vector<Instruction *> findIndirectCalls(Function &F) {
33 PGOIndirectCallVisitor ICV;
35 return ICV.IndirectCalls;