Skip to content

Commit a39fed2

Browse files
authored
JIT: Clean up RefPosition "killed registers" storage (#103560)
Avoid some ifdefs and rename the field to reflect more specifically what it represents. Also avoid calling `getWeight` entirely for `RefTypeKill` ref positions, even for dumping. Dumping this info does not make much sense since there was a requirement that it was never called in non-dump paths anyway.
1 parent 63b613c commit a39fed2

File tree

3 files changed

+44
-80
lines changed

3 files changed

+44
-80
lines changed

src/coreclr/jit/lsra.cpp

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,16 @@ void lsraAssignRegToTree(GenTree* tree, regNumber reg, unsigned regIdx)
178178
//
179179
// Returns:
180180
// Weight of ref position.
181-
weight_t LinearScan::getWeight(RefPosition* refPos DEBUG_ARG(bool forDump))
181+
weight_t LinearScan::getWeight(RefPosition* refPos)
182182
{
183+
// RefTypeKill does not have a valid treeNode field, so we do not expect
184+
// to see getWeight called for it
185+
assert(refPos->refType != RefTypeKill);
186+
183187
weight_t weight;
184188
GenTree* treeNode = refPos->treeNode;
185189

186-
#ifdef HAS_MORE_THAN_64_REGISTERS
187-
// If refType is `RefTypeKill`, we are using the killRegisterAssignment
188-
// and treeNode field is garbage.
189-
assert(forDump || refPos->refType != RefTypeKill);
190-
#endif
191-
192-
if (treeNode != nullptr
193-
#ifdef DEBUG
194-
&& (refPos->refType != RefTypeKill)
195-
#endif
196-
)
190+
if (treeNode != nullptr)
197191
{
198192
if (isCandidateLocalRef(treeNode))
199193
{
@@ -241,21 +235,6 @@ weight_t LinearScan::getWeight(RefPosition* refPos DEBUG_ARG(bool forDump))
241235
return weight;
242236
}
243237

244-
#ifdef DEBUG
245-
//-------------------------------------------------------------
246-
// getWeightForDump: Returns the weight of the RefPosition, for dump
247-
//
248-
// Arguments:
249-
// refPos - ref position
250-
//
251-
// Returns:
252-
// Weight of ref position.
253-
weight_t LinearScan::getWeightForDump(RefPosition* refPos)
254-
{
255-
return getWeight(refPos, true);
256-
}
257-
#endif
258-
259238
// allRegs represents a set of registers that can
260239
// be used to allocate the specified type in any point
261240
// in time (more of a 'bank' of registers).
@@ -303,11 +282,7 @@ void LinearScan::updateNextFixedRef(RegRecord* regRecord, RefPosition* nextRefPo
303282
RefPosition* kill = nextKill;
304283
while ((kill != nullptr) && (kill->nodeLocation < nextLocation))
305284
{
306-
#ifdef HAS_MORE_THAN_64_REGISTERS
307-
if (kill->killRegisterAssignment.IsRegNumInMask(regRecord->regNum))
308-
#else
309-
if ((kill->registerAssignment & genSingleTypeRegMask(regRecord->regNum)) != RBM_NONE)
310-
#endif
285+
if (kill->killedRegisters.IsRegNumInMask(regRecord->regNum))
311286
{
312287
nextLocation = kill->nodeLocation;
313288
break;
@@ -4066,7 +4041,7 @@ void LinearScan::processKills(RefPosition* killRefPosition)
40664041
{
40674042
RefPosition* nextKill = killRefPosition->nextRefPosition;
40684043

4069-
regMaskTP killedRegs = killRefPosition->getKillRegisterAssignment();
4044+
regMaskTP killedRegs = killRefPosition->getKilledRegisters();
40704045
while (killedRegs.IsNonEmpty())
40714046
{
40724047
regNumber killedReg = genFirstRegNumFromMaskAndToggle(killedRegs);
@@ -4086,9 +4061,9 @@ void LinearScan::processKills(RefPosition* killRefPosition)
40864061
updateNextFixedRef(regRecord, regNextRefPos, nextKill);
40874062
}
40884063

4089-
regsBusyUntilKill &= ~killRefPosition->getKillRegisterAssignment();
4064+
regsBusyUntilKill &= ~killRefPosition->getKilledRegisters();
40904065
INDEBUG(dumpLsraAllocationEvent(LSRA_EVENT_KILL_REGS, nullptr, REG_NA, nullptr, NONE,
4091-
killRefPosition->getKillRegisterAssignment()));
4066+
killRefPosition->getKilledRegisters()));
40924067
}
40934068

40944069
//------------------------------------------------------------------------
@@ -10420,36 +10395,34 @@ void RefPosition::dump(LinearScan* linearScan)
1042010395

1042110396
printf(" %s ", getRefTypeName(refType));
1042210397

10423-
if (this->IsPhysRegRef())
10398+
if (IsPhysRegRef())
1042410399
{
10425-
this->getReg()->tinyDump();
10400+
getReg()->tinyDump();
1042610401
}
1042710402
else if (getInterval())
1042810403
{
10429-
this->getInterval()->tinyDump();
10404+
getInterval()->tinyDump();
1043010405
}
10431-
if ((refType != RefTypeKill) && this->treeNode)
10406+
if ((refType != RefTypeKill) && treeNode)
1043210407
{
1043310408
printf("%s", treeNode->OpName(treeNode->OperGet()));
10434-
if (this->treeNode->IsMultiRegNode())
10409+
if (treeNode->IsMultiRegNode())
1043510410
{
10436-
printf("[%d]", this->multiRegIdx);
10411+
printf("[%d]", multiRegIdx);
1043710412
}
1043810413
printf(" ");
1043910414
}
10440-
printf(FMT_BB " ", this->bbNum);
10415+
printf(FMT_BB " ", bbNum);
1044110416

1044210417
printf("regmask=");
10443-
#ifdef HAS_MORE_THAN_64_REGISTERS
1044410418
if (refType == RefTypeKill)
1044510419
{
10446-
linearScan->compiler->dumpRegMask(getKillRegisterAssignment());
10420+
linearScan->compiler->dumpRegMask(getKilledRegisters());
1044710421
}
1044810422
else
10449-
#endif // HAS_MORE_THAN_64_REGISTERS
1045010423
{
1045110424
var_types type = TYP_UNKNOWN;
10452-
if ((refType == RefTypeBB) || (refType == RefTypeKillGCRefs) || (refType == RefTypeKill))
10425+
if ((refType == RefTypeBB) || (refType == RefTypeKillGCRefs))
1045310426
{
1045410427
// These refTypes do not have intervals
1045510428
type = TYP_INT;
@@ -10463,57 +10436,61 @@ void RefPosition::dump(LinearScan* linearScan)
1046310436

1046410437
printf(" minReg=%d", minRegCandidateCount);
1046510438

10466-
if (this->lastUse)
10439+
if (lastUse)
1046710440
{
1046810441
printf(" last");
1046910442
}
10470-
if (this->reload)
10443+
if (reload)
1047110444
{
1047210445
printf(" reload");
1047310446
}
10474-
if (this->spillAfter)
10447+
if (spillAfter)
1047510448
{
1047610449
printf(" spillAfter");
1047710450
}
10478-
if (this->singleDefSpill)
10451+
if (singleDefSpill)
1047910452
{
1048010453
printf(" singleDefSpill");
1048110454
}
10482-
if (this->writeThru)
10455+
if (writeThru)
1048310456
{
1048410457
printf(" writeThru");
1048510458
}
10486-
if (this->moveReg)
10459+
if (moveReg)
1048710460
{
1048810461
printf(" move");
1048910462
}
10490-
if (this->copyReg)
10463+
if (copyReg)
1049110464
{
1049210465
printf(" copy");
1049310466
}
10494-
if (this->isFixedRegRef)
10467+
if (isFixedRegRef)
1049510468
{
1049610469
printf(" fixed");
1049710470
}
10498-
if (this->isLocalDefUse)
10471+
if (isLocalDefUse)
1049910472
{
1050010473
printf(" local");
1050110474
}
10502-
if (this->delayRegFree)
10475+
if (delayRegFree)
1050310476
{
1050410477
printf(" delay");
1050510478
}
10506-
if (this->outOfOrder)
10479+
if (outOfOrder)
1050710480
{
1050810481
printf(" outOfOrder");
1050910482
}
1051010483

10511-
if (this->RegOptional())
10484+
if (RegOptional())
1051210485
{
1051310486
printf(" regOptional");
1051410487
}
1051510488

10516-
printf(" wt=%.2f", linearScan->getWeightForDump(this));
10489+
if (refType != RefTypeKill)
10490+
{
10491+
printf(" wt=%.2f", linearScan->getWeight(this));
10492+
}
10493+
1051710494
printf(">\n");
1051810495
}
1051910496

@@ -11116,7 +11093,7 @@ void LinearScan::TupleStyleDump(LsraTupleDumpMode mode)
1111611093
printf("\n Kill: ");
1111711094
killPrinted = true;
1111811095
}
11119-
compiler->dumpRegMask(currentRefPosition->getKillRegisterAssignment());
11096+
compiler->dumpRegMask(currentRefPosition->getKilledRegisters());
1112011097
printf(" ");
1112111098
break;
1112211099
case RefTypeFixedReg:
@@ -12130,7 +12107,7 @@ void LinearScan::verifyFinalAllocation()
1213012107

1213112108
case RefTypeKill:
1213212109
dumpLsraAllocationEvent(LSRA_EVENT_KILL_REGS, nullptr, REG_NA, currentBlock, NONE,
12133-
currentRefPosition.getKillRegisterAssignment());
12110+
currentRefPosition.getKilledRegisters());
1213412111
break;
1213512112

1213612113
case RefTypeFixedReg:

src/coreclr/jit/lsra.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,7 @@ class LinearScan : public LinearScanInterface
11851185

11861186
void associateRefPosWithInterval(RefPosition* rp);
11871187

1188-
weight_t getWeight(RefPosition* refPos DEBUG_ARG(bool forDump = false));
1189-
#ifdef DEBUG
1190-
weight_t getWeightForDump(RefPosition* refPos);
1191-
#endif // DEBUG
1188+
weight_t getWeight(RefPosition* refPos);
11921189

11931190
/*****************************************************************************
11941191
* Register management
@@ -2480,9 +2477,7 @@ class RefPosition
24802477
// After the allocation pass, this contains the actual assignment
24812478
SingleTypeRegSet registerAssignment;
24822479
};
2483-
#ifdef HAS_MORE_THAN_64_REGISTERS
2484-
regMaskTP killRegisterAssignment;
2485-
#endif
2480+
regMaskTP killedRegisters;
24862481
};
24872482
unsigned int bbNum;
24882483

@@ -2665,14 +2660,10 @@ class RefPosition
26652660
return referent->registerType;
26662661
}
26672662

2668-
regMaskTP getKillRegisterAssignment()
2663+
regMaskTP getKilledRegisters()
26692664
{
26702665
assert(refType == RefTypeKill);
2671-
#ifdef HAS_MORE_THAN_64_REGISTERS
2672-
return killRegisterAssignment;
2673-
#else
2674-
return registerAssignment;
2675-
#endif
2666+
return killedRegisters;
26762667
}
26772668

26782669
// Returns true if it is a reference on a GenTree node.

src/coreclr/jit/lsrabuild.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,16 +637,14 @@ RefPosition* LinearScan::newRefPosition(Interval* theInterval,
637637
theInterval->isSingleDef = theInterval->firstRefPosition == newRP;
638638
}
639639
#ifdef DEBUG
640-
#ifdef HAS_MORE_THAN_64_REGISTERS
641640
// Need to do this here do the dump can print the mask correctly.
642641
// Doing in DEBUG so we do not incur of cost of this check for
643642
// every RefPosition. We will set this anyway in addKillForRegs()
644643
// in RELEASE.
645644
if (theRefType == RefTypeKill)
646645
{
647-
newRP->killRegisterAssignment = mask;
646+
newRP->killedRegisters = mask;
648647
}
649-
#endif // HAS_MORE_THAN_64_REGISTERS
650648
#endif
651649
DBEXEC(VERBOSE, newRP->dump(this));
652650
return newRP;
@@ -710,9 +708,7 @@ void LinearScan::addKillForRegs(regMaskTP mask, LsraLocation currentLoc)
710708

711709
RefPosition* pos = newRefPosition((Interval*)nullptr, currentLoc, RefTypeKill, nullptr, mask.getLow());
712710

713-
#ifdef HAS_MORE_THAN_64_REGISTERS
714-
pos->killRegisterAssignment = mask;
715-
#endif
711+
pos->killedRegisters = mask;
716712

717713
*killTail = pos;
718714
killTail = &pos->nextRefPosition;

0 commit comments

Comments
 (0)