[LoopUtils] Move a private constructor nearer the other private members
[oota-llvm.git] / include / llvm / Transforms / Instrumentation.h
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 /// Instrumentation passes often insert conditional checks into entry blocks.
38 /// Call this function before splitting the entry block to move instructions
39 /// that must remain in the entry block up before the split point. Static
40 /// allocas and llvm.localescape calls, for example, must remain in the entry
41 /// block.
42 BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB,
43                                               BasicBlock::iterator IP);
44
45 class ModulePass;
46 class FunctionPass;
47
48 // Insert GCOV profiling instrumentation
49 struct GCOVOptions {
50   static GCOVOptions getDefault();
51
52   // Specify whether to emit .gcno files.
53   bool EmitNotes;
54
55   // Specify whether to modify the program to emit .gcda files when run.
56   bool EmitData;
57
58   // A four-byte version string. The meaning of a version string is described in
59   // gcc's gcov-io.h
60   char Version[4];
61
62   // Emit a "cfg checksum" that follows the "line number checksum" of a
63   // function. This affects both .gcno and .gcda files.
64   bool UseCfgChecksum;
65
66   // Add the 'noredzone' attribute to added runtime library calls.
67   bool NoRedZone;
68
69   // Emit the name of the function in the .gcda files. This is redundant, as
70   // the function identifier can be used to find the name from the .gcno file.
71   bool FunctionNamesInData;
72
73   // Emit the exit block immediately after the start block, rather than after
74   // all of the function body's blocks.
75   bool ExitBlockBeforeBody;
76 };
77 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
78                                    GCOVOptions::getDefault());
79
80 /// Options for the frontend instrumentation based profiling pass.
81 struct InstrProfOptions {
82   InstrProfOptions() : NoRedZone(false) {}
83
84   // Add the 'noredzone' attribute to added runtime library calls.
85   bool NoRedZone;
86
87   // Name of the profile file to use as output
88   std::string InstrProfileOutput;
89 };
90
91 /// Insert frontend instrumentation based profiling.
92 ModulePass *createInstrProfilingPass(
93     const InstrProfOptions &Options = InstrProfOptions());
94
95 // Insert AddressSanitizer (address sanity checking) instrumentation
96 FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false);
97 ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false);
98
99 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
100 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
101
102 // Insert ThreadSanitizer (race detection) instrumentation
103 FunctionPass *createThreadSanitizerPass();
104
105 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
106 ModulePass *createDataFlowSanitizerPass(
107     const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
108     void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
109
110 // Options for sanitizer coverage instrumentation.
111 struct SanitizerCoverageOptions {
112   SanitizerCoverageOptions()
113       : CoverageType(SCK_None), IndirectCalls(false), TraceBB(false),
114         TraceCmp(false), Use8bitCounters(false) {}
115
116   enum Type {
117     SCK_None = 0,
118     SCK_Function,
119     SCK_BB,
120     SCK_Edge
121   } CoverageType;
122   bool IndirectCalls;
123   bool TraceBB;
124   bool TraceCmp;
125   bool Use8bitCounters;
126 };
127
128 // Insert SanitizerCoverage instrumentation.
129 ModulePass *createSanitizerCoverageModulePass(
130     const SanitizerCoverageOptions &Options = SanitizerCoverageOptions());
131
132 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
133 inline ModulePass *createDataFlowSanitizerPassForJIT(
134     const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
135   return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
136                                      getDFSanRetValTLSPtrForJIT);
137 }
138 #endif
139
140 // BoundsChecking - This pass instruments the code to perform run-time bounds
141 // checking on loads, stores, and other memory intrinsics.
142 FunctionPass *createBoundsCheckingPass();
143
144 /// \brief This pass splits the stack into a safe stack and an unsafe stack to
145 /// protect against stack-based overflow vulnerabilities.
146 FunctionPass *createSafeStackPass();
147
148 } // End llvm namespace
149
150 #endif