IR: Split Metadata from Value
[oota-llvm.git] / include / llvm / IR / DebugLoc.h
1 //===- DebugLoc.h - Debug Location Information ------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a number of light weight data structures used
11 // to describe and track debug location information.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_DEBUGLOC_H
16 #define LLVM_IR_DEBUGLOC_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/IR/TrackingMDRef.h"
20
21 namespace llvm {
22
23   class LLVMContext;
24   class raw_ostream;
25   class MDNode;
26
27   /// DebugLoc - Debug location id.  This is carried by Instruction, SDNode,
28   /// and MachineInstr to compactly encode file/line/scope information for an
29   /// operation.
30   class DebugLoc {
31     TrackingMDNodeRef Loc;
32
33   public:
34     DebugLoc() {}
35     DebugLoc(DebugLoc &&X) : Loc(std::move(X.Loc)) {}
36     DebugLoc(const DebugLoc &X) : Loc(X.Loc) {}
37     DebugLoc &operator=(DebugLoc &&X) {
38       Loc = std::move(X.Loc);
39       return *this;
40     }
41     DebugLoc &operator=(const DebugLoc &X) {
42       Loc = X.Loc;
43       return *this;
44     }
45
46     /// \brief Check whether this has a trivial destructor.
47     bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
48
49     /// get - Get a new DebugLoc that corresponds to the specified line/col
50     /// scope/inline location.
51     static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope,
52                         MDNode *InlinedAt = nullptr);
53
54     /// getFromDILocation - Translate the DILocation quad into a DebugLoc.
55     static DebugLoc getFromDILocation(MDNode *N);
56
57     /// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
58     static DebugLoc getFromDILexicalBlock(MDNode *N);
59
60     /// isUnknown - Return true if this is an unknown location.
61     bool isUnknown() const { return !Loc; }
62
63     unsigned getLine() const;
64     unsigned getCol() const;
65
66     /// getScope - This returns the scope pointer for this DebugLoc, or null if
67     /// invalid.
68     MDNode *getScope() const;
69     MDNode *getScope(const LLVMContext &) const { return getScope(); }
70
71     /// getInlinedAt - This returns the InlinedAt pointer for this DebugLoc, or
72     /// null if invalid or not present.
73     MDNode *getInlinedAt() const;
74     MDNode *getInlinedAt(const LLVMContext &) const { return getInlinedAt(); }
75
76     /// getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
77     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const;
78     void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
79                               const LLVMContext &) const {
80       return getScopeAndInlinedAt(Scope, IA);
81     }
82
83     /// getScopeNode - Get MDNode for DebugLoc's scope, or null if invalid.
84     MDNode *getScopeNode() const;
85     MDNode *getScopeNode(const LLVMContext &) const { return getScopeNode(); }
86
87     // getFnDebugLoc - Walk up the scope chain of given debug loc and find line
88     // number info for the function.
89     DebugLoc getFnDebugLoc() const;
90     DebugLoc getFnDebugLoc(const LLVMContext &) const {
91       return getFnDebugLoc();
92     }
93
94     /// getAsMDNode - This method converts the compressed DebugLoc node into a
95     /// DILocation compatible MDNode.
96     MDNode *getAsMDNode() const;
97     MDNode *getAsMDNode(LLVMContext &) const { return getAsMDNode(); }
98
99     bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
100     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
101
102     void dump() const;
103     void dump(const LLVMContext &) const { dump(); }
104     /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
105     void print(raw_ostream &OS) const;
106     void print(const LLVMContext &, raw_ostream &OS) const { print(OS); }
107   };
108
109 } // end namespace llvm
110
111 #endif /* LLVM_SUPPORT_DEBUGLOC_H */