LLVM  7.0.0svn
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/Config/llvm-config.h"
15 #include "llvm/IR/Constants.h"
16 #include "llvm/IR/DebugInfo.h"
17 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Support/Debug.h"
20 
21 namespace llvm {
22 class AsmPrinter;
23 
24 /// This struct describes location entries emitted in the .debug_loc
25 /// section.
27  /// Begin and end symbols for the address range that this location is valid.
28  const MCSymbol *Begin;
29  const MCSymbol *End;
30 
31 public:
32  /// A single location or constant.
33  struct Value {
34  Value(const DIExpression *Expr, int64_t i)
35  : Expression(Expr), EntryKind(E_Integer) {
36  Constant.Int = i;
37  }
38  Value(const DIExpression *Expr, const ConstantFP *CFP)
40  Constant.CFP = CFP;
41  }
42  Value(const DIExpression *Expr, const ConstantInt *CIP)
44  Constant.CIP = CIP;
45  }
47  : Expression(Expr), EntryKind(E_Location), Loc(Loc) {
48  assert(cast<DIExpression>(Expr)->isValid());
49  }
50 
51  /// Any complex address location expression for this Value.
53 
54  /// Type of entry that this represents.
57 
58  /// Either a constant,
59  union {
60  int64_t Int;
61  const ConstantFP *CFP;
62  const ConstantInt *CIP;
63  } Constant;
64 
65  // Or a location in the machine frame.
67 
68  bool isLocation() const { return EntryKind == E_Location; }
69  bool isInt() const { return EntryKind == E_Integer; }
70  bool isConstantFP() const { return EntryKind == E_ConstantFP; }
71  bool isConstantInt() const { return EntryKind == E_ConstantInt; }
72  int64_t getInt() const { return Constant.Int; }
73  const ConstantFP *getConstantFP() const { return Constant.CFP; }
74  const ConstantInt *getConstantInt() const { return Constant.CIP; }
75  MachineLocation getLoc() const { return Loc; }
76  bool isFragment() const { return getExpression()->isFragment(); }
77  const DIExpression *getExpression() const { return Expression; }
78  friend bool operator==(const Value &, const Value &);
79  friend bool operator<(const Value &, const Value &);
80 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
81  LLVM_DUMP_METHOD void dump() const {
82  if (isLocation()) {
83  llvm::dbgs() << "Loc = { reg=" << Loc.getReg() << " ";
84  if (Loc.isIndirect())
85  llvm::dbgs() << "+0";
86  llvm::dbgs() << "} ";
87  }
88  else if (isConstantInt())
89  Constant.CIP->dump();
90  else if (isConstantFP())
91  Constant.CFP->dump();
92  if (Expression)
93  Expression->dump();
94  }
95 #endif
96  };
97 
98 private:
99  /// A nonempty list of locations/constants belonging to this entry,
100  /// sorted by offset.
101  SmallVector<Value, 1> Values;
102 
103 public:
104  DebugLocEntry(const MCSymbol *B, const MCSymbol *E, Value Val)
105  : Begin(B), End(E) {
106  Values.push_back(std::move(Val));
107  }
108 
109  /// If this and Next are describing different pieces of the same
110  /// variable, merge them by appending Next's values to the current
111  /// list of values.
112  /// Return true if the merge was successful.
113  bool MergeValues(const DebugLocEntry &Next);
114 
115  /// Attempt to merge this DebugLocEntry with Next and return
116  /// true if the merge was successful. Entries can be merged if they
117  /// share the same Loc/Constant and if Next immediately follows this
118  /// Entry.
119  bool MergeRanges(const DebugLocEntry &Next) {
120  // If this and Next are describing the same variable, merge them.
121  if ((End == Next.Begin && Values == Next.Values)) {
122  End = Next.End;
123  return true;
124  }
125  return false;
126  }
127 
128  const MCSymbol *getBeginSym() const { return Begin; }
129  const MCSymbol *getEndSym() const { return End; }
130  ArrayRef<Value> getValues() const { return Values; }
132  Values.append(Vals.begin(), Vals.end());
134  assert(all_of(Values, [](DebugLocEntry::Value V) {
135  return V.isFragment();
136  }) && "value must be a piece");
137  }
138 
139  // Sort the pieces by offset.
140  // Remove any duplicate entries by dropping all but the first.
142  llvm::sort(Values.begin(), Values.end());
143  Values.erase(
144  std::unique(
145  Values.begin(), Values.end(), [](const Value &A, const Value &B) {
146  return A.getExpression() == B.getExpression();
147  }),
148  Values.end());
149  }
150 
151  /// Lower this entry into a DWARF expression.
153  const DIBasicType *BT);
154 };
155 
156 /// Compare two Values for equality.
157 inline bool operator==(const DebugLocEntry::Value &A,
158  const DebugLocEntry::Value &B) {
159  if (A.EntryKind != B.EntryKind)
160  return false;
161 
162  if (A.Expression != B.Expression)
163  return false;
164 
165  switch (A.EntryKind) {
167  return A.Loc == B.Loc;
169  return A.Constant.Int == B.Constant.Int;
171  return A.Constant.CFP == B.Constant.CFP;
173  return A.Constant.CIP == B.Constant.CIP;
174  }
175  llvm_unreachable("unhandled EntryKind");
176 }
177 
178 /// Compare two fragments based on their offset.
179 inline bool operator<(const DebugLocEntry::Value &A,
180  const DebugLocEntry::Value &B) {
181  return A.getExpression()->getFragmentInfo()->OffsetInBits <
182  B.getExpression()->getFragmentInfo()->OffsetInBits;
183 }
184 
185 }
186 
187 #endif
bool MergeRanges(const DebugLocEntry &Next)
Attempt to merge this DebugLocEntry with Next and return true if the merge was successful.
ArrayRef< Value > getValues() const
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:26
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
iterator begin() const
Definition: ArrayRef.h:137
unsigned getReg() const
Value(const DIExpression *Expr, int64_t i)
Definition: DebugLocEntry.h:34
const DIExpression * Expression
Any complex address location expression for this Value.
Definition: DebugLocEntry.h:52
Value(const DIExpression *Expr, const ConstantFP *CFP)
Definition: DebugLocEntry.h:38
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:908
EntryType
Type of entry that this represents.
Definition: DebugLocEntry.h:55
const ConstantFP * CFP
Definition: DebugLocEntry.h:61
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:452
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:4216
const MCSymbol * getBeginSym() const
DebugLocEntry(const MCSymbol *B, const MCSymbol *E, Value Val)
Value(const DIExpression *Expr, const ConstantInt *CIP)
Definition: DebugLocEntry.h:42
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&#39;s...
Definition: DwarfDebug.cpp:968
static Optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
Value(const DIExpression *Expr, MachineLocation Loc)
Definition: DebugLocEntry.h:46
friend bool operator<(const Value &, const Value &)
Compare two fragments based on their offset.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
const DIExpression * getExpression() const
Definition: DebugLocEntry.h:77
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:117
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:264
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
const ConstantInt * getConstantInt() const
Definition: DebugLocEntry.h:74
LLVM_DUMP_METHOD void dump() const
Definition: DebugLocEntry.h:81
const ConstantInt * CIP
Definition: DebugLocEntry.h:62
iterator erase(const_iterator CI)
Definition: SmallVector.h:446
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:859
union llvm::DebugLocEntry::Value::@313 Constant
Either a constant,.
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
iterator end() const
Definition: ArrayRef.h:138
const MCSymbol * getEndSym() const
DWARF expression.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:395
A single location or constant.
Definition: DebugLocEntry.h:33
void finalize(const AsmPrinter &AP, DebugLocStream::ListBuilder &List, const DIBasicType *BT)
Lower this entry into a DWARF expression.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:121
const NodeList & List
Definition: RDFGraph.cpp:210
void dump() const
User-friendly dump.
Definition: AsmWriter.cpp:4238
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineLocation getLoc() const
Definition: DebugLocEntry.h:75
bool isFragment() const
Return whether this is a piece of an aggregate variable.
void addValues(ArrayRef< DebugLocEntry::Value > Vals)
const ConstantFP * getConstantFP() const
Definition: DebugLocEntry.h:73
Basic type, like &#39;int&#39; or &#39;float&#39;.