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