1 //=== ValueProfilePlugins.inc - set of plugins used by ValueProfileCollector =//
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
7 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #include "ValueProfileCollector.h"
17 #include "llvm/Analysis/IndirectCallVisitor.h"
18 #include "llvm/IR/InstVisitor.h"
21 using CandidateInfo = ValueProfileCollector::CandidateInfo;
23 ///--------------------------- MemIntrinsicPlugin ------------------------------
24 class MemIntrinsicPlugin : public InstVisitor<MemIntrinsicPlugin> {
26 std::vector<CandidateInfo> *Candidates;
29 static constexpr InstrProfValueKind Kind = IPVK_MemOPSize;
31 MemIntrinsicPlugin(Function &Fn) : F(Fn), Candidates(nullptr) {}
33 void run(std::vector<CandidateInfo> &Cs) {
38 void visitMemIntrinsic(MemIntrinsic &MI) {
39 Value *Length = MI.getLength();
40 // Not instrument constant length calls.
41 if (dyn_cast<ConstantInt>(Length))
44 Instruction *InsertPt = &MI;
45 Instruction *AnnotatedInst = &MI;
46 Candidates->emplace_back(CandidateInfo{Length, InsertPt, AnnotatedInst});
50 ///------------------------ IndirectCallPromotionPlugin ------------------------
51 class IndirectCallPromotionPlugin {
55 static constexpr InstrProfValueKind Kind = IPVK_IndirectCallTarget;
57 IndirectCallPromotionPlugin(Function &Fn) : F(Fn) {}
59 void run(std::vector<CandidateInfo> &Candidates) {
60 std::vector<Instruction *> Result = findIndirectCalls(F);
61 for (Instruction *I : Result) {
62 Value *Callee = CallSite(I).getCalledValue();
63 Instruction *InsertPt = I;
64 Instruction *AnnotatedInst = I;
65 Candidates.emplace_back(CandidateInfo{Callee, InsertPt, AnnotatedInst});
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 \
75 IndirectCallPromotionPlugin