]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/IndirectCallVisitor.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / IndirectCallVisitor.h
1 //===-- IndirectCallVisitor.h - indirect call visitor ---------------------===//
2 //
3 //                      The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements defines a visitor class and a helper function that find
11 // all indirect call-sites in a function.
12
13 #ifndef LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
14 #define LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
15
16 #include "llvm/IR/InstVisitor.h"
17 #include <vector>
18
19 namespace llvm {
20 // Visitor class that finds all indirect call.
21 struct PGOIndirectCallVisitor : public InstVisitor<PGOIndirectCallVisitor> {
22   std::vector<Instruction *> IndirectCalls;
23   PGOIndirectCallVisitor() {}
24
25   void visitCallBase(CallBase &Call) {
26     if (Call.isIndirectCall())
27       IndirectCalls.push_back(&Call);
28   }
29 };
30
31 // Helper function that finds all indirect call sites.
32 inline std::vector<Instruction *> findIndirectCalls(Function &F) {
33   PGOIndirectCallVisitor ICV;
34   ICV.visit(F);
35   return ICV.IndirectCalls;
36 }
37 } // namespace llvm
38
39 #endif