LLVM  6.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/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 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
80  LLVM_DUMP_METHOD void dump() const {
81  if (isLocation()) {
82  llvm::dbgs() << "Loc = { reg=" << Loc.getReg() << " ";
83  if (Loc.isIndirect())
84  llvm::dbgs() << "+0";
85  llvm::dbgs() << "} ";
86  }
87  else if (isConstantInt())
88  Constant.CIP->dump();
89  else if (isConstantFP())
90  Constant.CFP->dump();
91  if (Expression)
92  Expression->dump();
93  }
94 #endif
95  };
96 
97 private:
98  /// A nonempty list of locations/constants belonging to this entry,
99  /// sorted by offset.
100  SmallVector<Value, 1> Values;
101 
102 public:
103  DebugLocEntry(const MCSymbol *B, const MCSymbol *E, Value Val)
104  : Begin(B), End(E) {
105  Values.push_back(std::move(Val));
106  }
107 
108  /// \brief If this and Next are describing different pieces of the same
109  /// variable, merge them by appending Next's values to the current
110  /// list of values.
111  /// Return true if the merge was successful.
112  bool MergeValues(const DebugLocEntry &Next);
113 
114  /// \brief Attempt to merge this DebugLocEntry with Next and return
115  /// true if the merge was successful. Entries can be merged if they
116  /// share the same Loc/Constant and if Next immediately follows this
117  /// Entry.
118  bool MergeRanges(const DebugLocEntry &Next) {
119  // If this and Next are describing the same variable, merge them.
120  if ((End == Next.Begin && Values == Next.Values)) {
121  End = Next.End;
122  return true;
123  }
124  return false;
125  }
126 
127  const MCSymbol *getBeginSym() const { return Begin; }
128  const MCSymbol *getEndSym() const { return End; }
129  ArrayRef<Value> getValues() const { return Values; }
131  Values.append(Vals.begin(), Vals.end());
133  assert(all_of(Values, [](DebugLocEntry::Value V) {
134  return V.isFragment();
135  }) && "value must be a piece");
136  }
137 
138  // \brief Sort the pieces by offset.
139  // Remove any duplicate entries by dropping all but the first.
141  std::sort(Values.begin(), Values.end());
142  Values.erase(
143  std::unique(
144  Values.begin(), Values.end(), [](const Value &A, const Value &B) {
145  return A.getExpression() == B.getExpression();
146  }),
147  Values.end());
148  }
149 
150  /// \brief Lower this entry into a DWARF expression.
152  const DIBasicType *BT);
153 };
154 
155 /// \brief Compare two Values for equality.
156 inline bool operator==(const DebugLocEntry::Value &A,
157  const DebugLocEntry::Value &B) {
158  if (A.EntryKind != B.EntryKind)
159  return false;
160 
161  if (A.Expression != B.Expression)
162  return false;
163 
164  switch (A.EntryKind) {
166  return A.Loc == B.Loc;
168  return A.Constant.Int == B.Constant.Int;
170  return A.Constant.CFP == B.Constant.CFP;
172  return A.Constant.CIP == B.Constant.CIP;
173  }
174  llvm_unreachable("unhandled EntryKind");
175 }
176 
177 /// Compare two fragments based on their offset.
178 inline bool operator<(const DebugLocEntry::Value &A,
179  const DebugLocEntry::Value &B) {
180  return A.getExpression()->getFragmentInfo()->OffsetInBits <
181  B.getExpression()->getFragmentInfo()->OffsetInBits;
182 }
183 
184 }
185 
186 #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:25
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
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: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:767
EntryType
Type of entry that this represents.
Definition: DebugLocEntry.h:54
const ConstantFP * CFP
Definition: DebugLocEntry.h:60
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:3641
const MCSymbol * getBeginSym() const
DebugLocEntry(const MCSymbol *B, const MCSymbol *E, Value Val)
Value(const DIExpression *Expr, const ConstantInt *CIP)
Definition: DebugLocEntry.h:41
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:894
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:45
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:76
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:116
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:77
const ConstantInt * getConstantInt() const
Definition: DebugLocEntry.h:73
LLVM_DUMP_METHOD void dump() const
Definition: DebugLocEntry.h:80
const ConstantInt * CIP
Definition: DebugLocEntry.h:61
iterator erase(const_iterator CI)
Definition: SmallVector.h:449
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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:864
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:132
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:398
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
const NodeList & List
Definition: RDFGraph.cpp:210
void dump() const
User-friendly dump.
Definition: AsmWriter.cpp:3663
union llvm::DebugLocEntry::Value::@302 Constant
Either a constant,.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineLocation getLoc() const
Definition: DebugLocEntry.h:74
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
Definition: Parallel.h:199
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:72
Basic type, like &#39;int&#39; or &#39;float&#39;.