Skip to content

Commit 8e8edda

Browse files
committed
[SlotIndexes] Implement support for poison checks
In debug builds, mark slot indexes for deleted instructions as poisoned and add an isPoisoned method to allow writing assertions elsewhere in the compiler. This restores some of the functionality that was removed by 4cf8da9.
1 parent 8b429fc commit 8e8edda

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

llvm/include/llvm/CodeGen/SlotIndexes.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,40 @@ class raw_ostream;
4343
/// SlotIndex & SlotIndexes classes for the public interface to this
4444
/// information.
4545
class IndexListEntry : public ilist_node<IndexListEntry> {
46-
MachineInstr *mi;
46+
#if NDEBUG
47+
// Disable poison checks such that setPoison will do nothing and isPoisoned
48+
// will return false.
49+
static constexpr unsigned PoisonBits = 0;
50+
static constexpr unsigned PoisonVal = 0;
51+
#else
52+
static constexpr unsigned PoisonBits = 1;
53+
static constexpr unsigned PoisonVal = 1;
54+
#endif
55+
56+
PointerIntPair<MachineInstr *, PoisonBits, unsigned> mi;
4757
unsigned index;
4858

4959
public:
50-
IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi), index(index) {}
60+
IndexListEntry(MachineInstr *mi, unsigned index) : mi(mi, 0), index(index) {
61+
}
5162

52-
MachineInstr* getInstr() const { return mi; }
63+
MachineInstr* getInstr() const { return mi.getPointer(); }
5364
void setInstr(MachineInstr *mi) {
54-
this->mi = mi;
65+
this->mi.setPointer(mi);
5566
}
5667

5768
unsigned getIndex() const { return index; }
5869
void setIndex(unsigned index) {
5970
this->index = index;
6071
}
72+
73+
void setPoison() {
74+
mi.setInt(PoisonVal);
75+
}
76+
77+
bool isPoisoned() const {
78+
return mi.getInt();
79+
}
6180
};
6281

6382
template <>
@@ -285,6 +304,10 @@ class raw_ostream;
285304
SlotIndex getPrevIndex() const {
286305
return SlotIndex(&*--listEntry()->getIterator(), getSlot());
287306
}
307+
308+
bool isPoisoned() const {
309+
return listEntry()->isPoisoned();
310+
}
288311
};
289312

290313
inline raw_ostream& operator<<(raw_ostream &os, SlotIndex li) {

llvm/lib/CodeGen/SlotIndexes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void SlotIndexes::removeMachineInstrFromMaps(MachineInstr &MI,
126126
mi2iMap.erase(mi2iItr);
127127
// FIXME: Eventually we want to actually delete these indexes.
128128
MIEntry.setInstr(nullptr);
129+
MIEntry.setPoison();
129130
}
130131

131132
void SlotIndexes::removeSingleMachineInstrFromMaps(MachineInstr &MI) {
@@ -152,6 +153,7 @@ void SlotIndexes::removeSingleMachineInstrFromMaps(MachineInstr &MI) {
152153
} else {
153154
// FIXME: Eventually we want to actually delete these indexes.
154155
MIEntry.setInstr(nullptr);
156+
MIEntry.setPoison();
155157
}
156158
}
157159

0 commit comments

Comments
 (0)