Skip to content
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

JIT: Prezero memory for RefPosition and Interval (version 2) #103709

Closed
Closed
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
102 changes: 51 additions & 51 deletions src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,7 @@ LinearScanInterface* getLinearScanAllocator(Compiler* comp)
//
LinearScan::LinearScan(Compiler* theCompiler)
: compiler(theCompiler)
, intervals(theCompiler->getAllocator(CMK_LSRA_Interval))
, allocationPassComplete(false)
, refPositions(theCompiler->getAllocator(CMK_LSRA_RefPosition))
, killHead(nullptr)
, killTail(&killHead)
, listNodePool(theCompiler)
{
availableRegCount = ACTUAL_REG_COUNT;
Expand All @@ -827,6 +823,8 @@ LinearScan::LinearScan(Compiler* theCompiler)

firstColdLoc = MaxLocation;

currentRefPositionsBuffer = currentRefPositionsBufferEnd = nullptr;

#ifdef DEBUG
maxNodeLocation = 0;
consecutiveRegistersLocation = 0;
Expand Down Expand Up @@ -2457,8 +2455,8 @@ void LinearScan::checkLastUses(BasicBlock* block)
VARSET_TP computedLive(VarSetOps::MakeCopy(compiler, block->bbLiveOut));

bool foundDiff = false;
RefPositionReverseIterator currentRefPosition = refPositions.rbegin();
for (; currentRefPosition->refType != RefTypeBB; currentRefPosition++)
RefPosition* currentRefPosition = getAllRefPositionsTail();
for (; currentRefPosition->refType != RefTypeBB; currentRefPosition = currentRefPosition->prevAllRefPosition)
{
// We should never see ParamDefs or ZeroInits within a basic block.
assert(currentRefPosition->refType != RefTypeParamDef && currentRefPosition->refType != RefTypeZeroInit);
Expand Down Expand Up @@ -2517,7 +2515,7 @@ void LinearScan::checkLastUses(BasicBlock* block)
}
}

assert(currentRefPosition != refPositions.rend());
assert(currentRefPosition != nullptr);
}

VARSET_TP liveInNotComputedLive(VarSetOps::Diff(compiler, block->bbLiveIn, computedLive));
Expand Down Expand Up @@ -4862,9 +4860,9 @@ void LinearScan::dumpRefPositions(const char* str)
printf("------------\n");
printf("REFPOSITIONS %s: \n", str);
printf("------------\n");
for (RefPosition& refPos : refPositions)
for (RefPosition* refPos = allRefPositionsHead; refPos != nullptr; refPos = refPos->nextAllRefPosition)
{
refPos.dump(this);
refPos->dump(this);
}
}
#endif // DEBUG
Expand Down Expand Up @@ -4994,11 +4992,10 @@ void LinearScan::allocateRegistersMinimal()
DBEXEC(VERBOSE, lsraDumpIntervals("before allocateRegistersMinimal"));

// at start, nothing is active except for register args
for (Interval& interval : intervals)
for (Interval* interval = intervalsHead; interval != nullptr; interval = interval->nextInterval)
{
Interval* currentInterval = &interval;
currentInterval->recentRefPosition = nullptr;
assert(!currentInterval->isActive);
interval->recentRefPosition = nullptr;
assert(!interval->isActive);
}

resetRegState();
Expand Down Expand Up @@ -5049,8 +5046,10 @@ void LinearScan::allocateRegistersMinimal()

bool handledBlockEnd = false;

