1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-24 21:42:54 +02:00
llvm-mirror/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
Betul Buyukkurt 60f19e2f50 [PGO] Avoid instrumenting direct callee's at value sites.
Direct callees' that are cast to other function prototypes,
show up in the Call/Invoke instructions as ConstantExpr's.
Currently llvm::CallSite's getCalledFunction() fails
to return the callees in such expressions as direct calls.
Value profiling should avoid instrumenting such cases. Mostly NFC.

llvm-svn: 265330
2016-04-04 18:56:36 +00:00

44 lines
1.3 KiB
C++

//===-- 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;
}
}