LLVM  mainline
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 #include <vector>
00019 
00020 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
00021 inline void *getDFSanArgTLSPtrForJIT() {
00022   extern __thread __attribute__((tls_model("initial-exec")))
00023     void *__dfsan_arg_tls;
00024   return (void *)&__dfsan_arg_tls;
00025 }
00026 
00027 inline void *getDFSanRetValTLSPtrForJIT() {
00028   extern __thread __attribute__((tls_model("initial-exec")))
00029     void *__dfsan_retval_tls;
00030   return (void *)&__dfsan_retval_tls;
00031 }
00032 #endif
00033 
00034 namespace llvm {
00035 
00036 class ModulePass;
00037 class FunctionPass;
00038 
00039 // Insert GCOV profiling instrumentation
00040 struct GCOVOptions {
00041   static GCOVOptions getDefault();
00042 
00043   // Specify whether to emit .gcno files.
00044   bool EmitNotes;
00045 
00046   // Specify whether to modify the program to emit .gcda files when run.
00047   bool EmitData;
00048 
00049   // A four-byte version string. The meaning of a version string is described in
00050   // gcc's gcov-io.h
00051   char Version[4];
00052 
00053   // Emit a "cfg checksum" that follows the "line number checksum" of a
00054   // function. This affects both .gcno and .gcda files.
00055   bool UseCfgChecksum;
00056 
00057   // Add the 'noredzone' attribute to added runtime library calls.
00058   bool NoRedZone;
00059 
00060   // Emit the name of the function in the .gcda files. This is redundant, as
00061   // the function identifier can be used to find the name from the .gcno file.
00062   bool FunctionNamesInData;
00063 
00064   // Emit the exit block immediately after the start block, rather than after
00065   // all of the function body's blocks.
00066   bool ExitBlockBeforeBody;
00067 };
00068 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
00069                                    GCOVOptions::getDefault());
00070 
00071 /// Options for the frontend instrumentation based profiling pass.
00072 struct InstrProfOptions {
00073   InstrProfOptions() : NoRedZone(false) {}
00074 
00075   // Add the 'noredzone' attribute to added runtime library calls.
00076   bool NoRedZone;
00077 
00078   // Name of the profile file to use as output
00079   std::string InstrProfileOutput;
00080 };
00081 
00082 /// Insert frontend instrumentation based profiling.
00083 ModulePass *createInstrProfilingPass(
00084     const InstrProfOptions &Options = InstrProfOptions());
00085 
00086 // Insert AddressSanitizer (address sanity checking) instrumentation
00087 FunctionPass *createAddressSanitizerFunctionPass();
00088 ModulePass *createAddressSanitizerModulePass();
00089 
00090 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
00091 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
00092 
00093 // Insert ThreadSanitizer (race detection) instrumentation
00094 FunctionPass *createThreadSanitizerPass();
00095 
00096 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
00097 ModulePass *createDataFlowSanitizerPass(
00098     const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
00099     void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
00100 
00101 // Insert SanitizerCoverage instrumentation.
00102 ModulePass *createSanitizerCoverageModulePass(int CoverageLevel);
00103 
00104 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
00105 inline ModulePass *createDataFlowSanitizerPassForJIT(
00106     const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
00107   return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
00108                                      getDFSanRetValTLSPtrForJIT);
00109 }
00110 #endif
00111 
00112 // BoundsChecking - This pass instruments the code to perform run-time bounds
00113 // checking on loads, stores, and other memory intrinsics.
00114 FunctionPass *createBoundsCheckingPass();
00115 
00116 } // End llvm namespace
00117 
00118 #endif