Skip to content

Commit

Permalink
Cache known object info on TR::Nodes
Browse files Browse the repository at this point in the history
Allow known object information to be associated with arbitrary nodes.
This will permit more accurate association of refined known object
info, and allow it to be placed on arbitrary nodes.

A new 32-bit bit field is added to the Node class in the padding
space between two fields.  This incurs no TR::Node footprint increase
on 64-bit architectures.

Signed-off-by: Daryl Maier <maier@ca.ibm.com>
  • Loading branch information
0xdaryl committed Aug 19, 2021
1 parent a99c1b6 commit c7cb082
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
22 changes: 16 additions & 6 deletions compiler/il/OMRNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ OMR::Node::Node()
_visitCount(0),
_localIndex(0),
_referenceCount(0),
_knownObjectIndex(TR::KnownObjectTable::UNKNOWN),
_byteCodeInfo(),
_unionBase(),
_unionPropertyA()
Expand All @@ -138,6 +139,7 @@ OMR::Node::Node(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, uint16_t nu
_visitCount(0),
_localIndex(0),
_referenceCount(0),
_knownObjectIndex(TR::KnownObjectTable::UNKNOWN),
_byteCodeInfo(),
_unionBase(),
_unionPropertyA()
Expand Down Expand Up @@ -167,6 +169,7 @@ OMR::Node::Node(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, uint16_t nu
self()->setReferenceCount(0);
self()->setVisitCount(0);
self()->setLocalIndex(0);
self()->setKnownObjectIndex(TR::KnownObjectTable::UNKNOWN),
memset( &(_unionA), 0, sizeof( _unionA ) );
if (self()->getGlobalIndex() == MAX_NODE_COUNT)
{
Expand Down Expand Up @@ -237,6 +240,7 @@ OMR::Node::Node(TR::Node * from, uint16_t numChildren)
_visitCount(0),
_localIndex(0),
_referenceCount(0),
_knownObjectIndex(TR::KnownObjectTable::UNKNOWN),
_byteCodeInfo(),
_unionBase(),
_unionPropertyA()
Expand All @@ -257,6 +261,7 @@ OMR::Node::Node(TR::Node * from, uint16_t numChildren)
self()->setReferenceCount(from->getReferenceCount());
self()->setVisitCount(from->getVisitCount());
self()->setLocalIndex(from->getLocalIndex());
self()->setKnownObjectIndex(from->getKnownObjectIndex());
_unionA = from->_unionA;

if (self()->getGlobalIndex() == MAX_NODE_COUNT)
Expand Down Expand Up @@ -390,7 +395,7 @@ OMR::Node::copyValidProperties(TR::Node *fromNode, TR::Node *toNode)
UnionPropertyA_Type fromUnionPropertyA_Type = fromNode->getUnionPropertyA_Type();
UnionPropertyA_Type toUnionPropertyA_Type = toNode->getUnionPropertyA_Type();

toNode->copyChildren(fromNode);
toNode->copyChildren(fromNode);

if (fromUnionPropertyA_Type == toUnionPropertyA_Type)
{
Expand Down Expand Up @@ -602,6 +607,7 @@ OMR::Node::createInternal(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, u
vcount_t visitCount = originalNode->getVisitCount();
scount_t localIndex = originalNode->getLocalIndex();
rcount_t referenceCount = originalNode->getReferenceCount();
TR::KnownObjectTable::Index knownObjectIndex = originalNode->getKnownObjectIndex();
UnionA unionA = originalNode->_unionA;
const TR_ByteCodeInfo byteCodeInfo = originalNode->getByteCodeInfo(); // copy bytecode info into temporary variable
//TR::Node * node = new (TR::comp()->getNodePool(), poolIndex) TR::Node(0, op, numChildren);
Expand All @@ -612,6 +618,7 @@ OMR::Node::createInternal(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, u
node->setVisitCount(visitCount);
node->setLocalIndex(localIndex);
node->setReferenceCount(referenceCount);
node->setKnownObjectIndex(knownObjectIndex);
node->_unionA = unionA;

return node;
Expand Down Expand Up @@ -1746,7 +1753,7 @@ TR::Node *
OMR::Node::duplicateTreeForCodeMotion()
{
TR::Node *result = self()->duplicateTree(true);
result->resetFlagsForCodeMotion();
result->resetFlagsAndPropertiesForCodeMotion();
return result;
}

Expand Down Expand Up @@ -8605,7 +8612,7 @@ OMR::Node::printRequiresConditionCodes()
}

static void
resetFlagsForCodeMotionHelper(TR::Node *node, TR::NodeChecklist &visited)
resetFlagsAndPropertiesForCodeMotionHelper(TR::Node *node, TR::NodeChecklist &visited)
{
if (visited.contains(node))
return;
Expand All @@ -8614,7 +8621,7 @@ resetFlagsForCodeMotionHelper(TR::Node *node, TR::NodeChecklist &visited)

int32_t childNum;
for (childNum = 0; childNum < node->getNumChildren(); childNum++)
resetFlagsForCodeMotionHelper(node->getChild(childNum), visited);
resetFlagsAndPropertiesForCodeMotionHelper(node->getChild(childNum), visited);

if (node->getOpCodeValue() != TR::loadaddr)
{
Expand All @@ -8641,6 +8648,9 @@ resetFlagsForCodeMotionHelper(TR::Node *node, TR::NodeChecklist &visited)

if (node->chkIsReferenceNonNull())
node->setReferenceIsNonNull(false);

if (node->hasKnownObjectIndex())
node->setKnownObjectIndex(TR::KnownObjectTable::UNKNOWN);
}

// Clear out relevant flags set on the node; this will ensure
Expand All @@ -8649,10 +8659,10 @@ resetFlagsForCodeMotionHelper(TR::Node *node, TR::NodeChecklist &visited)
// as well (over the ones that are already reset).
//
void
OMR::Node::resetFlagsForCodeMotion()
OMR::Node::resetFlagsAndPropertiesForCodeMotion()
{
TR::NodeChecklist visited(TR::comp());
resetFlagsForCodeMotionHelper(self(), visited);
resetFlagsAndPropertiesForCodeMotionHelper(self(), visited);
}

/**
Expand Down
32 changes: 30 additions & 2 deletions compiler/il/OMRNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace OMR { typedef OMR::Node NodeConnector; }
#include <string.h>
#include "codegen/RegisterConstants.hpp"
#include "cs2/hashtab.h"
#include "env/KnownObjectTable.hpp"
#include "env/TRMemory.hpp"
#include "il/DataTypes.hpp"
#include "il/ILOpCodes.hpp"
Expand Down Expand Up @@ -817,6 +818,24 @@ class OMR_EXTENSIBLE Node
inline scount_t incLocalIndex();
inline scount_t decLocalIndex();

/**
* @brief Sets a known object index on this node
* @param[in] koi : the known object index
*/
void setKnownObjectIndex(TR::KnownObjectTable::Index koi) { _knownObjectIndex = koi; }

/**
* @brief Retrieve the known object index associated with this node, if any.
* @return Known object index, or TR::KnownObjectTable::UNKNOWN if none.
*/
TR::KnownObjectTable::Index getKnownObjectIndex() { return _knownObjectIndex; }

/**
* @brief Inquires whether this node has a known object index associated with it.
* @return true if a known object index is cached; false otherwise.
*/
bool hasKnownObjectIndex() { return _knownObjectIndex != TR::KnownObjectTable::UNKNOWN; }

inline scount_t getFutureUseCount();
inline scount_t setFutureUseCount(scount_t li);
inline scount_t incFutureUseCount();
Expand Down Expand Up @@ -1641,8 +1660,8 @@ class OMR_EXTENSIBLE Node
bool chkOpsNodeRequiresConditionCodes();
const char *printRequiresConditionCodes();

// Clear out relevant flags set on the node.
void resetFlagsForCodeMotion();
// Clear out relevant flags and properties set on the node.
void resetFlagsAndPropertiesForCodeMotion();

/**
* Node flags functions end
Expand Down Expand Up @@ -1839,6 +1858,15 @@ class OMR_EXTENSIBLE Node
/// References to this node.
rcount_t _referenceCount;

/// Known object index associated with this node, if any.
///
/// This field allows for more accurate placement of known object information
/// as it applies to a particular node.
///
/// If no such information is available this field is TR::KnownObjectTable::UNKNOWN
///
TR::KnownObjectTable::Index _knownObjectIndex;

UnionA _unionA;

/// Elements unioned with children.
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/LoopVersioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9871,7 +9871,7 @@ TR_LoopVersioner::LoopEntryPrep *TR_LoopVersioner::createLoopEntryPrep(
{
// This is the top-level call. Ensure that node's flags have been reset
// for code motion.
node->resetFlagsForCodeMotion();
node->resetFlagsAndPropertiesForCodeMotion();
}

// Because node will no longer appear verbatim in the trees, print it to
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/PartialRedundancy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ int32_t TR_PartialRedundancy::perform()
if (nextRedundantComputation != 0)
{
supportedNodesAsArray[nextRedundantComputation] = supportedNodesAsArray[nextRedundantComputation]->duplicateTreeWithCommoning(comp()->allocator());
supportedNodesAsArray[nextRedundantComputation]->resetFlagsForCodeMotion();
supportedNodesAsArray[nextRedundantComputation]->resetFlagsAndPropertiesForCodeMotion();
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/ras/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,8 @@ TR_Debug::printNodeInfo(TR::Node * node, TR_PrettyPrinterString& output, bool pr
output.append("%s", getName(node->getOpCode()));
}

if (node->hasKnownObjectIndex())
output.append(" (node obj%d)", node->getKnownObjectIndex());

if (node->getOpCode().isNullCheck())
{
Expand Down

0 comments on commit c7cb082

Please sign in to comment.