LLVM  10.0.0
ValueProfilePlugins.inc
Go to the documentation of this file.
1 //=== ValueProfilePlugins.inc - set of plugins used by ValueProfileCollector =//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a set of plugin classes used in ValueProfileCollectorImpl.
10 // Each plugin is responsible for collecting Value Profiling candidates for a
11 // particular optimization.
12 // Each plugin must satisfy the interface described in ValueProfileCollector.cpp
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "ValueProfileCollector.h"
18 #include "llvm/IR/InstVisitor.h"
19 
20 using namespace llvm;
21 using CandidateInfo = ValueProfileCollector::CandidateInfo;
22 
23 ///--------------------------- MemIntrinsicPlugin ------------------------------
24 class MemIntrinsicPlugin : public InstVisitor<MemIntrinsicPlugin> {
25  Function &F;
26  std::vector<CandidateInfo> *Candidates;
27 
28 public:
29  static constexpr InstrProfValueKind Kind = IPVK_MemOPSize;
30 
31  MemIntrinsicPlugin(Function &Fn) : F(Fn), Candidates(nullptr) {}
32 
33  void run(std::vector<CandidateInfo> &Cs) {
34  Candidates = &Cs;
35  visit(F);
36  Candidates = nullptr;
37  }
38  void visitMemIntrinsic(MemIntrinsic &MI) {
39  Value *Length = MI.getLength();
40  // Not instrument constant length calls.
41  if (dyn_cast<ConstantInt>(Length))
42  return;
43 
44  Instruction *InsertPt = &MI;
45  Instruction *AnnotatedInst = &MI;
46  Candidates->emplace_back(CandidateInfo{Length, InsertPt, AnnotatedInst});
47  }
48 };
49 
50 ///------------------------ IndirectCallPromotionPlugin ------------------------
51 class IndirectCallPromotionPlugin {
52  Function &F;
53 
54 public:
55  static constexpr InstrProfValueKind Kind = IPVK_IndirectCallTarget;
56 
57  IndirectCallPromotionPlugin(Function &Fn) : F(Fn) {}
58 
59  void run(std::vector<CandidateInfo> &Candidates) {
60  std::vector<Instruction *> Result = findIndirectCalls(F);
61  for (Instruction *I : Result) {
63  Instruction *InsertPt = I;
64  Instruction *AnnotatedInst = I;
65  Candidates.emplace_back(CandidateInfo{Callee, InsertPt, AnnotatedInst});
66  }
67  }
68 };
69 
70 ///----------------------- Registration of the plugins -------------------------
71 /// For now, registering a plugin with the ValueProfileCollector is done by
72 /// adding the plugin type to the VP_PLUGIN_LIST macro.
73 #define VP_PLUGIN_LIST \
74  MemIntrinsicPlugin, \
75  IndirectCallPromotionPlugin
Base class for instruction visitors.
Definition: InstVisitor.h:80
This class represents lattice values for constants.
Definition: AllocatorList.h:23
F(f)
Value * getLength() const
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Definition: CallSite.h:104
InstrProfValueKind
Definition: InstrProf.h:232
This is the common base class for memset/memcpy/memmove.
amdgpu Simplify well known AMD library false FunctionCallee Callee
std::vector< Instruction * > findIndirectCalls(Function &F)
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM Value Representation.
Definition: Value.h:74
IRTranslator LLVM IR MI