Skip to content

Commit

Permalink
Add classes for building IDT, performing abstract interpretation and …
Browse files Browse the repository at this point in the history
…handling loops.

This is the phase 3/3 of the BenefitInliner contribution.

* AbsInterpreter.hpp, AbsInterpreter.cpp: new class files for performing abstract interpretation. They are also able to handle loops during making the decision for inlining.
* AbsStackMachineState.hpp, AbsStackMachineState.cpp: new class files for handling abstract operand stacks and abstract operand arrays.
* IDTBuilder.hpp, J9IDTBuilder.hpp, J9IDTBuilder.cpp: new class files for building IDT.
* J9EstimateCodeSize.hpp, J9EstimateCodeSize.cpp: add method to generate CFG that will be used by building IDT, and add _hasBackEdges flag if there is loop in the code when generate CFG.

Co-authored-by: Mingwei Li <[email protected]>
Signed-off-by: Cijie Xia <[email protected]>
  • Loading branch information
xiacijie and mingweiarthurli committed Jul 15, 2024
1 parent 011aecc commit 643741b
Show file tree
Hide file tree
Showing 12 changed files with 3,552 additions and 1 deletion.
12 changes: 12 additions & 0 deletions runtime/compiler/build/files/common.mk.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ JIT_PRODUCT_BACKEND_SOURCES+=\
omr/compiler/optimizer/VPConstraint.cpp \
omr/compiler/optimizer/VPHandlers.cpp \
omr/compiler/optimizer/VPHandlersCommon.cpp \
omr/compiler/optimizer/BenefitInliner.cpp \
omr/compiler/optimizer/abstractinterpreter/AbsValue.cpp \
omr/compiler/optimizer/abstractinterpreter/AbsOpArray.cpp \
omr/compiler/optimizer/abstractinterpreter/AbsOpStack.cpp \
omr/compiler/optimizer/abstractinterpreter/IDT.cpp \
omr/compiler/optimizer/abstractinterpreter/IDTNode.cpp \
omr/compiler/optimizer/abstractinterpreter/OMRIDTBuilder.cpp \
omr/compiler/optimizer/abstractinterpreter/InliningMethodSummary.cpp \
omr/compiler/optimizer/abstractinterpreter/InliningProposal.cpp \
omr/compiler/ras/CallStack.cpp \
omr/compiler/ras/CFGChecker.cpp \
omr/compiler/ras/Debug.cpp \
Expand Down Expand Up @@ -350,6 +359,9 @@ JIT_PRODUCT_SOURCE_FILES+=\
compiler/optimizer/J9EstimateCodeSize.cpp \
compiler/optimizer/J9Inliner.cpp \
compiler/optimizer/InterpreterEmulator.cpp \
compiler/optimizer/abstractinterpreter/AbsStackMachineState.cpp \
compiler/optimizer/abstractinterpreter/J9IDTBuilder.cpp \
compiler/optimizer/abstractinterpreter/AbsInterpreter.cpp \
compiler/ras/HashTable.cpp \
compiler/ras/InternalFunctions.cpp \
compiler/ras/kca_offsets_generator.cpp \
Expand Down
3 changes: 3 additions & 0 deletions runtime/compiler/optimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ j9jit_files(
optimizer/VectorAPIExpansion.cpp
optimizer/VPBCDConstraint.cpp
optimizer/TreeLowering.cpp
optimizer/abstractinterpreter/J9IDTBuilder.cpp
optimizer/abstractinterpreter/AbsInterpreter.cpp
optimizer/abstractinterpreter/AbsStackMachineState.cpp
)
25 changes: 25 additions & 0 deletions runtime/compiler/optimizer/J9EstimateCodeSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,27 @@ TR_J9EstimateCodeSize::estimateCodeSize(TR_CallTarget *calltarget, TR_CallStack
return false;
}

