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