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 #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 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
00065                                    GCOVOptions::getDefault());
00066 
00067 /// Options for the frontend instrumentation based profiling pass.
00068 struct InstrProfOptions {
00069   InstrProfOptions() : NoRedZone(false) {}
00070 
00071   // Add the 'noredzone' attribute to added runtime library calls.
00072   bool NoRedZone;
00073 };
00074 
00075 /// Insert frontend instrumentation based profiling.
00076 ModulePass *createInstrProfilingPass(
00077     const InstrProfOptions &Options = InstrProfOptions());
00078 
00079 // Insert AddressSanitizer (address sanity checking) instrumentation
00080 FunctionPass *createAddressSanitizerFunctionPass();
00081 ModulePass *createAddressSanitizerModulePass();
00082 
00083 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
00084 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
00085 
00086 // Insert ThreadSanitizer (race detection) instrumentation
00087 FunctionPass *createThreadSanitizerPass();
00088 
00089 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
00090 ModulePass *createDataFlowSanitizerPass(
00091     const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
00092     void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
00093 
00094 // Insert SanitizerCoverage instrumentation.
00095 ModulePass *createSanitizerCoverageModulePass(int CoverageLevel);
00096 
00097 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
00098 inline ModulePass *createDataFlowSanitizerPassForJIT(
00099     const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
00100   return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
00101                                      getDFSanRetValTLSPtrForJIT);
00102 }
00103 #endif
00104 
00105 // BoundsChecking - This pass instruments the code to perform run-time bounds
00106 // checking on loads, stores, and other memory intrinsics.
00107 FunctionPass *createBoundsCheckingPass();
00108 
00109 } // End llvm namespace
00110 
00111 #endif