Skip to content

Commit

Permalink
Fix comments mention in the PR for phase2
Browse files Browse the repository at this point in the history
Fix initialization for index array and type signature

Fix build error

Fix log type on double for benefit
  • Loading branch information
dinolii committed Jul 12, 2021
1 parent e421043 commit 25d0d0f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 38 deletions.
91 changes: 57 additions & 34 deletions compiler/optimizer/abstractinterpreter/IDT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@ void TR::IDT::print()

if (!verboseInlining && !traceBIIDTGen)
return;

// print header line
char header[1024];
const uint32_t candidates = getNumNodes() - 1;
sprintf(header,"#IDT: %d candidate methods inlinable into %s with a budget %d",
candidates,
getRoot()->getName(comp()->trMemory()),
getRoot()->getBudget()
);

if (verboseInlining)
TR_VerboseLog::writeLineLocked(TR_Vlog_BI, header);
// print header line
int headerSize = 1 + snprintf(NULL, 0, "#IDT: %d candidate methods inlinable into %s with a budget %d",
candidates,
getRoot()->getName(comp()->trMemory()),
getRoot()->getBudget()
);
char *header = (char*) comp()->trMemory()->allocateStackMemory(headerSize);
int headerLen = snprintf(header, headerSize, "#IDT: %d candidate methods inlinable into %s with a budget %d",
candidates,
getRoot()->getName(comp()->trMemory()),
getRoot()->getBudget());
TR_ASSERT_FATAL(headerLen == headerSize -1, "Truncation in the header");

if (verboseInlining){
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::writeLine(TR_Vlog_BI, "%s\n", header);
TR_VerboseLog::vlogRelease();
}
if (traceBIIDTGen)
traceMsg(comp(), "%s\n", header);

