LLVM  4.0.0
DebugLocEntry.h
Go to the documentation of this file.
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 LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H
11 #define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGLOCENTRY_H
12 
13 #include "DebugLocStream.h"
14 #include "llvm/IR/Constants.h"
15 #include "llvm/IR/DebugInfo.h"
16 #include "llvm/MC/MCSymbol.h"
18 #include "llvm/Support/Debug.h"
19 
20 namespace llvm {
21 class AsmPrinter;
22 
23 /// \brief This struct describes location entries emitted in the .debug_loc
24 /// section.
26  /// Begin and end symbols for the address range that this location is valid.
27  const MCSymbol *Begin;
28  const MCSymbol *End;
29 
30 public:
31  /// \brief A single location or constant.
32  struct Value {
33  Value(const DIExpression *Expr, int64_t i)
34  : Expression(Expr), EntryKind(E_Integer) {
35  Constant.Int = i;
36  }
37  Value(const DIExpression *Expr, const ConstantFP *CFP)
39  Constant.CFP = CFP;
40  }
41  Value(const DIExpression *Expr, const ConstantInt *CIP)
43  Constant.CIP = CIP;
44  }
46  : Expression(Expr), EntryKind(E_Location), Loc(Loc) {
47  assert(cast<DIExpression>(Expr)->isValid());
48  }
49 
50  /// Any complex address location expression for this Value.
52 
53  /// Type of entry that this represents.
56 
57  /// Either a constant,
58  union {
59  int64_t Int;
60  const ConstantFP *CFP;
61  const ConstantInt *CIP;
62  } Constant;
63 
64  // Or a location in the machine frame.
66 
67  bool isLocation() const { return EntryKind == E_Location; }
68  bool isInt() const { return EntryKind == E_Integer; }
69  bool isConstantFP() const { return EntryKind == E_ConstantFP; }
70  bool isConstantInt() const { return EntryKind == E_ConstantInt; }
71  int64_t getInt() const { return Constant.Int; }
72  const ConstantFP *getConstantFP() const { return Constant.CFP; }
73  const ConstantInt *getConstantInt() const { return Constant.CIP; }
74  MachineLocation getLoc() const { return Loc; }
75  bool isFragment() const { return getExpression()->isFragment(); }
76  const DIExpression *getExpression() const { return Expression; }
77  friend bool operator==(const Value &, const Value &);
78  friend bool operator<(const Value &, const Value &);
79  void dump() const {
80  if (isLocation()) {
81  llvm::dbgs() << "Loc = { reg=" << Loc.getReg() << " ";
82  if (Loc.isIndirect())
83  llvm::dbgs() << '+' << Loc.getOffset();
84  llvm::dbgs() << "} ";
85  }
86  else if (isConstantInt())
87  Constant.CIP->dump();
88  else if (isConstantFP())
89  Constant.CFP->dump();
90  if (Expression)
91  Expression->dump();
92  }
93  };
94 
95 private:
96  /// A nonempty list of locations/constants belonging to this entry,
97  /// sorted by offset.
98  SmallVector<Value, 1> Values;
99 
100 public:
101  DebugLocEntry(const MCSymbol *B, const MCSymbol *E, Value Val)
102  : Begin(B), End(E) {
103  Values.push_back(std::move(Val));
104  }
105 
106  /// \brief If this and Next are describing different pieces of the same
107  /// variable, merge them by appending Next's values to the current
108  /// list of values.
109  /// Return true if the merge was successful.
110  bool MergeValues(const DebugLocEntry &Next);
111 
112  /// \brief Attempt to merge this DebugLocEntry with Next and return
113  /// true if the merge was successful. Entries can be merged if they
114  /// share the same Loc/Constant and if Next immediately follows this
115  /// Entry.
116  bool MergeRanges(const DebugLocEntry &Next) {
117  // If this and Next are describing the same variable, merge them.
118  if ((End == Next.Begin && Values == Next.Values)) {
119  End = Next.End;
120  return true;
121  }
122  return false;
123  }
124 
125  const MCSymbol *getBeginSym() const { return Begin; }
126  const MCSymbol *getEndSym() const { return End; }
127  ArrayRef<Value> getValues() const { return Values; }
129  Values.append(Vals.begin(), Vals.end());
131  assert(all_of(Values, [](DebugLocEntry::Value V) {
132  return V.isFragment();
133  }) && "value must be a piece");
134  }
135 
136  // \brief Sort the pieces by offset.
137  // Remove any duplicate entries by dropping all but the first.
139  std::sort(Values.begin(), Values.end());
140  Values.erase(
141  std::unique(
142  Values.begin(), Values.end(), [](const Value &A, const Value &B) {
143  return A.getExpression() == B.getExpression();
144  }),
145  Values.end());
146  }
147 
148  /// \brief Lower this entry into a DWARF expression.
150  const DIBasicType *BT);
151 };
152 
153 /// \brief Compare two Values for equality.
154 inline bool operator==(const DebugLocEntry::Value &A,
155  const DebugLocEntry::Value &B) {
156  if (A.EntryKind != B.EntryKind)
157  return false;
158 
159  if (A.Expression != B.Expression)
160  return false;
161 
162  switch (A.EntryKind) {
164  return A.Loc == B.Loc;
166  return A.Constant.Int == B.Constant.Int;
168  return A.Constant.CFP == B.Constant.CFP;
170  return A.Constant.CIP == B.Constant.CIP;
171  }
172  llvm_unreachable("unhandled EntryKind");
173 }
174 
175 /// Compare two fragments based on their offset.
176 inline bool operator<(const DebugLocEntry::Value &A,
177  const DebugLocEntry::Value &B) {
178  return A.getExpression()->getFragmentInfo()->OffsetInBits <
179  B.getExpression()->getFragmentInfo()->OffsetInBits;
180 }
181 
182 }
183 
184 #endif
MachineLocation getLoc() const
Definition: DebugLocEntry.h:74
bool MergeRanges(const DebugLocEntry &Next)
Attempt to merge this DebugLocEntry with Next and return true if the merge was successful.
const ConstantInt * getConstantInt() const
Definition: DebugLocEntry.h:73
Builder for DebugLocStream lists.
friend bool operator==(const Value &, const Value &)
Compare two Values for equality.
This struct describes location entries emitted in the .debug_loc section.
Definition: DebugLocEntry.h:25
size_t i
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
const ConstantFP * getConstantFP() const
Definition: DebugLocEntry.h:72
iterator end() const
Definition: ArrayRef.h:130
Value(const DIExpression *Expr, int64_t i)
Definition: DebugLocEntry.h:33
const DIExpression * Expression
Any complex address location expression for this Value.
Definition: DebugLocEntry.h:51
Value(const DIExpression *Expr, const ConstantFP *CFP)
Definition: DebugLocEntry.h:37
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:736
EntryType
Type of entry that this represents.
Definition: DebugLocEntry.h:54
ArrayRef< Value > getValues() const
const ConstantFP * CFP
Definition: DebugLocEntry.h:60
bool isIndirect() const
const DIExpression * getExpression() const
Definition: DebugLocEntry.h:76
DebugLocEntry(const MCSymbol *B, const MCSymbol *E, Value Val)
Value(const DIExpression *Expr, const ConstantInt *CIP)
Definition: DebugLocEntry.h:41
const MCSymbol * getBeginSym() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool MergeValues(const DebugLocEntry &Next)
If this and Next are describing different pieces of the same variable, merge them by appending Next's...
Definition: DwarfDebug.cpp:823
static Optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
Value(const DIExpression *Expr, MachineLocation Loc)
Definition: DebugLocEntry.h:45
const MCSymbol * getEndSym() const
bool isFragment() const
Return whether this is a piece of an aggregate variable.
friend bool operator<(const Value &, const Value &)
Compare two fragments based on their offset.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:269
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:67
iterator begin() const
Definition: ArrayRef.h:129
const ConstantInt * CIP
Definition: DebugLocEntry.h:61
void dump() const
User-friendly dump.
Definition: AsmWriter.cpp:3562
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:3540
uint64_t * Vals
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
INITIALIZE_PASS(HexagonGenMux,"hexagon-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
union llvm::DebugLocEntry::Value::@246 Constant
Either a constant,.
DWARF expression.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
A single location or constant.
Definition: DebugLocEntry.h:32
void finalize(const AsmPrinter &AP, DebugLocStream::ListBuilder &List, const DIBasicType *BT)
Lower this entry into a DWARF expression.
const NodeList & List
Definition: RDFGraph.cpp:205
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:326
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1722
unsigned getReg() const
void addValues(ArrayRef< DebugLocEntry::Value > Vals)
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
int64_t getInt() const
Definition: DebugLocEntry.h:71
Basic type, like 'int' or 'float'.