LLVM  4.0.0
InstrProfiling.h
Go to the documentation of this file.
1 //===- Transforms/InstrProfiling.h - Instrumentation passes ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This file provides the interface for LLVM's PGO Instrumentation lowering
11 /// pass.
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_INSTRPROFILING_H
15 #define LLVM_TRANSFORMS_INSTRPROFILING_H
16 
17 #include "llvm/IR/IntrinsicInst.h"
18 #include "llvm/IR/PassManager.h"
21 
22 namespace llvm {
23 
24 class TargetLibraryInfo;
25 
26 /// Instrumentation based profiling lowering pass. This pass lowers
27 /// the profile instrumented code generated by FE or the IR based
28 /// instrumentation pass.
29 class InstrProfiling : public PassInfoMixin<InstrProfiling> {
30 public:
32  InstrProfiling(const InstrProfOptions &Options) : Options(Options) {}
33 
35  bool run(Module &M, const TargetLibraryInfo &TLI);
36 
37 private:
38  InstrProfOptions Options;
39  Module *M;
40  const TargetLibraryInfo *TLI;
41  struct PerFunctionProfileData {
42  uint32_t NumValueSites[IPVK_Last + 1];
43  GlobalVariable *RegionCounters;
44  GlobalVariable *DataVar;
45  PerFunctionProfileData() : RegionCounters(nullptr), DataVar(nullptr) {
46  memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
47  }
48  };
49  DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
50  std::vector<GlobalValue *> UsedVars;
51  std::vector<GlobalVariable *> ReferencedNames;
52  GlobalVariable *NamesVar;
53  size_t NamesSize;
54 
55  bool isMachO() const;
56 
57  /// Get the section name for the counter variables.
58  StringRef getCountersSection() const;
59 
60  /// Get the section name for the name variables.
61  StringRef getNameSection() const;
62 
63  /// Get the section name for the profile data variables.
64  StringRef getDataSection() const;
65 
66  /// Get the section name for the coverage mapping data.
67  StringRef getCoverageSection() const;
68 
69  /// Count the number of instrumented value sites for the function.
70  void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
71 
72  /// Replace instrprof_value_profile with a call to runtime library.
73  void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
74 
75  /// Replace instrprof_increment with an increment of the appropriate value.
76  void lowerIncrement(InstrProfIncrementInst *Inc);
77 
78  /// Force emitting of name vars for unused functions.
79  void lowerCoverageData(GlobalVariable *CoverageNamesVar);
80 
81  /// Get the region counters for an increment, creating them if necessary.
82  ///
83  /// If the counter array doesn't yet exist, the profile data variables
84  /// referring to them will also be created.
85  GlobalVariable *getOrCreateRegionCounters(InstrProfIncrementInst *Inc);
86 
87  /// Emit the section with compressed function names.
88  void emitNameData();
89 
90  /// Emit value nodes section for value profiling.
91  void emitVNodes();
92 
93  /// Emit runtime registration functions for each profile data variable.
94  void emitRegistration();
95 
96  /// Emit the necessary plumbing to pull in the runtime initialization.
97  void emitRuntimeHook();
98 
99  /// Add uses of our data variables and runtime hook.
100  void emitUses();
101 
102  /// Create a static initializer for our data, on platforms that need it,
103  /// and for any profile output file that was specified.
104  void emitInitialization();
105 };
106 
107 } // End llvm namespace
108 #endif
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
Instrumentation based profiling lowering pass.
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:311
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
Provides information about what library functions are available for the current target.
Options for the frontend instrumentation based profiling pass.
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
InstrProfiling(const InstrProfOptions &Options)