Skip to content

Commit d6f906e

Browse files
authored
[SlotIndexes] Use simple_ilist instead of ilist. NFC. (#96747)
simple_ilist does not take ownership of its nodes, which is fine for SlotIndexes because the IndexListEntry nodes are allocated with a BumpPtrAllocator and do not need to be freed.
1 parent 847d046 commit d6f906e

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

llvm/include/llvm/CodeGen/SlotIndexes.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "llvm/ADT/IntervalMap.h"
2323
#include "llvm/ADT/PointerIntPair.h"
2424
#include "llvm/ADT/SmallVector.h"
25-
#include "llvm/ADT/ilist.h"
25+
#include "llvm/ADT/simple_ilist.h"
2626
#include "llvm/CodeGen/MachineBasicBlock.h"
2727
#include "llvm/CodeGen/MachineFunction.h"
2828
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -60,10 +60,6 @@ class raw_ostream;
6060
}
6161
};
6262

63-
template <>
64-
struct ilist_alloc_traits<IndexListEntry>
65-
: public ilist_noalloc_traits<IndexListEntry> {};
66-
6763
/// SlotIndex - An opaque wrapper around machine indexes.
6864
class SlotIndex {
6965
friend class SlotIndexes;
@@ -302,7 +298,7 @@ class raw_ostream;
302298
// IndexListEntry allocator.
303299
BumpPtrAllocator ileAllocator;
304300

305-
using IndexList = ilist<IndexListEntry>;
301+
using IndexList = simple_ilist<IndexListEntry>;
306302
IndexList indexList;
307303

308304
MachineFunction *mf = nullptr;
@@ -549,7 +545,7 @@ class raw_ostream;
549545

550546
// Insert a new list entry for MI.
551547
IndexList::iterator newItr =
552-
indexList.insert(nextItr, createEntry(&MI, newNumber));
548+
indexList.insert(nextItr, *createEntry(&MI, newNumber));
553549

554550
// Renumber locally if we need to.
555551
if (dist == 0)
@@ -608,7 +604,7 @@ class raw_ostream;
608604
mbb->empty() ? endEntry
609605
: getInstructionIndex(mbb->front()).listEntry();
610606
IndexList::iterator newItr =
611-
indexList.insert(insEntry->getIterator(), startEntry);
607+
indexList.insert(insEntry->getIterator(), *startEntry);
612608

613609
SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
614610
SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);

