Skip to content

Commit

Permalink
Merge pull request #8759 from rpshukla/refactor-prexarginfo
Browse files Browse the repository at this point in the history
Decouple TR_PrexArgInfo from TR_InlinerTracer
  • Loading branch information
fjeremic committed Mar 13, 2020
2 parents d3fda77 + c226bfd commit bbb2806
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 36 deletions.
53 changes: 30 additions & 23 deletions runtime/compiler/optimizer/InlinerTempForJ9.cpp
Expand Up @@ -3230,14 +3230,14 @@ bool TR_MultipleCallTargetInliner::inlineCallTargets(TR::ResolvedMethodSymbol *c
if (tracer()->heuristicLevel())
{
alwaysTrace(tracer(), "compArgInfo :");
tracer()->dumpPrexArgInfo(compArgInfo);
compArgInfo->dumpTrace();
}
compArgInfo->clearArgInfoForNonInvariantArguments(thisCallSiteCallerSymbol, tracer());
TR_PrexArgInfo::propagateArgsFromCaller(thisCallSiteCallerSymbol, callsite, compArgInfo, tracer());
if (tracer()->heuristicLevel())
{
alwaysTrace(tracer(), "callsite->getTarget(0)->_ecsPrexArgInfo :");
tracer()->dumpPrexArgInfo(callsite->getTarget(0)->_ecsPrexArgInfo);
callsite->getTarget(0)->_ecsPrexArgInfo->dumpTrace();
}
}

