LLVM  14.0.0git
ValueProfileCollector.cpp
Go to the documentation of this file.
1 //===- ValueProfileCollector.cpp - determine what to value profile --------===//
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 // The implementation of the ValueProfileCollector via ValueProfileCollectorImpl
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "ValueProfilePlugins.inc"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/InstIterator.h"
16 #include "llvm/IR/IntrinsicInst.h"
17 #include "llvm/InitializePasses.h"
18 #include <cassert>
19 
20 using namespace llvm;
21 
22 namespace {
23 
24 /// A plugin-based class that takes an arbitrary number of Plugin types.
25 /// Each plugin type must satisfy the following API:
26 /// 1) the constructor must take a `Function &f`. Typically, the plugin would
27 /// scan the function looking for candidates.
28 /// 2) contain a member function with the following signature and name:
29 /// void run(std::vector<CandidateInfo> &Candidates);
30 /// such that the plugin would append its result into the vector parameter.
31 ///
32 /// Plugins are defined in ValueProfilePlugins.inc
33 template <class... Ts> class PluginChain;
34 
35 /// The type PluginChainFinal is the final chain of plugins that will be used by
36 /// ValueProfileCollectorImpl.
37 using PluginChainFinal = PluginChain<VP_PLUGIN_LIST>;
38 
39 template <> class PluginChain<> {
40 public:
41  PluginChain(Function &F, TargetLibraryInfo &TLI) {}
42  void get(InstrProfValueKind K, std::vector<CandidateInfo> &Candidates) {}
43 };
44 
45 template <class PluginT, class... Ts>
46 class PluginChain<PluginT, Ts...> : public PluginChain<Ts...> {
47  PluginT Plugin;
48  using Base = PluginChain<Ts...>;
49 
50 public:
51  PluginChain(Function &F, TargetLibraryInfo &TLI)
52  : PluginChain<Ts...>(F, TLI), Plugin(F, TLI) {}
53 
54  void get(InstrProfValueKind K, std::vector<CandidateInfo> &Candidates) {
55  if (K == PluginT::Kind)
56  Plugin.run(Candidates);
57  Base::get(K, Candidates);
58  }
59 };
60 
61 } // end anonymous namespace
62 
63 /// ValueProfileCollectorImpl inherits the API of PluginChainFinal.
65 public:
66  using PluginChainFinal::PluginChainFinal;
67 };
68 
70  TargetLibraryInfo &TLI)
71  : PImpl(new ValueProfileCollectorImpl(F, TLI)) {}
72 
74 
75 std::vector<CandidateInfo>
77  std::vector<CandidateInfo> Result;
78  PImpl->get(Kind, Result);
79  return Result;
80 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
IntrinsicInst.h
InstIterator.h
llvm::Function
Definition: Function.h:62
llvm::ValueProfileCollector::ValueProfileCollectorImpl
ValueProfileCollectorImpl inherits the API of PluginChainFinal.
Definition: ValueProfileCollector.cpp:64
llvm::ValueProfileCollector::~ValueProfileCollector
~ValueProfileCollector()
PluginChainFinal
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::ValueProfileCollector::ValueProfileCollector
ValueProfileCollector(Function &Fn, TargetLibraryInfo &TLI)
Definition: ValueProfileCollector.cpp:69
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
ValueProfilePlugins.inc
llvm::InstrProfValueKind
InstrProfValueKind
Definition: InstrProf.h:238
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
Function.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
InitializePasses.h
llvm::ValueProfileCollector::get
std::vector< CandidateInfo > get(InstrProfValueKind Kind) const
returns a list of value profiling candidates of the given kind
Definition: ValueProfileCollector.cpp:76
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58