Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
99 changes: 38 additions & 61 deletions src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,16 @@ void lsraAssignRegToTree(GenTree* tree, regNumber reg, unsigned regIdx)
//
// Returns:
// Weight of ref position.
weight_t LinearScan::getWeight(RefPosition* refPos DEBUG_ARG(bool forDump))
weight_t LinearScan::getWeight(RefPosition* refPos)
{
// RefTypeKill does not have a valid treeNode field, but we do not expect
// to see getWeight called for it
assert(refPos->refType != RefTypeKill);

weight_t weight;
GenTree* treeNode = refPos->treeNode;

#ifdef HAS_MORE_THAN_64_REGISTERS
// If refType is `RefTypeKill`, we are using the killRegisterAssignment
// and treeNode field is garbage.
assert(forDump || refPos->refType != RefTypeKill);
#endif

if (treeNode != nullptr
#ifdef DEBUG
&& (refPos->refType != RefTypeKill)
#endif
)
if (treeNode != nullptr)
{
if (isCandidateLocalRef(treeNode))
{
Expand Down Expand Up @@ -241,21 +235,6 @@ weight_t LinearScan::getWeight(RefPosition* refPos DEBUG_ARG(bool forDump))
return weight;
}

#ifdef DEBUG
//-------------------------------------------------------------
// getWeightForDump: Returns the weight of the RefPosition, for dump
//
// Arguments:
// refPos - ref position
//
// Returns:
// Weight of ref position.
weight_t LinearScan::getWeightForDump(RefPosition* refPos)
{
return getWeight(refPos, true);
}
#endif

// allRegs represents a set of registers that can
// be used to allocate the specified type in any point
// in time (more of a 'bank' of registers).
Expand Down Expand Up @@ -303,11 +282,7 @@ void LinearScan::updateNextFixedRef(RegRecord* regRecord, RefPosition* nextRefPo
RefPosition* kill = nextKill;
while ((kill != nullptr) && (kill->nodeLocation < nextLocation))
{
#ifdef HAS_MORE_THAN_64_REGISTERS
if (kill->killRegisterAssignment.IsRegNumInMask(regRecord->regNum))
#else
if ((kill->registerAssignment & genSingleTypeRegMask(regRecord->regNum)) != RBM_NONE)
#endif
if (kill->killedRegisters.IsRegNumInMask(regRecord->regNum))
{
nextLocation = kill->nodeLocation;
break;
Expand Down Expand Up @@ -4066,7 +4041,7 @@ void LinearScan::processKills(RefPosition* killRefPosition)
{
RefPosition* nextKill = killRefPosition->nextRefPosition;

regMaskTP killedRegs = killRefPosition->getKillRegisterAssignment();
regMaskTP killedRegs = killRefPosition->getKilledRegisters();
while (killedRegs.IsNonEmpty())
{
regNumber killedReg = genFirstRegNumFromMaskAndToggle(killedRegs);
Expand All @@ -4086,9 +4061,9 @@ void LinearScan::processKills(RefPosition* killRefPosition)
updateNextFixedRef(regRecord, regNextRefPos, nextKill);
}

regsBusyUntilKill &= ~killRefPosition->getKillRegisterAssignment();
regsBusyUntilKill &= ~killRefPosition->getKilledRegisters();
INDEBUG(dumpLsraAllocationEvent(LSRA_EVENT_KILL_REGS, nullptr, REG_NA, nullptr, NONE,
killRefPosition->getKillRegisterAssignment()));
killRefPosition->getKilledRegisters()));
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -10420,36 +10395,34 @@ void RefPosition::dump(LinearScan* linearScan)

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

if (this->IsPhysRegRef())
if (IsPhysRegRef())
{
this->getReg()->tinyDump();
getReg()->tinyDump();
}
else if (getInterval())
{
this->getInterval()->tinyDump();
getInterval()->tinyDump();
}
if ((refType != RefTypeKill) && this->treeNode)
if ((refType != RefTypeKill) && treeNode)
{
printf("%s", treeNode->OpName(treeNode->OperGet()));
if (this->treeNode->IsMultiRegNode())
if (treeNode->IsMultiRegNode())
{
printf("[%d]", this->multiRegIdx);
printf("[%d]", multiRegIdx);
}
printf(" ");
}
printf(FMT_BB " ", this->bbNum);
printf(FMT_BB " ", bbNum);

printf("regmask=");
#ifdef HAS_MORE_THAN_64_REGISTERS
if (refType == RefTypeKill)
{
linearScan->compiler->dumpRegMask(getKillRegisterAssignment());
linearScan->compiler->dumpRegMask(getKilledRegisters());
}
else
#endif // HAS_MORE_THAN_64_REGISTERS
{
var_types type = TYP_UNKNOWN;
if ((refType == RefTypeBB) || (refType == RefTypeKillGCRefs) || (refType == RefTypeKill))
if ((refType == RefTypeBB) || (refType == RefTypeKillGCRefs))
{
// These refTypes do not have intervals
type = TYP_INT;
Expand All @@ -10463,57 +10436,61 @@ void RefPosition::dump(LinearScan* linearScan)

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

if (this->lastUse)
if (lastUse)
{
printf(" last");
}
if (this->reload)
if (reload)
{
printf(" reload");
}
if (this->spillAfter)
if (spillAfter)
{
printf(" spillAfter");
}
if (this->singleDefSpill)
if (singleDefSpill)
{
printf(" singleDefSpill");
}
if (this->writeThru)
if (writeThru)
{
printf(" writeThru");
}
if (this->moveReg)
if (moveReg)
{
printf(" move");
}
if (this->copyReg)
if (copyReg)
{
printf(" copy");
}
if (this->isFixedRegRef)
if (isFixedRegRef)
{
printf(" fixed");
}
if (this->isLocalDefUse)
if (isLocalDefUse)
{
printf(" local");
}
if (this->delayRegFree)
if (delayRegFree)
{
printf(" delay");
}
if (this->outOfOrder)
if (outOfOrder)
{
printf(" outOfOrder");
}

if (this->RegOptional())
if (RegOptional())
{
printf(" regOptional");
}

printf(" wt=%.2f", linearScan->getWeightForDump(this));
if (refType != RefTypeKill)
{
printf(" wt=%.2f", linearScan->getWeight(this));
}

printf(">\n");
}

Expand Down Expand Up @@ -11116,7 +11093,7 @@ void LinearScan::TupleStyleDump(LsraTupleDumpMode mode)
printf("\n Kill: ");
killPrinted = true;
}
compiler->dumpRegMask(currentRefPosition->getKillRegisterAssignment());
compiler->dumpRegMask(currentRefPosition->getKilledRegisters());
printf(" ");
break;
case RefTypeFixedReg:
Expand Down Expand Up @@ -12130,7 +12107,7 @@ void LinearScan::verifyFinalAllocation()

case RefTypeKill:
dumpLsraAllocationEvent(LSRA_EVENT_KILL_REGS, nullptr, REG_NA, currentBlock, NONE,
currentRefPosition.getKillRegisterAssignment());
currentRefPosition.getKilledRegisters());
break;

case RefTypeFixedReg:
Expand Down
17 changes: 4 additions & 13 deletions src/coreclr/jit/lsra.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,10 +1185,7 @@ class LinearScan : public LinearScanInterface

void associateRefPosWithInterval(RefPosition* rp);

weight_t getWeight(RefPosition* refPos DEBUG_ARG(bool forDump = false));
#ifdef DEBUG
weight_t getWeightForDump(RefPosition* refPos);
#endif // DEBUG
weight_t getWeight(RefPosition* refPos);

/*****************************************************************************
* Register management
Expand Down Expand Up @@ -2480,9 +2477,7 @@ class RefPosition
// After the allocation pass, this contains the actual assignment
SingleTypeRegSet registerAssignment;
};
#ifdef HAS_MORE_THAN_64_REGISTERS
regMaskTP killRegisterAssignment;
#endif
regMaskTP killedRegisters;
};
unsigned int bbNum;

Expand Down Expand Up @@ -2665,14 +2660,10 @@ class RefPosition
return referent->registerType;
}

regMaskTP getKillRegisterAssignment()
regMaskTP getKilledRegisters()
{
assert(refType == RefTypeKill);
#ifdef HAS_MORE_THAN_64_REGISTERS
return killRegisterAssignment;
#else
return registerAssignment;
#endif
return killedRegisters;
}

// Returns true if it is a reference on a GenTree node.
Expand Down
8 changes: 2 additions & 6 deletions src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,16 +647,14 @@ RefPosition* LinearScan::newRefPosition(Interval* theInterval,
theInterval->isSingleDef = theInterval->firstRefPosition == newRP;
}
#ifdef DEBUG
#ifdef HAS_MORE_THAN_64_REGISTERS
// Need to do this here do the dump can print the mask correctly.
// Doing in DEBUG so we do not incur of cost of this check for
// every RefPosition. We will set this anyway in addKillForRegs()
// in RELEASE.
if (theRefType == RefTypeKill)
{
newRP->killRegisterAssignment = mask;
newRP->killedRegisters = mask;
}
#endif // HAS_MORE_THAN_64_REGISTERS
#endif
DBEXEC(VERBOSE, newRP->dump(this));
return newRP;
Expand Down Expand Up @@ -720,9 +718,7 @@ void LinearScan::addKillForRegs(regMaskTP mask, LsraLocation currentLoc)

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

#ifdef HAS_MORE_THAN_64_REGISTERS
pos->killRegisterAssignment = mask;
#endif
pos->killedRegisters = mask;

*killTail = pos;
killTail = &pos->nextRefPosition;
Expand Down