for (RefPosition& currentRefPosition : refPositions)
for (RefPosition* pCurrentRefPosition = allRefPositionsHead; pCurrentRefPosition != nullptr; pCurrentRefPosition = pCurrentRefPosition->nextAllRefPosition)
{
RefPosition& currentRefPosition = *pCurrentRefPosition;

// TODO: Can we combine this with the freeing of registers below? It might
// mess with the dump, since this was previously being done before the call below
// to dumpRegRecords.
Expand Down Expand Up @@ -5613,12 +5612,12 @@ void LinearScan::allocateRegistersMinimal()
// provide a Reset function (!) - we'll probably replace this so don't bother
// adding it

for (Interval& interval : intervals)
for (Interval* interval = intervalsHead; interval != nullptr; interval = interval->nextInterval)
{
if (interval.isActive)
if (interval->isActive)
{
printf("Active ");
interval.dump(this->compiler);
interval->dump(this->compiler);
}
}

Expand All @@ -5640,17 +5639,16 @@ void LinearScan::allocateRegisters()
DBEXEC(VERBOSE, lsraDumpIntervals("before allocateRegisters"));

// at start, nothing is active except for register args
for (Interval& interval : intervals)
for (Interval* interval = intervalsHead; interval != nullptr; interval = interval->nextInterval)
{
Interval* currentInterval = &interval;
currentInterval->recentRefPosition = nullptr;
currentInterval->isActive = false;
if (currentInterval->isLocalVar && !stressInitialParamReg())
interval->recentRefPosition = nullptr;
interval->isActive = false;
if (interval->isLocalVar && !stressInitialParamReg())
{
LclVarDsc* varDsc = currentInterval->getLocalVar(compiler);
if (varDsc->lvIsRegArg && currentInterval->firstRefPosition != nullptr)
LclVarDsc* varDsc = interval->getLocalVar(compiler);
if (varDsc->lvIsRegArg && interval->firstRefPosition != nullptr)
{
currentInterval->isActive = true;
interval->isActive = true;
}
}
}
Expand Down Expand Up @@ -5733,8 +5731,9 @@ void LinearScan::allocateRegisters()

bool handledBlockEnd = false;

for (RefPosition& currentRefPosition : refPositions)
for (RefPosition* pCurrentRefPosition = allRefPositionsHead; pCurrentRefPosition != nullptr; pCurrentRefPosition = pCurrentRefPosition->nextAllRefPosition)
{
RefPosition& currentRefPosition = *pCurrentRefPosition;
RefPosition* nextRefPosition = currentRefPosition.nextRefPosition;

// TODO: Can we combine this with the freeing of registers below? It might
Expand Down Expand Up @@ -6914,12 +6913,12 @@ void LinearScan::allocateRegisters()
// provide a Reset function (!) - we'll probably replace this so don't bother
// adding it

for (Interval& interval : intervals)
for (Interval* interval = intervalsHead; interval != nullptr; interval = interval->nextInterval)
{
if (interval.isActive)
if (interval->isActive)
{
printf("Active ");
interval.dump(this->compiler);
interval->dump(this->compiler);
}
}

Expand Down Expand Up @@ -8018,12 +8017,12 @@ void LinearScan::resolveRegisters()
}

// handle incoming arguments and special temps
RefPositionIterator currentRefPosition = refPositions.begin();
RefPosition* currentRefPosition = allRefPositionsHead;

if (localVarsEnregistered)
{
VarToRegMap entryVarToRegMap = inVarToRegMaps[compiler->fgFirstBB->bbNum];
for (; currentRefPosition != refPositions.end(); ++currentRefPosition)
for (; currentRefPosition != nullptr; currentRefPosition = currentRefPosition->nextAllRefPosition)
{
if (currentRefPosition->refType != RefTypeParamDef && currentRefPosition->refType != RefTypeZeroInit)
{
Expand All @@ -8050,7 +8049,7 @@ void LinearScan::resolveRegisters()
}
else
{
assert(currentRefPosition == refPositions.end() ||
assert(currentRefPosition == nullptr ||
(currentRefPosition->refType != RefTypeParamDef && currentRefPosition->refType != RefTypeZeroInit));
}

Expand All @@ -8071,7 +8070,7 @@ void LinearScan::resolveRegisters()
}

// Handle the DummyDefs, updating the incoming var location.
for (; currentRefPosition != refPositions.end(); ++currentRefPosition)
for (; currentRefPosition != nullptr; currentRefPosition = currentRefPosition->nextAllRefPosition)
{
if (currentRefPosition->refType != RefTypeDummyDef)
{
Expand All @@ -8097,12 +8096,12 @@ void LinearScan::resolveRegisters()
}

// The next RefPosition should be for the block. Move past it.
assert(currentRefPosition != refPositions.end());
assert(currentRefPosition != nullptr);
assert(currentRefPosition->refType == RefTypeBB);
++currentRefPosition;
currentRefPosition = currentRefPosition->nextAllRefPosition;

// Handle the RefPositions for the block
for (; currentRefPosition != refPositions.end(); ++currentRefPosition)
for (; currentRefPosition != nullptr; currentRefPosition = currentRefPosition->nextAllRefPosition)
{
if (currentRefPosition->refType == RefTypeBB || currentRefPosition->refType == RefTypeDummyDef)
{
Expand Down Expand Up @@ -10169,8 +10168,8 @@ void LinearScan::dumpLsraStats(FILE* file)
fprintf(file, "Total Tracked Vars: %d\n", compiler->lvaTrackedCount);
fprintf(file, "Total Reg Cand Vars: %d\n", regCandidateVarCount);
fprintf(file, "Total number of Intervals: %d\n",
static_cast<unsigned>((intervals.size() == 0 ? 0 : (intervals.size() - 1))));
fprintf(file, "Total number of RefPositions: %d\n", static_cast<unsigned>(refPositions.size() - 1));
static_cast<unsigned>((numIntervals == 0 ? 0 : (numIntervals - 1))));
fprintf(file, "Total number of RefPositions: %d\n", static_cast<unsigned>(numRefPositions));

// compute total number of spill temps created
unsigned numSpillTemps = 0;
Expand Down Expand Up @@ -10675,11 +10674,11 @@ void LinearScan::dumpDefList()
void LinearScan::lsraDumpIntervals(const char* msg)
{
printf("\nLinear scan intervals %s:\n", msg);
for (Interval& interval : intervals)
for (Interval* interval = intervalsHead; interval != nullptr; interval = interval->nextInterval)
{
// only dump something if it has references
// if (interval->firstRefPosition)
interval.dump(this->compiler);
interval->dump(this->compiler);
}

printf("\n");
Expand Down Expand Up @@ -10877,7 +10876,7 @@ void LinearScan::TupleStyleDump(LsraTupleDumpMode mode)
// currentRefPosition is not used for LSRA_DUMP_PRE
// We keep separate iterators for defs, so that we can print them
// on the lhs of the dump
RefPositionIterator currentRefPosition = refPositions.begin();
RefPosition* currentRefPosition = allRefPositionsHead;

switch (mode)
{
Expand All @@ -10898,7 +10897,7 @@ void LinearScan::TupleStyleDump(LsraTupleDumpMode mode)
if (mode != LSRA_DUMP_PRE)
{
printf("Incoming Parameters: ");
for (; currentRefPosition != refPositions.end(); ++currentRefPosition)
for (; currentRefPosition != nullptr; currentRefPosition = currentRefPosition->nextAllRefPosition)
{
if (currentRefPosition->refType == RefTypeBB)
{
Expand Down Expand Up @@ -10944,7 +10943,7 @@ void LinearScan::TupleStyleDump(LsraTupleDumpMode mode)
{
bool printedBlockHeader = false;
// We should find the boundary RefPositions in the order of exposed uses, dummy defs, and the blocks
for (; currentRefPosition != refPositions.end(); ++currentRefPosition)
for (; currentRefPosition != nullptr; currentRefPosition = currentRefPosition->nextAllRefPosition)
{
Interval* interval = nullptr;
if (currentRefPosition->isIntervalRef())
Expand Down Expand Up @@ -11036,7 +11035,7 @@ void LinearScan::TupleStyleDump(LsraTupleDumpMode mode)
// and combining the fixed regs with their associated def or use
bool killPrinted = false;
RefPosition* lastFixedRegRefPos = nullptr;
for (; currentRefPosition != refPositions.end(); ++currentRefPosition)
for (; currentRefPosition != nullptr; currentRefPosition = currentRefPosition->nextAllRefPosition)
{
if (!(currentRefPosition->nodeLocation == tree->gtSeqNum ||
currentRefPosition->nodeLocation == tree->gtSeqNum + 1))
Expand Down Expand Up @@ -11417,7 +11416,7 @@ void LinearScan::dumpRegRecordHeader()

// First, determine the width of each register column (which holds a reg name in the
// header, and an interval name in each subsequent row).
int intervalNumberWidth = (int)log10((double)intervals.size()) + 1;
int intervalNumberWidth = (int)log10((double)numIntervals) + 1;
// The regColumnWidth includes the identifying character (I or V) and an 'i', 'p' or 'a' (inactive,
// partially-spilled or active)
regColumnWidth = intervalNumberWidth + 2;
Expand All @@ -11443,10 +11442,10 @@ void LinearScan::dumpRegRecordHeader()
maxNodeLocation = (maxNodeLocation == 0) ? 1 : maxNodeLocation; // corner case of a method with an infinite loop
// without any GenTree nodes
assert(maxNodeLocation >= 1);
assert(refPositions.size() >= 1);
assert(numRefPositions >= 1);
int treeIdWidth = 9; /* '[XXXXX] '*/
int nodeLocationWidth = (int)log10((double)maxNodeLocation) + 1;
int refPositionWidth = (int)log10((double)refPositions.size()) + 1;
int refPositionWidth = (int)log10((double)numRefPositions) + 1;
int refTypeInfoWidth = 4 /*TYPE*/ + 2 /* last-use and delayed */ + 1 /* space */;
int locationAndRPNumWidth = nodeLocationWidth + 2 /* .# */ + refPositionWidth + 1 /* space */;
int shortRefPositionDumpWidth = locationAndRPNumWidth + regColumnWidth + 1 /* space */ + refTypeInfoWidth;
Expand Down Expand Up @@ -11960,19 +11959,20 @@ void LinearScan::verifyFinalAllocation()
physRegRecord->assignedInterval = nullptr;
}

for (Interval& interval : intervals)
for (Interval* interval = intervalsHead; interval != nullptr; interval = interval->nextInterval)
{
interval.assignedReg = nullptr;
interval.physReg = REG_NA;
interval->assignedReg = nullptr;
interval->physReg = REG_NA;
}

DBEXEC(VERBOSE, dumpRegRecordTitle());

BasicBlock* currentBlock = nullptr;
GenTree* firstBlockEndResolutionNode = nullptr;
LsraLocation currentLocation = MinLocation;
for (RefPosition& currentRefPosition : refPositions)
for (RefPosition* pCurrentRefPosition = allRefPositionsHead; pCurrentRefPosition != nullptr; pCurrentRefPosition = pCurrentRefPosition->nextAllRefPosition)
{
RefPosition& currentRefPosition = *pCurrentRefPosition;
Interval* interval = nullptr;
RegRecord* regRecord = nullptr;
regNumber regNum = REG_NA;
Expand Down
Loading
Loading