David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DebugLocEntry.h - Entry in debug_loc list -*- 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 | #ifndef CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H__ |
| 11 | #define CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H__ |
| 12 | #include "llvm/IR/Constants.h" |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame^] | 13 | #include "llvm/IR/DebugInfo.h" |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MachineLocation.h" |
| 15 | #include "llvm/MC/MCSymbol.h" |
| 16 | |
| 17 | namespace llvm { |
| 18 | class DwarfCompileUnit; |
| 19 | class MDNode; |
| 20 | /// \brief This struct describes location entries emitted in the .debug_loc |
| 21 | /// section. |
| 22 | class DebugLocEntry { |
| 23 | // Begin and end symbols for the address range that this location is valid. |
| 24 | const MCSymbol *Begin; |
| 25 | const MCSymbol *End; |
| 26 | |
Adrian Prantl | e19e5ef | 2014-04-27 18:25:40 +0000 | [diff] [blame] | 27 | public: |
| 28 | /// A single location or constant. |
| 29 | struct Value { |
| 30 | Value(const MDNode *Var, int64_t i) |
| 31 | : Variable(Var), EntryKind(E_Integer) { |
| 32 | Constant.Int = i; |
| 33 | } |
| 34 | Value(const MDNode *Var, const ConstantFP *CFP) |
| 35 | : Variable(Var), EntryKind(E_ConstantFP) { |
| 36 | Constant.CFP = CFP; |
| 37 | } |
| 38 | Value(const MDNode *Var, const ConstantInt *CIP) |
| 39 | : Variable(Var), EntryKind(E_ConstantInt) { |
| 40 | Constant.CIP = CIP; |
| 41 | } |
| 42 | Value(const MDNode *Var, MachineLocation Loc) |
| 43 | : Variable(Var), EntryKind(E_Location), Loc(Loc) { |
David Blaikie | d306baf | 2014-04-01 22:04:07 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Adrian Prantl | e19e5ef | 2014-04-27 18:25:40 +0000 | [diff] [blame] | 46 | // The variable to which this location entry corresponds. |
| 47 | const MDNode *Variable; |
| 48 | |
| 49 | // Type of entry that this represents. |
| 50 | enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt }; |
| 51 | enum EntryType EntryKind; |
| 52 | |
| 53 | // Either a constant, |
| 54 | union { |
| 55 | int64_t Int; |
| 56 | const ConstantFP *CFP; |
| 57 | const ConstantInt *CIP; |
| 58 | } Constant; |
| 59 | |
| 60 | // Or a location in the machine frame. |
| 61 | MachineLocation Loc; |
| 62 | |
| 63 | bool operator==(const Value &other) const { |
| 64 | if (EntryKind != other.EntryKind) |
| 65 | return false; |
| 66 | |
| 67 | switch (EntryKind) { |
| 68 | case E_Location: |
| 69 | return Loc == other.Loc; |
| 70 | case E_Integer: |
| 71 | return Constant.Int == other.Constant.Int; |
| 72 | case E_ConstantFP: |
| 73 | return Constant.CFP == other.Constant.CFP; |
| 74 | case E_ConstantInt: |
| 75 | return Constant.CIP == other.Constant.CIP; |
| 76 | } |
| 77 | llvm_unreachable("unhandled EntryKind"); |
| 78 | } |
| 79 | |
| 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; } |
| 89 | }; |
| 90 | private: |
| 91 | /// A list of locations/constants belonging to this entry. |
| 92 | SmallVector<Value, 1> Values; |
| 93 | |
| 94 | /// The compile unit that this location entry is referenced by. |
| 95 | const DwarfCompileUnit *Unit; |
David Blaikie | d306baf | 2014-04-01 22:04:07 +0000 | [diff] [blame] | 96 | |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 97 | public: |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 98 | DebugLocEntry() : Begin(nullptr), End(nullptr), Unit(nullptr) {} |
Adrian Prantl | e19e5ef | 2014-04-27 18:25:40 +0000 | [diff] [blame] | 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)); |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Adrian Prantl | 3c5453c | 2014-04-01 23:34:45 +0000 | [diff] [blame] | 105 | /// \brief Attempt to merge this DebugLocEntry with Next and return |
| 106 | /// true if the merge was successful. Entries can be merged if they |
Adrian Prantl | a731cf0 | 2014-04-02 15:49:45 +0000 | [diff] [blame] | 107 | /// share the same Loc/Constant and if Next immediately follows this |
| 108 | /// Entry. |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 109 | bool Merge(const DebugLocEntry &Next) { |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame^] | 110 | // If this and Next are describing different pieces of the same |
| 111 | // variable, merge them by appending next's values to the current |
| 112 | // list of values. |
| 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()); |
| 119 | End = Next.End; |
| 120 | return true; |
| 121 | } |
| 122 | } |
| 123 | // If this and Next are describing the same variable, merge them. |
Adrian Prantl | e19e5ef | 2014-04-27 18:25:40 +0000 | [diff] [blame] | 124 | if ((End == Next.Begin && Values == Next.Values)) { |
David Blaikie | 6fa9966 | 2014-04-01 23:19:23 +0000 | [diff] [blame] | 125 | End = Next.End; |
| 126 | return true; |
| 127 | } |
| 128 | return false; |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 129 | } |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame^] | 130 | |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 131 | const MCSymbol *getBeginSym() const { return Begin; } |
| 132 | const MCSymbol *getEndSym() const { return End; } |
| 133 | const DwarfCompileUnit *getCU() const { return Unit; } |
Adrian Prantl | e19e5ef | 2014-04-27 18:25:40 +0000 | [diff] [blame] | 134 | const ArrayRef<Value> getValues() const { return Values; } |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame^] | 135 | void addValue(Value Val) { |
| 136 | assert(DIVariable(Val.Variable).isVariablePiece() && |
| 137 | "multi-value DebugLocEntries must be pieces"); |
| 138 | Values.push_back(Val); |
| 139 | } |
David Blaikie | 1275e4f | 2014-04-01 21:49:04 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | } |
| 143 | #endif |