| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_CODEGEN_DBGENTITYHISTORYCALCULATOR_H |
| 10 |
#define LLVM_CODEGEN_DBGENTITYHISTORYCALCULATOR_H |
| 11 |
|
| 12 |
#include "llvm/ADT/MapVector.h" |
| 13 |
#include "llvm/ADT/PointerIntPair.h" |
| 14 |
#include "llvm/ADT/SmallVector.h" |
| 15 |
#include "llvm/CodeGen/LexicalScopes.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 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class InstructionOrdering { |
| 31 |
public: |
| 32 |
void initialize(const MachineFunction &MF); |
| 33 |
void clear() { InstNumberMap.clear(); } |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
bool isBefore(const MachineInstr *A, const MachineInstr *B) const; |
| 38 |
|
| 39 |
private: |
| 40 |
|
| 41 |
DenseMap<const MachineInstr *, unsigned> InstNumberMap; |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
class DbgValueHistoryMap { |
| 47 |
public: |
| 48 |
|
| 49 |
typedef size_t EntryIndex; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
static const EntryIndex NoEntry = std::numeric_limits<EntryIndex>::max(); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
class Entry { |
| 73 |
friend DbgValueHistoryMap; |
| 74 |
|
| 75 |
public: |
| 76 |
enum EntryKind { DbgValue, Clobber }; |
| 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: |
| 92 |
PointerIntPair<const MachineInstr *, 1, EntryKind> Instr; |
| 93 |
EntryIndex EndIndex; |
| 94 |
}; |
| 95 |
using Entries = SmallVector<Entry, 4>; |
| 96 |
using InlinedEntity = std::pair<const DINode *, const DILocation *>; |
| 97 |
using EntriesMap = MapVector<InlinedEntity, Entries>; |
| 98 |
|
| 99 |
private: |
| 100 |
EntriesMap VarEntries; |
| 101 |
|
| 102 |
public: |
| 103 |
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, |
| 104 |
EntryIndex &NewIndex); |
| 105 |
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI); |
| 106 |
|
| 107 |
Entry &getEntry(InlinedEntity Var, EntryIndex Index) { |
| 108 |
auto &Entries = VarEntries[Var]; |
| 109 |
return Entries[Index]; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
bool hasNonEmptyLocation(const Entries &Entries) const; |
| 115 |
|
| 116 |
|
| 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 |
|
| 130 |
|
| 131 |
|
| 132 |
class DbgLabelInstrMap { |
| 133 |
public: |
| 134 |
using InlinedEntity = std::pair<const DINode *, const DILocation *>; |
| 135 |
using InstrMap = MapVector<InlinedEntity, const MachineInstr *>; |
| 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 |
} |
| 155 |
|
| 156 |
#endif |