LLVM  14.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 
17 #include "llvm/IR/TrackingMDRef.h"
18 #include "llvm/Support/DataTypes.h"
19 
20 namespace 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.
87  MDNode *getInlinedAtScope() const;
88 
89  /// Find the debug info location for the start of the function.
90  ///
91  /// Walk up the scope chain of given debug loc and find line number info
92  /// for the function.
93  ///
94  /// FIXME: Remove this. Users should use DILocation/DILocalScope API to
95  /// find the subprogram, and then DILocation::get().
96  DebugLoc getFnDebugLoc() const;
97 
98  /// Return \c this as a bar \a MDNode.
99  MDNode *getAsMDNode() const { return Loc; }
100 
101  /// Check if the DebugLoc corresponds to an implicit code.
102  bool isImplicitCode() const;
103  void setImplicitCode(bool ImplicitCode);
104 
105  bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
106  bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
107 
108  void dump() const;
109 
110  /// prints source location /path/to/file.exe:line:col @[inlined at]
111  void print(raw_ostream &OS) const;
112  };
113 
114 } // end namespace llvm
115 
116 #endif // LLVM_IR_DEBUGLOC_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DebugLoc::getAsMDNode
MDNode * getAsMDNode() const
Return this as a bar MDNode.
Definition: DebugLoc.h:99
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1562
llvm::DebugLoc::getInlinedAt
DILocation * getInlinedAt() const
Definition: DebugLoc.cpp:40
llvm::DebugLoc::DebugLoc
DebugLoc()=default
llvm::DebugLoc::getCol
unsigned getCol() const
Definition: DebugLoc.cpp:30
llvm::DebugLoc::getFnDebugLoc
DebugLoc getFnDebugLoc() const
Find the debug info location for the start of the function.
Definition: DebugLoc.cpp:49
llvm::DebugLoc::dump
void dump() const
Definition: DebugLoc.cpp:101
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::DebugLoc::appendInlinedAt
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:71
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DenseMap
Definition: DenseMap.h:714
llvm::DebugLoc::get
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:21
llvm::DebugLoc::operator==
bool operator==(const DebugLoc &DL) const
Definition: DebugLoc.h:105
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::DebugLoc::hasTrivialDestructor
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Definition: DebugLoc.h:69
llvm::TypedTrackingMDRef::hasTrivialDestructor
bool hasTrivialDestructor() const
Check whether this has a trivial destructor.
Definition: TrackingMDRef.h:138
llvm::DebugLoc::setImplicitCode
void setImplicitCode(bool ImplicitCode)
Definition: DebugLoc.cpp:65
llvm::DebugLoc::isImplicitCode
bool isImplicitCode() const
Check if the DebugLoc corresponds to an implicit code.
Definition: DebugLoc.cpp:58
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::DebugLoc::operator!=
bool operator!=(const DebugLoc &DL) const
Definition: DebugLoc.h:106
llvm::DebugLoc::ReplaceLastInlinedAt
@ ReplaceLastInlinedAt
Definition: DebugLoc.h:71
llvm::DebugLoc::operator*
DILocation & operator*() const
Definition: DebugLoc.h:57
TrackingMDRef.h
llvm::DebugLoc::print
void print(raw_ostream &OS) const
prints source location /path/to/file.exe:line:col @[inlined at]
Definition: DebugLoc.cpp:104
llvm::DebugLoc::getLine
unsigned getLine() const
Definition: DebugLoc.cpp:25
llvm::TypedTrackingMDRef< MDNode >
N
#define N
DataTypes.h
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::DebugLoc::getInlinedAtScope
MDNode * getInlinedAtScope() const
Get the fully inlined-at scope for a DebugLoc.
Definition: DebugLoc.cpp:45
llvm::DebugLoc::getScope
MDNode * getScope() const
Definition: DebugLoc.cpp:35
llvm::DebugLoc::operator->
DILocation * operator->() const
Definition: DebugLoc.h:56