Skip to content
Open
27 changes: 21 additions & 6 deletions llvm/include/llvm/CodeGen/SlotIndexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,34 @@ class raw_ostream;
/// SlotIndex & SlotIndexes classes for the public interface to this
/// information.
class IndexListEntry : public ilist_node<IndexListEntry> {
MachineInstr *mi;
#if NDEBUG
// Disable poison checks such that setPoison will do nothing and isPoisoned
// will return false.
static constexpr unsigned PoisonBits = 0;
static constexpr unsigned PoisonVal = 0;
#else
static constexpr unsigned PoisonBits = 1;
static constexpr unsigned PoisonVal = 1;
#endif

PointerIntPair<MachineInstr *, PoisonBits, unsigned> mi;
Comment thread
jayfoad marked this conversation as resolved.
Outdated
unsigned index;

public:
IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {}
IndexListEntry(MachineInstr *mi, unsigned index)
: mi(mi, 0), index(index) {}

MachineInstr* getInstr() const { return mi; }
void setInstr(MachineInstr *mi) {
this->mi = mi;
}
MachineInstr *getInstr() const { return mi.getPointer(); }
void setInstr(MachineInstr *mi) { this->mi.setPointer(mi); }

unsigned getIndex() const { return index; }
void setIndex(unsigned index) {
this->index = index;
}

void setPoison() { mi.setInt(PoisonVal); }

bool isPoisoned() const { return mi.getInt(); }
};

template <>
Expand Down Expand Up @@ -285,6 +298,8 @@ class raw_ostream;
SlotIndex getPrevIndex() const {
return SlotIndex(&*--listEntry()->getIterator(), getSlot());
}

bool isPoisoned() const { return listEntry()->isPoisoned(); }
};

inline raw_ostream& operator<<(raw_ostream &os, SlotIndex li) {
Expand Down
17 changes: 17 additions & 0 deletions llvm/lib/CodeGen/LiveDebugVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ class UserValue {
/// Return DebugLoc of this UserValue.
const DebugLoc &getDebugLoc() { return dl; }

void verify() const {
for (auto I = locInts.begin(), E = locInts.end(); I != E; ++I) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto I = locInts.begin(), E = locInts.end(); I != E; ++I) {
for (auto I : locInts) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works because I need to call start and stop which are methods on the iterator itself (an instance of IntervalMap::const_iterator).

assert(!I.start().isPoisoned());
assert(!I.stop().isPoisoned());
}
}

void print(raw_ostream &, const TargetRegisterInfo *);
};

Expand Down Expand Up @@ -655,6 +662,11 @@ class LDVImpl {
ModifiedMF = false;
}

void verify() const {
for (auto [DV, UV] : userVarMap)
UV->verify();
}

/// Map virtual register to an equivalence class.
void mapVirtReg(Register VirtReg, UserValue *EC);

Expand Down Expand Up @@ -1320,6 +1332,11 @@ void LiveDebugVariables::releaseMemory() {
static_cast<LDVImpl*>(pImpl)->clear();
}

void LiveDebugVariables::verifyAnalysis() const {
if (pImpl)
static_cast<LDVImpl *>(pImpl)->verify();
}

LiveDebugVariables::~LiveDebugVariables() {
if (pImpl)
delete static_cast<LDVImpl*>(pImpl);
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/LiveDebugVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class LLVM_LIBRARY_VISIBILITY LiveDebugVariables : public MachineFunctionPass {
bool runOnMachineFunction(MachineFunction &) override;
void releaseMemory() override;
void getAnalysisUsage(AnalysisUsage &) const override;
void verifyAnalysis() const override;

MachineFunctionProperties getSetProperties() const override {
return MachineFunctionProperties().set(
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/SlotIndexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void SlotIndexes::removeMachineInstrFromMaps(MachineInstr &MI,
mi2iMap.erase(mi2iItr);
// FIXME: Eventually we want to actually delete these indexes.
MIEntry.setInstr(nullptr);
MIEntry.setPoison();
}

void SlotIndexes::removeSingleMachineInstrFromMaps(MachineInstr &MI) {
Expand All @@ -152,6 +153,7 @@ void SlotIndexes::removeSingleMachineInstrFromMaps(MachineInstr &MI) {
} else {
// FIXME: Eventually we want to actually delete these indexes.
MIEntry.setInstr(nullptr);
MIEntry.setPoison();
}
}

Expand Down