extsrc/mesa/src/glsl/opt_dead_code_local.cpp
/**
 * Adds an entry to the available copy list if it's a plain assignment
 * of a variable to a variable.
 */
Adds an entry to the available copy list if it's a plain assignment
of a variable to a variable.
Adds an entry to the available copy list if it ' s a plain assignment of a variable to a variable .
static bool
process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
{
   ir_variable *var = NULL;
   bool progress = false;
   kill_for_derefs_visitor v(assignments);
   ir->rhs->accept(&v);
   if (ir->condition) {
      ir->condition->accept(&v);
   }
   array_index_visit::run(ir->lhs, &v);
   var = ir->lhs->variable_referenced();
   assert(var);
   if (!ir->condition && (ir->whole_variable_written() != NULL)) {
      if (debug)
	 printf("looking for %s to remove\n", var->name);
      foreach_iter(exec_list_iterator, iter, *assignments) {
	 assignment_entry *entry = (assignment_entry *)iter.get();
	 if (entry->lhs == var) {
	    if (debug)
	       printf("removing %s\n", var->name);
	    entry->ir->remove();
	    entry->remove();
	    progress = true;
	 }
      }
   }
   if (ir_has_call(ir))
      return progress;
   assignment_entry *entry = new(ctx) assignment_entry(var, ir);
   assignments->push_tail(entry);
   if (debug) {
      printf("add %s\n", var->name);
      printf("current entries\n");
      foreach_iter(exec_list_iterator, iter, *assignments) {
	 assignment_entry *entry = (assignment_entry *)iter.get();
	 printf("    %s\n", entry->lhs->name);
      }
   }
   return progress;
}
static bool process_assignment ( void * ctx , ir_assignment * ir , exec_list * assignments ) { ir_variable * var = NULL ; bool progress = false ; kill_for_derefs_visitor v ( assignments ) ; ir -> rhs -> accept ( & v ) ; if ( ir -> condition ) { ir -> condition -> accept ( & v ) ; } array_index_visit :: run ( ir -> lhs , & v ) ; var = ir -> lhs -> variable_referenced ( ) ; assert ( var ) ; if ( ! ir -> condition && ( ir -> whole_variable_written ( ) != NULL ) ) { if ( debug ) printf ( " \n " , var -> name ) ; foreach_iter ( exec_list_iterator , iter , * assignments ) { assignment_entry * entry = ( assignment_entry * ) iter . get ( ) ; if ( entry -> lhs == var ) { if ( debug ) printf ( " \n " , var -> name ) ; entry -> ir -> remove ( ) ; entry -> remove ( ) ; progress = true ; } } } if ( ir_has_call ( ir ) ) return progress ; assignment_entry * entry = new ( ctx ) assignment_entry ( var , ir ) ; assignments -> push_tail ( entry ) ; if ( debug ) { printf ( " \n " , var -> name ) ; printf ( " \n " ) ; foreach_iter ( exec_list_iterator , iter , * assignments ) { assignment_entry * entry = ( assignment_entry * ) iter . get ( ) ; printf ( " \n " , entry -> lhs -> name ) ; } } return progress ; }
Adds an entry to the available copy list if it's a plain assignment
 of a variable to a variable.
Adds an entry to the available copy list if it ' s a plain assignment of a variable to a variable .
/* Kill assignment entries for things used to produce this assignment. */ /* Kill assignment enties used as array indices.
    */ /* Now, check if we did a whole-variable assignment. */ /* We did a whole-variable assignment.  So, any instruction in
       * the assignment list with the same LHS is dead.
       */ /* Add this instruction to the assignment list available to be removed.
    * But not if the assignment has other side effects.
    */