]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/CodeGen/DbgEntityHistoryCalculator.h
MFV r368464:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / CodeGen / DbgEntityHistoryCalculator.h
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"
13 #include "llvm/ADT/PointerIntPair.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.
28 class DbgValueHistoryMap {
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:
56     enum EntryKind { DbgValue, Clobber };
57
58     Entry(const MachineInstr *Instr, EntryKind Kind)
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:
72     PointerIntPair<const MachineInstr *, 1, EntryKind> Instr;
73     EntryIndex EndIndex;
74   };
75   using Entries = SmallVector<Entry, 4>;
76   using InlinedEntity = std::pair<const DINode *, const DILocation *>;
77   using EntriesMap = MapVector<InlinedEntity, Entries>;
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.
105 class DbgLabelInstrMap {
106 public:
107   using InlinedEntity = std::pair<const DINode *, const DILocation *>;
108   using InstrMap = MapVector<InlinedEntity, const MachineInstr *>;
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
122 void calculateDbgEntityHistory(const MachineFunction *MF,
123                                const TargetRegisterInfo *TRI,
124                                DbgValueHistoryMap &DbgValues,
125                                DbgLabelInstrMap &DbgLabels);
126
127 } // end namespace llvm
128
129 #endif // LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H