Expand All @@ -74,24 +81,41 @@ void TR::IDT::print()
// skip root node
if (index != -1)
{
char line[1024];
sprintf(line, "#IDT: #%d: #%d inlinable @%d -> bcsz=%d %s target %s, static benefit = %d, benefit = %llu, cost = %d, budget = %d, callratio = %f, rootcallratio = %f",
index,
currentNode->getParentGloablIndex(),
currentNode->getByteCodeIndex(),
currentNode->getByteCodeSize(),
currentNode->getResolvedMethodSymbol()->signature(comp()->trMemory()),
currentNode->getName(comp()->trMemory()),
currentNode->getStaticBenefit(),
currentNode->getBenefit(),
currentNode->getCost(),
currentNode->getBudget(),
currentNode->getCallRatio(),
currentNode->getRootCallRatio()
);

if (verboseInlining)
TR_VerboseLog::writeLineLocked(TR_Vlog_BI, line);
int lineSize = 1 + snprintf(NULL, 0, "#IDT: #%d: #%d inlinable @%d -> bcsz=%d %s target %s, static benefit = %d, benefit = %f, cost = %d, budget = %d, callratio = %f, rootcallratio = %f",
index,
currentNode->getParentGloablIndex(),
currentNode->getByteCodeIndex(),
currentNode->getByteCodeSize(),
currentNode->getResolvedMethodSymbol()->signature(comp()->trMemory()),
currentNode->getName(comp()->trMemory()),
currentNode->getStaticBenefit(),
currentNode->getBenefit(),
currentNode->getCost(),
currentNode->getBudget(),
currentNode->getCallRatio(),
currentNode->getRootCallRatio()
);
char *line = (char*) comp()->trMemory()->allocateStackMemory(lineSize);
int lineLen = snprintf(line, lineSize, "#IDT: #%d: #%d inlinable @%d -> bcsz=%d %s target %s, static benefit = %d, benefit = %f, cost = %d, budget = %d, callratio = %f, rootcallratio = %f",
index,
currentNode->getParentGloablIndex(),
currentNode->getByteCodeIndex(),
currentNode->getByteCodeSize(),
currentNode->getResolvedMethodSymbol()->signature(comp()->trMemory()),
currentNode->getName(comp()->trMemory()),
currentNode->getStaticBenefit(),
currentNode->getBenefit(),
currentNode->getCost(),
currentNode->getBudget(),
currentNode->getCallRatio(),
currentNode->getRootCallRatio()
);
TR_ASSERT_FATAL(lineLen = lineSize -1, "Truncation in log line");
if (verboseInlining){
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::writeLine(TR_Vlog_BI, "%s\n", line);
TR_VerboseLog::vlogRelease();
}

if (traceBIIDTGen)
traceMsg(comp(), "%s\n", line);
Expand All @@ -111,9 +135,7 @@ void TR::IDT::flattenIDT()

// initialize nodes index array
uint32_t numNodes = getNumNodes();
_indices = new (_region) TR::IDTNode *[numNodes];

memset(_indices, 0, sizeof(TR::IDTNode*) * numNodes);
_indices = new (_region) TR::IDTNode *[numNodes]();

// add all the descendents of the root node to the indices array
TR::deque<TR::IDTNode*, TR::Region&> idtNodeQueue(comp()->trMemory()->currentStackRegion());
Expand All @@ -140,6 +162,7 @@ TR::IDTNode *TR::IDT::getNodeByGlobalIndex(int32_t index)
{
TR_ASSERT_FATAL(_indices, "Call flattenIDT() first");
TR_ASSERT_FATAL(index < getNextGlobalIDTNodeIndex(), "Index out of range!");
TR_ASSERT_FATAL(index >= -1, "Index too low!");
return _indices[index + 1];
}

Expand All @@ -163,7 +186,7 @@ TR::IDTNode* TR::IDTPreorderPriorityQueue::get(uint32_t index)

if (index > idtSize - 1)
return NULL;

TR_ASSERT_FATAL(index < idtSize, "IDTPreorderPriorityQueue::get index out of bound!");
// not in entries yet. Update entries.
while (_entries.size() <= index)
{
Expand All @@ -179,4 +202,4 @@ TR::IDTNode* TR::IDTPreorderPriorityQueue::get(uint32_t index)

return _entries.at(index);
}


6 changes: 3 additions & 3 deletions compiler/optimizer/abstractinterpreter/IDTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ TR::IDTNode* TR::IDTNode::addChild(
if (getNumChildren() == 1)
{
TR::IDTNode* onlyChild = getOnlyChild();
_children = new (region) TR::vector<TR::IDTNode*, TR::Region&>(region);
_children = new (region) TR::vector<TR::IDTNode*, TR::Region&>(region);
TR_ASSERT_FATAL(!((uintptr_t)_children & SINGLE_CHILD_BIT), "Maligned memory address.\n");
_children->push_back(onlyChild);
}

Expand Down Expand Up @@ -130,7 +131,7 @@ TR::IDTNode* TR::IDTNode::getChild(uint32_t index)
return (*_children)[index];
}

uint64_t TR::IDTNode::getBenefit()
double TR::IDTNode::getBenefit()
{
return _rootCallRatio * (1 + _staticBenefit) * 10;
}
Expand All @@ -148,7 +149,6 @@ TR::IDTNode* TR::IDTNode::findChildWithBytecodeIndex(uint32_t bcIndex)
return onlyChild->getByteCodeIndex() == bcIndex ? onlyChild : NULL;
}

TR::IDTNode* child = NULL;
for (uint32_t i = 0; i < size; i ++)
{
if ((*_children)[i]->getByteCodeIndex() == bcIndex)
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/abstractinterpreter/IDTNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class IDTNode
int32_t getGlobalIndex() { return _idx; }
int32_t getParentGloablIndex() { return isRoot() ? -2 : getParent()->getGlobalIndex(); }

uint64_t getBenefit();
double getBenefit();

uint32_t getStaticBenefit() { return _staticBenefit; };

Expand Down

0 comments on commit 25d0d0f

Please sign in to comment.