1 //===-- IndirectCallVisitor.h - indirect call visitor ---------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements defines a visitor class and a helper function that find
10 // all indirect call-sites in a function.
12 #ifndef LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
13 #define LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
15 #include "llvm/IR/InstVisitor.h"
19 // Visitor class that finds all indirect call.
20 struct PGOIndirectCallVisitor
: public InstVisitor
<PGOIndirectCallVisitor
> {
21 std::vector
<Instruction
*> IndirectCalls
;
22 PGOIndirectCallVisitor() {}
24 void visitCallBase(CallBase
&Call
) {
25 if (Call
.isIndirectCall())
26 IndirectCalls
.push_back(&Call
);
30 // Helper function that finds all indirect call sites.
31 inline std::vector
<Instruction
*> findIndirectCalls(Function
&F
) {
32 PGOIndirectCallVisitor ICV
;
34 return ICV
.IndirectCalls
;