LLVM  12.0.0git
DbgEntityHistoryCalculator.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/DbgEntityHistoryCalculator.h ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H
10 #define LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H
11 
12 #include "llvm/ADT/MapVector.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include <utility>
16 
17 namespace llvm {
18 
19 class DILocalVariable;
20 class DILocation;
21 class DINode;
22 class MachineFunction;
23 class MachineInstr;
24 class TargetRegisterInfo;
25 
26 /// For each user variable, keep a list of instruction ranges where this
27 /// variable is accessible. The variables are listed in order of appearance.
29 public:
30  /// Index in the entry vector.
31  typedef size_t EntryIndex;
32 
33  /// Special value to indicate that an entry is valid until the end of the
34  /// function.
35  static const EntryIndex NoEntry = std::numeric_limits<EntryIndex>::max();
36 
37  /// Specifies a change in a variable's debug value history.
38  ///
39  /// There exist two types of entries:
40  ///
41  /// * Debug value entry:
42  ///
43  /// A new debug value becomes live. If the entry's \p EndIndex is \p NoEntry,
44  /// the value is valid until the end of the function. For other values, the
45  /// index points to the entry in the entry vector that ends this debug
46  /// value. The ending entry can either be an overlapping debug value, or
47  /// an instruction that clobbers the value.
48  ///
49  /// * Clobbering entry:
50  ///
51  /// This entry's instruction clobbers one or more preceding
52  /// register-described debug values that have their end index
53  /// set to this entry's position in the entry vector.
54  class Entry {
55  public:
57 
59  : Instr(Instr, Kind), EndIndex(NoEntry) {}
60 
61  const MachineInstr *getInstr() const { return Instr.getPointer(); }
62  EntryIndex getEndIndex() const { return EndIndex; }
63  EntryKind getEntryKind() const { return Instr.getInt(); }
64 
65  bool isClobber() const { return getEntryKind() == Clobber; }
66  bool isDbgValue() const { return getEntryKind() == DbgValue; }
67  bool isClosed() const { return EndIndex != NoEntry; }
68 
69  void endEntry(EntryIndex EndIndex);
70 
71  private:
73  EntryIndex EndIndex;
74  };
76  using InlinedEntity = std::pair<const DINode *, const DILocation *>;
78 
79 private:
80  EntriesMap VarEntries;
81 
82 public:
83  bool startDbgValue(InlinedEntity Var, const MachineInstr &MI,
84  EntryIndex &NewIndex);
85  EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI);
86 
87  Entry &getEntry(InlinedEntity Var, EntryIndex Index) {
88  auto &Entries = VarEntries[Var];
89  return Entries[Index];
90  }
91 
92  bool empty() const { return VarEntries.empty(); }
93  void clear() { VarEntries.clear(); }
94  EntriesMap::const_iterator begin() const { return VarEntries.begin(); }
95  EntriesMap::const_iterator end() const { return VarEntries.end(); }
96 
97 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
98  LLVM_DUMP_METHOD void dump() const;
99 #endif
100 };
101 
102 /// For each inlined instance of a source-level label, keep the corresponding
103 /// DBG_LABEL instruction. The DBG_LABEL instruction could be used to generate
104 /// a temporary (assembler) label before it.
106 public:
107  using InlinedEntity = std::pair<const DINode *, const DILocation *>;
109 
110 private:
111  InstrMap LabelInstr;
112 
113 public:
114  void addInstr(InlinedEntity Label, const MachineInstr &MI);
115 
116  bool empty() const { return LabelInstr.empty(); }
117  void clear() { LabelInstr.clear(); }
118  InstrMap::const_iterator begin() const { return LabelInstr.begin(); }
119  InstrMap::const_iterator end() const { return LabelInstr.end(); }
120 };
121 
123  const TargetRegisterInfo *TRI,
124  DbgValueHistoryMap &DbgValues,
125  DbgLabelInstrMap &DbgLabels);
126 
127 } // end namespace llvm
128 
129 #endif // LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction...
void clear()
Definition: MapVector.h:88
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:508
EntriesMap::const_iterator begin() const
unsigned const TargetRegisterInfo * TRI
For each user variable, keep a list of instruction ranges where this variable is accessible.
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)
std::pair< const DINode *, const DILocation * > InlinedEntity
bool empty() const
Definition: MapVector.h:79
size_t EntryIndex
Index in the entry vector.
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
InstrMap::const_iterator begin() const
PointerIntPair - This class implements a pair of a pointer and small integer.
Specifies a change in a variable&#39;s debug value history.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
std::pair< const DINode *, const DILocation * > InlinedEntity
Entry(const MachineInstr *Instr, EntryKind Kind)
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:350
InstrMap::const_iterator end() const
typename std::vector< std::pair< InlinedEntity, Entries >> ::const_iterator const_iterator
Definition: MapVector.h:50
EntriesMap::const_iterator end() const
Representation of each machine instruction.
Definition: MachineInstr.h:62
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
iterator begin()
Definition: MapVector.h:69
iterator end()
Definition: MapVector.h:71
IRTranslator LLVM IR MI
const MachineInstr * getInstr() const
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
LLVM_DUMP_METHOD void dump() const
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)