LLVM  4.0.0
Instrumentation.h
Go to the documentation of this file.
1 //===- Transforms/Instrumentation.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 //
10 // This file defines constructor functions for instrumentation passes.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
15 #define LLVM_TRANSFORMS_INSTRUMENTATION_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/IR/BasicBlock.h"
19 #include <vector>
20 
21 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
22 inline void *getDFSanArgTLSPtrForJIT() {
23  extern __thread __attribute__((tls_model("initial-exec")))
24  void *__dfsan_arg_tls;
25  return (void *)&__dfsan_arg_tls;
26 }
27 
28 inline void *getDFSanRetValTLSPtrForJIT() {
29  extern __thread __attribute__((tls_model("initial-exec")))
30  void *__dfsan_retval_tls;
31  return (void *)&__dfsan_retval_tls;
32 }
33 #endif
34 
35 namespace llvm {
36 
37 class TargetMachine;
38 
39 /// Instrumentation passes often insert conditional checks into entry blocks.
40 /// Call this function before splitting the entry block to move instructions
41 /// that must remain in the entry block up before the split point. Static
42 /// allocas and llvm.localescape calls, for example, must remain in the entry
43 /// block.
46 
47 class ModulePass;
48 class FunctionPass;
49 
50 // Insert GCOV profiling instrumentation
51 struct GCOVOptions {
52  static GCOVOptions getDefault();
53 
54  // Specify whether to emit .gcno files.
55  bool EmitNotes;
56 
57  // Specify whether to modify the program to emit .gcda files when run.
58  bool EmitData;
59 
60  // A four-byte version string. The meaning of a version string is described in
61  // gcc's gcov-io.h
62  char Version[4];
63 
64  // Emit a "cfg checksum" that follows the "line number checksum" of a
65  // function. This affects both .gcno and .gcda files.
67 
68  // Add the 'noredzone' attribute to added runtime library calls.
69  bool NoRedZone;
70 
71  // Emit the name of the function in the .gcda files. This is redundant, as
72  // the function identifier can be used to find the name from the .gcno file.
74 
75  // Emit the exit block immediately after the start block, rather than after
76  // all of the function body's blocks.
78 };
81 
82 // PGO Instrumention
84 ModulePass *
87 
88 /// Options for the frontend instrumentation based profiling pass.
91 
92  // Add the 'noredzone' attribute to added runtime library calls.
93  bool NoRedZone;
94 
95  // Name of the profile file to use as output
96  std::string InstrProfileOutput;
97 };
98 
99 /// Insert frontend instrumentation based profiling.
101  const InstrProfOptions &Options = InstrProfOptions());
102 
103 // Insert AddressSanitizer (address sanity checking) instrumentation
104 FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false,
105  bool Recover = false,
106  bool UseAfterScope = false);
107 ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false,
108  bool Recover = false);
109 
110 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
111 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0,
112  bool Recover = false);
113 
114 // Insert ThreadSanitizer (race detection) instrumentation
116 
117 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
119  const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
120  void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
121 
122 // Options for EfficiencySanitizer sub-tools.
125  enum Type {
129  } ToolType;
130 };
131 
132 // Insert EfficiencySanitizer instrumentation.
134  const EfficiencySanitizerOptions &Options = EfficiencySanitizerOptions());
135 
136 // Options for sanitizer coverage instrumentation.
142 
143  enum Type {
144  SCK_None = 0,
148  } CoverageType;
150  bool TraceBB;
151  bool TraceCmp;
152  bool TraceDiv;
153  bool TraceGep;
155  bool TracePC;
157 };
158 
159 // Insert SanitizerCoverage instrumentation.
162 
163 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
164 inline ModulePass *createDataFlowSanitizerPassForJIT(
165  const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
166  return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
167  getDFSanRetValTLSPtrForJIT);
168 }
169 #endif
170 
171 // BoundsChecking - This pass instruments the code to perform run-time bounds
172 // checking on loads, stores, and other memory intrinsics.
173 FunctionPass *createBoundsCheckingPass();
174 
175 /// \brief Calculate what to divide by to scale counts.
176 ///
177 /// Given the maximum count, calculate a divisor that will scale all the
178 /// weights to strictly less than UINT32_MAX.
179 static inline uint64_t calculateCountScale(uint64_t MaxCount) {
180  return MaxCount < UINT32_MAX ? 1 : MaxCount / UINT32_MAX + 1;
181 }
182 
183 /// \brief Scale an individual branch count.
184 ///
185 /// Scale a 64-bit weight down to 32-bits using \c Scale.
186 ///
187 static inline uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale) {
188  uint64_t Scaled = Count / Scale;
189  assert(Scaled <= UINT32_MAX && "overflow 32-bits");
190  return Scaled;
191 }
192 
193 } // End llvm namespace
194 
195 #endif
ModulePass * createPGOInstrumentationGenLegacyPass()
enum llvm::EfficiencySanitizerOptions::Type ToolType
FunctionPass * createBoundsCheckingPass()
Various leaf nodes.
Definition: ISDOpcodes.h:60
static GCOVOptions getDefault()
ModulePass * createGCOVProfilerPass(const GCOVOptions &Options=GCOVOptions::getDefault())
ModulePass * createInstrProfilingLegacyPass(const InstrProfOptions &Options=InstrProfOptions())
Insert frontend instrumentation based profiling.
ModulePass * createEfficiencySanitizerPass(const EfficiencySanitizerOptions &Options=EfficiencySanitizerOptions())
__attribute__((weak)) int LLVMFuzzerInitialize(int *argc
Function Alias Analysis false
ModulePass * createAddressSanitizerModulePass(bool CompileKernel=false, bool Recover=false)
ModulePass * createPGOInstrumentationUseLegacyPass(StringRef Filename=StringRef(""))
ModulePass * createPGOIndirectCallPromotionLegacyPass(bool InLTO=false)
FunctionPass * createThreadSanitizerPass()
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
static uint64_t calculateCountScale(uint64_t MaxCount)
Calculate what to divide by to scale counts.
static uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale)
Scale an individual branch count.
std::string InstrProfileOutput
always inline
enum llvm::SanitizerCoverageOptions::Type CoverageType
BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB, BasicBlock::iterator IP)
Instrumentation passes often insert conditional checks into entry blocks.
Options for the frontend instrumentation based profiling pass.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:235
ModulePass * createSanitizerCoverageModulePass(const SanitizerCoverageOptions &Options=SanitizerCoverageOptions())
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ModulePass * createDataFlowSanitizerPass(const std::vector< std::string > &ABIListFiles=std::vector< std::string >(), void *(*getArgTLS)()=nullptr, void *(*getRetValTLS)()=nullptr)
FunctionPass * createMemorySanitizerPass(int TrackOrigins=0, bool Recover=false)
FunctionPass * createAddressSanitizerFunctionPass(bool CompileKernel=false, bool Recover=false, bool UseAfterScope=false)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:83