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 // Insert SanitizerCoverage instrumentation.
00082 ModulePass *createSanitizerCoverageModulePass(int CoverageLevel);
00083 
00084 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
00085 inline ModulePass *createDataFlowSanitizerPassForJIT(StringRef ABIListFile =
00086                                                          StringRef()) {
00087   return createDataFlowSanitizerPass(ABIListFile, getDFSanArgTLSPtrForJIT,
00088                                      getDFSanRetValTLSPtrForJIT);
00089 }
00090 #endif
00091 
00092 // BoundsChecking - This pass instruments the code to perform run-time bounds
00093 // checking on loads, stores, and other memory intrinsics.
00094 FunctionPass *createBoundsCheckingPass();
00095 
00096 /// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB (or
00097 ///                     GDB) and generate a file with the LLVM IR to be
00098 ///                     displayed in the debugger.
00099 ///
00100 /// Existing debug metadata is preserved (but may be modified) in order to allow
00101 /// accessing variables in the original source. The line table and file
00102 /// information is modified to correspond to the lines in the LLVM IR. If
00103 /// Filename and Directory are empty, a file name is generated based on existing
00104 /// debug information. If no debug information is available, a temporary file
00105 /// name is generated.
00106 ///
00107 /// @param HideDebugIntrinsics  Omit debug intrinsics in emitted IR source file.
00108 /// @param HideDebugMetadata    Omit debug metadata in emitted IR source file.
00109 /// @param Directory            Embed this directory in the debug information.
00110 /// @param Filename             Embed this file name in the debug information.
00111 ModulePass *createDebugIRPass(bool HideDebugIntrinsics,
00112                               bool HideDebugMetadata,
00113                               StringRef Directory = StringRef(),
00114                               StringRef Filename = StringRef());
00115 
00116 /// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB
00117 ///                     (or GDB) with an existing IR file on disk. When creating
00118 ///                     a DebugIR pass with this function, no source file is
00119 ///                     output to disk and the existing one is unmodified. Debug
00120 ///                     metadata in the Module is created/updated to point to
00121 ///                     the existing textual IR file on disk.
00122 /// NOTE: If the IR file to be debugged is not on disk, use the version of this
00123 ///       function with parameters in order to generate the file that will be
00124 ///       seen by the debugger.
00125 ModulePass *createDebugIRPass();
00126 
00127 } // End llvm namespace
00128 
00129 #endif