LLVM  13.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_DBGENTITYHISTORYCALCULATOR_H
10 #define LLVM_CODEGEN_DBGENTITYHISTORYCALCULATOR_H
11 
12 #include "llvm/ADT/MapVector.h"
14 #include "llvm/ADT/SmallVector.h"
16 #include <utility>
17 
18 namespace llvm {
19 
20 class DILocalVariable;
21 class DILocation;
22 class DINode;
23 class MachineFunction;
24 class MachineInstr;
25 class TargetRegisterInfo;
26 
27 /// Record instruction ordering so we can query their relative positions within
28 /// a function. Meta instructions are given the same ordinal as the preceding
29 /// non-meta instruction. Class state is invalid if MF is modified after
30 /// calling initialize.
32 public:
33  void initialize(const MachineFunction &MF);
34  void clear() { InstNumberMap.clear(); }
35 
36  /// Check if instruction \p A comes before \p B, where \p A and \p B both
37  /// belong to the MachineFunction passed to initialize().
38  bool isBefore(const MachineInstr *A, const MachineInstr *B) const;
39 
40 private:
41  /// Each instruction is assigned an order number.
43 };
44 
45 /// For each user variable, keep a list of instruction ranges where this
46 /// variable is accessible. The variables are listed in order of appearance.
48 public:
49  /// Index in the entry vector.
50  typedef size_t EntryIndex;
51 
52  /// Special value to indicate that an entry is valid until the end of the
53  /// function.
55 
56  /// Specifies a change in a variable's debug value history.
57  ///
58  /// There exist two types of entries:
59  ///
60  /// * Debug value entry:
61  ///
62  /// A new debug value becomes live. If the entry's \p EndIndex is \p NoEntry,
63  /// the value is valid until the end of the function. For other values, the
64  /// index points to the entry in the entry vector that ends this debug
65  /// value. The ending entry can either be an overlapping debug value, or
66  /// an instruction that clobbers the value.
67  ///
68  /// * Clobbering entry:
69  ///
70  /// This entry's instruction clobbers one or more preceding
71  /// register-described debug values that have their end index
72  /// set to this entry's position in the entry vector.
73  class Entry {
74  friend DbgValueHistoryMap;
75 
76  public:
78 
80  : Instr(Instr, Kind), EndIndex(NoEntry) {}
81 
82  const MachineInstr *getInstr() const { return Instr.getPointer(); }
83  EntryIndex getEndIndex() const { return EndIndex; }
84  EntryKind getEntryKind() const { return Instr.getInt(); }
85 
86  bool isClobber() const { return getEntryKind() == Clobber; }
87  bool isDbgValue() const { return getEntryKind() == DbgValue; }
88  bool isClosed() const { return EndIndex != NoEntry; }
89 
90  void endEntry(EntryIndex EndIndex);
91 
92  private:
94  EntryIndex EndIndex;
95  };
97  using InlinedEntity = std::pair<const DINode *, const DILocation *>;
99 
100 private:
101  EntriesMap VarEntries;
102 
103 public:
104  bool startDbgValue(InlinedEntity Var, const MachineInstr &MI,
105  EntryIndex &NewIndex);
107 
109  auto &Entries = VarEntries[Var];
110  return Entries[Index];
111  }
112 
113  /// Test whether a vector of entries features any non-empty locations. It
114  /// could have no entries, or only DBG_VALUE $noreg entries.
115  bool hasNonEmptyLocation(const Entries &Entries) const;
116 
117  /// Drop location ranges which exist entirely outside each variable's scope.
118  void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes,
119  const InstructionOrdering &Ordering);
120  bool empty() const { return VarEntries.empty(); }
121  void clear() { VarEntries.clear(); }
122  EntriesMap::const_iterator begin() const { return VarEntries.begin(); }
123  EntriesMap::const_iterator end() const { return VarEntries.end(); }
124 
125 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
126  LLVM_DUMP_METHOD void dump() const;
127 #endif
128 };
129 
130 /// For each inlined instance of a source-level label, keep the corresponding
131 /// DBG_LABEL instruction. The DBG_LABEL instruction could be used to generate
132 /// a temporary (assembler) label before it.
134 public:
135  using InlinedEntity = std::pair<const DINode *, const DILocation *>;
137 
138 private:
139  InstrMap LabelInstr;
140 
141 public:
142  void addInstr(InlinedEntity Label, const MachineInstr &MI);
143 
144  bool empty() const { return LabelInstr.empty(); }
145  void clear() { LabelInstr.clear(); }
146  InstrMap::const_iterator begin() const { return LabelInstr.begin(); }
147  InstrMap::const_iterator end() const { return LabelInstr.end(); }
148 };
149 
150 void calculateDbgEntityHistory(const MachineFunction *MF,
151  const TargetRegisterInfo *TRI,
152  DbgValueHistoryMap &DbgValues,
153  DbgLabelInstrMap &DbgLabels);
154 
155 } // end namespace llvm
156 
157 #endif // LLVM_CODEGEN_DBGENTITYHISTORYCALCULATOR_H
llvm::DbgValueHistoryMap::Entry::EntryKind
EntryKind
Definition: DbgEntityHistoryCalculator.h:77
llvm::InstructionOrdering::initialize
void initialize(const MachineFunction &MF)
Definition: DbgEntityHistoryCalculator.cpp:40
llvm::DbgLabelInstrMap::begin
InstrMap::const_iterator begin() const
Definition: DbgEntityHistoryCalculator.h:146
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:499
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DbgLabelInstrMap
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
Definition: DbgEntityHistoryCalculator.h:133
llvm::DbgValueHistoryMap::Entry
Specifies a change in a variable's debug value history.
Definition: DbgEntityHistoryCalculator.h:73
llvm::MapVector::clear
void clear()
Definition: MapVector.h:88
llvm::SmallVector< Entry, 4 >
MapVector.h
llvm::DbgValueHistoryMap::EntryIndex
size_t EntryIndex
Index in the entry vector.
Definition: DbgEntityHistoryCalculator.h:50
llvm::DbgValueHistoryMap::Entry::Entry
Entry(const MachineInstr *Instr, EntryKind Kind)
Definition: DbgEntityHistoryCalculator.h:79
llvm::MapVector< InlinedEntity, Entries >
llvm::DbgValueHistoryMap::begin
EntriesMap::const_iterator begin() const
Definition: DbgEntityHistoryCalculator.h:122
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::DbgValueHistoryMap::startDbgValue
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
Definition: DbgEntityHistoryCalculator.cpp:71
size_t
llvm::DbgValueHistoryMap::Entry::getEndIndex
EntryIndex getEndIndex() const
Definition: DbgEntityHistoryCalculator.h:83
PointerIntPair.h
llvm::MapVector< InlinedEntity, Entries >::const_iterator
typename std::vector< std::pair< InlinedEntity, Entries >> ::const_iterator const_iterator
Definition: MapVector.h:50
llvm::DbgValueHistoryMap::Entry::getInstr
const MachineInstr * getInstr() const
Definition: DbgEntityHistoryCalculator.h:82
llvm::DbgValueHistoryMap::Entry::isClosed
bool isClosed() const
Definition: DbgEntityHistoryCalculator.h:88
llvm::DbgValueHistoryMap::Entry::isDbgValue
bool isDbgValue() const
Definition: DbgEntityHistoryCalculator.h:87
llvm::MapVector::begin
iterator begin()
Definition: MapVector.h:69
llvm::DbgValueHistoryMap::end
EntriesMap::const_iterator end() const
Definition: DbgEntityHistoryCalculator.h:123
llvm::calculateDbgEntityHistory
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)
Definition: DbgEntityHistoryCalculator.cpp:450
llvm::InstructionOrdering::isBefore
bool isBefore(const MachineInstr *A, const MachineInstr *B) const
Check if instruction A comes before B, where A and B both belong to the MachineFunction passed to ini...
Definition: DbgEntityHistoryCalculator.cpp:63
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::DbgValueHistoryMap::Entry::Clobber
@ Clobber
Definition: DbgEntityHistoryCalculator.h:77
LexicalScopes.h
llvm::DbgValueHistoryMap::InlinedEntity
std::pair< const DINode *, const DILocation * > InlinedEntity
Definition: DbgEntityHistoryCalculator.h:97
llvm::DbgValueHistoryMap::hasNonEmptyLocation
bool hasNonEmptyLocation(const Entries &Entries) const
Test whether a vector of entries features any non-empty locations.
Definition: DbgEntityHistoryCalculator.cpp:260
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::InstructionOrdering
Record instruction ordering so we can query their relative positions within a function.
Definition: DbgEntityHistoryCalculator.h:31
llvm::DbgValueHistoryMap::startClobber
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)
Definition: DbgEntityHistoryCalculator.cpp:91
llvm::DbgLabelInstrMap::empty
bool empty() const
Definition: DbgEntityHistoryCalculator.h:144
llvm::DbgValueHistoryMap::dump
LLVM_DUMP_METHOD void dump() const
Definition: DbgEntityHistoryCalculator.cpp:559
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::InstructionOrdering::clear
void clear()
Definition: DbgEntityHistoryCalculator.h:34
llvm::DenseMap
Definition: DenseMap.h:714
llvm::DbgValueHistoryMap::NoEntry
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
Definition: DbgEntityHistoryCalculator.h:54
llvm::DbgLabelInstrMap::clear
void clear()
Definition: DbgEntityHistoryCalculator.h:145
llvm::DbgValueHistoryMap::Entry::isClobber
bool isClobber() const
Definition: DbgEntityHistoryCalculator.h:86
llvm::DbgValueHistoryMap::Entry::endEntry
void endEntry(EntryIndex EndIndex)
Definition: DbgEntityHistoryCalculator.cpp:102
llvm::DbgValueHistoryMap::getEntry
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
Definition: DbgEntityHistoryCalculator.h:108
llvm::DbgValueHistoryMap::Entries
SmallVector< Entry, 4 > Entries
Definition: DbgEntityHistoryCalculator.h:96
llvm::DbgValueHistoryMap::trimLocationRanges
void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes, const InstructionOrdering &Ordering)
Drop location ranges which exist entirely outside each variable's scope.
Definition: DbgEntityHistoryCalculator.cpp:130
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::DbgValueHistoryMap::Entry::DbgValue
@ DbgValue
Definition: DbgEntityHistoryCalculator.h:77
llvm::MapVector::end
iterator end()
Definition: MapVector.h:71
llvm::DbgValueHistoryMap
For each user variable, keep a list of instruction ranges where this variable is accessible.
Definition: DbgEntityHistoryCalculator.h:47
llvm::MapVector::empty
bool empty() const
Definition: MapVector.h:79
llvm::DbgLabelInstrMap::addInstr
void addInstr(InlinedEntity Label, const MachineInstr &MI)
Definition: DbgEntityHistoryCalculator.cpp:277
llvm::DbgValueHistoryMap::empty
bool empty() const
Definition: DbgEntityHistoryCalculator.h:120
llvm::DbgLabelInstrMap::InlinedEntity
std::pair< const DINode *, const DILocation * > InlinedEntity
Definition: DbgEntityHistoryCalculator.h:135
llvm::DbgLabelInstrMap::end
InstrMap::const_iterator end() const
Definition: DbgEntityHistoryCalculator.h:147
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:45
llvm::DbgValueHistoryMap::clear
void clear()
Definition: DbgEntityHistoryCalculator.h:121
SmallVector.h
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::LexicalScopes
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
Definition: LexicalScopes.h:141
llvm::DbgValueHistoryMap::Entry::getEntryKind
EntryKind getEntryKind() const
Definition: DbgEntityHistoryCalculator.h:84