Skip to content

Commit

Permalink
Use interprocedural analysis for property read case.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed Jan 8, 2024
1 parent 8a9ed84 commit 75f5544
Showing 1 changed file with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ private static Set<PointsToSetVariable> getDataflowSources(
int objectRef = propertyRead.getObjectRef();
SSAInstruction def = du.getDef(objectRef);

if (def instanceof EachElementGetInstruction || def instanceof PythonPropertyRead) {
if (def == null) {
// definition is unavailable from the local DefUse. Use interprocedural analysis using
// the PA.
processInstructionInterprocedurally(
propertyRead, objectRef, localPointerKeyNode, src, sources, pointerAnalysis);
} else if (def instanceof EachElementGetInstruction
|| def instanceof PythonPropertyRead) {
processInstruction(
def, du, localPointerKeyNode, src, sources, callGraph, pointerAnalysis);
}
Expand All @@ -164,37 +170,49 @@ private static void processInstruction(
SSAInstruction def = du.getDef(use);

if (def == null) {
logger.info(
() ->
"Can't find potential tensor iterable definition for use: "
+ use
+ " of instruction: "
+ instruction
+ ". Trying interprocedural analysis...");

// Look up the use in the pointer analysis to see if it points to a dataset.
PointerKey usePointerKey =
pointerAnalysis.getHeapModel().getPointerKeyForLocal(localPointerKeyNode, use);

for (InstanceKey ik : pointerAnalysis.getPointsToSet(usePointerKey)) {
if (ik instanceof AllocationSiteInNode) {
AllocationSiteInNode asin = (AllocationSiteInNode) ik;
IClass concreteType = asin.getConcreteType();
TypeReference reference = concreteType.getReference();

if (reference.equals(DATASET)) {
sources.add(src);
logger.info("Added dataflow source from tensor dataset: " + src + ".");
break;
}
}
}
// definition is unavailable from the local DefUse. Use interprocedural analysis using the PA.
processInstructionInterprocedurally(
instruction, use, localPointerKeyNode, src, sources, pointerAnalysis);
} else if (definesTensorIterable(def, localPointerKeyNode, callGraph, pointerAnalysis)) {
sources.add(src);
logger.info("Added dataflow source from tensor iterable: " + src + ".");
}
}

private static void processInstructionInterprocedurally(
SSAInstruction instruction,
int use,
CGNode localPointerKeyNode,
PointsToSetVariable src,
Set<PointsToSetVariable> sources,
PointerAnalysis<InstanceKey> pointerAnalysis) {
logger.info(
() ->
"Can't find potential tensor iterable definition for use: "
+ use
+ " of instruction: "
+ instruction
+ ". Trying interprocedural analysis...");

// Look up the use in the pointer analysis to see if it points to a dataset.
PointerKey usePointerKey =
pointerAnalysis.getHeapModel().getPointerKeyForLocal(localPointerKeyNode, use);

for (InstanceKey ik : pointerAnalysis.getPointsToSet(usePointerKey)) {
if (ik instanceof AllocationSiteInNode) {
AllocationSiteInNode asin = (AllocationSiteInNode) ik;
IClass concreteType = asin.getConcreteType();
TypeReference reference = concreteType.getReference();

if (reference.equals(DATASET)) {
sources.add(src);
logger.info("Added dataflow source from tensor dataset: " + src + ".");
break;
}
}
}
}

/**
* True iff the given {@link EachElementGetInstruction} constitutes individual elements.
*
Expand Down

0 comments on commit 75f5544

Please sign in to comment.