Instrumentation.h revision 280031
1//===- Transforms/Instrumentation.h - Instrumentation passes ----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines constructor functions for instrumentation passes. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H 15#define LLVM_TRANSFORMS_INSTRUMENTATION_H 16 17#include "llvm/ADT/StringRef.h" 18 19#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID) 20inline void *getDFSanArgTLSPtrForJIT() { 21 extern __thread __attribute__((tls_model("initial-exec"))) 22 void *__dfsan_arg_tls; 23 return (void *)&__dfsan_arg_tls; 24} 25 26inline void *getDFSanRetValTLSPtrForJIT() { 27 extern __thread __attribute__((tls_model("initial-exec"))) 28 void *__dfsan_retval_tls; 29 return (void *)&__dfsan_retval_tls; 30} 31#endif 32 33namespace llvm { 34 35class ModulePass; 36class FunctionPass; 37 38// Insert GCOV profiling instrumentation 39struct GCOVOptions { 40 static GCOVOptions getDefault(); 41 42 // Specify whether to emit .gcno files. 43 bool EmitNotes; 44 45 // Specify whether to modify the program to emit .gcda files when run. 46 bool EmitData; 47 48 // A four-byte version string. The meaning of a version string is described in 49 // gcc's gcov-io.h 50 char Version[4]; 51 52 // Emit a "cfg checksum" that follows the "line number checksum" of a 53 // function. This affects both .gcno and .gcda files. 54 bool UseCfgChecksum; 55 56 // Add the 'noredzone' attribute to added runtime library calls. 57 bool NoRedZone; 58 59 // Emit the name of the function in the .gcda files. This is redundant, as 60 // the function identifier can be used to find the name from the .gcno file. 61 bool FunctionNamesInData; 62}; 63ModulePass *createGCOVProfilerPass(const GCOVOptions &Options = 64 GCOVOptions::getDefault()); 65 66/// Options for the frontend instrumentation based profiling pass. 67struct InstrProfOptions { 68 InstrProfOptions() : NoRedZone(false) {} 69 70 // Add the 'noredzone' attribute to added runtime library calls. 71 bool NoRedZone; 72}; 73 74/// Insert frontend instrumentation based profiling. 75ModulePass *createInstrProfilingPass( 76 const InstrProfOptions &Options = InstrProfOptions()); 77 78// Insert AddressSanitizer (address sanity checking) instrumentation 79FunctionPass *createAddressSanitizerFunctionPass(); 80ModulePass *createAddressSanitizerModulePass(); 81 82// Insert MemorySanitizer instrumentation (detection of uninitialized reads) 83FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0); 84 85// Insert ThreadSanitizer (race detection) instrumentation 86FunctionPass *createThreadSanitizerPass(); 87 88// Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation 89ModulePass *createDataFlowSanitizerPass(StringRef ABIListFile = StringRef(), 90 void *(*getArgTLS)() = nullptr, 91 void *(*getRetValTLS)() = nullptr); 92 93// Insert SanitizerCoverage instrumentation. 94ModulePass *createSanitizerCoverageModulePass(int CoverageLevel); 95 96#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID) 97inline ModulePass *createDataFlowSanitizerPassForJIT(StringRef ABIListFile = 98 StringRef()) { 99 return createDataFlowSanitizerPass(ABIListFile, getDFSanArgTLSPtrForJIT, 100 getDFSanRetValTLSPtrForJIT); 101} 102#endif 103 104// BoundsChecking - This pass instruments the code to perform run-time bounds 105// checking on loads, stores, and other memory intrinsics. 106FunctionPass *createBoundsCheckingPass(); 107 108} // End llvm namespace 109 110#endif 111