Skip to content

Commit

Permalink
Excluding self exit node when finding ranges which terminate in a giv…
Browse files Browse the repository at this point in the history
…en range
  • Loading branch information
avishek-sen-gupta committed Nov 17, 2024
1 parent e93deb7 commit 1ed9b4e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public SLIFORangeCriterionTask(Set<Pair<ProcedureRange, Set<ProcedureRange>>> ra

public Set<ProcedureRange> rangesTerminatingIn(ProcedureRange range) {
Set<ProcedureRange> procedureRanges = rangesWithChildren.stream().map(Pair::getLeft).collect(Collectors.toUnmodifiableSet());
Set<TranspilerInstruction> body = range.body().vertexSet();
Set<TranspilerInstruction> bodyVertices = range.body().vertexSet();
Set<TranspilerInstruction> selfExit = bodyVertices.stream().filter(v -> v == range.exit()).collect(Collectors.toUnmodifiableSet());
Set<TranspilerInstruction> body = Sets.difference(bodyVertices, selfExit);
Set<ProcedureRange> rangesTerminatingInCurrentRangeIncludingSelf = procedureRanges.stream()
.filter(bbr -> body.contains(bbr.exit()))
.collect(Collectors.toUnmodifiableSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ public CallRangesTask(TranspilerNode tree, List<TranspilerInstruction> instructi

public Set<Pair<TranspilerInstruction, TranspilerInstruction>> run() {
Set<TranspilerNode> allCalls = findAllRecursive(tree, n -> n instanceof JumpTranspilerNode l && l.getEnd() != LocationNode.NULL).stream().collect(Collectors.toUnmodifiableSet());
return allCalls.stream().map(call -> {
TranspilerNode entryBlock = labelledBlock(((JumpTranspilerNode) call).getStart());
TranspilerNode exitBlock = labelledBlock(((JumpTranspilerNode) call).getEnd());
return ImmutablePair.of(
entryOrExitVertex(entryBlock, CodeSentinelType.ENTER),
entryOrExitVertex(exitBlock, CodeSentinelType.EXIT));
}).collect(Collectors.toUnmodifiableSet());
List<TranspilerNode> allBlocks = findAllRecursiveOrdered(tree, n -> n instanceof LabelledTranspilerCodeBlockNode).stream().toList();
Pair<TranspilerInstruction, TranspilerInstruction> programLevelRange = ImmutablePair.of(
entryOrExitVertex(allBlocks.getFirst(), CodeSentinelType.ENTER),
entryOrExitVertex(allBlocks.getLast(), CodeSentinelType.EXIT));

return Stream.concat(Stream.of(programLevelRange),
allCalls.stream().map(call -> {
TranspilerNode entryBlock = labelledBlock(((JumpTranspilerNode) call).getStart());
TranspilerNode exitBlock = labelledBlock(((JumpTranspilerNode) call).getEnd());
return ImmutablePair.of(
entryOrExitVertex(entryBlock, CodeSentinelType.ENTER),
entryOrExitVertex(exitBlock, CodeSentinelType.EXIT));
})).collect(Collectors.toUnmodifiableSet());
}

private TranspilerNode labelledBlock(LocationNode locationNode) {
Expand All @@ -45,6 +51,12 @@ private Set<TranspilerNode> findAllRecursive(TranspilerNode current, Function<Tr
return childResults(current, match).collect(Collectors.toUnmodifiableSet());
}

private List<TranspilerNode> findAllRecursiveOrdered(TranspilerNode current, Function<TranspilerNode, Boolean> match) {
if (match.apply(current))
return Stream.concat(Stream.of(current), childResults(current, match)).toList();
return childResults(current, match).toList();
}

private Stream<TranspilerNode> childResults(TranspilerNode current, Function<TranspilerNode, Boolean> match) {
return current.astChildren().stream().flatMap(c -> findAllRecursive(c, match).stream());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public void canDetermineSLIFORangesInductively() {
Graph<TranspilerInstruction, DefaultEdge> implicitCFG = new BuildImplicitInstructionControlFlowgraphTask(instructions, ImmutableList.of()).run();
Set<Pair<ProcedureRange, Set<ProcedureRange>>> rangesWithChildren = new ProcedureBodyTask(program, instructions, implicitCFG).run();
SLIFORangeCriterionTask task = new SLIFORangeCriterionTask(rangesWithChildren);
assertEquals(2, rangesWithChildren.size());
assertEquals(3, rangesWithChildren.size());
Set<Pair<ProcedureRange, Set<ProcedureRange>>> allSLIFORanges = task.allSLIFORanges(rangesWithChildren);
assertEquals(2, allSLIFORanges.size());
assertEquals(3, allSLIFORanges.size());
}

private static PrintTranspilerNode p() {
Expand Down

0 comments on commit 1ed9b4e

Please sign in to comment.