LLVM 19.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"
16#include <utility>
17
18namespace llvm {
19
20class DILocation;
21class LexicalScopes;
22class DINode;
23class MachineFunction;
24class 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.
31public:
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
39private:
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.
47public:
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.
53 static const EntryIndex NoEntry = std::numeric_limits<EntryIndex>::max();
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
78 Entry(const MachineInstr *Instr, EntryKind Kind)
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
99private:
100 EntriesMap VarEntries;
101
102public:
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(StringRef FuncName) 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.
133public:
134 using InlinedEntity = std::pair<const DINode *, const DILocation *>;
136
137private:
138 InstrMap LabelInstr;
139
140public:
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
149void 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
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:529
IRTranslator LLVM IR MI
unsigned const TargetRegisterInfo * TRI
This file implements a map that provides insertion order iteration.
This file defines the PointerIntPair class.
This file defines the SmallVector class.
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
InstrMap::const_iterator end() const
std::pair< const DINode *, const DILocation * > InlinedEntity
void addInstr(InlinedEntity Label, const MachineInstr &MI)
InstrMap::const_iterator begin() const
Specifies a change in a variable's debug value history.
const MachineInstr * getInstr() const
Entry(const MachineInstr *Instr, EntryKind Kind)
For each user variable, keep a list of instruction ranges where this variable is accessible.
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes, const InstructionOrdering &Ordering)
Drop location ranges which exist entirely outside each variable's scope.
size_t EntryIndex
Index in the entry vector.
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)
EntriesMap::const_iterator begin() const
SmallVector< Entry, 4 > Entries
EntriesMap::const_iterator end() const
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
LLVM_DUMP_METHOD void dump(StringRef FuncName) const
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
bool hasNonEmptyLocation(const Entries &Entries) const
Test whether a vector of entries features any non-empty locations.
std::pair< const DINode *, const DILocation * > InlinedEntity
Record instruction ordering so we can query their relative positions within a function.
void initialize(const MachineFunction &MF)
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...
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
Representation of each machine instruction.
Definition: MachineInstr.h:69
iterator end()
Definition: MapVector.h:71
bool empty() const
Definition: MapVector.h:79
iterator begin()
Definition: MapVector.h:69
typename VectorType::const_iterator const_iterator
Definition: MapVector.h:50
void clear()
Definition: MapVector.h:88
PointerIntPair - This class implements a pair of a pointer and small integer.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)