[llvm] r350508 - [CallSite removal] Port `IndirectCallSiteVisitor` to use `CallBase` and
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 6 23:15:51 PST 2019
Author: chandlerc
Date: Sun Jan 6 23:15:51 2019
New Revision: 350508
URL: http://llvm.org/viewvc/llvm-project?rev=350508&view=rev
Log:
[CallSite removal] Port `IndirectCallSiteVisitor` to use `CallBase` and
update client code.
Also rename it to use the more generic term `call` instead of something
that could be confused with a praticular type.
Differential Revision: https://reviews.llvm.org/D56183
Added:
llvm/trunk/include/llvm/Analysis/IndirectCallVisitor.h
Removed:
llvm/trunk/include/llvm/Analysis/IndirectCallSiteVisitor.h
Modified:
llvm/trunk/include/llvm/IR/InstrTypes.h
llvm/trunk/lib/Analysis/IndirectCallPromotionAnalysis.cpp
llvm/trunk/lib/IR/Instructions.cpp
llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Removed: llvm/trunk/include/llvm/Analysis/IndirectCallSiteVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/IndirectCallSiteVisitor.h?rev=350507&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Analysis/IndirectCallSiteVisitor.h (original)
+++ llvm/trunk/include/llvm/Analysis/IndirectCallSiteVisitor.h (removed)
@@ -1,40 +0,0 @@
-//===-- 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.
-
-#ifndef LLVM_ANALYSIS_INDIRECTCALLSITEVISITOR_H
-#define LLVM_ANALYSIS_INDIRECTCALLSITEVISITOR_H
-
-#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.isIndirectCall())
- IndirectCallInsts.push_back(CS.getInstruction());
- }
-};
-
-// Helper function that finds all indirect call sites.
-inline std::vector<Instruction *> findIndirectCallSites(Function &F) {
- PGOIndirectCallSiteVisitor ICV;
- ICV.visit(F);
- return ICV.IndirectCallInsts;
-}
-}
-
-#endif
Added: llvm/trunk/include/llvm/Analysis/IndirectCallVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/IndirectCallVisitor.h?rev=350508&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Analysis/IndirectCallVisitor.h (added)
+++ llvm/trunk/include/llvm/Analysis/IndirectCallVisitor.h Sun Jan 6 23:15:51 2019
@@ -0,0 +1,39 @@
+//===-- IndirectCallVisitor.h - indirect call 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.
+
+#ifndef LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
+#define LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
+
+#include "llvm/IR/InstVisitor.h"
+#include <vector>
+
+namespace llvm {
+// Visitor class that finds all indirect call.
+struct PGOIndirectCallVisitor : public InstVisitor<PGOIndirectCallVisitor> {
+ std::vector<Instruction *> IndirectCalls;
+ PGOIndirectCallVisitor() {}
+
+ void visitCallBase(CallBase &Call) {
+ if (Call.isIndirectCall())
+ IndirectCalls.push_back(&Call);
+ }
+};
+
+// Helper function that finds all indirect call sites.
+inline std::vector<Instruction *> findIndirectCalls(Function &F) {
+ PGOIndirectCallVisitor ICV;
+ ICV.visit(F);
+ return ICV.IndirectCalls;
+}
+} // namespace llvm
+
+#endif
Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=350508&r1=350507&r2=350508&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Sun Jan 6 23:15:51 2019
@@ -1182,6 +1182,9 @@ public:
return dyn_cast_or_null<Function>(getCalledOperand());
}
+ /// Return true if the callsite is an indirect call.
+ bool isIndirectCall() const;
+
/// Helper to get the caller (the parent function).
Function *getCaller();
const Function *getCaller() const {
Modified: llvm/trunk/lib/Analysis/IndirectCallPromotionAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IndirectCallPromotionAnalysis.cpp?rev=350508&r1=350507&r2=350508&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IndirectCallPromotionAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/IndirectCallPromotionAnalysis.cpp Sun Jan 6 23:15:51 2019
@@ -15,7 +15,7 @@
#include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/Analysis/IndirectCallSiteVisitor.h"
+#include "llvm/Analysis/IndirectCallVisitor.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstVisitor.h"
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=350508&r1=350507&r2=350508&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Sun Jan 6 23:15:51 2019
@@ -257,6 +257,16 @@ void LandingPadInst::addClause(Constant
Function *CallBase::getCaller() { return getParent()->getParent(); }
+bool CallBase::isIndirectCall() const {
+ const Value *V = getCalledValue();
+ if (isa<Function>(V) || isa<Constant>(V))
+ return false;
+ if (const CallInst *CI = dyn_cast<CallInst>(this))
+ if (CI->isInlineAsm())
+ return false;
+ return true;
+}
+
Intrinsic::ID CallBase::getIntrinsicID() const {
if (auto *F = getCalledFunction())
return F->getIntrinsicID();
Modified: llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp?rev=350508&r1=350507&r2=350508&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp Sun Jan 6 23:15:51 2019
@@ -19,7 +19,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
-#include "llvm/Analysis/IndirectCallSiteVisitor.h"
+#include "llvm/Analysis/IndirectCallVisitor.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/IR/Attributes.h"
@@ -41,8 +41,8 @@
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Error.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
@@ -352,7 +352,7 @@ uint32_t ICallPromotionFunc::tryToPromot
bool ICallPromotionFunc::processFunction(ProfileSummaryInfo *PSI) {
bool Changed = false;
ICallPromotionAnalysis ICallAnalysis;
- for (auto &I : findIndirectCallSites(F)) {
+ for (auto &I : findIndirectCalls(F)) {
uint32_t NumVals, NumCandidates;
uint64_t TotalCount;
auto ICallProfDataRef = ICallAnalysis.getPromotionCandidatesForInstruction(
Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=350508&r1=350507&r2=350508&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Sun Jan 6 23:15:51 2019
@@ -63,7 +63,7 @@
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/CFG.h"
-#include "llvm/Analysis/IndirectCallSiteVisitor.h"
+#include "llvm/Analysis/IndirectCallVisitor.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/IR/Attributes.h"
@@ -544,7 +544,7 @@ public:
MIVisitor.countMemIntrinsics(Func);
NumOfPGOSelectInsts += SIVisitor.getNumOfSelectInsts();
NumOfPGOMemIntrinsics += MIVisitor.getNumOfMemIntrinsics();
- ValueSites[IPVK_IndirectCallTarget] = findIndirectCallSites(Func);
+ ValueSites[IPVK_IndirectCallTarget] = findIndirectCalls(Func);
ValueSites[IPVK_MemOPSize] = MIVisitor.findMemIntrinsics(Func);
FuncName = getPGOFuncName(F);
@@ -754,12 +754,12 @@ static void instrumentOneFunc(
if (DisableValueProfiling)
return;
- unsigned NumIndirectCallSites = 0;
+ unsigned NumIndirectCalls = 0;
for (auto &I : FuncInfo.ValueSites[IPVK_IndirectCallTarget]) {
CallSite CS(I);
Value *Callee = CS.getCalledValue();
LLVM_DEBUG(dbgs() << "Instrument one indirect call: CallSite Index = "
- << NumIndirectCallSites << "\n");
+ << NumIndirectCalls << "\n");
IRBuilder<> Builder(I);
assert(Builder.GetInsertPoint() != I->getParent()->end() &&
"Cannot get the Instrumentation point");
@@ -769,9 +769,9 @@ static void instrumentOneFunc(
Builder.getInt64(FuncInfo.FunctionHash),
Builder.CreatePtrToInt(Callee, Builder.getInt64Ty()),
Builder.getInt32(IPVK_IndirectCallTarget),
- Builder.getInt32(NumIndirectCallSites++)});
+ Builder.getInt32(NumIndirectCalls++)});
}
- NumOfPGOICall += NumIndirectCallSites;
+ NumOfPGOICall += NumIndirectCalls;
// Now instrument memop intrinsic calls.
FuncInfo.MIVisitor.instrumentMemIntrinsics(
More information about the llvm-commits
mailing list