File indexing completed on 2026-05-10 08:43:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CODEGEN_DBGENTITYHISTORYCALCULATOR_H
0010 #define LLVM_CODEGEN_DBGENTITYHISTORYCALCULATOR_H
0011
0012 #include "llvm/ADT/MapVector.h"
0013 #include "llvm/ADT/PointerIntPair.h"
0014 #include "llvm/ADT/SmallVector.h"
0015 #include "llvm/CodeGen/MachineInstr.h"
0016 #include <utility>
0017
0018 namespace llvm {
0019
0020 class DILocation;
0021 class LexicalScopes;
0022 class DINode;
0023 class MachineFunction;
0024 class TargetRegisterInfo;
0025
0026
0027
0028
0029
0030 class InstructionOrdering {
0031 public:
0032 void initialize(const MachineFunction &MF);
0033 void clear() { InstNumberMap.clear(); }
0034
0035
0036
0037 bool isBefore(const MachineInstr *A, const MachineInstr *B) const;
0038
0039 private:
0040
0041 DenseMap<const MachineInstr *, unsigned> InstNumberMap;
0042 };
0043
0044
0045
0046 class DbgValueHistoryMap {
0047 public:
0048
0049 typedef size_t EntryIndex;
0050
0051
0052
0053 static const EntryIndex NoEntry = std::numeric_limits<EntryIndex>::max();
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 class Entry {
0073 friend DbgValueHistoryMap;
0074
0075 public:
0076 enum EntryKind { DbgValue, Clobber };
0077
0078 Entry(const MachineInstr *Instr, EntryKind Kind)
0079 : Instr(Instr, Kind), EndIndex(NoEntry) {}
0080
0081 const MachineInstr *getInstr() const { return Instr.getPointer(); }
0082 EntryIndex getEndIndex() const { return EndIndex; }
0083 EntryKind getEntryKind() const { return Instr.getInt(); }
0084
0085 bool isClobber() const { return getEntryKind() == Clobber; }
0086 bool isDbgValue() const { return getEntryKind() == DbgValue; }
0087 bool isClosed() const { return EndIndex != NoEntry; }
0088
0089 void endEntry(EntryIndex EndIndex);
0090
0091 private:
0092 PointerIntPair<const MachineInstr *, 1, EntryKind> Instr;
0093 EntryIndex EndIndex;
0094 };
0095 using Entries = SmallVector<Entry, 4>;
0096 using InlinedEntity = std::pair<const DINode *, const DILocation *>;
0097 using EntriesMap = MapVector<InlinedEntity, Entries>;
0098
0099 private:
0100 EntriesMap VarEntries;
0101
0102 public:
0103 bool startDbgValue(InlinedEntity Var, const MachineInstr &MI,
0104 EntryIndex &NewIndex);
0105 EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI);
0106
0107 Entry &getEntry(InlinedEntity Var, EntryIndex Index) {
0108 auto &Entries = VarEntries[Var];
0109 return Entries[Index];
0110 }
0111
0112
0113
0114 bool hasNonEmptyLocation(const Entries &Entries) const;
0115
0116
0117 void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes,
0118 const InstructionOrdering &Ordering);
0119 bool empty() const { return VarEntries.empty(); }
0120 void clear() { VarEntries.clear(); }
0121 EntriesMap::const_iterator begin() const { return VarEntries.begin(); }
0122 EntriesMap::const_iterator end() const { return VarEntries.end(); }
0123
0124 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0125 LLVM_DUMP_METHOD void dump(StringRef FuncName) const;
0126 #endif
0127 };
0128
0129
0130
0131
0132 class DbgLabelInstrMap {
0133 public:
0134 using InlinedEntity = std::pair<const DINode *, const DILocation *>;
0135 using InstrMap = MapVector<InlinedEntity, const MachineInstr *>;
0136
0137 private:
0138 InstrMap LabelInstr;
0139
0140 public:
0141 void addInstr(InlinedEntity Label, const MachineInstr &MI);
0142
0143 bool empty() const { return LabelInstr.empty(); }
0144 void clear() { LabelInstr.clear(); }
0145 InstrMap::const_iterator begin() const { return LabelInstr.begin(); }
0146 InstrMap::const_iterator end() const { return LabelInstr.end(); }
0147 };
0148
0149 void calculateDbgEntityHistory(const MachineFunction *MF,
0150 const TargetRegisterInfo *TRI,
0151 DbgValueHistoryMap &DbgValues,
0152 DbgLabelInstrMap &DbgLabels);
0153
0154 }
0155
0156 #endif