Skip to content

Commit 3f1d7c8

Browse files
authored
Merge pull request #242 from hzongaro/issue17033-commoning-store-sinking-0.54.0
[0.54.0] Track distinct live commoned loads of locals for Store Sinking
2 parents 1c85e61 + f8b8e06 commit 3f1d7c8

File tree

3 files changed

+130
-18
lines changed

3 files changed

+130
-18
lines changed

compiler/optimizer/DataFlowAnalysis.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,20 @@ class TR_LiveVariableInformation
766766
int32_t numNodes() { return _numNodes; }
767767

768768
TR_BitVector *liveCommonedLoads() { return _liveCommonedLoads; }
769+
770+
/**
771+
* The number of distinct commoned loads that are live for a particular
772+
* local variable during a backwards tree walk.
773+
* \param localIdx The index of a local variable
774+
* \returns The number of distinct commoned loads of the local variable
775+
* that are live, or zero if the number of distinct commoned
776+
* loads is not being tracked.
777+
*/
778+
int32_t numDistinctCommonedLoads(int32_t localIdx)
779+
{
780+
return (_distinctCommonedLoads == NULL) ? 0 : _distinctCommonedLoads[localIdx];
781+
}
782+
769783
void createGenAndKillSetCaches();
770784
void initializeGenAndKillSetInfo(TR_BitVector **genSetInfo, TR_BitVector **killSetInfo,
771785
TR_BitVector **exceptionGenSetInfo, TR_BitVector **exceptionKillSetInfo);
@@ -815,6 +829,20 @@ class TR_LiveVariableInformation
815829

816830
// this bit vector tracks which commoned loads are currently live
817831
TR_BitVector *_liveCommonedLoads;
832+
833+
/**
834+
* A \ref TR::NodeChecklist that is used to keep track of whether a particular
835+
* commoned \ref TR::Node for the load of a local variable has already been
836+
* encountered during a backwards tree walk.
837+
*/
838+
TR::NodeChecklist *_seenCommonedNodeForLoadOfLocal;
839+
840+
/**
841+
* An array that is used to keep track of the number of distinct commoned
842+
* loads of a local variable that are live at a given point in a backwards
843+
* tree walk.
844+
*/
845+
int32_t *_distinctCommonedLoads;
818846
};
819847

820848

compiler/optimizer/LiveVariableInformation.cpp

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class TR_Structure;
5454
namespace TR { class Optimizer; }
5555

5656
TR_LiveVariableInformation::TR_LiveVariableInformation(TR::Compilation *c,
57-
TR::Optimizer *optimizer,
58-
TR_Structure *rootStructure,
59-
bool splitLongs,
60-
bool includeParms,
57+
TR::Optimizer *optimizer,
58+
TR_Structure *rootStructure,
59+
bool splitLongs,
60+
bool includeParms,
6161
bool ignoreOSRUses)
6262
: _compilation(c), _trMemory(c->trMemory()), _ignoreOSRUses(ignoreOSRUses)
6363
{
@@ -77,6 +77,8 @@ TR_LiveVariableInformation::TR_LiveVariableInformation(TR::Compilation *c,
7777

7878
_haveCachedGenAndKillSets = false;
7979
_liveCommonedLoads = NULL;
80+
_seenCommonedNodeForLoadOfLocal = NULL;
81+
_distinctCommonedLoads = NULL;
8082
}
8183

8284
void TR_LiveVariableInformation::collectLiveVariableInformation()
@@ -413,10 +415,10 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
413415
{
414416
if (movingForwardThroughTrees)
415417
traceMsg(comp(), " Looking forward for uses in node %p has visitCount = %d and comp() visitCount = %d\n",
416-
node, node->getVisitCount(), visitCount);
418+
node, node->getVisitCount(), visitCount);
417419
else
418420
traceMsg(comp(), " Looking backward for uses in node %p has future use count = %d and reference count = %d\n",
419-
node, node->getFutureUseCount(), node->getReferenceCount());
421+
node, node->getFutureUseCount(), node->getReferenceCount());
420422
}
421423

