Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 990ecc7

Browse files
committed
LSRA: Replace operandToLocationInfoMap with a list
formatting
1 parent 8370991 commit 990ecc7

File tree

2 files changed

+56
-27
lines changed

2 files changed

+56
-27
lines changed

src/jit/lsra.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,7 +3488,7 @@ void LinearScan::buildRefPositionsForNode(GenTree* tree,
34883488
#ifdef DEBUG
34893489
if (VERBOSE)
34903490
{
3491-
dumpOperandToLocationInfoMap();
3491+
dumpDefList();
34923492
compiler->gtDispTree(tree, nullptr, nullptr, true);
34933493
}
34943494
#endif // DEBUG
@@ -3583,8 +3583,7 @@ void LinearScan::buildRefPositionsForNode(GenTree* tree,
35833583
assert(produce != 0);
35843584

35853585
locationInfo->interval = getIntervalForLocalVar(varIndex);
3586-
bool added = operandToLocationInfoMap->AddOrUpdate(tree, locationInfo);
3587-
assert(added);
3586+
defList.Append(locationInfo);
35883587
}
35893588
return;
35903589
}
@@ -3991,8 +3990,7 @@ void LinearScan::buildRefPositionsForNode(GenTree* tree,
39913990
{
39923991
locationInfo->interval = interval;
39933992
prevInterval = interval;
3994-
bool added = operandToLocationInfoMap->AddOrUpdate(tree, locationInfo);
3995-
assert(added);
3993+
defList.Append(locationInfo);
39963994
}
39973995
else
39983996
{
@@ -4505,8 +4503,6 @@ void LinearScan::buildIntervals()
45054503
}
45064504

45074505
LocationInfoListNodePool listNodePool(compiler, 8);
4508-
OperandToLocationInfoMap theOperandToLocationInfoMap(compiler);
4509-
operandToLocationInfoMap = &theOperandToLocationInfoMap;
45104506

45114507
BasicBlock* predBlock = nullptr;
45124508
BasicBlock* prevBlock = nullptr;
@@ -4627,7 +4623,7 @@ void LinearScan::buildIntervals()
46274623

46284624
// Note: the visited set is cleared in LinearScan::doLinearScan()
46294625
markBlockVisited(block);
4630-
assert(operandToLocationInfoMap->Count() == 0);
4626+
assert(defList.IsEmpty());
46314627

46324628
if (enregisterLocalVars)
46334629
{
@@ -11418,17 +11414,15 @@ void TreeNodeInfo::dump(LinearScan* lsra)
1141811414
printf(">");
1141911415
}
1142011416

11421-
void LinearScan::dumpOperandToLocationInfoMap()
11417+
void LinearScan::dumpDefList()
1142211418
{
11423-
JITDUMP("OperandToLocationInfoMap: { ");
11419+
JITDUMP("DefList: { ");
1142411420
bool first = true;
11425-
for (auto kvp : *operandToLocationInfoMap)
11421+
for (LocationInfoListNode *listNode = defList.Begin(), *end = defList.End(); listNode != end;
11422+
listNode = listNode->Next())
1142611423
{
11427-
GenTree* node = kvp.Key();
11428-
LocationInfoListNode* def = kvp.Value();
11429-
11424+
GenTree* node = listNode->treeNode;
1143011425
JITDUMP("%sN%03u.t%d. %s", first ? "" : "; ", node->gtSeqNum, node->gtTreeID, GenTree::OpName(node->OperGet()));
11431-
1143211426
first = false;
1143311427
}
1143411428
JITDUMP(" }\n");

src/jit/lsra.h

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,43 @@ class LocationInfoList final
235235
// from the useList being constructed. Note that, if the user knows the order of the operands,
236236
// it is expected that they should just retrieve them directly.
237237

238+
LocationInfoListNode* removeListNode(GenTree* node)
239+
{
240+
LocationInfoListNode* prevListNode = nullptr;
241+
for (LocationInfoListNode *listNode = Begin(), *end = End(); listNode != end; listNode = listNode->Next())
242+
{
243+
if (listNode->treeNode == node)
244+
{
245+
LocationInfoListNode* nextNode = listNode->Next();
246+
if (prevListNode == nullptr)
247+
{
248+
m_head = nextNode;
249+
}
250+
else
251+
{
252+
prevListNode->m_next = nextNode;
253+
}
254+
if (nextNode == nullptr)
255+
{
256+
m_tail = prevListNode;
257+
}
258+
listNode->m_next = nullptr;
259+
return listNode;
260+
}
261+
prevListNode = listNode;
262+
}
263+
assert(!"GetTreeNodeInfo didn't find the node");
264+
unreached();
265+
}
266+
267+
//------------------------------------------------------------------------
268+
// GetTreeNodeInfo - retrieve the TreeNodeInfo for the given node
269+
//
270+
// Notes:
271+
// The TreeNodeInfoInit methods use this helper to retrieve the TreeNodeInfo for child nodes
272+
// from the useList being constructed. Note that, if the user knows the order of the operands,
273+
// it is expected that they should just retrieve them directly.
274+
238275
TreeNodeInfo& GetTreeNodeInfo(GenTree* node)
239276
{
240277
for (LocationInfoListNode *listNode = Begin(), *end = End(); listNode != end; listNode = listNode->Next())
@@ -843,7 +880,7 @@ class LinearScan : public LinearScanInterface
843880
}
844881

845882
// Dump support
846-
void dumpOperandToLocationInfoMap();
883+
void dumpDefList();
847884
void lsraDumpIntervals(const char* msg);
848885
void dumpRefPositions(const char* msg);
849886
void dumpVarRefPositions(const char* msg);
@@ -1445,30 +1482,28 @@ class LinearScan : public LinearScanInterface
14451482
// TreeNodeInfo methods
14461483
//-----------------------------------------------------------------------
14471484

1448-
// The operandToLocationInfoMap is used for the transient TreeNodeInfo that is computed by
1485+
// The defList is used for the transient TreeNodeInfo that is computed by
14491486
// the TreeNodeInfoInit methods, and used in building RefPositions.
1450-
typedef SmallHashTable<GenTree*, LocationInfoListNode*, 32> OperandToLocationInfoMap;
1451-
OperandToLocationInfoMap* operandToLocationInfoMap;
1487+
// When Def RefPositions are built for a node, their NodeInfo is placed
1488+
// in the defList. As the consuming node is handled, it moves the NodeInfo
1489+
// into an ordered useList corresponding to the uses for that node.
1490+
LocationInfoList defList;
14521491
// The useList is constructed for each node by the TreeNodeInfoInit methods.
14531492
// It contains the TreeNodeInfo for its operands, in their order of use.
14541493
LocationInfoList useList;
14551494

1456-
// Get the LocationInfoListNode for the given node, and put it into the useList.
1495+
// Remove the LocationInfoListNode for the given node from the defList, and put it into the useList.
14571496
// The node must not be contained, and must have been processed by buildRefPositionsForNode().
14581497
void appendLocationInfoToList(GenTree* node)
14591498
{
1460-
LocationInfoListNode* locationInfo;
1461-
bool found = operandToLocationInfoMap->TryRemove(node, &locationInfo);
1462-
assert(found);
1499+
LocationInfoListNode* locationInfo = defList.removeListNode(node);
14631500
useList.Append(locationInfo);
14641501
}
14651502
// Get the LocationInfoListNodes for the given node, and return it, but don't put it into the useList.
14661503
// The node must not be contained, and must have been processed by buildRefPositionsForNode().
14671504
LocationInfoListNode* getLocationInfo(GenTree* node)
14681505
{
1469-
LocationInfoListNode* locationInfo;
1470-
bool found = operandToLocationInfoMap->TryRemove(node, &locationInfo);
1471-
assert(found);
1506+
LocationInfoListNode* locationInfo = defList.removeListNode(node);
14721507
return locationInfo;
14731508
}
14741509
//------------------------------------------------------------------------
@@ -1483,7 +1518,7 @@ class LinearScan : public LinearScanInterface
14831518
//
14841519
// Notes:
14851520
// The operands must already have been processed by buildRefPositionsForNode, and their
1486-
// LocationInfoListNodes placed in the operandToLocationInfoMap.
1521+
// LocationInfoListNodes placed in the defList.
14871522
//
14881523
int appendBinaryLocationInfoToList(GenTreeOp* node)
14891524
{

0 commit comments

Comments
 (0)