upStreamItems = (prevInitCount * prevPush);   if (previous != null && previous.contents instanceof SIRTwoStageFilter) { upStreamItems -= ((SIRTwoStageFilter)previous.contents).getPushInt(); upStreamItems += ((SIRTwoStageFilter)previous.contents).getInitPush(); }
    void calculateItems(SIRFilter filter)     {	int pop = filter.getPopInt();	int peek = filter.getPeekInt();		//set up prePop, prePeek	int prePop = 0;	int prePeek = 0;		if (filter instanceof SIRTwoStageFilter) {	    prePop = ((SIRTwoStageFilter)filter).getInitPop();	    prePeek = ((SIRTwoStageFilter)filter).getInitPeek();	}		//the number of times this filter fires in the initialization	//schedule	initFire = 0;	// initExec counts might be null if we're calling for work	// estimation before exec counts have been determined.	if (RawBackend.initExecutionCounts!=null) {	    Integer init = (Integer)RawBackend.initExecutionCounts.		get(Layout.getNode(Layout.getTile(filter)));		    if (init != null) 		initFire = init.intValue();	} else {	    // otherwise, we should be doing this only for work	    // estimation--check that the filter is the only thing in the graph	    Utils.assert(filter.getParent()==null ||			 filter.getParent().size()==1 && filter.getParent().getParent()==null,			 "Found null pointer where unexpected.");	}		//if this is not a twostage, fake it by adding to initFire,	//so we always think the preWork is called	if (!(filter instanceof SIRTwoStageFilter))	    initFire++;	//the number of items produced by the upstream filter in	//initialization	int upStreamItems = 0;	//number of times the previous node fires in init	int prevInitCount = 0;	//its push rate	int prevPush = 0;		FlatNode node = Layout.getNode(Layout.getTile(filter));	FlatNode previous = null;		if (node.inputs > 0) {	    previous = node.incoming[0];	    prevInitCount = Util.getCountPrev(RawBackend.initExecutionCounts, 					 previous, node);	    if (prevInitCount > 0) {		if (previous.contents instanceof SIRSplitter || 		    previous.contents instanceof SIRJoiner) {		    prevPush = 1;		}		else		    prevPush = ((SIRFilter)previous.contents).getPushInt();	    }	    //System.out.println("previous: " + previous.getName());	    //System.out.println("prev Push: " + prevPush + " prev init: " + prevInitCount);	}		//calculate the total items produced by the upstream node	upStreamItems = (prevInitCount * prevPush);	//if the previous node is a two stage filter then count its initWork	//in the initialItemsTo Receive	if (previous != null && previous.contents instanceof SIRTwoStageFilter) {	    upStreamItems -= ((SIRTwoStageFilter)previous.contents).getPushInt();	    upStreamItems += ((SIRTwoStageFilter)previous.contents).getInitPush();	}	//see my thesis for an explanation of this calculation	if (initFire  - 1 > 0) {	    bottomPeek = Math.max(0, 				  peek - (prePeek - prePop));	}	else	    bottomPeek = 0;		remaining = upStreamItems -	    (prePeek + 	     bottomPeek + 	     Math.max((initFire - 2), 0) * pop);	    }        //returns the expression that will create the buffer array.  A JNewArrayExpression    //with the proper type, dimensions, and size...    private JExpression bufferInitExp(SIRFilter filter, CType inputType,				      int buffersize)     {	if (inputType.isArrayType()) {	    CType baseType = ((CArrayType)inputType).getBaseType();	    //create the array to hold the dims of the buffer	    JExpression baseTypeDims[] = ((CArrayType)inputType).getDims();	    JExpression[] dims =  new JExpression[baseTypeDims.length + 1];	    //the first dim is the buffersize	    dims[0] = new JIntLiteral(buffersize);	    //copy the dims for the basetype	    for (int i = 1; i < dims.length; i++)		dims[i] = baseTypeDims[i];	    	    return new JNewArrayExpression(null, baseType, dims, null);	}		JExpression dims[] = {new JIntLiteral(buffersize)};	return new JNewArrayExpression(null, inputType, dims, null);	    }