1 //===- DebugLoc.h - Debug Location Information ------------------*- 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 a number of light weight data structures used
11 // to describe and track debug location information.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_DEBUGLOC_H
16 #define LLVM_IR_DEBUGLOC_H
18 #include "llvm/IR/TrackingMDRef.h"
19 #include "llvm/Support/DataTypes.h"
27 /// \brief A debug info location.
29 /// This class is a wrapper around a tracking reference to an \a DILocation
32 /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
33 /// one based on relatively opaque \a MDNode pointers.
35 TrackingMDNodeRef Loc;
40 /// \brief Construct from an \a DILocation.
41 DebugLoc(const DILocation *L);
43 /// \brief Construct from an \a MDNode.
45 /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
46 /// accessors will crash. However, construction from other nodes is
47 /// supported in order to handle forward references when reading textual
49 explicit DebugLoc(const MDNode *N);
51 /// \brief Get the underlying \a DILocation.
53 /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
55 DILocation *get() const;
56 operator DILocation *() const { return get(); }
57 DILocation *operator->() const { return get(); }
58 DILocation &operator*() const { return *get(); }
61 /// \brief Check for null.
63 /// Check for null in a way that is safe with broken debug info. Unlike
64 /// the conversion to \c DILocation, this doesn't require that \c Loc is of
65 /// the right type. Important for cases like \a llvm::StripDebugInfo() and
66 /// \a Instruction::hasMetadata().
67 explicit operator bool() const { return Loc; }
69 /// \brief Check whether this has a trivial destructor.
70 bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
72 /// \brief Create a new DebugLoc.
74 /// Create a new DebugLoc at the specified line/col and scope/inline. This
75 /// forwards to \a DILocation::get().
77 /// If \c !Scope, returns a default-constructed \a DebugLoc.
79 /// FIXME: Remove this. Users should use DILocation::get().
80 static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope,
81 const MDNode *InlinedAt = nullptr);
83 enum { ReplaceLastInlinedAt = true };
84 /// Rebuild the entire inlined-at chain for this instruction so that the top of
85 /// the chain now is inlined-at the new call site.
86 /// \param InlinedAt The new outermost inlined-at in the chain.
87 /// \param ReplaceLast Replace the last location in the inlined-at chain.
88 static DebugLoc appendInlinedAt(DebugLoc DL, DILocation *InlinedAt,
90 DenseMap<const MDNode *, MDNode *> &Cache,
91 bool ReplaceLast = false);
93 unsigned getLine() const;
94 unsigned getCol() const;
95 MDNode *getScope() const;
96 DILocation *getInlinedAt() const;
98 /// \brief Get the fully inlined-at scope for a DebugLoc.
100 /// Gets the inlined-at scope for a DebugLoc.
101 MDNode *getInlinedAtScope() const;
103 /// \brief Find the debug info location for the start of the function.
105 /// Walk up the scope chain of given debug loc and find line number info
106 /// for the function.
108 /// FIXME: Remove this. Users should use DILocation/DILocalScope API to
109 /// find the subprogram, and then DILocation::get().
110 DebugLoc getFnDebugLoc() const;
112 /// \brief Return \c this as a bar \a MDNode.
113 MDNode *getAsMDNode() const { return Loc; }
115 bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
116 bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
120 /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
121 void print(raw_ostream &OS) const;
124 } // end namespace llvm
126 #endif /* LLVM_SUPPORT_DEBUGLOC_H */