LLVM 20.0.0git
DebugLoc.h
Go to the documentation of this file.
1//===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines a number of light weight data structures used
10// to describe and track debug location information.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_DEBUGLOC_H
15#define LLVM_IR_DEBUGLOC_H
16
19
20namespace llvm {
21
22 class LLVMContext;
23 class raw_ostream;
24 class DILocation;
25
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 {
35
36 public:
37 DebugLoc() = default;
38
39 /// Construct from an \a DILocation.
40 DebugLoc(const DILocation *L);
41
42 /// Construct from an \a MDNode.
43 ///
44 /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
45 /// accessors will crash. However, construction from other nodes is
46 /// supported in order to handle forward references when reading textual
47 /// IR.
48 explicit DebugLoc(const MDNode *N);
49
50 /// Get the underlying \a DILocation.
51 ///
52 /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
53 /// @{
54 DILocation *get() const;
55 operator DILocation *() const { return get(); }
56 DILocation *operator->() const { return get(); }
57 DILocation &operator*() const { return *get(); }
58 /// @}
59
60 /// Check for null.
61 ///
62 /// Check for null in a way that is safe with broken debug info. Unlike
63 /// the conversion to \c DILocation, this doesn't require that \c Loc is of
64 /// the right type. Important for cases like \a llvm::StripDebugInfo() and
65 /// \a Instruction::hasMetadata().
66 explicit operator bool() const { return Loc; }
67
68 /// Check whether this has a trivial destructor.
69 bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
70
71 enum { ReplaceLastInlinedAt = true };
72 /// Rebuild the entire inlined-at chain for this instruction so that the top of
73 /// the chain now is inlined-at the new call site.
74 /// \param InlinedAt The new outermost inlined-at in the chain.
75 static DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt,
76 LLVMContext &Ctx,
78
79 unsigned getLine() const;
80 unsigned getCol() const;
81 MDNode *getScope() const;
82 DILocation *getInlinedAt() const;
83
84 /// Get the fully inlined-at scope for a DebugLoc.
85 ///
86 /// Gets the inlined-at scope for a DebugLoc.
88
89 /// Rebuild the entire inline-at chain by replacing the subprogram at the
90 /// end of the chain with NewSP.
91 static DebugLoc
93 LLVMContext &Ctx,
95
96 /// Find the debug info location for the start of the function.
97 ///
98 /// Walk up the scope chain of given debug loc and find line number info
99 /// for the function.
100 ///
101 /// FIXME: Remove this. Users should use DILocation/DILocalScope API to
102 /// find the subprogram, and then DILocation::get().
103 DebugLoc getFnDebugLoc() const;
104
105 /// Return \c this as a bar \a MDNode.
106 MDNode *getAsMDNode() const { return Loc; }
107
108 /// Check if the DebugLoc corresponds to an implicit code.
109 bool isImplicitCode() const;
110 void setImplicitCode(bool ImplicitCode);
111
112 bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
113 bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
114
115 void dump() const;
116
117 /// prints source location /path/to/file.exe:line:col @[inlined at]
118 void print(raw_ostream &OS) const;
119 };
120
121} // end namespace llvm
122
123#endif // LLVM_IR_DEBUGLOC_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
raw_pwrite_stream & OS
Debug location.
Subprogram description.
A debug info location.
Definition: DebugLoc.h:33
void setImplicitCode(bool ImplicitCode)
Definition: DebugLoc.cpp:64
DILocation & operator*() const
Definition: DebugLoc.h:57
bool operator==(const DebugLoc &DL) const
Definition: DebugLoc.h:112
DebugLoc()=default
unsigned getLine() const
Definition: DebugLoc.cpp:24
DebugLoc getFnDebugLoc() const
Find the debug info location for the start of the function.
Definition: DebugLoc.cpp:48
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:20
MDNode * getScope() const
Definition: DebugLoc.cpp:34
static DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inlined-at chain for this instruction so that the top of the chain now is inlined-...
Definition: DebugLoc.cpp:110
DILocation * operator->() const
Definition: DebugLoc.h:56
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Definition: DebugLoc.h:69
void print(raw_ostream &OS) const
prints source location /path/to/file.exe:line:col @[inlined at]
Definition: DebugLoc.cpp:143
MDNode * getAsMDNode() const
Return this as a bar MDNode.
Definition: DebugLoc.h:106
unsigned getCol() const
Definition: DebugLoc.cpp:29
static DebugLoc replaceInlinedAtSubprogram(const DebugLoc &DL, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inline-at chain by replacing the subprogram at the end of the chain with NewSP.
Definition: DebugLoc.cpp:70
bool isImplicitCode() const
Check if the DebugLoc corresponds to an implicit code.
Definition: DebugLoc.cpp:57
void dump() const
Definition: DebugLoc.cpp:140
DILocation * getInlinedAt() const
Definition: DebugLoc.cpp:39
@ ReplaceLastInlinedAt
Definition: DebugLoc.h:71
bool operator!=(const DebugLoc &DL) const
Definition: DebugLoc.h:113
MDNode * getInlinedAtScope() const
Get the fully inlined-at scope for a DebugLoc.
Definition: DebugLoc.cpp:44
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1069
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
#define N