TR::CFG *
TR_J9EstimateCodeSize::generateCFG(TR_CallTarget *calltarget, TR::Region &region)
{
TR::ResolvedMethodSymbol* methodSymbol = TR::ResolvedMethodSymbol::create(comp()->trHeapMemory(), calltarget->_calleeMethod, comp());
TR_J9ByteCodeIterator bci(methodSymbol, static_cast<TR_ResolvedJ9Method*>(methodSymbol->getResolvedMethod()), static_cast<TR_J9VMBase*>(comp()->fe()), comp());

NeedsPeekingHeuristic nph(calltarget, bci, methodSymbol, comp());

int32_t maxIndex = bci.maxByteCodeIndex() + 5;

TR::Block * * blocks = (TR::Block * *) comp()->trMemory()->allocateStackMemory(maxIndex * sizeof(TR::Block *));
memset(blocks, 0, maxIndex * sizeof(TR::Block *));

flags8_t * flags = (flags8_t *) comp()->trMemory()->allocateStackMemory(maxIndex * sizeof(flags8_t));
memset(flags, 0, maxIndex * sizeof(flags8_t));

processBytecodeAndGenerateCFG(calltarget, region, bci, nph, blocks, flags);

return calltarget->_cfg;
}

TR::CFG&
TR_J9EstimateCodeSize::processBytecodeAndGenerateCFG(TR_CallTarget *calltarget, TR::Region &cfgRegion, TR_J9ByteCodeIterator& bci, NeedsPeekingHeuristic &nph, TR::Block** blocks, flags8_t * flags)
{
Expand Down Expand Up @@ -1136,13 +1157,17 @@ TR_J9EstimateCodeSize::processBytecodeAndGenerateCFG(TR_CallTarget *calltarget,
calltarget->_calleeMethod, i + bci.relativeBranch(),
cfg));
addFallThruEdge = true;
if (bci.relativeBranch() < 0)
cfg.setHasBackEdges();
break;
}
case J9BCgoto:
case J9BCgotow:
setupLastTreeTop(currentBlock, bc, i, getBlock(comp(), blocks, calltarget->_calleeMethod, i + bci.relativeBranch(), cfg), calltarget->_calleeMethod, comp());
cfg.addEdge(currentBlock, getBlock(comp(), blocks, calltarget->_calleeMethod, i + bci.relativeBranch(), cfg));
addFallThruEdge = false;
if (bci.relativeBranch() < 0)
cfg.setHasBackEdges();
break;
case J9BCReturnC:
case J9BCReturnS:
Expand Down
2 changes: 2 additions & 0 deletions runtime/compiler/optimizer/J9EstimateCodeSize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class TR_J9EstimateCodeSize : public TR_EstimateCodeSize
uint32_t bcIndex, TR::Block *destinationBlock, TR_ResolvedMethod *feMethod,
TR::Compilation *comp);

TR::CFG* generateCFG(TR_CallTarget *calltarget, TR::Region &region);

protected:
bool estimateCodeSize(TR_CallTarget *, TR_CallStack * , bool recurseDown = true);

Expand Down
4 changes: 3 additions & 1 deletion runtime/compiler/optimizer/J9Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
#include "optimizer/MethodHandleTransformer.hpp"
#include "optimizer/VectorAPIExpansion.hpp"
#include "optimizer/CatchBlockProfiler.hpp"
#include "optimizer/SelectOpt.hpp"
#include "optimizer/BenefitInliner.hpp"


static const OptimizationStrategy J9EarlyGlobalOpts[] =
Expand Down Expand Up @@ -826,7 +828,7 @@ J9::Optimizer::Optimizer(TR::Compilation *comp, TR::ResolvedMethodSymbol *method
// initialize additional J9 optimizations

_opts[OMR::inlining] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_Inliner::create, OMR::inlining);
new (comp->allocator()) TR::OptimizationManager(self(), comp->getOption(TR_EnableBenefitInliner) ? TR::BenefitInlinerWrapper::create : TR_Inliner::create, OMR::inlining);
_opts[OMR::targetedInlining] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_Inliner::create, OMR::targetedInlining);
_opts[OMR::targetedInlining]->setOptPolicy(new (comp->allocator()) TR_J9JSR292InlinerPolicy(comp));
Expand Down
Loading

0 comments on commit 643741b

Please sign in to comment.