summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2016-04-01 23:16:44 +0000
committerRong Xu <xur@google.com>2016-04-01 23:16:44 +0000
commit0eb360362617a75fc9c7bb4e7fce50ad9196e49d (patch)
tree19b3f8ea5bf2beb7d2f02fe5e17bf62da57e2545 /llvm/lib/Transforms
parent5dad9df9f7bd38a076e3c7cdf22270faa17b877f (diff)
downloadbcm5719-llvm-0eb360362617a75fc9c7bb4e7fce50ad9196e49d.tar.gz
bcm5719-llvm-0eb360362617a75fc9c7bb4e7fce50ad9196e49d.zip
[PGO] Use a helper function to find all indirect call-sites
Use a helper function to find all the direct-calls-sites in a function. Also split the code into a separated file as this will be use by indirect-call-promotion transformation. Differential Revision: http://reviews.llvm.org/D18704 llvm-svn: 265199
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h41
-rw-r--r--llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp31
2 files changed, 46 insertions, 26 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h b/llvm/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
new file mode 100644
index 00000000000..baf49c79f6d
--- /dev/null
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
@@ -0,0 +1,41 @@
+//===-- 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;
+ }
+ 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;
+}
+}
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 5feeccb6293..d6e9c31d8aa 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -49,6 +49,7 @@
//===----------------------------------------------------------------------===//
#include "CFGMST.h"
+#include "IndirectCallSiteVisitor.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
@@ -60,7 +61,6 @@
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
-#include "llvm/IR/InstVisitor.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MDBuilder.h"
@@ -326,24 +326,6 @@ BasicBlock *FuncPGOInstrumentation<Edge, BBInfo>::getInstrBB(Edge *E) {
return InstrBB;
}
-// 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;
- }
- IndirectCallInsts.push_back(I);
- }
-};
-
// Visit all edge and instrument the edges not in MST, and do value profiling.
// Critical edges will be split.
static void instrumentOneFunc(Function &F, Module *M,
@@ -377,9 +359,7 @@ static void instrumentOneFunc(Function &F, Module *M,
return;
unsigned NumIndirectCallSites = 0;
- PGOIndirectCallSiteVisitor ICV;
- ICV.visit(F);
- for (auto &I : ICV.IndirectCallInsts) {
+ for (auto &I : findIndirectCallSites(F)) {
CallSite CS(I);
Value *Callee = CS.getCalledValue();
DEBUG(dbgs() << "Instrument one indirect call: CallSite Index = "
@@ -756,11 +736,10 @@ void PGOUseFunc::annotateIndirectCallSites() {
createPGOFuncNameMetadata(F);
unsigned IndirectCallSiteIndex = 0;
- PGOIndirectCallSiteVisitor ICV;
- ICV.visit(F);
+ auto IndirectCallSites = findIndirectCallSites(F);
unsigned NumValueSites =
ProfileRecord.getNumValueSites(IPVK_IndirectCallTarget);
- if (NumValueSites != ICV.IndirectCallInsts.size()) {
+ if (NumValueSites != IndirectCallSites.size()) {
std::string Msg =
std::string("Inconsistent number of indirect call sites: ") +
F.getName().str();
@@ -770,7 +749,7 @@ void PGOUseFunc::annotateIndirectCallSites() {
return;
}
- for (auto &I : ICV.IndirectCallInsts) {
+ for (auto &I : IndirectCallSites) {
DEBUG(dbgs() << "Read one indirect call instrumentation: Index="
<< IndirectCallSiteIndex << " out of " << NumValueSites
<< "\n");
OpenPOWER on IntegriCloud