Skip to content

Commit

Permalink
VectorAPI analyze guard for VectorAPI package
Browse files Browse the repository at this point in the history
If the Virtual guards is generated to guard a inlined method from Vector
API package, set them to do not kill fear.

Signed-off-by: Rahil Shah <rahil@ca.ibm.com>
  • Loading branch information
r30shah committed Nov 28, 2022
1 parent d012930 commit 50998f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
32 changes: 26 additions & 6 deletions runtime/compiler/optimizer/FearPointAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,31 @@
#include "infra/BitVector.hpp"
#include "infra/Checklist.hpp"

bool TR_FearPointAnalysis::virtualGuardsKillFear(TR::Compilation *comp)

bool TR_FearPointAnalysis::virtualGuardKillsFear(TR::Compilation *comp, TR::Node *virtualGuardNode)
{
static bool kill = (feGetEnv("TR_FPAnalaysisGuardsDoNotKillFear") == NULL);
return kill && !(!comp->getOption(TR_DisableVectorAPIExpansion) && comp->getMethodSymbol()->hasVectorAPI());
if (!comp->cg()->supportsMergingGuards())
return false;

static bool kill = (feGetEnv("TR_FPAnalaysisGuardsDoNotKillFear")) == NULL;

if (kill && !comp->getOption(TR_DisableVectorAPIExpansion) && comp->getMethodSymbol()->hasVectorAPI())
{
TR_VirtualGuard *guardInfo = comp->findVirtualGuardInfo(virtualGuardNode);
if (guardInfo->isInlineGuard())
{
TR::Method *guardedMethod = guardInfo->getSymbolReference()->getSymbol()->castToMethodSymbol()->getMethod();
uint32_t classNameLength = guardedMethod->classNameLength();
char* className = guardedMethod->classNameChars();
// Set Virtual guard to not kill fear if it is guarding calls to method in two VectorJEP packages.
if ((classNameLength >= 20 && strncmp("jdk/incubator/vector", className, 20) == 0)
|| (classNameLength >= 22 && strncmp("jdk/internal/vm/vector", className, 22) == 0))
{
return false;
}
}
}
return kill;
}

int32_t TR_FearPointAnalysis::getNumberOfBits() { return 1; }
Expand Down Expand Up @@ -246,9 +267,8 @@ void TR_FearPointAnalysis::initializeGenAndKillSetInfo()
}

// kill any fear originating from inside
if (virtualGuardsKillFear(comp())
&& treeTop->getNode()->isTheVirtualGuardForAGuardedInlinedCall()
&& comp()->cg()->supportsMergingGuards())
if (treeTop->getNode()->isTheVirtualGuardForAGuardedInlinedCall()
&& virtualGuardKillsFear(comp(), treeTop->getNode()))
{
_regularKillSetInfo[currentBlock->getNumber()]->setAll(getNumberOfBits());
_exceptionKillSetInfo[currentBlock->getNumber()]->setAll(getNumberOfBits());
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/optimizer/FearPointAnalysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TR_FearPointAnalysis : public TR_BackwardUnionSingleBitContainerAnalysis
virtual bool postInitializationProcessing();
TR_SingleBitContainer *generatedFear(TR::Node *node);

static bool virtualGuardsKillFear(TR::Compilation *comp);
static bool virtualGuardKillsFear(TR::Compilation *comp, TR::Node *virtualGuardNode);

private:
void computeFear(TR::Compilation *comp, TR::Node *node, TR::NodeChecklist &checklist);
Expand Down
6 changes: 2 additions & 4 deletions runtime/compiler/optimizer/HCRGuardAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,10 @@ void TR_HCRGuardAnalysis::initializeGenAndKillSetInfo()
isKill = false;
}
}
else if (ttNode->isTheVirtualGuardForAGuardedInlinedCall()
&& TR_FearPointAnalysis::virtualGuardsKillFear(comp())
&& comp()->cg()->supportsMergingGuards())
else if (ttNode->isTheVirtualGuardForAGuardedInlinedCall())
{
TR_VirtualGuard *guardInfo = comp()->findVirtualGuardInfo(ttNode);
if (guardInfo->getKind() != TR_HCRGuard)
if (guardInfo->getKind() != TR_HCRGuard && TR_FearPointAnalysis::virtualGuardKillsFear(comp(), ttNode))
{
// Theoretically, the guard should only kill its inlined path. However, making it right require adding
// complications to the data flow and/or optimizations using the result of the analysis. Based on the
Expand Down
12 changes: 5 additions & 7 deletions runtime/compiler/optimizer/OSRGuardInsertion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ void TR_OSRGuardInsertion::removeHCRGuards(TR_BitVector &fearGeneratingNodes, TR

// if virtual guards kill fear we can short cut additional analysis if the method still has a guard
// we can mark that guard as an OSR guard and continue without needing a data flow analysis
if (TR_FearPointAnalysis::virtualGuardsKillFear(comp())
&& additionalVirtualGuard
&& comp()->cg()->supportsMergingGuards())
if (additionalVirtualGuard
&& TR_FearPointAnalysis::virtualGuardKillsFear(comp(), potentialGuard))
{
TR_VirtualGuard *additionalGuardInfo = comp()->findVirtualGuardInfo(potentialGuard);
TR_ASSERT(additionalGuardInfo, "guard info should exist for a virtual guard");
Expand All @@ -412,7 +411,7 @@ void TR_OSRGuardInsertion::removeHCRGuards(TR_BitVector &fearGeneratingNodes, TR
{
comp()->addClassForOSRRedefinition(guardInfo->getThisClass());
guardInfo->setMergedWithHCRGuard(false);
if (TR_FearPointAnalysis::virtualGuardsKillFear(comp()))
if (TR_FearPointAnalysis::virtualGuardKillsFear(comp(), node))
guardInfo->setMergedWithOSRGuard();
else
{
Expand Down Expand Up @@ -475,9 +474,8 @@ int32_t TR_OSRGuardInsertion::insertOSRGuards(TR_BitVector &fearGeneratingNodes)
continue;
}

if (TR_FearPointAnalysis::virtualGuardsKillFear(comp())
&& cursor->getNode()->isTheVirtualGuardForAGuardedInlinedCall()
&& comp()->cg()->supportsMergingGuards())
if (cursor->getNode()->isTheVirtualGuardForAGuardedInlinedCall()
&& TR_FearPointAnalysis::virtualGuardKillsFear(comp(), cursor->getNode()))
{
TR::DebugCounter::prependDebugCounter(comp(), TR::DebugCounter::debugCounterName(comp(), "osrGuardSummary/patch/vguard/%s/=%d", comp()->getHotnessName(comp()->getMethodHotness()), block->getFrequency()), cursor);
TR::DebugCounter::prependDebugCounter(comp(), TR::DebugCounter::debugCounterName(comp(), "osrGuardVGLocation/%s/(%s)/block_%d@%d", comp()->getHotnessName(comp()->getMethodHotness()), comp()->signature(), block->getNumber(), block->getFrequency()), cursor);
Expand Down

0 comments on commit 50998f9

Please sign in to comment.