SIRFilter splitFilter = null; if (sj.getSplitter().getType()!=SIRSplitType.DUPLICATE && rep.splitter!=0) { splitFilter = makeFilter(sj.getParent(), "Pre_" + sj.getIdent(), makeSplitFilterBody(sj.getSplitter(), rep, sj.getInputType()), pop, pop, pop, sj.getInputType()); }   SIRFilter joinFilter = null; if (rep.joiner!=0) { joinFilter = makeFilter(sj.getParent(), "Post_" + sj.getIdent(), makeJoinFilterBody(sj.getJoiner(), rep, sj.getOutputType()), push, push, push, sj.getOutputType()); }
SIRPipeline fused = makeFusedPipe(sj, rep, rate, newFilter);
    public static SIRStream fuse(SIRSplitJoin sj)    {	// check the parent	if (!(sj.getParent() instanceof SIRPipeline)) {	    System.err.println("Didn't fuse SJ because parent is of " + sj.getParent().getClass());	    return sj;	}        // Check the ratios.        Iterator childIter = sj.getParallelStreams().iterator();        while (childIter.hasNext()) {            SIRStream str = (SIRStream)childIter.next();            if (!(str instanceof SIRFilter))                return sj;            SIRFilter filter = (SIRFilter)str;	    // don't allow two-stage filters, since we aren't dealing	    // with how to fuse their initWork functions.            if (filter instanceof SIRTwoStageFilter) {		System.err.println("Didn't fuse SJ because this child is a 2-stage filter: " + filter);                return sj;	    }        }	System.err.println("Fusing " + (sj.size()) + " SplitJoin filters!");        // Rename all of the child streams of this.        RenameAll ra = new RenameAll();        List children = sj.getParallelStreams();        Iterator iter = children.iterator();        while (iter.hasNext()) {	    ra.renameFilterContents((SIRFilter)iter.next());        }		// calculate the repetitions for the split-join	RepInfo rep = RepInfo.calcReps(sj);        // So at this point we have an eligible split/join; flatten it.        JMethodDeclaration newWork = makeWorkFunction(sj, children, rep);        JFieldDeclaration[] newFields = makeFields(sj, children);        JMethodDeclaration[] newMethods = makeMethods(sj, children);        /* Make names of things within the split/join unique.        ra.findDecls(newFields);        ra.findDecls(newMethods);        for (int i = 0; i < newFields.length; i++)            newFields[i] = (JFieldDeclaration)newFields[i].accept(ra);        for (int i = 0; i < newMethods.length; i++)            newMethods[i] = (JMethodDeclaration)newMethods[i].accept(ra);        newWork = (JMethodDeclaration)newWork.accept(ra);	*/        // Get the init function now, using renamed names of things.        JMethodDeclaration newInit = makeInitFunction(sj, children);	// calculate the push/pop/peek ratio	int push = rep.joiner * sj.getJoiner().getSumOfWeights();	int pop;	if (sj.getSplitter().getType()==SIRSplitType.DUPLICATE) {	    pop = rep.splitter;	} else {	    pop = rep.splitter * sj.getSplitter().getSumOfWeights();;	}	// calculate the peek amount...	// get the max peeked by a child, in excess of its popping        children = sj.getParallelStreams();        iter = children.iterator();	int maxPeek = 0;        while (iter.hasNext()) {	    SIRFilter filter = (SIRFilter)iter.next();	    maxPeek = Math.max(maxPeek, 			       filter.getPeekInt()-			       filter.getPopInt());	}	// calculate the peek as the amount we'll look into the input	// during execution	int peek = pop+maxPeek;        // Build the new filter.        SIRFilter newFilter = new SIRFilter(sj.getParent(),                                            "Fused_" + sj.getIdent(),                                            newFields,                                            newMethods,                                            new JIntLiteral(peek),                                            new JIntLiteral(pop),                                            new JIntLiteral(push),                                            newWork,                                            sj.getInputType(),                                            sj.getOutputType());        // Use the new init function.        newFilter.setInit(newInit);	// make a splitFilter only if it's not a duplicate and it's	// not a null split	SIRFilter splitFilter = null;	if (sj.getSplitter().getType()!=SIRSplitType.DUPLICATE &&	    rep.splitter!=0) {	    splitFilter = makeFilter(sj.getParent(),				     "Pre_" + sj.getIdent(),				     makeSplitFilterBody(sj.getSplitter(), 							 rep,							 sj.getInputType()), 				     pop, pop, pop,				     sj.getInputType());	}		// make a joinFilter only if it's not a not a null join	SIRFilter joinFilter = null;	if (rep.joiner!=0) {	    joinFilter = makeFilter(sj.getParent(),					  "Post_" + sj.getIdent(),					  makeJoinFilterBody(sj.getJoiner(), 							     rep,							     sj.getOutputType()),					  push, push, push,					  sj.getOutputType());	}	// add these filters to the parent, which we require is a pipeline for now	SIRPipeline parent = (SIRPipeline)sj.getParent();	// get the index where we did the replace	int index = parent.indexOf(sj);	parent.replace(sj, newFilter);	// add <joinFilter> after <newFilter>	if (joinFilter!=null) {	    parent.add(index+1, joinFilter);	}	// add <splitFilter> before <newFilter>, if it's not a duplicate	if (splitFilter!=null) {	    parent.add(index, splitFilter);	}        return newFilter;    }