1 //===-- IndirectCallSiteVisitor.h - indirect call-sites 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 #include "llvm/IR/InstVisitor.h"
17 // Visitor class that finds all indirect call sites.
18 struct PGOIndirectCallSiteVisitor
19 : public InstVisitor<PGOIndirectCallSiteVisitor> {
20 std::vector<Instruction *> IndirectCallInsts;
21 PGOIndirectCallSiteVisitor() {}
23 void visitCallSite(CallSite CS) {
24 if (CS.getCalledFunction() || !CS.getCalledValue())
26 Instruction *I = CS.getInstruction();
27 if (CallInst *CI = dyn_cast<CallInst>(I)) {
28 if (CI->isInlineAsm())
31 if (isa<Constant>(CS.getCalledValue()))
33 IndirectCallInsts.push_back(I);
37 // Helper function that finds all indirect call sites.
38 static inline std::vector<Instruction *> findIndirectCallSites(Function &F) {
39 PGOIndirectCallSiteVisitor ICV;
41 return ICV.IndirectCallInsts;