@@ -54,10 +54,10 @@ class TR_Structure;
54
54
namespace TR { class Optimizer ; }
55
55
56
56
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,
61
61
bool ignoreOSRUses)
62
62
: _compilation(c), _trMemory(c->trMemory ()), _ignoreOSRUses(ignoreOSRUses)
63
63
{
@@ -77,6 +77,8 @@ TR_LiveVariableInformation::TR_LiveVariableInformation(TR::Compilation *c,
77
77
78
78
_haveCachedGenAndKillSets = false ;
79
79
_liveCommonedLoads = NULL ;
80
+ _seenCommonedNodeForLoadOfLocal = NULL ;
81
+ _distinctCommonedLoads = NULL ;
80
82
}
81
83
82
84
void TR_LiveVariableInformation::collectLiveVariableInformation ()
@@ -413,10 +415,10 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
413
415
{
414
416
if (movingForwardThroughTrees)
415
417
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);
417
419
else
418
420
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 ());
420
422
}
421
423
422
424
uint16_t localIndex = INVALID_LIVENESS_INDEX;
@@ -468,6 +470,26 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
468
470
if (traceLiveVarInfo ())
469
471
traceMsg (comp (), " not first reference\n " );
470
472
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
+
471
493
// traversal should either end here (for regular traversal) or track that we're below a commoned node
472
494
if (visitEntireTree)
473
495
belowCommonedNode = true ;
@@ -476,12 +498,60 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
476
498
}
477
499
else
478
500
{
479
- if (traceLiveVarInfo ())
480
- traceMsg (comp (), " first reference\n " );
501
+ bool otherReferencesStillLive = false ;
481
502
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
483
505
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
+ }
485
555
}
486
556
}
487
557
@@ -522,6 +592,19 @@ void TR_LiveVariableInformation::visitTreeForLocals(TR::Node *node, TR_BitVector
522
592
if (traceLiveVarInfo ())
523
593
traceMsg (comp (), " Marking %d as live commoned load\n " , localIndex);
524
594
_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
+ }
525
608
}
526
609
}
527
610
if (_localObjects != NULL && local && local->isLocalObject ())
0 commit comments