if (!initMode) { list.add(Utils.makeForLoop(new JExpressionStatement(null, new SIRPopExpression(type), null), popCount)); }
if (!initMode && popCount > 0) { list.add(new JExpressionStatement( new SIRPopExpression(type, popCount))); }
    private static JBlock doPeeking(SIRSplitter split,				    SJChildInfo[] childInfo,				    RepInfo rep,				    Rate rate,				    CType type,				    boolean initMode) {	// get splitter weights	int[] weights = split.getWeights();	boolean isDup = split.getType()==SIRSplitType.DUPLICATE;	int[] partialSum = new int[weights.length];	JExpression[] partialSumExpression = new JExpression[weights.length];	JExpression[] weightsExpression = new JExpression[weights.length];	// calculate partial sums of weights	partialSumExpression[0] = new JIntLiteral(0);	weightsExpression[0] = new JIntLiteral(weights[0]);	for (int i=1; i<weights.length; i++) {	    partialSum[i] = partialSum[i-1] + weights[i-1];	    partialSumExpression[i] = new JIntLiteral(partialSum[i]);	    weightsExpression[i] = new JIntLiteral(weights[i]);	}	// get total weights	int sumOfWeights = split.getSumOfWeights();	// calculate number of times the split executes in this mode	int numExec;	if (initMode) {	    numExec = (int) Math.ceil(((float)rate.initPeek) / ((float) (isDup ? 1 : sumOfWeights)));	} else {	    numExec = rep.splitter;	}	// make list of statements for work function	LinkedList list = new LinkedList();	// in initMode, don't worry about code size	if (initMode) {	    for (int k=0; k<weights.length; k++) {		for (int i=0; i<numExec; i++) {		    for (int j=0; j<weights[k]; j++) {			// calculate index of this peek			int index = i * (isDup ? 1 : sumOfWeights) + (isDup ? 0 : partialSum[k]) + j;			// if we're in initmode, then don't look past an index of <rate.initPeek>			if (index<rate.initPeek) {			    //&& (childInfo[i].filter instanceof SIRTwoStageFilter) &&			    //	      i*weights[k]+j < ((SIRTwoStageFilter)childInfo[i].filter).getInitPeek())) {			    // make a peek expression			    JExpression peekVal = new SIRPeekExpression(new JIntLiteral(index), type);			    // make an assignment to the proper peek array			    JAssignmentExpression assign = makeBufferPush(childInfo[k].peekBuffer,									  peekVal);			    // make an expression statement			    list.add(new JExpressionStatement(null, assign, null));			}		    }		}	    }	} else {	    // see how many statements we would generate	    int numStatements = 0;	    for (int k=0; k<weights.length; k++) {		for (int i=0; i<numExec; i++) {		    for (int j=0; j<weights[k]; j++) {	    			numStatements++;		    }		}	    }	    if (numStatements<=SPLITTER_JOINER_LOOP_THRESHOLD()) {		//System.err.println("FuseSplit: unrolling " + numStatements + " ( <= " + SPLITTER_JOINER_LOOP_THRESHOLD());		// if only have a few, generate them plain		for (int k=0; k<weights.length; k++) {		    for (int i=0; i<numExec; i++) {			for (int j=0; j<weights[k]; j++) {			    int index;			    if (isDup) {				// calculate index of this peek				index = i + j + rate.initPeek;			    } else {				index = i * sumOfWeights + partialSum[k] + j + rate.initPeek;			    }			    // make a peek expression			    JExpression peekVal = new SIRPeekExpression(new JIntLiteral(index), type);			    // make an assignment to the proper peek array			    JAssignmentExpression assign = makeBufferPush(childInfo[k].peekBuffer, peekVal);			    list.add(new JExpressionStatement(null, assign, null));			}		    }		}	    } else {		//System.err.println("FuseSplit: compacting " + numStatements + " ( > " + SPLITTER_JOINER_LOOP_THRESHOLD());		// otherwise, optimize for imem...		// _weights[N] = { , , }		JArrayInitializer _weightsInit = new JArrayInitializer(null, weightsExpression);		JVariableDefinition _weights = new JVariableDefinition(null, 								       0, 								       new CArrayType(CStdType.Integer, 1, new JExpression[] { new JIntLiteral(weights.length) } ),								       "_weights", 								       _weightsInit);		list.add(new JVariableDeclarationStatement(null, new JVariableDefinition[] {_weights}, null));		// _partialSum[N] = { , , }		JArrayInitializer _partialSumInit = new JArrayInitializer(null, partialSumExpression);		JVariableDefinition _partialSum = new JVariableDefinition(null, 									  0, 									  new CArrayType(CStdType.Integer, 1, new JExpression[] { new JIntLiteral(weights.length) } ),									  "_partialSum", 									  _partialSumInit);		list.add(new JVariableDeclarationStatement(null, new JVariableDefinition[] {_partialSum}, null));		// it's non-trivial to move the k loop into dynamically-generated code because we reference childInfo[k]		for (int k=0; k<weights.length; k++) {		    // make loop variables		    JVariableDefinition _i = new JVariableDefinition(null, 0, CStdType.Integer, "_i", new JIntLiteral(0));		    JVariableDefinition _j = new JVariableDefinition(null, 0, CStdType.Integer, "_j", new JIntLiteral(0));		    JExpression index;		    if (isDup) {			index = new JAddExpression(null, 						   new JLocalVariableExpression(null, _i),						   new JAddExpression(null,								      new JLocalVariableExpression(null, _j),								      new JIntLiteral(rate.initPeek)));		    } else {			index = new JAddExpression(null,						   new JMultExpression(null,								       new JLocalVariableExpression(null, _i),								       new JIntLiteral(sumOfWeights)),						   new JAddExpression(null,								      new JAddExpression(null, 											 new JArrayAccessExpression(null, 														    new JLocalVariableExpression(null, _partialSum),														    new JIntLiteral(k)),											 new JLocalVariableExpression(null, _j)),								      new JIntLiteral(rate.initPeek)));		    }		    JExpression peekVal = new SIRPeekExpression(index, type);		    JStatement assign = new JExpressionStatement(null, makeBufferPush(childInfo[k].peekBuffer, peekVal), null);		    // add i loop		    JStatement jLoop = Utils.makeForLoop(assign, new JArrayAccessExpression(null, new JLocalVariableExpression(null, _weights), new JIntLiteral(k)), _j);		    JStatement iLoop = Utils.makeForLoop(jLoop, new JIntLiteral(numExec), _i);		    list.add(iLoop);		}	    }	}	// pop items at end	int popCount = initMode ? rate.initPeek : rate.pop;	if (!initMode) {	    list.add(Utils.makeForLoop(new JExpressionStatement(null,								new SIRPopExpression(type),								null),				       popCount));	}	return new JBlock(null, list, null);    }