DebugLoc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines a number of light weight data structures used
  15. // to describe and track debug location information.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_DEBUGLOC_H
  19. #define LLVM_IR_DEBUGLOC_H
  20. #include "llvm/IR/TrackingMDRef.h"
  21. #include "llvm/Support/DataTypes.h"
  22. namespace llvm {
  23. class LLVMContext;
  24. class raw_ostream;
  25. class DILocation;
  26. /// A debug info location.
  27. ///
  28. /// This class is a wrapper around a tracking reference to an \a DILocation
  29. /// pointer.
  30. ///
  31. /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
  32. /// one based on relatively opaque \a MDNode pointers.
  33. class DebugLoc {
  34. TrackingMDNodeRef Loc;
  35. public:
  36. DebugLoc() = default;
  37. /// Construct from an \a DILocation.
  38. DebugLoc(const DILocation *L);
  39. /// Construct from an \a MDNode.
  40. ///
  41. /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
  42. /// accessors will crash. However, construction from other nodes is
  43. /// supported in order to handle forward references when reading textual
  44. /// IR.
  45. explicit DebugLoc(const MDNode *N);
  46. /// Get the underlying \a DILocation.
  47. ///
  48. /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
  49. /// @{
  50. DILocation *get() const;
  51. operator DILocation *() const { return get(); }
  52. DILocation *operator->() const { return get(); }
  53. DILocation &operator*() const { return *get(); }
  54. /// @}
  55. /// Check for null.
  56. ///
  57. /// Check for null in a way that is safe with broken debug info. Unlike
  58. /// the conversion to \c DILocation, this doesn't require that \c Loc is of
  59. /// the right type. Important for cases like \a llvm::StripDebugInfo() and
  60. /// \a Instruction::hasMetadata().
  61. explicit operator bool() const { return Loc; }
  62. /// Check whether this has a trivial destructor.
  63. bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
  64. enum { ReplaceLastInlinedAt = true };
  65. /// Rebuild the entire inlined-at chain for this instruction so that the top of
  66. /// the chain now is inlined-at the new call site.
  67. /// \param InlinedAt The new outermost inlined-at in the chain.
  68. static DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt,
  69. LLVMContext &Ctx,
  70. DenseMap<const MDNode *, MDNode *> &Cache);
  71. unsigned getLine() const;
  72. unsigned getCol() const;
  73. MDNode *getScope() const;
  74. DILocation *getInlinedAt() const;
  75. /// Get the fully inlined-at scope for a DebugLoc.
  76. ///
  77. /// Gets the inlined-at scope for a DebugLoc.
  78. MDNode *getInlinedAtScope() const;
  79. /// Find the debug info location for the start of the function.
  80. ///
  81. /// Walk up the scope chain of given debug loc and find line number info
  82. /// for the function.
  83. ///
  84. /// FIXME: Remove this. Users should use DILocation/DILocalScope API to
  85. /// find the subprogram, and then DILocation::get().
  86. DebugLoc getFnDebugLoc() const;
  87. /// Return \c this as a bar \a MDNode.
  88. MDNode *getAsMDNode() const { return Loc; }
  89. /// Check if the DebugLoc corresponds to an implicit code.
  90. bool isImplicitCode() const;
  91. void setImplicitCode(bool ImplicitCode);
  92. bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
  93. bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
  94. void dump() const;
  95. /// prints source location /path/to/file.exe:line:col @[inlined at]
  96. void print(raw_ostream &OS) const;
  97. };
  98. } // end namespace llvm
  99. #endif // LLVM_IR_DEBUGLOC_H
  100. #ifdef __GNUC__
  101. #pragma GCC diagnostic pop
  102. #endif