1259698Sdim//===- llvm/Transforms/Instrumentation/DebugIR.h - Interface ----*- C++ -*-===// 2259698Sdim// 3259698Sdim// The LLVM Compiler Infrastructure 4259698Sdim// 5259698Sdim// This file is distributed under the University of Illinois Open Source 6259698Sdim// License. See LICENSE.TXT for details. 7259698Sdim// 8259698Sdim//===----------------------------------------------------------------------===// 9259698Sdim// 10259698Sdim// This file defines the interface of the DebugIR pass. For most users, 11259698Sdim// including Instrumentation.h and calling createDebugIRPass() is sufficient and 12259698Sdim// there is no need to include this file. 13259698Sdim// 14259698Sdim//===----------------------------------------------------------------------===// 15259698Sdim 16259698Sdim#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H 17259698Sdim#define LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H 18259698Sdim 19259698Sdim#include "llvm/ADT/OwningPtr.h" 20259698Sdim#include "llvm/Pass.h" 21259698Sdim 22259698Sdimnamespace llvm { 23259698Sdim 24259698Sdimclass DebugIR : public llvm::ModulePass { 25259698Sdim /// If true, write a source file to disk. 26259698Sdim bool WriteSourceToDisk; 27259698Sdim 28259698Sdim /// Hide certain (non-essential) debug information (only relevant if 29259698Sdim /// createSource is true. 30259698Sdim bool HideDebugIntrinsics; 31259698Sdim bool HideDebugMetadata; 32259698Sdim 33259698Sdim /// The location of the source file. 34259698Sdim std::string Directory; 35259698Sdim std::string Filename; 36259698Sdim 37259698Sdim /// True if a temporary file name was generated. 38259698Sdim bool GeneratedPath; 39259698Sdim 40259698Sdim /// True if the file name was read from the Module. 41259698Sdim bool ParsedPath; 42259698Sdim 43259698Sdimpublic: 44259698Sdim static char ID; 45259698Sdim 46259698Sdim const char *getPassName() const { return "DebugIR"; } 47259698Sdim 48259698Sdim /// Generate a file on disk to be displayed in a debugger. If Filename and 49259698Sdim /// Directory are empty, a temporary path will be generated. 50259698Sdim DebugIR(bool HideDebugIntrinsics, bool HideDebugMetadata, 51259698Sdim llvm::StringRef Directory, llvm::StringRef Filename) 52259698Sdim : ModulePass(ID), WriteSourceToDisk(true), 53259698Sdim HideDebugIntrinsics(HideDebugIntrinsics), 54259698Sdim HideDebugMetadata(HideDebugMetadata), Directory(Directory), 55259698Sdim Filename(Filename), GeneratedPath(false), ParsedPath(false) {} 56259698Sdim 57259698Sdim /// Modify input in-place; do not generate additional files, and do not hide 58259698Sdim /// any debug intrinsics/metadata that might be present. 59259698Sdim DebugIR() 60259698Sdim : ModulePass(ID), WriteSourceToDisk(false), HideDebugIntrinsics(false), 61259698Sdim HideDebugMetadata(false), GeneratedPath(false), ParsedPath(false) {} 62259698Sdim 63259698Sdim /// Run pass on M and set Path to the source file path in the output module. 64259698Sdim bool runOnModule(llvm::Module &M, std::string &Path); 65259698Sdim bool runOnModule(llvm::Module &M); 66259698Sdim 67259698Sdimprivate: 68259698Sdim 69259698Sdim /// Returns the concatenated Directory + Filename, without error checking 70259698Sdim std::string getPath(); 71259698Sdim 72259698Sdim /// Attempts to read source information from debug information in M, and if 73259698Sdim /// that fails, from M's identifier. Returns true on success, false otherwise. 74259698Sdim bool getSourceInfo(const llvm::Module &M); 75259698Sdim 76259698Sdim /// Replace the extension of Filename with NewExtension, and return true if 77259698Sdim /// successful. Return false if extension could not be found or Filename is 78259698Sdim /// empty. 79259698Sdim bool updateExtension(llvm::StringRef NewExtension); 80259698Sdim 81259698Sdim /// Generate a temporary filename and open an fd 82259698Sdim void generateFilename(llvm::OwningPtr<int> &fd); 83259698Sdim 84259698Sdim /// Creates DWARF CU/Subroutine metadata 85259698Sdim void createDebugInfo(llvm::Module &M, 86259698Sdim llvm::OwningPtr<llvm::Module> &DisplayM); 87259698Sdim 88259698Sdim /// Returns true if either Directory or Filename is missing, false otherwise. 89259698Sdim bool isMissingPath(); 90259698Sdim 91259698Sdim /// Write M to disk, optionally passing in an fd to an open file which is 92259698Sdim /// closed by this function after writing. If no fd is specified, a new file 93259698Sdim /// is opened, written, and closed. 94259698Sdim void writeDebugBitcode(const llvm::Module *M, int *fd = 0); 95259698Sdim}; 96259698Sdim 97259698Sdim} // llvm namespace 98259698Sdim 99259698Sdim#endif // LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H 100