Skip to content

[SlotIndexes] Use simple_ilist instead of ilist. NFC. #96747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions llvm/include/llvm/CodeGen/SlotIndexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/simple_ilist.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
Expand Down Expand Up @@ -60,10 +60,6 @@ class raw_ostream;
}
};

template <>
struct ilist_alloc_traits<IndexListEntry>
: public ilist_noalloc_traits<IndexListEntry> {};

/// SlotIndex - An opaque wrapper around machine indexes.
class SlotIndex {
friend class SlotIndexes;
Expand Down Expand Up @@ -302,7 +298,7 @@ class raw_ostream;
// IndexListEntry allocator.
BumpPtrAllocator ileAllocator;

using IndexList = ilist<IndexListEntry>;
using IndexList = simple_ilist<IndexListEntry>;
IndexList indexList;

MachineFunction *mf = nullptr;
Expand Down Expand Up @@ -549,7 +545,7 @@ class raw_ostream;

// Insert a new list entry for MI.
IndexList::iterator newItr =
indexList.insert(nextItr, createEntry(&MI, newNumber));
indexList.insert(nextItr, *createEntry(&MI, newNumber));

// Renumber locally if we need to.
if (dist == 0)
Expand Down Expand Up @@ -608,7 +604,7 @@ class raw_ostream;
mbb->empty() ? endEntry
: getInstructionIndex(mbb->front()).listEntry();
IndexList::iterator newItr =
indexList.insert(insEntry->getIterator(), startEntry);
indexList.insert(insEntry->getIterator(), *startEntry);

SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/SlotIndexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SlotIndexes::SlotIndexes() : MachineFunctionPass(ID) {

SlotIndexes::~SlotIndexes() {
// The indexList's nodes are all allocated in the BumpPtrAllocator.
indexList.clearAndLeakNodesUnsafely();
indexList.clear();
}

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

indexList.push_back(createEntry(nullptr, index));
indexList.push_back(*createEntry(nullptr, index));

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

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

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

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

MBBRanges[MBB.getNumber()].first = blockStartIndex;
MBBRanges[MBB.getNumber()].second = SlotIndex(&indexList.back(),
Expand Down
16 changes: 8 additions & 8 deletions llvm/unittests/CodeGen/MLRegAllocDevelopmentFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
protected:
SmallVector<LRStartEndInfo>
setupOverlapProblem(const SmallVectorImpl<LRPosInfoIndexes> &Segments,
ilist<IndexListEntry> &IndexList) {
simple_ilist<IndexListEntry> &IndexList) {
SmallVector<LRStartEndInfo> PositionsToReturn;
PositionsToReturn.reserve(Segments.size());
for (auto CurrentPosIndexInfo : Segments) {
Expand All @@ -61,7 +61,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
Allocator.Allocate(sizeof(IndexListEntry), alignof(IndexListEntry)));
auto *CurrentListEntry =
new (CurrentLEMem) IndexListEntry(nullptr, CurrentIndex);
IndexList.push_back(CurrentListEntry);
IndexList.push_back(*CurrentListEntry);
for (size_t CurrentPosInfoIndex = 0;
CurrentPosInfoIndex < Segments.size(); ++CurrentPosInfoIndex) {
if ((CurrentIndex / SlotIndex::InstrDist) ==
Expand Down Expand Up @@ -107,7 +107,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
}

void runOverlapTest(SmallVectorImpl<LRPosInfoIndexes> &OverlapSetup) {
ilist<IndexListEntry> IndexList;
simple_ilist<IndexListEntry> IndexList;
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
NoInferenceModelRunner ModelRunner = setupModelRunner();
size_t MaxIndex = 0;
Expand All @@ -131,7 +131,7 @@ class RegAllocDevelopmentFeaturesTest : public ::Test {
NumberOfInterferences * ModelMaxSupportedInstructionCount);
ASSERT_THAT(MappingMatrix,
ContainerEq(getExpectedMappingMatrix(OverlapSetup)));
IndexList.clearAndLeakNodesUnsafely();
IndexList.clear();
}

BumpPtrAllocator Allocator;
Expand All @@ -144,7 +144,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest,
SmallVector<LRPosInfoIndexes, 2> OverlapSetup;
OverlapSetup.push_back({0, 5, 0});
OverlapSetup.push_back({5, 10, 0});
ilist<IndexListEntry> IndexList;
simple_ilist<IndexListEntry> IndexList;
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
ASSERT_EQ(OverlapProblem[0].End.distance(OverlapProblem[1].End),
5 * SlotIndex::InstrDist);
Expand All @@ -154,7 +154,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest,
TEST_F(RegAllocDevelopmentFeaturesTest, MetaSlotIndicesAreValid) {
SmallVector<LRPosInfoIndexes, 1> OverlapSetup;
OverlapSetup.push_back({0, 10, 0});
ilist<IndexListEntry> IndexList;
simple_ilist<IndexListEntry> IndexList;
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
ASSERT_TRUE(OverlapProblem[0].Begin.isValid());
ASSERT_TRUE(OverlapProblem[0].End.isValid());
Expand All @@ -165,7 +165,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest, MetaSlotIndicesAreValid) {
TEST_F(RegAllocDevelopmentFeaturesTest, InstructionOpcodesAreCorrect) {
SmallVector<LRPosInfoIndexes, 1> OverlapSetup;
OverlapSetup.push_back({0, ModelMaxSupportedInstructionCount - 1, 0});
ilist<IndexListEntry> IndexList;
simple_ilist<IndexListEntry> IndexList;
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
NoInferenceModelRunner ModelRunner = setupModelRunner();
SlotIndex LastIndex = OverlapProblem[0].End;
Expand Down Expand Up @@ -247,7 +247,7 @@ TEST_F(RegAllocDevelopmentFeaturesTest, SingleMBBTest) {
TEST_F(RegAllocDevelopmentFeaturesTest, MBBFullTruncated) {
SmallVector<LRPosInfoIndexes, 1> OverlapSetup;
OverlapSetup.push_back({0, ModelMaxSupportedInstructionCount - 1, 0});
ilist<IndexListEntry> IndexList;
simple_ilist<IndexListEntry> IndexList;
auto OverlapProblem = setupOverlapProblem(OverlapSetup, IndexList);
NoInferenceModelRunner ModelRunner = setupModelRunner();
SlotIndex LastIndex = OverlapProblem[0].End;
Expand Down
Loading