Expand Down Expand Up @@ -5090,7 +5090,7 @@ bool TR_J9InlinerUtil::needTargetedInlining(TR::ResolvedMethodSymbol *callee)
If a parameter refers to a constant class, set the known object index in _ecsPrexArgInfo
of the target.
*/
void TR_J9InlinerUtil::checkForConstClass(TR_CallTarget *target, TR_InlinerTracer *tracer)
void TR_J9InlinerUtil::checkForConstClass(TR_CallTarget *target, TR_LogTracer *tracer)
{
static char *disableCCI=feGetEnv("TR_DisableConstClassInlining");

Expand All @@ -5109,7 +5109,7 @@ void TR_J9InlinerUtil::checkForConstClass(TR_CallTarget *target, TR_InlinerTrace
bool tracePrex = comp->trace(OMR::inlining) || comp->trace(OMR::invariantArgumentPreexistence);

if (tracePrex)
traceMsg(comp, "checkForConstClass parm for [%p] %s %s\n", callNode, callNode->getOpCode().getName(), callNode->getSymbol()->castToMethodSymbol()->getMethod()->signature(tracer->trMemory(), stackAlloc));
traceMsg(comp, "checkForConstClass parm for [%p] %s %s\n", callNode, callNode->getOpCode().getName(), callNode->getSymbol()->castToMethodSymbol()->getMethod()->signature(comp->trMemory(), stackAlloc));

// loop over args
int32_t firstArgIndex = callNode->getFirstArgumentIndex();
Expand Down Expand Up @@ -5169,13 +5169,13 @@ void TR_J9InlinerUtil::checkForConstClass(TR_CallTarget *target, TR_InlinerTrace
{
if (knownObjectClass)
{
ecsArgInfo->set(argOrdinal, new (tracer->trStackMemory()) TR_PrexArgument(knownObjectIndex, comp));
ecsArgInfo->set(argOrdinal, new (comp->trStackMemory()) TR_PrexArgument(knownObjectIndex, comp));
if (tracePrex)
traceMsg(comp, "checkForConstClass: %p: is known object obj%d (knownObjectClass)\n", ecsArgInfo->get(argOrdinal), knownObjectIndex);
}
else
{
ecsArgInfo->set(argOrdinal, new (tracer->trStackMemory()) TR_PrexArgument(argument->getSymbolReference()->getKnownObjectIndex(), comp));
ecsArgInfo->set(argOrdinal, new (comp->trStackMemory()) TR_PrexArgument(argument->getSymbolReference()->getKnownObjectIndex(), comp));
if (tracePrex)
traceMsg(comp, "checkForConstClass: %p: is known object obj%d\n", ecsArgInfo->get(argOrdinal), argument->getSymbolReference()->getKnownObjectIndex());
}
Expand All @@ -5189,14 +5189,16 @@ void TR_J9InlinerUtil::checkForConstClass(TR_CallTarget *target, TR_InlinerTrace
} // checkForConstClass

//@TODO this can be re-used as we start building prexargs for every callsite
TR_PrexArgInfo* TR_PrexArgInfo::buildPrexArgInfoForMethodSymbol(TR::ResolvedMethodSymbol* methodSymbol, TR_InlinerTracer* tracer)
TR_PrexArgInfo* TR_PrexArgInfo::buildPrexArgInfoForMethodSymbol(TR::ResolvedMethodSymbol* methodSymbol, TR_PREXARGINFO_TRACER_CLASS* tracer)
{
int numArgs = methodSymbol->getParameterList().getSize();
TR_ResolvedMethod *feMethod = methodSymbol->getResolvedMethod();
ListIterator<TR::ParameterSymbol> parms(&methodSymbol->getParameterList());

TR_PrexArgInfo *argInfo = new (tracer->trHeapMemory()) TR_PrexArgInfo(numArgs, tracer->trMemory());
heuristicTrace(tracer, "PREX-CSI: Populating parmInfo of current method %s\n", feMethod->signature(tracer->trMemory()));
TR::Compilation *comp = tracer->comp();

TR_PrexArgInfo *argInfo = new (comp->trHeapMemory()) TR_PrexArgInfo(numArgs, comp->trMemory());
heuristicTrace(tracer, "PREX-CSI: Populating parmInfo of current method %s\n", feMethod->signature(comp->trMemory()));
int index = 0;
for (TR::ParameterSymbol *p = parms.getFirst(); p != NULL; index++, p = parms.getNext())
{
Expand All @@ -5206,10 +5208,10 @@ TR_PrexArgInfo* TR_PrexArgInfo::buildPrexArgInfoForMethodSymbol(TR::ResolvedMeth

if (*sig == 'L')
{
TR_OpaqueClassBlock *clazz = tracer->fe()->getClassFromSignature(sig, len, feMethod);
TR_OpaqueClassBlock *clazz = comp->fe()->getClassFromSignature(sig, len, feMethod);
if (clazz)
{
argInfo->set(index, new (tracer->trHeapMemory()) TR_PrexArgument(TR_PrexArgument::ClassIsPreexistent, clazz));
argInfo->set(index, new (comp->trHeapMemory()) TR_PrexArgument(TR_PrexArgument::ClassIsPreexistent, clazz));
heuristicTrace(tracer, "PREX-CSI: Parm %d class %p in %p is %.*s\n", index, argInfo->get(index)->getClass(), argInfo->get(index), len, sig);
}
}
Expand Down Expand Up @@ -5261,7 +5263,7 @@ static char* classSignature (TR::Method * m, TR::Compilation* comp) //tracer hel
return classNameToSignature(m->classNameChars(), len /*don't care, cos this gives us a null terminated string*/, comp);
}

TR::Node* TR_PrexArgInfo::getCallNode (TR::ResolvedMethodSymbol* methodSymbol, TR_CallSite* callsite, TR_InlinerTracer* tracer)
TR::Node* TR_PrexArgInfo::getCallNode (TR::ResolvedMethodSymbol* methodSymbol, TR_CallSite* callsite, TR_PREXARGINFO_TRACER_CLASS* tracer)
{
if (callsite->_callNode)
return callsite->_callNode;
Expand Down Expand Up @@ -5373,13 +5375,14 @@ TR_PrexArgument* TR_PrexArgInfo::getArgForChild(TR::Node *child, TR_PrexArgInfo*
}

void TR_PrexArgInfo::propagateReceiverInfoIfAvailable (TR::ResolvedMethodSymbol* methodSymbol, TR_CallSite* callsite,
TR_PrexArgInfo * argInfo, TR_InlinerTracer *tracer)
TR_PrexArgInfo * argInfo, TR_PREXARGINFO_TRACER_CLASS *tracer)
{
//this implies we have some argInfo available
TR_ASSERT(argInfo, "otherwise we shouldn't even peek");
TR::Node* callNode = TR_PrexArgInfo::getCallNode(methodSymbol, callsite, tracer);
TR::Compilation *comp = tracer->comp();
heuristicTrace(tracer, "ARGS PROPAGATION: trying to propagate receiver's info for callsite %p at %p", callsite, callNode);
if (!callNode || TR::comp()->getOption(TR_DisableInlinerArgsPropagation))
if (!callNode || comp->getOption(TR_DisableInlinerArgsPropagation))
return;

uint32_t numOfArgs = callNode->getNumChildren()-callNode->getFirstArgumentIndex();
Expand All @@ -5393,12 +5396,12 @@ void TR_PrexArgInfo::propagateReceiverInfoIfAvailable (TR::ResolvedMethodSymbol*
if (TR_PrexArgInfo::hasArgInfoForChild(child, argInfo))
{
heuristicTrace(tracer, "ARGS PROPAGATION: the receiver for callsite %p is also one of the caller's args", callsite);
callsite->_ecsPrexArgInfo = new (tracer->trHeapMemory()) TR_PrexArgInfo(numOfArgs, tracer->trMemory());
callsite->_ecsPrexArgInfo = new (comp->trHeapMemory()) TR_PrexArgInfo(numOfArgs, comp->trMemory());
callsite->_ecsPrexArgInfo->set(0, TR_PrexArgInfo::getArgForChild(child, argInfo));
}
}

bool TR_PrexArgInfo::validateAndPropagateArgsFromCalleeSymbol(TR_PrexArgInfo* argsFromSymbol, TR_PrexArgInfo* argsFromTarget, TR_InlinerTracer *tracer)
bool TR_PrexArgInfo::validateAndPropagateArgsFromCalleeSymbol(TR_PrexArgInfo* argsFromSymbol, TR_PrexArgInfo* argsFromTarget, TR_PREXARGINFO_TRACER_CLASS *tracer)
{
if (!argsFromSymbol || !argsFromTarget || tracer->comp()->getOption(TR_DisableInlinerArgsPropagation))
{
Expand All @@ -5407,7 +5410,8 @@ bool TR_PrexArgInfo::validateAndPropagateArgsFromCalleeSymbol(TR_PrexArgInfo* ar
}

heuristicTrace(tracer, "ARGS PROPAGATION: argsFromSymbol (from calleeSymbol)");
tracer->dumpPrexArgInfo(argsFromSymbol);
if (tracer->heuristicLevel())
argsFromSymbol->dumpTrace();

//validation
TR_FrontEnd* fe = tracer->comp()->fe();
Expand Down Expand Up @@ -5440,13 +5444,14 @@ bool TR_PrexArgInfo::validateAndPropagateArgsFromCalleeSymbol(TR_PrexArgInfo* ar
TR_PrexArgInfo::enhance(argsFromTarget, argsFromSymbol, tracer->comp()); //otherwise just pick more specific

heuristicTrace(tracer, "ARGS PROPAGATION: final argInfo after merging argsFromTarget %p", argsFromTarget);
tracer->dumpPrexArgInfo(argsFromTarget);
if (tracer->heuristicLevel())
argsFromTarget->dumpTrace();

return true;
}


void TR_PrexArgInfo::clearArgInfoForNonInvariantArguments(TR::ResolvedMethodSymbol* methodSymbol, TR_InlinerTracer* tracer)
void TR_PrexArgInfo::clearArgInfoForNonInvariantArguments(TR::ResolvedMethodSymbol* methodSymbol, TR_PREXARGINFO_TRACER_CLASS* tracer)
{
if (tracer->comp()->getOption(TR_DisableInlinerArgsPropagation))
return;
Expand All @@ -5473,12 +5478,13 @@ bool TR_PrexArgInfo::validateAndPropagateArgsFromCalleeSymbol(TR_PrexArgInfo* ar
if (cleanedAnything)
{
debugTrace(tracer, "ARGS PROPAGATION: argInfo %p after clear arg info for non-invariant arguments", this);
tracer->dumpPrexArgInfo(this);
if (tracer->heuristicLevel())
dumpTrace();
}
}

void TR_PrexArgInfo::propagateArgsFromCaller(TR::ResolvedMethodSymbol* methodSymbol, TR_CallSite* callsite,
TR_PrexArgInfo * argInfo, TR_InlinerTracer *tracer)
TR_PrexArgInfo * argInfo, TR_PREXARGINFO_TRACER_CLASS *tracer)
{
if (tracer->comp()->getOption(TR_DisableInlinerArgsPropagation))
return;
Expand Down Expand Up @@ -5508,7 +5514,8 @@ void TR_PrexArgInfo::propagateArgsFromCaller(TR::ResolvedMethodSymbol* methodSym

heuristicTrace(tracer, "ARGS PROPAGATION: argsFromTarget before args propagation");
for (int i = 0; i < callsite->numTargets(); i++)
tracer->dumpPrexArgInfo(callsite->getTarget(i)->_ecsPrexArgInfo);
if (tracer->heuristicLevel())
callsite->getTarget(i)->_ecsPrexArgInfo->dumpTrace();

for (int i = callNode->getFirstArgumentIndex(); i < callNode->getNumChildren(); i++)
{
Expand Down Expand Up @@ -5550,7 +5557,7 @@ void TR_PrexArgInfo::propagateArgsFromCaller(TR::ResolvedMethodSymbol* methodSym
{
heuristicTrace(tracer, "ARGS PROPAGATION: ArgInfo after propagating the args from the caller");
for (int i = 0; i < callsite->numTargets(); i++)
tracer->dumpPrexArgInfo(callsite->getTarget(i)->_ecsPrexArgInfo);
callsite->getTarget(i)->_ecsPrexArgInfo->dumpTrace();
}
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/compiler/optimizer/InterpreterEmulator.cpp
Expand Up @@ -645,7 +645,7 @@ InterpreterEmulator::debugUnresolvedOrCold(TR_ResolvedMethod *resolvedMethod)
if(tracer()->heuristicLevel())
{
if (resolvedMethod)
heuristicTrace(tracer(), "Depth %d: Call at bc index %d is Cold. Not searching for targets. Signature %s", _recursionDepth, _bcIndex ,tracer()->traceSignature(resolvedMethod));
heuristicTrace(tracer(), "Depth %d: Call at bc index %d is Cold. Not searching for targets. Signature %s", _recursionDepth, _bcIndex, resolvedMethod->signature(comp()->trMemory()));
else
{
switch (current())
Expand All @@ -658,7 +658,7 @@ InterpreterEmulator::debugUnresolvedOrCold(TR_ResolvedMethod *resolvedMethod)
break;
}
TR::Method *meth = comp()->fej9()->createMethod(this->trMemory(), _calltarget->_calleeMethod->containingClass(), cpIndex);
heuristicTrace(tracer(), "Depth %d: Call at bc index %d is Cold. Not searching for targets. Signature %s", _recursionDepth, _bcIndex, tracer()->traceSignature(meth));
heuristicTrace(tracer(), "Depth %d: Call at bc index %d is Cold. Not searching for targets. Signature %s", _recursionDepth, _bcIndex, meth->signature(comp()->trMemory()));
}
}
}
Expand Down Expand Up @@ -931,7 +931,7 @@ InterpreterEmulator::findTargetAndUpdateInfoForCallsite(TR_CallSite *callsite)
{
alwaysTrace(tracer(), "propagateReceiverInfoIfAvailable :");
if (callsite->_ecsPrexArgInfo)
tracer()->dumpPrexArgInfo(callsite->_ecsPrexArgInfo);
callsite->_ecsPrexArgInfo->dumpTrace();
}
}
}
Expand All @@ -948,7 +948,7 @@ InterpreterEmulator::findTargetAndUpdateInfoForCallsite(TR_CallSite *callsite)
{
alwaysTrace(tracer(), "propagateArgs :");
if (callsite->numTargets() && callsite->getTarget(0)->_ecsPrexArgInfo)
tracer()->dumpPrexArgInfo(callsite->getTarget(0)->_ecsPrexArgInfo);
callsite->getTarget(0)->_ecsPrexArgInfo->dumpTrace();
}
}

Expand Down
13 changes: 7 additions & 6 deletions runtime/compiler/optimizer/InterpreterEmulator.hpp
Expand Up @@ -48,14 +48,15 @@
#ifndef INTERPRETER_EMULATOR_INCL
#define INTERPRETER_EMULATOR_INCL

#include "compile/Compilation.hpp"
#include "env/TRMemory.hpp"
#include "il/Block.hpp"
#include "ilgen/ByteCodeIteratorWithState.hpp"
#include "ilgen/J9ByteCodeIterator.hpp"
#include "compile/Compilation.hpp"
#include "optimizer/Inliner.hpp"
#include "optimizer/J9Inliner.hpp"
#include "optimizer/J9EstimateCodeSize.hpp"
#include "env/TRMemory.hpp"
#include "optimizer/J9Inliner.hpp"
#include "optimizer/PreExistence.hpp" // TR_PREXARGINFO_TRACER_CLASS

class IconstOperand;
class KnownObjOperand;
Expand Down Expand Up @@ -157,7 +158,7 @@ class InterpreterEmulator : public TR_ByteCodeIteratorWithState<TR_J9ByteCode, J
TR::ResolvedMethodSymbol * methodSymbol,
TR_J9VMBase * fe,
TR::Compilation * comp,
TR_InlinerTracer *tracer,
TR_PREXARGINFO_TRACER_CLASS *tracer,
TR_EstimateCodeSize *ecs)
: Base(methodSymbol, comp),
_calltarget(calltarget),
Expand All @@ -169,7 +170,7 @@ class InterpreterEmulator : public TR_ByteCodeIteratorWithState<TR_J9ByteCode, J
_flags = NULL;
_stacks = NULL;
}
TR_InlinerTracer *tracer() { return _tracer; }
TR_PREXARGINFO_TRACER_CLASS *tracer() { return _tracer; }
/* \brief Initialize data needed for looking for callsites
*
* \param blocks
Expand Down Expand Up @@ -284,7 +285,7 @@ class InterpreterEmulator : public TR_ByteCodeIteratorWithState<TR_J9ByteCode, J
bool isCurrentCallUnresolvedOrCold(TR_ResolvedMethod *resolvedMethod, bool isUnresolvedInCP);
void debugUnresolvedOrCold(TR_ResolvedMethod *resolvedMethod);

TR_InlinerTracer *_tracer;
TR_PREXARGINFO_TRACER_CLASS *_tracer;
TR_EstimateCodeSize *_ecs;
Operand * _unknownOperand; // used whenever the iterator can't reason about an operand
TR_CallTarget *_calltarget; // the target method to inline
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/optimizer/J9EstimateCodeSize.cpp
Expand Up @@ -1049,7 +1049,7 @@ TR_J9EstimateCodeSize::realEstimateCodeSize(TR_CallTarget *calltarget, TR_CallSt
if (tracer()->heuristicLevel() && calltarget->_ecsPrexArgInfo)
{
heuristicTrace(tracer(), "ECS CSI -- ArgInfo :");
tracer()->dumpPrexArgInfo(calltarget->_ecsPrexArgInfo);
calltarget->_ecsPrexArgInfo->dumpTrace();
}

TR_InlinerDelimiter delimiter(tracer(), "realEstimateCodeSize");
Expand Down
5 changes: 3 additions & 2 deletions runtime/compiler/optimizer/J9Inliner.hpp
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -24,6 +24,7 @@
#define INLINERTEMPFORJ9_INCL

#include "j9cfg.h"
#include "ras/LogTracer.hpp"
#include "runtime/J9ValueProfiler.hpp"

class OMR_InlinerPolicy;
Expand Down Expand Up @@ -153,7 +154,7 @@ class TR_J9InlinerUtil: public OMR_InlinerUtil
bool &appendTestToBlock1, TR::ResolvedMethodSymbol * callerSymbol, TR::TreeTop *cursorTree,
TR::TreeTop *&virtualGuard, TR::Block *block4);
virtual void refineInliningThresholds(TR::Compilation *comp, int32_t &callerWeightLimit, int32_t &maxRecursiveCallByteCodeSizeEstimate, int32_t &methodByteCodeSizeThreshold, int32_t &methodInWarmBlockByteCodeSizeThreshold, int32_t &methodInColdBlockByteCodeSizeThreshold, int32_t &nodeCountThreshold, int32_t size);
static void checkForConstClass(TR_CallTarget *target, TR_InlinerTracer *tracer);
static void checkForConstClass(TR_CallTarget *target, TR_LogTracer *tracer);
virtual bool needTargetedInlining(TR::ResolvedMethodSymbol *callee);
virtual void requestAdditionalOptimizations(TR_CallTarget *calltarget);
protected:
Expand Down

0 comments on commit bbb2806

Please sign in to comment.