1 //===-- llvm/CodeGen/DebugLocEntry.h - Entry in debug_loc list -*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H__
11 #define CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H__
12 #include "llvm/IR/Constants.h"
13 #include "llvm/IR/DebugInfo.h"
14 #include "llvm/MC/MachineLocation.h"
15 #include "llvm/MC/MCSymbol.h"
18 class DwarfCompileUnit;
20 /// \brief This struct describes location entries emitted in the .debug_loc
23 // Begin and end symbols for the address range that this location is valid.
24 const MCSymbol *Begin;
28 /// A single location or constant.
30 Value(const MDNode *Var, int64_t i)
31 : Variable(Var), EntryKind(E_Integer) {
34 Value(const MDNode *Var, const ConstantFP *CFP)
35 : Variable(Var), EntryKind(E_ConstantFP) {
38 Value(const MDNode *Var, const ConstantInt *CIP)
39 : Variable(Var), EntryKind(E_ConstantInt) {
42 Value(const MDNode *Var, MachineLocation Loc)
43 : Variable(Var), EntryKind(E_Location), Loc(Loc) {
46 // The variable to which this location entry corresponds.
47 const MDNode *Variable;
49 // Type of entry that this represents.
50 enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
51 enum EntryType EntryKind;
56 const ConstantFP *CFP;
57 const ConstantInt *CIP;
60 // Or a location in the machine frame.
63 bool operator==(const Value &other) const {
64 if (EntryKind != other.EntryKind)
69 return Loc == other.Loc;
71 return Constant.Int == other.Constant.Int;
73 return Constant.CFP == other.Constant.CFP;
75 return Constant.CIP == other.Constant.CIP;
77 llvm_unreachable("unhandled EntryKind");
80 bool isLocation() const { return EntryKind == E_Location; }
81 bool isInt() const { return EntryKind == E_Integer; }
82 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
83 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
84 int64_t getInt() const { return Constant.Int; }
85 const ConstantFP *getConstantFP() const { return Constant.CFP; }
86 const ConstantInt *getConstantInt() const { return Constant.CIP; }
87 MachineLocation getLoc() const { return Loc; }
88 const MDNode *getVariable() const { return Variable; }
91 /// A list of locations/constants belonging to this entry.
92 SmallVector<Value, 1> Values;
94 /// The compile unit that this location entry is referenced by.
95 const DwarfCompileUnit *Unit;
98 DebugLocEntry() : Begin(nullptr), End(nullptr), Unit(nullptr) {}
99 DebugLocEntry(const MCSymbol *B, const MCSymbol *E,
100 Value Val, const DwarfCompileUnit *U)
101 : Begin(B), End(E), Unit(U) {
102 Values.push_back(std::move(Val));
105 /// \brief Attempt to merge this DebugLocEntry with Next and return
106 /// true if the merge was successful. Entries can be merged if they
107 /// share the same Loc/Constant and if Next immediately follows this
109 bool Merge(const DebugLocEntry &Next) {
110 // If this and Next are describing different pieces of the same
111 // variable, merge them by appending next's values to the current
113 if (Begin == Next.Begin && Values.size() > 0 && Next.Values.size() > 0) {
114 DIVariable Var(Values[0].Variable);
115 DIVariable NextVar(Next.Values[0].Variable);
116 if (Var.getName() == NextVar.getName() &&
117 Var.isVariablePiece() && NextVar.isVariablePiece()) {
118 Values.append(Next.Values.begin(), Next.Values.end());
123 // If this and Next are describing the same variable, merge them.
124 if ((End == Next.Begin && Values == Next.Values)) {
131 const MCSymbol *getBeginSym() const { return Begin; }
132 const MCSymbol *getEndSym() const { return End; }
133 const DwarfCompileUnit *getCU() const { return Unit; }
134 const ArrayRef<Value> getValues() const { return Values; }
135 void addValue(Value Val) {
136 assert(DIVariable(Val.Variable).isVariablePiece() &&
137 "multi-value DebugLocEntries must be pieces");
138 Values.push_back(Val);