summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
blob: 71a8cb886321676b9e2919ca59cdaa8f05b1a4d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//===-- IndirectCallSiteVisitor.h - indirect call-sites visitor -----------===//
//
//                      The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements defines a visitor class and a helper function that find
// all indirect call-sites in a function.

#include "llvm/IR/InstVisitor.h"
#include <vector>

namespace llvm {
// Visitor class that finds all indirect call sites.
struct PGOIndirectCallSiteVisitor
    : public InstVisitor<PGOIndirectCallSiteVisitor> {
  std::vector<Instruction *> IndirectCallInsts;
  PGOIndirectCallSiteVisitor() {}

  void visitCallSite(CallSite CS) {
    if (CS.getCalledFunction() || !CS.getCalledValue())
      return;
    Instruction *I = CS.getInstruction();
    if (CallInst *CI = dyn_cast<CallInst>(I)) {
      if (CI->isInlineAsm())
        return;
    }
    if (isa<Constant>(CS.getCalledValue()))
      return;
    IndirectCallInsts.push_back(I);
  }
};

// Helper function that finds all indirect call sites.
static inline std::vector<Instruction *> findIndirectCallSites(Function &F) {
  PGOIndirectCallSiteVisitor ICV;
  ICV.visit(F);
  return ICV.IndirectCallInsts;
}
}
OpenPOWER on IntegriCloud