blob: 3beb799203b790238702db56af4c212ec2bbd30f [file] [log] [blame]
David Blaikie1275e4f2014-04-01 21:49:04 +00001//===-- 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"
13#include "llvm/MC/MachineLocation.h"
14#include "llvm/MC/MCSymbol.h"
15
16namespace llvm {
17class DwarfCompileUnit;
18class MDNode;
19/// \brief This struct describes location entries emitted in the .debug_loc
20/// section.
21class DebugLocEntry {
22 // Begin and end symbols for the address range that this location is valid.
23 const MCSymbol *Begin;
24 const MCSymbol *End;
25
Adrian Prantle19e5ef2014-04-27 18:25:40 +000026public:
27 /// A single location or constant.
28 struct Value {
29 Value(const MDNode *Var, int64_t i)
30 : Variable(Var), EntryKind(E_Integer) {
31 Constant.Int = i;
32 }
33 Value(const MDNode *Var, const ConstantFP *CFP)
34 : Variable(Var), EntryKind(E_ConstantFP) {
35 Constant.CFP = CFP;
36 }
37 Value(const MDNode *Var, const ConstantInt *CIP)
38 : Variable(Var), EntryKind(E_ConstantInt) {
39 Constant.CIP = CIP;
40 }
41 Value(const MDNode *Var, MachineLocation Loc)
42 : Variable(Var), EntryKind(E_Location), Loc(Loc) {
David Blaikied306baf2014-04-01 22:04:07 +000043 }
44
Adrian Prantle19e5ef2014-04-27 18:25:40 +000045 // The variable to which this location entry corresponds.
46 const MDNode *Variable;
47
48 // Type of entry that this represents.
49 enum EntryType { E_Location, E_Integer, E_ConstantFP, E_ConstantInt };
50 enum EntryType EntryKind;
51
52 // Either a constant,
53 union {
54 int64_t Int;
55 const ConstantFP *CFP;
56 const ConstantInt *CIP;
57 } Constant;
58
59 // Or a location in the machine frame.
60 MachineLocation Loc;
61
62 bool operator==(const Value &other) const {
63 if (EntryKind != other.EntryKind)
64 return false;
65
66 switch (EntryKind) {
67 case E_Location:
68 return Loc == other.Loc;
69 case E_Integer:
70 return Constant.Int == other.Constant.Int;
71 case E_ConstantFP:
72 return Constant.CFP == other.Constant.CFP;
73 case E_ConstantInt:
74 return Constant.CIP == other.Constant.CIP;
75 }
76 llvm_unreachable("unhandled EntryKind");
77 }
78
79 bool isLocation() const { return EntryKind == E_Location; }
80 bool isInt() const { return EntryKind == E_Integer; }
81 bool isConstantFP() const { return EntryKind == E_ConstantFP; }
82 bool isConstantInt() const { return EntryKind == E_ConstantInt; }
83 int64_t getInt() const { return Constant.Int; }
84 const ConstantFP *getConstantFP() const { return Constant.CFP; }
85 const ConstantInt *getConstantInt() const { return Constant.CIP; }
86 MachineLocation getLoc() const { return Loc; }
87 const MDNode *getVariable() const { return Variable; }
88 };
89private:
90 /// A list of locations/constants belonging to this entry.
91 SmallVector<Value, 1> Values;
92
93 /// The compile unit that this location entry is referenced by.
94 const DwarfCompileUnit *Unit;
David Blaikied306baf2014-04-01 22:04:07 +000095
David Blaikie1275e4f2014-04-01 21:49:04 +000096public:
Craig Toppere73658d2014-04-28 04:05:08 +000097 DebugLocEntry() : Begin(nullptr), End(nullptr), Unit(nullptr) {}
Adrian Prantle19e5ef2014-04-27 18:25:40 +000098 DebugLocEntry(const MCSymbol *B, const MCSymbol *E,
99 Value Val, const DwarfCompileUnit *U)
100 : Begin(B), End(E), Unit(U) {
101 Values.push_back(std::move(Val));
David Blaikie1275e4f2014-04-01 21:49:04 +0000102 }
103
Adrian Prantl3c5453c2014-04-01 23:34:45 +0000104 /// \brief Attempt to merge this DebugLocEntry with Next and return
105 /// true if the merge was successful. Entries can be merged if they
Adrian Prantla731cf02014-04-02 15:49:45 +0000106 /// share the same Loc/Constant and if Next immediately follows this
107 /// Entry.
David Blaikie1275e4f2014-04-01 21:49:04 +0000108 bool Merge(const DebugLocEntry &Next) {
Adrian Prantle19e5ef2014-04-27 18:25:40 +0000109 if ((End == Next.Begin && Values == Next.Values)) {
David Blaikie6fa99662014-04-01 23:19:23 +0000110 End = Next.End;
111 return true;
112 }
113 return false;
David Blaikie1275e4f2014-04-01 21:49:04 +0000114 }
David Blaikie1275e4f2014-04-01 21:49:04 +0000115 const MCSymbol *getBeginSym() const { return Begin; }
116 const MCSymbol *getEndSym() const { return End; }
117 const DwarfCompileUnit *getCU() const { return Unit; }
Adrian Prantle19e5ef2014-04-27 18:25:40 +0000118 const ArrayRef<Value> getValues() const { return Values; }
119 void addValue(Value Val) { Values.push_back(Val); }
David Blaikie1275e4f2014-04-01 21:49:04 +0000120};
121
122}
123#endif