1145516Sdarrenr//===- Transforms/Instrumentation.h - Instrumentation passes ----*- C++ -*-===// 2145516Sdarrenr// 3145516Sdarrenr// The LLVM Compiler Infrastructure 4145516Sdarrenr// 5145516Sdarrenr// This file is distributed under the University of Illinois Open Source 6145516Sdarrenr// License. See LICENSE.TXT for details. 7145516Sdarrenr// 8145516Sdarrenr//===----------------------------------------------------------------------===// 9145516Sdarrenr// 10172776Sdarrenr// This file defines constructor functions for instrumentation passes. 11145516Sdarrenr// 12145516Sdarrenr//===----------------------------------------------------------------------===// 13145516Sdarrenr 14145516Sdarrenr#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H 15145516Sdarrenr#define LLVM_TRANSFORMS_INSTRUMENTATION_H 16145516Sdarrenr 17145516Sdarrenr#include "llvm/ADT/StringRef.h" 18145516Sdarrenr 19145516Sdarrenr#if defined(__GNUC__) && defined(__linux__) 20145516Sdarrenrinline void *getDFSanArgTLSPtrForJIT() { 21145516Sdarrenr extern __thread __attribute__((tls_model("initial-exec"))) 22145516Sdarrenr void *__dfsan_arg_tls; 23145516Sdarrenr return (void *)&__dfsan_arg_tls; 24145516Sdarrenr} 25145516Sdarrenr 26145516Sdarrenrinline void *getDFSanRetValTLSPtrForJIT() { 27145516Sdarrenr extern __thread __attribute__((tls_model("initial-exec"))) 28145516Sdarrenr void *__dfsan_retval_tls; 29145516Sdarrenr return (void *)&__dfsan_retval_tls; 30145516Sdarrenr} 31145516Sdarrenr#endif 32145516Sdarrenr 33145516Sdarrenrnamespace llvm { 34145516Sdarrenr 35145516Sdarrenrclass ModulePass; 36145516Sdarrenrclass FunctionPass; 37145516Sdarrenr 38145516Sdarrenr// Insert GCOV profiling instrumentation 39145516Sdarrenrstruct GCOVOptions { 40145516Sdarrenr static GCOVOptions getDefault(); 41145516Sdarrenr 42145516Sdarrenr // Specify whether to emit .gcno files. 43145516Sdarrenr bool EmitNotes; 44145516Sdarrenr 45145516Sdarrenr // Specify whether to modify the program to emit .gcda files when run. 46145516Sdarrenr bool EmitData; 47145516Sdarrenr 48145516Sdarrenr // A four-byte version string. The meaning of a version string is described in 49145516Sdarrenr // gcc's gcov-io.h 50145516Sdarrenr char Version[4]; 51145516Sdarrenr 52145516Sdarrenr // Emit a "cfg checksum" that follows the "line number checksum" of a 53145516Sdarrenr // function. This affects both .gcno and .gcda files. 54145516Sdarrenr bool UseCfgChecksum; 55145516Sdarrenr 56145516Sdarrenr // Add the 'noredzone' attribute to added runtime library calls. 57145516Sdarrenr bool NoRedZone; 58145516Sdarrenr 59145516Sdarrenr // Emit the name of the function in the .gcda files. This is redundant, as 60170268Sdarrenr // the function identifier can be used to find the name from the .gcno file. 61170268Sdarrenr bool FunctionNamesInData; 62170268Sdarrenr}; 63170268SdarrenrModulePass *createGCOVProfilerPass(const GCOVOptions &Options = 64170268Sdarrenr GCOVOptions::getDefault()); 65181803Sbz 66181803Sbz// Insert AddressSanitizer (address sanity checking) instrumentation 67181803SbzFunctionPass *createAddressSanitizerFunctionPass( 68181803Sbz bool CheckInitOrder = true, bool CheckUseAfterReturn = false, 69181803Sbz bool CheckLifetime = false, StringRef BlacklistFile = StringRef(), 70181803Sbz bool ZeroBaseShadow = false); 71145516SdarrenrModulePass *createAddressSanitizerModulePass( 72145516Sdarrenr bool CheckInitOrder = true, StringRef BlacklistFile = StringRef(), 73145516Sdarrenr bool ZeroBaseShadow = false); 74145516Sdarrenr 75170268Sdarrenr// Insert MemorySanitizer instrumentation (detection of uninitialized reads) 76170268SdarrenrFunctionPass *createMemorySanitizerPass(bool TrackOrigins = false, 77170268Sdarrenr StringRef BlacklistFile = StringRef()); 78145516Sdarrenr 79145516Sdarrenr// Insert ThreadSanitizer (race detection) instrumentation 80145516SdarrenrFunctionPass *createThreadSanitizerPass(StringRef BlacklistFile = StringRef()); 81145516Sdarrenr 82145516Sdarrenr// Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation 83145516SdarrenrModulePass *createDataFlowSanitizerPass(StringRef ABIListFile = StringRef(), 84145516Sdarrenr void *(*getArgTLS)() = 0, 85145516Sdarrenr void *(*getRetValTLS)() = 0); 86145516Sdarrenr 87145516Sdarrenr#if defined(__GNUC__) && defined(__linux__) 88145516Sdarrenrinline ModulePass *createDataFlowSanitizerPassForJIT(StringRef ABIListFile = 89145516Sdarrenr StringRef()) { 90145516Sdarrenr return createDataFlowSanitizerPass(ABIListFile, getDFSanArgTLSPtrForJIT, 91145516Sdarrenr getDFSanRetValTLSPtrForJIT); 92145516Sdarrenr} 93145516Sdarrenr#endif 94145516Sdarrenr 95189105Sbz// BoundsChecking - This pass instruments the code to perform run-time bounds 96189105Sbz// checking on loads, stores, and other memory intrinsics. 97189105SbzFunctionPass *createBoundsCheckingPass(); 98145516Sdarrenr 99145516Sdarrenr/// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB (or 100145516Sdarrenr/// GDB) and generate a file with the LLVM IR to be 101145516Sdarrenr/// displayed in the debugger. 102145516Sdarrenr/// 103145516Sdarrenr/// Existing debug metadata is preserved (but may be modified) in order to allow 104145516Sdarrenr/// accessing variables in the original source. The line table and file 105145516Sdarrenr/// information is modified to correspond to the lines in the LLVM IR. If 106145516Sdarrenr/// Filename and Directory are empty, a file name is generated based on existing 107145516Sdarrenr/// debug information. If no debug information is available, a temporary file 108145516Sdarrenr/// name is generated. 109145516Sdarrenr/// 110145516Sdarrenr/// @param HideDebugIntrinsics Omit debug intrinsics in emitted IR source file. 111145516Sdarrenr/// @param HideDebugMetadata Omit debug metadata in emitted IR source file. 112145516Sdarrenr/// @param Directory Embed this directory in the debug information. 113145516Sdarrenr/// @param Filename Embed this file name in the debug information. 114145516SdarrenrModulePass *createDebugIRPass(bool HideDebugIntrinsics, 115145516Sdarrenr bool HideDebugMetadata, 116145516Sdarrenr StringRef Directory = StringRef(), 117145516Sdarrenr StringRef Filename = StringRef()); 118145516Sdarrenr 119145516Sdarrenr/// createDebugIRPass - Enable interactive stepping through LLVM IR in LLDB 120145516Sdarrenr/// (or GDB) with an existing IR file on disk. When creating 121145516Sdarrenr/// a DebugIR pass with this function, no source file is 122145516Sdarrenr/// output to disk and the existing one is unmodified. Debug 123145516Sdarrenr/// metadata in the Module is created/updated to point to 124145516Sdarrenr/// the existing textual IR file on disk. 125145516Sdarrenr/// NOTE: If the IR file to be debugged is not on disk, use the version of this 126145516Sdarrenr/// function with parameters in order to generate the file that will be 127185419Szec/// seen by the debugger. 128145516SdarrenrModulePass *createDebugIRPass(); 129145516Sdarrenr 130145516Sdarrenr} // End llvm namespace 131145516Sdarrenr 132151897Srwatson#endif 133145516Sdarrenr