1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//                     The LLVM Compiler Infrastructure
4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source
6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details.
7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file defines a number of light weight data structures used
11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// to describe and track debug location information.
12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_IR_DEBUGLOC_H
16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_IR_DEBUGLOC_H
17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/TrackingMDRef.h"
19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/DataTypes.h"
20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace llvm {
22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class LLVMContext;
24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class raw_ostream;
25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class DILocation;
26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A debug info location.
28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This class is a wrapper around a tracking reference to an \a DILocation
30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// pointer.
31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// one based on relatively opaque \a MDNode pointers.
34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class DebugLoc {
35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    TrackingMDNodeRef Loc;
36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  public:
38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DebugLoc() = default;
39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Construct from an \a DILocation.
41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DebugLoc(const DILocation *L);
42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Construct from an \a MDNode.
44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// accessors will crash.  However, construction from other nodes is
47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// supported in order to handle forward references when reading textual
48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// IR.
49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    explicit DebugLoc(const MDNode *N);
50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Get the underlying \a DILocation.
52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// @{
55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DILocation *get() const;
56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    operator DILocation *() const { return get(); }
57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DILocation *operator->() const { return get(); }
58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DILocation &operator*() const { return *get(); }
59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// @}
60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Check for null.
62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Check for null in a way that is safe with broken debug info.  Unlike
64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// the conversion to \c DILocation, this doesn't require that \c Loc is of
65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// the right type.  Important for cases like \a llvm::StripDebugInfo() and
66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \a Instruction::hasMetadata().
67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    explicit operator bool() const { return Loc; }
68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Check whether this has a trivial destructor.
70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Create a new DebugLoc.
73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Create a new DebugLoc at the specified line/col and scope/inline.  This
75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// forwards to \a DILocation::get().
76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// If \c !Scope, returns a default-constructed \a DebugLoc.
78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// FIXME: Remove this.  Users should use DILocation::get().
80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope,
81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                        const MDNode *InlinedAt = nullptr);
82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    enum { ReplaceLastInlinedAt = true };
84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Rebuild the entire inlined-at chain for this instruction so that the top of
85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// the chain now is inlined-at the new call site.
86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \param   InlinedAt    The new outermost inlined-at in the chain.
87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \param   ReplaceLast  Replace the last location in the inlined-at chain.
88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    static DebugLoc appendInlinedAt(DebugLoc DL, DILocation *InlinedAt,
89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                    LLVMContext &Ctx,
90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                    DenseMap<const MDNode *, MDNode *> &Cache,
91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                    bool ReplaceLast = false);
92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned getLine() const;
94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned getCol() const;
95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    MDNode *getScope() const;
96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DILocation *getInlinedAt() const;
97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Get the fully inlined-at scope for a DebugLoc.
99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Gets the inlined-at scope for a DebugLoc.
101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    MDNode *getInlinedAtScope() const;
102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Find the debug info location for the start of the function.
104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Walk up the scope chain of given debug loc and find line number info
106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// for the function.
107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// FIXME: Remove this.  Users should use DILocation/DILocalScope API to
109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// find the subprogram, and then DILocation::get().
110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DebugLoc getFnDebugLoc() const;
111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief Return \c this as a bar \a MDNode.
113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    MDNode *getAsMDNode() const { return Loc; }
114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void dump() const;
119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void print(raw_ostream &OS) const;
122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // end namespace llvm
125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif /* LLVM_SUPPORT_DEBUGLOC_H */
127