/** * Merge the list of loopVertices into a single LoopVertex. * @param loopVertices list of LoopVertices to merge. * @return the merged single LoopVertex. */ private LoopVertex mergeLoopVertices(final Set<LoopVertex> loopVertices) { final String newName = String.join("+", loopVertices.stream().map(LoopVertex::getName).collect(Collectors.toList())); final LoopVertex mergedLoopVertex = new LoopVertex(newName); loopVertices.forEach(loopVertex -> { final DAG<IRVertex, IREdge> dagToCopy = loopVertex.getDAG(); dagToCopy.topologicalDo(v -> { mergedLoopVertex.getBuilder().addVertex(v); dagToCopy.getIncomingEdgesOf(v).forEach(mergedLoopVertex.getBuilder()::connectVertices); }); loopVertex.getDagIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagIncomingEdge)); loopVertex.getIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addIterativeIncomingEdge)); loopVertex.getNonIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addNonIterativeIncomingEdge)); loopVertex.getDagOutgoingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagOutgoingEdge)); }); return mergedLoopVertex; }
/** * Merge the list of loopVertices into a single LoopVertex. * @param loopVertices list of LoopVertices to merge. * @return the merged single LoopVertex. */ private LoopVertex mergeLoopVertices(final Set<LoopVertex> loopVertices) { final String newName = String.join("+", loopVertices.stream().map(LoopVertex::getName).collect(Collectors.toList())); final LoopVertex mergedLoopVertex = new LoopVertex(newName); loopVertices.forEach(loopVertex -> { final DAG<IRVertex, IREdge> dagToCopy = loopVertex.getDAG(); dagToCopy.topologicalDo(v -> { mergedLoopVertex.getBuilder().addVertex(v); dagToCopy.getIncomingEdgesOf(v).forEach(mergedLoopVertex.getBuilder()::connectVertices); }); loopVertex.getDagIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagIncomingEdge)); loopVertex.getIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addIterativeIncomingEdge)); loopVertex.getNonIterativeIncomingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addNonIterativeIncomingEdge)); loopVertex.getDagOutgoingEdges().forEach((v, es) -> es.forEach(mergedLoopVertex::addDagOutgoingEdge)); }); return mergedLoopVertex; } }
finalRootLoopVertex.getDagOutgoingEdges().clear(); loopVertex.getDagOutgoingEdges().forEach((srcVertex, edges) -> edges.forEach(edge -> { final IRVertex dstVertex = edge.getDst(); final IRVertex equivalentSrcVertex = equivalentVertices.get(srcVertex);
finalRootLoopVertex.getDagOutgoingEdges().clear(); loopVertex.getDagOutgoingEdges().forEach((srcVertex, edges) -> edges.forEach(edge -> { final IRVertex dstVertex = edge.getDst(); final IRVertex equivalentSrcVertex = equivalentVertices.get(srcVertex);
getDagOutgoingEdges().forEach((srcVertex, irEdges) -> irEdges.forEach(edge -> { final IREdge newIrEdge = new IREdge(edge.getPropertyValue(CommunicationPatternProperty.class).get(), originalToNewIRVertex.get(srcVertex), edge.getDst());
getDagOutgoingEdges().forEach((srcVertex, irEdges) -> irEdges.forEach(edge -> { final IREdge newIrEdge = new IREdge(edge.getPropertyValue(CommunicationPatternProperty.class).get(), originalToNewIRVertex.get(srcVertex), edge.getDst());