LLVM API Documentation

Instrumentation.h
Go to the documentation of this file.
00001 //===- Transforms/Instrumentation.h - Instrumentation passes ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines constructor functions for instrumentation passes.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
00015 #define LLVM_TRANSFORMS_INSTRUMENTATION_H
00016 
00017 #include "llvm/ADT/StringRef.h"
00018 
00019 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
00020 inline void *getDFSanArgTLSPtrForJIT() {
00021   extern __thread __attribute__((tls_model("initial-exec")))
00022     void *__dfsan_arg_tls;
00023   return (void *)&__dfsan_arg_tls;
00024 }
00025 
00026 inline void *getDFSanRetValTLSPtrForJIT() {
00027   extern __thread __attribute__((tls_model("initial-exec")))
00028     void *__dfsan_retval_tls;
00029   return (void *)&__dfsan_retval_tls;
00030 }
00031 #endif
00032 
00033 namespace llvm {
00034 
00035 class ModulePass;
00036 class FunctionPass;
00037 
00038 // Insert GCOV profiling instrumentation
00039 struct GCOVOptions {
00040   static GCOVOptions getDefault();
00041 
00042   // Specify whether to emit .gcno files.
00043   bool EmitNotes;
00044 
00045   // Specify whether to modify the program to emit .gcda files when run.
00046   bool EmitData;
00047 
00048   // A four-byte version string. The meaning of a version string is described in
00049   // gcc's gcov-io.h
00050   char Version[4];
00051 
00052   // Emit a "cfg checksum" that follows the "line number checksum" of a
00053   // function. This affects both .gcno and .gcda files.
00054   bool UseCfgChecksum;
00055 
00056   // Add the 'noredzone' attribute to added runtime library calls.
00057   bool NoRedZone;
00058 
00059   // Emit the name of the function in the .gcda files. This is redundant, as
00060   // the function identifier can be used to find the name from the .gcno file.
00061   bool FunctionNamesInData;
00062 };
00063 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
00064                                    GCOVOptions::getDefault());
00065 
00066 // Insert AddressSanitizer (address sanity checking) instrumentation
00067 FunctionPass *createAddressSanitizerFunctionPass();
00068 ModulePass *createAddressSanitizerModulePass();
00069 
00070 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
00071 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
00072 
00073 // Insert ThreadSanitizer (race detection) instrumentation
00074 FunctionPass *createThreadSanitizerPass();
00075 
00076 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
00077 ModulePass *createDataFlowSanitizerPass(StringRef ABIListFile = StringRef(),
00078                                         void *(*getArgTLS)() = nullptr,
00079                                         void *(*getRetValTLS)() = nullptr);
00080 
00081 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
00082 inline ModulePass *createDataFlowSanitizerPassForJIT(StringRef ABIListFile =
00083                                                          StringRef()) {
00084   return createDataFlowSanitizerPass(ABIListFile, getDFSanArgTLSPtrForJIT,
00085                                      getDFSanRetValTLSPtrForJIT);
00086 }
00087 #endif
00088 
00089 // BoundsChecking - This pass instruments the code to perform run-time bounds
00090 // checking on loads, stores, and other memory intrinsics.
00091 FunctionPass *createBoundsCheckingPass();
00092 
00093 /// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB (or
00094 ///                     GDB) and generate a file with the LLVM IR to be
00095 ///                     displayed in the debugger.
00096 ///
00097 /// Existing debug metadata is preserved (but may be modified) in order to allow
00098 /// accessing variables in the original source. The line table and file
00099 /// information is modified to correspond to the lines in the LLVM IR. If
00100 /// Filename and Directory are empty, a file name is generated based on existing
00101 /// debug information. If no debug information is available, a temporary file
00102 /// name is generated.
00103 ///
00104 /// @param HideDebugIntrinsics  Omit debug intrinsics in emitted IR source file.
00105 /// @param HideDebugMetadata    Omit debug metadata in emitted IR source file.
00106 /// @param Directory            Embed this directory in the debug information.
00107 /// @param Filename             Embed this file name in the debug information.
00108 ModulePass *createDebugIRPass(bool HideDebugIntrinsics,
00109                               bool HideDebugMetadata,
00110                               StringRef Directory = StringRef(),
00111                               StringRef Filename = StringRef());
00112 
00113 /// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB
00114 ///                     (or GDB) with an existing IR file on disk. When creating
00115 ///                     a DebugIR pass with this function, no source file is
00116 ///                     output to disk and the existing one is unmodified. Debug
00117 ///                     metadata in the Module is created/updated to point to
00118 ///                     the existing textual IR file on disk.
00119 /// NOTE: If the IR file to be debugged is not on disk, use the version of this
00120 ///       function with parameters in order to generate the file that will be
00121 ///       seen by the debugger.
00122 ModulePass *createDebugIRPass();
00123 
00124 } // End llvm namespace
00125 
00126 #endif