GraphFlattener flattener = new GraphFlattener(str); count = flattener.getNumTiles();
count = Partitioner.countTilesNeeded(str, joinersNeedTiles);
    private int fuseAll() {	// how many tiles we have occupied	int count = 0;	// whether or not we're done trying to fuse	boolean done = false;	int aggressive=0;	do {	    // get how many tiles we have	    GraphFlattener flattener = new GraphFlattener(str);	    count = flattener.getNumTiles();	    System.out.println("  Partitioner detects " + count + " tiles.");	    if (count>target) {		//boolean tried=false;		// make a fresh work estimate		this.work = WorkEstimate.getWorkEstimate(str);		// get the containers in the order of work for filters		// immediately contained		WorkList list = work.getSortedContainerWork();		//System.out.println(list);		// work up through this list until we fuse something		for (int i=0; i<list.size(); i++) {		    SIRContainer cont = list.getContainer(i);		    if (cont instanceof SIRSplitJoin) {			//System.out.println("trying to fuse " + cont.size() + "-way split " + ((SIRSplitJoin)cont).getName());			if(aggressive==0) {			    // skip this container if it has an identity child			    boolean attempt=true;			    for(int j=0;j<cont.size();j++) {				if (cont.get(j) instanceof SIRIdentity) {				    attempt=false;				}			    }			    if(attempt) {				SIRStream newstr = FuseSplit.semiFuse((SIRSplitJoin)cont);				// replace toplevel stream if we're replacing it				if (cont==str) {				    str = newstr;				}				// if we fused something, quit loop				if (newstr!=cont) {				    aggressive=0;				    break;				}			    }			} else if(aggressive==1) {			    // skip this container if it has nothing but identity children			    boolean attempt=false;			    for(int j=0;j<cont.size();j++) {				if (!(cont.get(j) instanceof SIRIdentity)) {				    attempt=true;				}			    }			    if(attempt) {				SIRStream newstr = FuseSplit.semiFuse((SIRSplitJoin)cont);				// replace toplevel stream if we're replacing it				if (cont==str) {				    str = newstr;				}				// if we fused something, quit loop				if (newstr!=cont) {				    aggressive=0;				    break;				}			    }			} else {			    // otherwise, always fuse if we can			    SIRStream newstr = FuseSplit.semiFuse((SIRSplitJoin)cont);			    // replace toplevel stream if we're replacing it			    if (cont==str) {				str = newstr;			    }			    // if we fused something, quit loop			    if (newstr!=cont) {				aggressive=0;				//tried=true;				break;			    }			}		    } else if (cont instanceof SIRPipeline) {			//System.out.println("trying to fuse " + (count-target) + " from " 			//+ cont.size() + "-long pipe " + ((SIRPipeline)cont).getName());			int elim=0;			if(cont.size()<=2) {			    elim = FusePipe.fuse((SIRPipeline)cont, count-target);			    			    Lifter.eliminatePipe((SIRPipeline)cont);			} else {			    int best=Integer.MAX_VALUE;			    int index=0;			    SIRStream cur=cont.get(0);			    for(int j=0;j<cont.size()-1;j++) {				SIRStream next=cont.get(j+1);				if((cur instanceof SIRFilter)&&(next instanceof SIRFilter)) {				    int newWork=work.getWork((SIRFilter)cont.get(j))+work.getWork((SIRFilter)cont.get(j+1));				    if(newWork<best) {					best=newWork;					index=j;				    }				}				cur=next;			    }			    if(best!=Integer.MAX_VALUE) {				elim = FusePipe.fuseTwo((SIRPipeline)cont, index);			    }			}			// try lifting			if (elim!=0) {			    //System.out.println("FUSED: "+elim);			    aggressive=0;			    break;			}		    }		    // if we made it to the end of the last loop, then		    // we're done trying to fuse (we didn't reach target.)		    if (i==list.size()-1) { 			if(aggressive>=2)			    done=true;			else			    //if(!tried)			    aggressive++;		    }		}	    }	} while (count>target && !done);	return count;    }