llvm/lib/CodeGen/SlotIndexes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SlotIndexes::SlotIndexes() : MachineFunctionPass(ID) {
2626

2727
SlotIndexes::~SlotIndexes() {
2828
// The indexList's nodes are all allocated in the BumpPtrAllocator.
29-
indexList.clearAndLeakNodesUnsafely();
29+
indexList.clear();
3030
}
3131

3232
INITIALIZE_PASS(SlotIndexes, DEBUG_TYPE,
@@ -75,7 +75,7 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
7575
MBBRanges.resize(mf->getNumBlockIDs());
7676
idx2MBBMap.reserve(mf->size());
7777

78-
indexList.push_back(createEntry(nullptr, index));
78+
indexList.push_back(*createEntry(nullptr, index));
7979

8080
// Iterate over the function.
8181
for (MachineBasicBlock &MBB : *mf) {
@@ -87,15 +87,15 @@ bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
8787
continue;
8888

8989
// Insert a store index for the instr.
90-
indexList.push_back(createEntry(&MI, index += SlotIndex::InstrDist));
90+
indexList.push_back(*createEntry(&MI, index += SlotIndex::InstrDist));
9191

9292
// Save this base index in the maps.
9393
mi2iMap.insert(std::make_pair(
9494
&MI, SlotIndex(&indexList.back(), SlotIndex::Slot_Block)));
9595
}
9696

9797
// We insert one blank instructions between basic blocks.
98-
indexList.push_back(createEntry(nullptr, index += SlotIndex::InstrDist));
98+
indexList.push_back(*createEntry(nullptr, index += SlotIndex::InstrDist));
9999

100100
MBBRanges[MBB.getNumber()].first = blockStartIndex;
101101
MBBRanges[MBB.getNumber()].second = SlotIndex(&indexList.back(),

llvm/unittests/CodeGen/MLRegAllocDevelopmentFeatures.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
4646
protected:
4747
SmallVector<LRStartEndInfo>
4848
setupOverlapProblem(const SmallVectorImpl<LRPosInfoIndexes> &Segments,
49-
ilist<IndexListEntry> &IndexList) {
49+
simple_ilist<IndexListEntry> &IndexList) {
5050
SmallVector<LRStartEndInfo> PositionsToReturn;
5151
PositionsToReturn.reserve(Segments.size());
5252
for (auto CurrentPosIndexInfo : Segments) {
@@ -61,7 +61,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
6161
Allocator.Allocate(sizeof(IndexListEntry), alignof(IndexListEntry)));
6262
auto *CurrentListEntry =
6363
new (CurrentLEMem) IndexListEntry(nullptr, CurrentIndex);
64-
IndexList.push_back(CurrentListEntry);
64+
IndexList.push_back(*CurrentListEntry);
6565
for (size_t CurrentPosInfoIndex = 0;
6666
CurrentPosInfoIndex < Segments.size(); ++CurrentPosInfoIndex) {
6767
if ((CurrentIndex / SlotIndex::InstrDist) ==
@@ -107,7 +107,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
107107
}
108108

109109
void runOverlapTest(SmallVectorImpl<LRPosInfoIndexes> &OverlapSetup) {
110-
ilist<IndexListEntry> IndexList;
110+
simple_ilist<IndexListEntry> IndexList;
111111
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
112112
NoInferenceModelRunner ModelRunner = setupModelRunner();
113113
size_t MaxIndex = 0;
@@ -131,7 +131,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
131131
NumberOfInterferences * ModelMaxSupportedInstructionCount);
132132
ASSERT_THAT(MappingMatrix,
133133
ContainerEq(getExpectedMappingMatrix(OverlapSetup)));
134-
IndexList.clearAndLeakNodesUnsafely();
134+
IndexList.clear();
135135
}
136136

137137
BumpPtrAllocator Allocator;
@@ -144,7 +144,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest,
144144
SmallVector<LRPosInfoIndexes, 2> OverlapSetup;
145145
OverlapSetup.push_back({0, 5, 0});
146146
OverlapSetup.push_back({5, 10, 0});
147-
ilist<IndexListEntry> IndexList;
147+
simple_ilist<IndexListEntry> IndexList;
148148
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
149149
ASSERT_EQ(OverlapProblem[0].End.distance(OverlapProblem[1].End),
150150
5 * SlotIndex::InstrDist);
@@ -154,7 +154,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest,
154154
TEST_F(RegAllocDevelopmentFeaturesTest, MetaSlotIndicesAreValid) {
155155
SmallVector<LRPosInfoIndexes, 1> OverlapSetup;
156156
OverlapSetup.push_back({0, 10, 0});
157-
ilist<IndexListEntry> IndexList;
157+
simple_ilist<IndexListEntry> IndexList;
158158
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
159159
ASSERT_TRUE(OverlapProblem[0].Begin.isValid());
160160
ASSERT_TRUE(OverlapProblem[0].End.isValid());
@@ -165,7 +165,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest, MetaSlotIndicesAreValid) {
165165
TEST_F(RegAllocDevelopmentFeaturesTest, InstructionOpcodesAreCorrect) {
166166
SmallVector<LRPosInfoIndexes, 1> OverlapSetup;
167167
OverlapSetup.push_back({0, ModelMaxSupportedInstructionCount - 1, 0});
168-
ilist<IndexListEntry> IndexList;
168+
simple_ilist<IndexListEntry> IndexList;
169169
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
170170
NoInferenceModelRunner ModelRunner = setupModelRunner();
171171
SlotIndex LastIndex = OverlapProblem[0].End;
@@ -247,7 +247,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest, SingleMBBTest) {
247247
TEST_F(RegAllocDevelopmentFeaturesTest, MBBFullTruncated) {
248248
SmallVector<LRPosInfoIndexes, 1> OverlapSetup;
249249
OverlapSetup.push_back({0, ModelMaxSupportedInstructionCount - 1, 0});
250-
ilist<IndexListEntry> IndexList;
250+
simple_ilist<IndexListEntry> IndexList;
251251
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
252252
NoInferenceModelRunner ModelRunner = setupModelRunner();
253253
SlotIndex LastIndex = OverlapProblem[0].End;

0 commit comments

Comments
 (0)