[llvm] r265199 - [PGO] Use a helper function to find all indirect call-sites
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 1 16:16:44 PDT 2016
Author: xur
Date: Fri Apr 1 18:16:44 2016
New Revision: 265199
URL: http://llvm.org/viewvc/llvm-project?rev=265199&view=rev
Log:
[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
Added:
llvm/trunk/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
Modified:
llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Added: llvm/trunk/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h?rev=265199&view=auto
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h (added)
+++ llvm/trunk/lib/Transforms/Instrumentation/IndirectCallSiteVisitor.h Fri Apr 1 18:16:44 2016
@@ -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;
+}
+}
Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=265199&r1=265198&r2=265199&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Fri Apr 1 18:16:44 2016
@@ -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,
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 &
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::annotateIndirectCallSit
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::annotateIndirectCallSit
return;
}
- for (auto &I : ICV.IndirectCallInsts) {
+ for (auto &I : IndirectCallSites) {
DEBUG(dbgs() << "Read one indirect call instrumentation: Index="
<< IndirectCallSiteIndex << " out of " << NumValueSites
<< "\n");
More information about the llvm-commits
mailing list