Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 pmbaty 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 {
34
    TrackingMDNodeRef Loc;
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,
77
                                    DenseMap<const MDNode *, MDNode *> &Cache);
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
    /// Rebuild the entire inline-at chain by replacing the subprogram at the
90
    /// end of the chain with NewSP.
91
    static DebugLoc
92
    replaceInlinedAtSubprogram(const DebugLoc &DL, DISubprogram &NewSP,
93
                               LLVMContext &Ctx,
94
                               DenseMap<const MDNode *, MDNode *> &Cache);
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