Pwh_list_2 GDALParceling::splitter(Polygon_2 &rect) { Pwh_list_2 ress; Point_2 p1 = rect.vertex(0); Point_2 p2 = rect.vertex(1); Point_2 p3 = rect.vertex(2); Point_2 p4 = rect.vertex(3); Vector_2 v1 = (p2-p1)/2; Vector_2 v2 = (p3-p2)/2; bool v1_bigger = true; if (v1.squared_length() < v2.squared_length()) { v1_bigger = false; } //Left if (v1_bigger && v1.squared_length() >= this->length*this->length) { split_left(p3, ress, p2, p4, p1, v1); return ress; } if (!v1_bigger && v2.squared_length() >= this->length*this->length) { split_up(ress, p3, p1, p4, v2, p2); return ress; } if (v1_bigger && v2.squared_length() >= this->width*this->width){ split_up(ress, p3, p1, p4, v2, p2); return ress; } if (!v1_bigger && v1.squared_length() >= this->width*this->width){ split_left(p3, ress, p2, p4, p1, v1); return ress; } return ress; }
//------------------------------do_split_if------------------------------------ // Found an If getting its condition-code input from a Phi in the same block. // Split thru the Region. void PhaseIdealLoop::do_split_if( Node *iff ) { #ifndef PRODUCT if( PrintOpto && VerifyLoopOptimizations ) tty->print_cr("Split-if"); #endif C->set_major_progress(); Node *region = iff->in(0); Node *region_dom = idom(region); // We are going to clone this test (and the control flow with it) up through // the incoming merge point. We need to empty the current basic block. // Clone any instructions which must be in this block up through the merge // point. DUIterator i, j; bool progress = true; while (progress) { progress = false; for (i = region->outs(); region->has_out(i); i++) { Node* n = region->out(i); if( n == region ) continue; // The IF to be split is OK. if( n == iff ) continue; if( !n->is_Phi() ) { // Found pinned memory op or such if (split_up(n, region, iff)) { i = region->refresh_out_pos(i); progress = true; } continue; } assert( n->in(0) == region, "" ); // Recursively split up all users of a Phi for (j = n->outs(); n->has_out(j); j++) { Node* m = n->out(j); // If m is dead, throw it away, and declare progress if (_nodes[m->_idx] == NULL) { _igvn.remove_dead_node(m); // fall through } else if (m != iff && split_up(m, region, iff)) { // fall through } else { continue; } // Something unpredictable changed. // Tell the iterators to refresh themselves, and rerun the loop. i = region->refresh_out_pos(i); j = region->refresh_out_pos(j); progress = true; } } } // Now we have no instructions in the block containing the IF. // Split the IF. Node *new_iff = split_thru_region( iff, region ); // Replace both uses of 'new_iff' with Regions merging True/False // paths. This makes 'new_iff' go dead. Node *old_false, *old_true; Node *new_false, *new_true; for (DUIterator_Last j2min, j2 = iff->last_outs(j2min); j2 >= j2min; --j2) { Node *ifp = iff->last_out(j2); assert( ifp->Opcode() == Op_IfFalse || ifp->Opcode() == Op_IfTrue, "" ); ifp->set_req(0, new_iff); Node *ifpx = split_thru_region( ifp, region ); // Replace 'If' projection of a Region with a Region of // 'If' projections. ifpx->set_req(0, ifpx); // A TRUE RegionNode // Setup dominator info set_idom(ifpx, region_dom, dom_depth(region_dom) + 1); // Check for splitting loop tails if( get_loop(iff)->tail() == ifp ) get_loop(iff)->_tail = ifpx; // Replace in the graph with lazy-update mechanism new_iff->set_req(0, new_iff); // hook self so it does not go dead lazy_replace_proj( ifp, ifpx ); new_iff->set_req(0, region); // Record bits for later xforms if( ifp->Opcode() == Op_IfFalse ) { old_false = ifp; new_false = ifpx; } else { old_true = ifp; new_true = ifpx; } } _igvn.remove_dead_node(new_iff); // Lazy replace IDOM info with the region's dominator lazy_replace( iff, region_dom ); // Now make the original merge point go dead, by handling all its uses. small_cache region_cache; // Preload some control flow in region-cache region_cache.lru_insert( new_false, new_false ); region_cache.lru_insert( new_true , new_true ); // Now handle all uses of the splitting block for (DUIterator_Last kmin, k = region->last_outs(kmin); k >= kmin; --k) { Node* phi = region->last_out(k); if( !phi->in(0) ) { // Dead phi? Remove it _igvn.remove_dead_node(phi); continue; } assert( phi->in(0) == region, "" ); if( phi == region ) { // Found the self-reference phi->set_req(0, NULL); continue; // Break the self-cycle } // Expected common case: Phi hanging off of Region if( phi->is_Phi() ) { // Need a per-def cache. Phi represents a def, so make a cache small_cache phi_cache; // Inspect all Phi uses to make the Phi go dead for (DUIterator_Last lmin, l = phi->last_outs(lmin); l >= lmin; --l) { Node* use = phi->last_out(l); // Compute the new DEF for this USE. New DEF depends on the path // taken from the original DEF to the USE. The new DEF may be some // collection of PHI's merging values from different paths. The Phis // inserted depend only on the location of the USE. We use a // 2-element cache to handle multiple uses from the same block. handle_use( use, phi, &phi_cache, region_dom, new_false, new_true, old_false, old_true ); } // End of while phi has uses // Because handle_use might relocate region->_out, // we must refresh the iterator. k = region->last_outs(kmin); // Remove the dead Phi _igvn.remove_dead_node( phi ); } else { // Random memory op guarded by Region. Compute new DEF for USE. handle_use( phi, region, ®ion_cache, region_dom, new_false, new_true, old_false, old_true ); } } // End of while merge point has phis // Any leftover bits in the splitting block must not have depended on local // Phi inputs (these have already been split-up). Hence it's safe to hoist // these guys to the dominating point. lazy_replace( region, region_dom ); #ifndef PRODUCT if( VerifyLoopOptimizations ) verify(); #endif }
//------------------------------split_up--------------------------------------- // Split block-local op up through the phis to empty the current block bool PhaseIdealLoop::split_up( Node *n, Node *blk1, Node *blk2 ) { if( n->is_CFG() ) { assert( n->in(0) != blk1, "Lousy candidate for split-if" ); return false; } if( get_ctrl(n) != blk1 && get_ctrl(n) != blk2 ) return false; // Not block local if( n->is_Phi() ) return false; // Local PHIs are expected // Recursively split-up inputs for (uint i = 1; i < n->req(); i++) { if( split_up( n->in(i), blk1, blk2 ) ) { // Got split recursively and self went dead? if (n->outcnt() == 0) _igvn.remove_dead_node(n); return true; } } // Check for needing to clone-up a compare. Can't do that, it forces // another (nested) split-if transform. Instead, clone it "down". if( n->is_Cmp() ) { assert(get_ctrl(n) == blk2 || get_ctrl(n) == blk1, "must be in block with IF"); // Check for simple Cmp/Bool/CMove which we can clone-up. Cmp/Bool/CMove // sequence can have no other users and it must all reside in the split-if // block. Non-simple Cmp/Bool/CMove sequences are 'cloned-down' below - // private, per-use versions of the Cmp and Bool are made. These sink to // the CMove block. If the CMove is in the split-if block, then in the // next iteration this will become a simple Cmp/Bool/CMove set to clone-up. Node *bol, *cmov; if( !(n->outcnt() == 1 && n->unique_out()->is_Bool() && (bol = n->unique_out()->as_Bool()) && (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) && bol->outcnt() == 1 && bol->unique_out()->is_CMove() && (cmov = bol->unique_out()->as_CMove()) && (get_ctrl(cmov) == blk1 || get_ctrl(cmov) == blk2) ) ) { // Must clone down #ifndef PRODUCT if( PrintOpto && VerifyLoopOptimizations ) { tty->print("Cloning down: "); n->dump(); } #endif // Clone down any block-local BoolNode uses of this CmpNode for (DUIterator i = n->outs(); n->has_out(i); i++) { Node* bol = n->out(i); assert( bol->is_Bool(), "" ); if (bol->outcnt() == 1) { Node* use = bol->unique_out(); Node *use_c = use->is_If() ? use->in(0) : get_ctrl(use); if (use_c == blk1 || use_c == blk2) { continue; } } if (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) { // Recursively sink any BoolNode #ifndef PRODUCT if( PrintOpto && VerifyLoopOptimizations ) { tty->print("Cloning down: "); bol->dump(); } #endif for (DUIterator_Last jmin, j = bol->last_outs(jmin); j >= jmin; --j) { // Uses are either IfNodes or CMoves Node* iff = bol->last_out(j); assert( iff->in(1) == bol, "" ); // Get control block of either the CMove or the If input Node *iff_ctrl = iff->is_If() ? iff->in(0) : get_ctrl(iff); Node *x = bol->clone(); register_new_node(x, iff_ctrl); _igvn.hash_delete(iff); iff->set_req(1, x); _igvn._worklist.push(iff); } _igvn.remove_dead_node( bol ); --i; } } // Clone down this CmpNode for (DUIterator_Last jmin, j = n->last_outs(jmin); j >= jmin; --j) { Node* bol = n->last_out(j); assert( bol->in(1) == n, "" ); Node *x = n->clone(); register_new_node(x, get_ctrl(bol)); _igvn.hash_delete(bol); bol->set_req(1, x); _igvn._worklist.push(bol); } _igvn.remove_dead_node( n ); return true; } } // See if splitting-up a Store. Any anti-dep loads must go up as // well. An anti-dep load might be in the wrong block, because in // this particular layout/schedule we ignored anti-deps and allow // memory to be alive twice. This only works if we do the same // operations on anti-dep loads as we do their killing stores. if( n->is_Store() && n->in(MemNode::Memory)->in(0) == n->in(0) ) { // Get store's memory slice int alias_idx = C->get_alias_index(_igvn.type(n->in(MemNode::Address))->is_ptr()); // Get memory-phi anti-dep loads will be using Node *memphi = n->in(MemNode::Memory); assert( memphi->is_Phi(), "" ); // Hoist any anti-dep load to the splitting block; // it will then "split-up". for (DUIterator_Fast imax,i = memphi->fast_outs(imax); i < imax; i++) { Node *load = memphi->fast_out(i); if( load->is_Load() && alias_idx == C->get_alias_index(_igvn.type(load->in(MemNode::Address))->is_ptr()) ) set_ctrl(load,blk1); } } // Found some other Node; must clone it up #ifndef PRODUCT if( PrintOpto && VerifyLoopOptimizations ) { tty->print("Cloning up: "); n->dump(); } #endif // Now actually split-up this guy. One copy per control path merging. Node *phi = PhiNode::make_blank(blk1, n); for( uint j = 1; j < blk1->req(); j++ ) { Node *x = n->clone(); if( n->in(0) && n->in(0) == blk1 ) x->set_req( 0, blk1->in(j) ); for( uint i = 1; i < n->req(); i++ ) { Node *m = n->in(i); if( get_ctrl(m) == blk1 ) { assert( m->in(0) == blk1, "" ); x->set_req( i, m->in(j) ); } } register_new_node( x, blk1->in(j) ); phi->init_req( j, x ); } // Announce phi to optimizer register_new_node(phi, blk1); // Remove cloned-up value from optimizer; use phi instead _igvn.hash_delete(n); _igvn.subsume_node( n, phi ); // (There used to be a self-recursive call to split_up() here, // but it is not needed. All necessary forward walking is done // by do_split_if() below.) return true; }
int main() { char line[1024],action[512],*action2[20],file[512],*file2[5],arg; int i,epflag=0,mypipe[2],pid,outcopy=dup(1),incopy=dup(0),rederect=0,len,*status; int pipeflag=0,errlognum; FILE *errors_log; if((errors_log=fopen("errors.log","a"))==NULL) err("fopen"); errlognum=fileno(errors_log); if(dup2(errlognum,2)==-1) err("dup2"); while(1) { pipeflag=0; epflag=0; fflush(stdin); fflush(stdout); if(dup2(outcopy,1)==-1) err("dup2"); if(dup2(incopy,0)==-1) err("dup2"); fflush(NULL); memset(line,'\0',sizeof(line)); printf("$:"); get_line(line); if(strncmp(line,"exit",4)==0) { printf("\ngood bye...\n"); exit(0); } while(line[i]!='\0') { i=0; memset(action,'\0',sizeof(action)); memset(file,'\0',sizeof(file)); while(line[i]!='|'&&line[i]!='>'&&line[i]!='<'&&line[i]!='\0') i++; arg=line[i]; strncpy(action,line,(const char)i); set_line(line,(i+1)); int s=split_up(action,action2); action2[s]=(char *)NULL; i=0; if(action2[s-1][0]=='&'){ epflag=1; action2[s-1][0]='\0'; action2[s-1]=(char *)NULL; } if(arg=='\0') { memset(line,'\0',sizeof(line)); if((pid=fork())<0) err("fork"); if(pid==0) { execvp(action2[0],(char* const*)action2); err("execvp"); } if(epflag==0){ if(pipeflag==0) wait(); else { wait(); wait(); pipeflag=0; } } epflag=0; break; } if(arg=='|') { pipeflag=1; pipe(mypipe); if((pid=fork())<0) err("fork"); if(pid==0) { close(mypipe[0]); if(dup2(mypipe[1],1)==-1) err("dup2"); close(mypipe[1]); execvp(action2[0],(char* const*)action2); err("execvp"); } else { close(mypipe[1]); if(dup2(mypipe[0],0)==-1) err("dup2"); close(mypipe[0]); continue; } } if(arg=='>'||arg=='<') { if(arg=='>') if(line[0]=='>') { rederect=3; set_line(line,1); } else rederect=2; else rederect=1; len=strlen(line); strncpy(file,line,len); set_line(line,len); i=0; int s2=split_up(file,file2); file2[s2]=(char*)NULL; if(file2[s2-1][0]=='&') { epflag=1; file2[s2-1]=NULL; if((pid=fork())==-1) err("fork"); if(pid>0){ continue; } setpgid(0,0); } if(rederect==1) { fromfile(action2,file2); } if(rederect==2) { char temp='w'; tofile_append(action2,file2,&temp); } if(rederect==3) { char temp='a'; tofile_append(action2,file2,&temp); } } if(epflag==1){ epflag=0; exit(0); } } } return 0; }