blob: a30b59fee4f443cd59534a1dec89311a41070270 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- IndirectCallSiteVisitor.h - indirect call-sites 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
Andrew Scull0372a572018-11-16 15:47:06 +000013#ifndef LLVM_ANALYSIS_INDIRECTCALLSITEVISITOR_H
14#define LLVM_ANALYSIS_INDIRECTCALLSITEVISITOR_H
15
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010016#include "llvm/IR/InstVisitor.h"
17#include <vector>
18
19namespace llvm {
20// Visitor class that finds all indirect call sites.
21struct PGOIndirectCallSiteVisitor
22 : public InstVisitor<PGOIndirectCallSiteVisitor> {
23 std::vector<Instruction *> IndirectCallInsts;
24 PGOIndirectCallSiteVisitor() {}
25
26 void visitCallSite(CallSite CS) {
27 if (CS.isIndirectCall())
28 IndirectCallInsts.push_back(CS.getInstruction());
29 }
30};
31
32// Helper function that finds all indirect call sites.
33inline std::vector<Instruction *> findIndirectCallSites(Function &F) {
34 PGOIndirectCallSiteVisitor ICV;
35 ICV.visit(F);
36 return ICV.IndirectCallInsts;
37}
38}
Andrew Scull0372a572018-11-16 15:47:06 +000039
40#endif