1 //===- llvm/Transforms/Instrumentation/DebugIR.h - Interface ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface of the DebugIR pass. For most users,
11 // including Instrumentation.h and calling createDebugIRPass() is sufficient and
12 // there is no need to include this file.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
17 #define LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
19 #include "llvm/ADT/OwningPtr.h"
20 #include "llvm/Pass.h"
24 class DebugIR : public llvm::ModulePass {
25 /// If true, write a source file to disk.
26 bool WriteSourceToDisk;
28 /// Hide certain (non-essential) debug information (only relevant if
29 /// createSource is true.
30 bool HideDebugIntrinsics;
31 bool HideDebugMetadata;
33 /// The location of the source file.
34 std::string Directory;
37 /// True if a temporary file name was generated.
40 /// True if the file name was read from the Module.
46 const char *getPassName() const { return "DebugIR"; }
48 /// Generate a file on disk to be displayed in a debugger. If Filename and
49 /// Directory are empty, a temporary path will be generated.
50 DebugIR(bool HideDebugIntrinsics, bool HideDebugMetadata,
51 llvm::StringRef Directory, llvm::StringRef Filename)
52 : ModulePass(ID), WriteSourceToDisk(true),
53 HideDebugIntrinsics(HideDebugIntrinsics),
54 HideDebugMetadata(HideDebugMetadata), Directory(Directory),
55 Filename(Filename), GeneratedPath(false), ParsedPath(false) {}
57 /// Modify input in-place; do not generate additional files, and do not hide
58 /// any debug intrinsics/metadata that might be present.
60 : ModulePass(ID), WriteSourceToDisk(false), HideDebugIntrinsics(false),
61 HideDebugMetadata(false), GeneratedPath(false), ParsedPath(false) {}
63 /// Run pass on M and set Path to the source file path in the output module.
64 bool runOnModule(llvm::Module &M, std::string &Path);
65 bool runOnModule(llvm::Module &M);
69 /// Returns the concatenated Directory + Filename, without error checking
70 std::string getPath();
72 /// Attempts to read source information from debug information in M, and if
73 /// that fails, from M's identifier. Returns true on success, false otherwise.
74 bool getSourceInfo(const llvm::Module &M);
76 /// Replace the extension of Filename with NewExtension, and return true if
77 /// successful. Return false if extension could not be found or Filename is
79 bool updateExtension(llvm::StringRef NewExtension);
81 /// Generate a temporary filename and open an fd
82 void generateFilename(llvm::OwningPtr<int> &fd);
84 /// Creates DWARF CU/Subroutine metadata
85 void createDebugInfo(llvm::Module &M,
86 llvm::OwningPtr<llvm::Module> &DisplayM);
88 /// Returns true if either Directory or Filename is missing, false otherwise.
91 /// Write M to disk, optionally passing in an fd to an open file which is
92 /// closed by this function after writing. If no fd is specified, a new file
93 /// is opened, written, and closed.
94 void writeDebugBitcode(const llvm::Module *M, int *fd = 0);
99 #endif // LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H