422424
uint16_t localIndex = INVALID_LIVENESS_INDEX;
@@ -468,6 +470,26 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
468470
if (traceLiveVarInfo())
469471
traceMsg(comp(), " not first reference\n");
470472

473+
if (_liveCommonedLoads != NULL && local != NULL)
474+
{
475+
if (_seenCommonedNodeForLoadOfLocal == NULL)
476+
{
477+
_seenCommonedNodeForLoadOfLocal = new (trStackMemory()) TR::NodeChecklist(comp());
478+
_distinctCommonedLoads = (int32_t *) comp()->trMemory()->allocateStackMemory(_numLocals * sizeof(int32_t));
479+
memset(_distinctCommonedLoads, 0x0, _numLocals * sizeof(int32_t));
480+
}
481+
482+
// Has this load of a local variable been encountered before in this backwards
483+
// tree walk? If not, add the node to the checklist and bump the number of distinct
484+
// commoned loads of the local variable.
485+
//
486+
if (!_seenCommonedNodeForLoadOfLocal->contains(node))
487+
{
488+
_seenCommonedNodeForLoadOfLocal->add(node);
489+
_distinctCommonedLoads[localIndex] = _distinctCommonedLoads[localIndex] + 1;
490+
}
491+
}
492+
471493
// traversal should either end here (for regular traversal) or track that we're below a commoned node
472494
if (visitEntireTree)
473495
belowCommonedNode = true;
@@ -476,12 +498,60 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
476498
}
477499
else
478500
{
479-
if (traceLiveVarInfo())
480-
traceMsg(comp(), " first reference\n");
501+
bool otherReferencesStillLive = false;
481502

482-
// if this is a load, clear it in liveCommonedLoads if we've been asked to track them
503+
// if this is a load, and there are no other live commoned loads of the local,
504+
// clear it in liveCommonedLoads if we've been asked to track them
483505
if (_liveCommonedLoads != NULL && local != NULL)
484-
_liveCommonedLoads->reset(localIndex);
506+
{
507+
if (_seenCommonedNodeForLoadOfLocal != NULL)
508+
{
509+
// If we've encountered a commoned reference to this node, decrease
510+
// the number of distinct commoned references of the local that are
511+
// are still live. If there are no more live commoned references to
512+
// the local, remove it from _liveCommonedLoads
513+
//
514+
if (_seenCommonedNodeForLoadOfLocal->contains(node))
515+
{
516+
int32_t numDistinctCommonedLoads = _distinctCommonedLoads[localIndex];
517+
_distinctCommonedLoads[localIndex] = numDistinctCommonedLoads - 1;
518+
519+
_seenCommonedNodeForLoadOfLocal->remove(node);
520+
521+
if (numDistinctCommonedLoads == 1)
522+
{
523+
_liveCommonedLoads->reset(localIndex);
524+
}
525+
else
526+
{
527+
otherReferencesStillLive = true;
528+
}
529+
}
530+
}
531+
else
532+
{
533+
_liveCommonedLoads->reset(localIndex);
534+
}
535+
}
536+
537+
if (traceLiveVarInfo())
538+
{
539+
if (otherReferencesStillLive)
540+
{
541+
traceMsg(comp(), " First reference to this node, but other commoned references to this local sym are still live\n");
542+
}
543+
else
544+
{
545+
if (local != NULL)
546+
{
547+
traceMsg(comp(), " First reference to this node, and either this is the first of all commoned references to this sym or this it is not a commoned reference\n");
548+
}
549+
else
550+
{
551+
traceMsg(comp(), " First reference to this node\n");
552+
}
553+
}
554+
}
485555
}
486556
}
487557

