DataFlowSanitizer: greylist is now ABI list.
[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
19 #if defined(__GNUC__) && defined(__linux__)
20 inline void *getDFSanArgTLSPtrForJIT() {
21   extern __thread __attribute__((tls_model("initial-exec")))
22     void *__dfsan_arg_tls;
23   return (void *)&__dfsan_arg_tls;
24 }
25
26 inline void *getDFSanRetValTLSPtrForJIT() {
27   extern __thread __attribute__((tls_model("initial-exec")))
28     void *__dfsan_retval_tls;
29   return (void *)&__dfsan_retval_tls;
30 }
31 #endif
32
33 namespace llvm {
34
35 class ModulePass;
36 class FunctionPass;
37
38 // Insert edge profiling instrumentation
39 ModulePass *createEdgeProfilerPass();
40
41 // Insert optimal edge profiling instrumentation
42 ModulePass *createOptimalEdgeProfilerPass();
43
44 // Insert path profiling instrumentation
45 ModulePass *createPathProfilerPass();
46
47 // Insert GCOV profiling instrumentation
48 struct GCOVOptions {
49   static GCOVOptions getDefault();
50
51   // Specify whether to emit .gcno files.
52   bool EmitNotes;
53
54   // Specify whether to modify the program to emit .gcda files when run.
55   bool EmitData;
56
57   // A four-byte version string. The meaning of a version string is described in
58   // gcc's gcov-io.h
59   char Version[4];
60
61   // Emit a "cfg checksum" that follows the "line number checksum" of a
62   // function. This affects both .gcno and .gcda files.
63   bool UseCfgChecksum;
64
65   // Add the 'noredzone' attribute to added runtime library calls.
66   bool NoRedZone;
67
68   // Emit the name of the function in the .gcda files. This is redundant, as
69   // the function identifier can be used to find the name from the .gcno file.
70   bool FunctionNamesInData;
71 };
72 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
73                                    GCOVOptions::getDefault());
74
75 // Insert AddressSanitizer (address sanity checking) instrumentation
76 FunctionPass *createAddressSanitizerFunctionPass(
77     bool CheckInitOrder = true, bool CheckUseAfterReturn = false,
78     bool CheckLifetime = false, StringRef BlacklistFile = StringRef(),
79     bool ZeroBaseShadow = false);
80 ModulePass *createAddressSanitizerModulePass(
81     bool CheckInitOrder = true, StringRef BlacklistFile = StringRef(),
82     bool ZeroBaseShadow = false);
83
84 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
85 FunctionPass *createMemorySanitizerPass(bool TrackOrigins = false,
86                                         StringRef BlacklistFile = StringRef());
87
88 // Insert ThreadSanitizer (race detection) instrumentation
89 FunctionPass *createThreadSanitizerPass(StringRef BlacklistFile = StringRef());
90
91 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
92 ModulePass *createDataFlowSanitizerPass(StringRef ABIListFile = StringRef(),
93                                         void *(*getArgTLS)() = 0,
94                                         void *(*getRetValTLS)() = 0);
95
96 #if defined(__GNUC__) && defined(__linux__)
97 inline ModulePass *createDataFlowSanitizerPassForJIT(StringRef ABIListFile =
98                                                          StringRef()) {
99   return createDataFlowSanitizerPass(ABIListFile, getDFSanArgTLSPtrForJIT,
100                                      getDFSanRetValTLSPtrForJIT);
101 }
102 #endif
103
104 // BoundsChecking - This pass instruments the code to perform run-time bounds
105 // checking on loads, stores, and other memory intrinsics.
106 FunctionPass *createBoundsCheckingPass();
107
108 /// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB (or
109 ///                     GDB) and generate a file with the LLVM IR to be
110 ///                     displayed in the debugger.
111 ///
112 /// Existing debug metadata is preserved (but may be modified) in order to allow
113 /// accessing variables in the original source. The line table and file
114 /// information is modified to correspond to the lines in the LLVM IR. If
115 /// Filename and Directory are empty, a file name is generated based on existing
116 /// debug information. If no debug information is available, a temporary file
117 /// name is generated.
118 ///
119 /// @param HideDebugIntrinsics  Omit debug intrinsics in emitted IR source file.
120 /// @param HideDebugMetadata    Omit debug metadata in emitted IR source file.
121 /// @param Directory            Embed this directory in the debug information.
122 /// @param Filename             Embed this file name in the debug information.
123 ModulePass *createDebugIRPass(bool HideDebugIntrinsics,
124                               bool HideDebugMetadata,
125                               StringRef Directory = StringRef(),
126                               StringRef Filename = StringRef());
127
128 /// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB
129 ///                     (or GDB) with an existing IR file on disk. When creating
130 ///                     a DebugIR pass with this function, no source file is
131 ///                     output to disk and the existing one is unmodified. Debug
132 ///                     metadata in the Module is created/updated to point to
133 ///                     the existing textual IR file on disk.
134 /// NOTE: If the IR file to be debugged is not on disk, use the version of this
135 ///       function with parameters in order to generate the file that will be
136 ///       seen by the debugger.
137 ModulePass *createDebugIRPass();
138
139 } // End llvm namespace
140
141 #endif