Skip to content

Commit

Permalink
Make _targetTrees field into a local allocated in StackMemoryRegion
Browse files Browse the repository at this point in the history
The _targetTrees List is used to keep track of TR::TreeTops that are
being processed.  In applying the optimization to requested blocks, the
DeadTreesElimination::process(TR::TreeTop*,TR::TreeTop*) method is
called for all TR::TreeTops in an entire extended basic block;
otherwise it is called for all TR::TreeTops in the method.

After the process method returns, TR:TreeTops in that range will not
need to be visited again during the current application of Dead Trees
Elimination, so there's no need to track them in a _targetTrees field
associated with the optimization.  Instead the field can be made into a
local variable in the process method, with memory allocated in the in
scope StackMemoryRegion object.

The TreeInfo objects that are stored in the List by the
findOrCreateTreeInfo function should be allocated from the same
TR::Region that the List uses for allocation of its nodes to ensure that
their lifetime is as long as that of the containing List object.
  • Loading branch information
hzongaro committed Apr 22, 2024
1 parent 8037ccd commit 149b872
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions compiler/optimizer/DeadTreesElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static OMR::TreeInfo *findOrCreateTreeInfo(TR::TreeTop *treeTop, List<OMR::TreeI
return t;
}

t = new (comp->trStackMemory()) OMR::TreeInfo(treeTop, 0);
t = new (targetTrees->getRegion()) OMR::TreeInfo(treeTop, 0);
targetTrees->add(t);
return t;
}
Expand Down Expand Up @@ -433,8 +433,7 @@ TR::Optimization *TR::DeadTreesElimination::create(TR::OptimizationManager *mana


TR::DeadTreesElimination::DeadTreesElimination(TR::OptimizationManager *manager)
: TR::Optimization(manager),
_targetTrees(manager->trMemory())
: TR::Optimization(manager)
{
_cannotBeEliminated = false;
_delayedRegStores = false;
Expand Down Expand Up @@ -474,8 +473,6 @@ void TR::DeadTreesElimination::prePerformOnBlocks()
_cannotBeEliminated = false;
_delayedRegStores = false;

_targetTrees.deleteAll();

/*
* Walk through all the blocks to remove trivial dead trees in the following forms:
*
Expand Down Expand Up @@ -759,6 +756,9 @@ static bool treeCanPossiblyBeRemoved(TR::Node *node)
int32_t TR::DeadTreesElimination::process(TR::TreeTop *startTree, TR::TreeTop *endTree)
{
TR::StackMemoryRegion stackRegion(*comp()->trMemory());

List<OMR::TreeInfo> targetTrees(stackRegion);

LongestPathMap longestPaths(std::less<TR::Node*>(), stackRegion);

typedef TR::typed_allocator<CRAnchor, TR::Region&> CRAnchorAlloc;
Expand Down Expand Up @@ -894,7 +894,7 @@ int32_t TR::DeadTreesElimination::process(TR::TreeTop *startTree, TR::TreeTop *e
visitCount,
comp(),
this,
&_targetTrees,
&targetTrees,
_cannotBeEliminated,
longestPaths);
}
Expand Down
1 change: 0 additions & 1 deletion compiler/optimizer/DeadTreesElimination.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class DeadTreesElimination : public TR::Optimization

int32_t process(TR::TreeTop *, TR::TreeTop *);

List<OMR::TreeInfo> _targetTrees;
bool _cannotBeEliminated;
bool _delayedRegStores;
};
Expand Down

0 comments on commit 149b872

Please sign in to comment.