@@ -522,6 +592,19 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
522592
if (traceLiveVarInfo())
523593
traceMsg(comp(), " Marking %d as live commoned load\n", localIndex);
524594
_liveCommonedLoads->set(localIndex);
595+
596+
if (!movingForwardThroughTrees && _seenCommonedNodeForLoadOfLocal != NULL)
597+
{
598+
// Has this load of a local variable been encountered before in this backwards
599+
// tree walk? If not, add the node to the checklist and bump the number of distinct
600+
// commoned loads of the local variable.
601+
//
602+
if (!_seenCommonedNodeForLoadOfLocal->contains(node))
603+
{
604+
_distinctCommonedLoads[localIndex] = _distinctCommonedLoads[localIndex] + 1;
605+
_seenCommonedNodeForLoadOfLocal->add(node);
606+
}
607+
}
525608
}
526609
}
527610
if (_localObjects != NULL && local && local->isLocalObject())

compiler/optimizer/SinkStores.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ void TR_SinkStores::lookForSinkableStores()
715715

716716
// for keeping track of dataflow for each tree
717717
TR_BitVector *savedLiveCommonedLoads = new (trStackMemory()) TR_BitVector(numLocals, trMemory());
718-
TR_BitVector *satisfiedLiveCommonedLoads = new (trStackMemory()) TR_BitVector(numLocals, trMemory());
719718
TR_BitVector *killedLiveCommonedLoads = new (trStackMemory()) TR_BitVector(numLocals, trMemory());
720719

721720
// treeVisitCount will be incremented for each tree in an EBB
@@ -781,6 +780,7 @@ void TR_SinkStores::lookForSinkableStores()
781780
foundException = true;
782781
}
783782

783+
// remember the currently live commoned loads so that we can figure out later if we can move this store
784784
(*savedLiveCommonedLoads) = (*_liveVarInfo->liveCommonedLoads());
785785

786786
if (trace())
@@ -789,14 +789,10 @@ void TR_SinkStores::lookForSinkableStores()
789789
savedLiveCommonedLoads->print(comp());
790790
traceMsg(comp(), "\n");
791791
}
792+
792793
// visit the tree below this node and find all the symbols it uses
793794
TR_BitVector *usedSymbols = new (trStackMemory()) TR_BitVector(numLocals, trMemory());
794795
TR_BitVector *killedSymbols = new (trStackMemory()) TR_BitVector(numLocals, trMemory());
795-
// remove any commoned loads where the first reference to the load has been seen (it is 'satisfied')
796-
// satisfiedLiveCommonedLoads was initialized, if required, on the previous node examined
797-
798-
// remember the currently live commoned loads so that we can figure out later if we can move this store
799-
(*savedLiveCommonedLoads) = (*_liveVarInfo->liveCommonedLoads());
800796

801797
treeCommonedLoads->empty();
802798
if (trace())
@@ -2305,8 +2301,13 @@ TR_SinkStores::genStoreToTempSyms(TR::TreeTop *storeLocation,
23052301
"%s Create new temp store node for commoned loads sym %d and place above store [" POINTER_PRINTF_FORMAT "]\n",OPT_DETAILS, symIdx, storeLocation->getNode())
23062302
&& performThisTransformation())
23072303
{
2308-
// found first ref so reset killed commoned loads for this sym
2309-
killedLiveCommonedLoads->reset(symIdx);
2304+
// Found first reference to this commoned load. If there are no other
2305+
// live commoned loads of this local, reset killed commoned loads for it
2306+
if (_liveVarInfo->numDistinctCommonedLoads(symIdx) == 0)
2307+
{
2308+
killedLiveCommonedLoads->reset(symIdx);
2309+
}
2310+
23102311
TR::SymbolReference *symRef0 = comp()->getSymRefTab()->createTemporary(comp()->getMethodSymbol(), node->getDataType());
23112312
TR::Node *store0 = TR::Node::createStore(symRef0, node);
23122313
TR::TreeTop *store0_tt = TR::TreeTop::create(comp(), store0);

0 commit comments

Comments
 (0)