Exemple #1
0
void Basic_block::comput_pred_succ_dep(){
   
  link_instructions();
   
  Instruction *i_current=this->get_last_instruction();
  Instruction *itmp;
  
  /*il faut faire ce qu'il faut pour remplir les listes */

  list <dep*> _succ_dep; // instructions qui dépendent de this avec type de dep
  list <dep*> _pred_dep; // instructions dont depend this avec type de dep de la classe Instruction pour chacune des instructions du BB
   


  /*   NB : la fonction add_dep_link ci-dessus peut vous être utile...  */ 
  for(;i_current != this->get_first_instruction();i_current=i_current->get_prev()) {
    int waw_war= 0; // waw = 1, war = -1
    bool raw1 = false, raw2 = false;
    // waw | war | raw
    for(itmp=i_current->get_prev() ;; itmp=itmp->get_prev()) {
      if(waw_war != 1) {
	// WAW
	if(itmp->is_dep_WAW(i_current)) {
	  if(waw_war == 0) {	     
	    add_dep_link(itmp, i_current, WAW);
	  }
	  waw_war = 1;
	} else if(itmp->is_dep_WAR(i_current)) {
	  // WAR
	  add_dep_link(itmp, i_current, WAR);
	}
      }
      // RAW1
      if(!raw1 && itmp->is_dep_RAW1(i_current)) {
	add_dep_link(itmp, i_current, RAW);
	raw1 = true;
      }
      // RAW2
      if(!raw2 && itmp->is_dep_RAW2(i_current)) {
	add_dep_link(itmp, i_current, RAW);
	raw2 = true;
      }

      // break
      if(waw_war == 1 && raw1 && raw2 || itmp ==this->get_first_instruction())
	break;
    }

    if(i_current->is_mem()) {
      for(itmp=i_current->get_prev(); itmp !=this->get_first_instruction(); itmp=itmp->get_prev()) {
	if(itmp->is_dep_MEM(i_current)) {
	  add_dep_link(itmp, i_current, MEMDEP);
	}
      }
    }
  }


  //il faut  rattacher toute les instructions sans successeurs(dependances) 
  //au saut de fin de BB par une dépendance de controle si le BB se termine par un saut
   
  // itmp = saut
  if((itmp = this->get_last_instruction()->get_prev())->is_branch()) {
    for(i_current = itmp->get_prev() ; i_current != this->get_first_instruction() ; i_current=i_current->get_prev()) {
      if(i_current->get_nb_succ() == 0) {
	add_dep_link(i_current, itmp, CONTROL);
      }
    }
  }
}
Exemple #2
0
void Basic_block::comput_pred_succ_dep(){
   
  // IMPORTANT : laisser les 2 instructions ci-dessous 
   link_instructions();
   if (dep_done) return;

   /**** DEBUT: TP3 Question1 ****/

   Instruction *current, *tmp;
   int i = size() - 1;
   int j;
   
   /* si la dernière instruction est un delayed slot, je ne la traite pas */
   current = get_instruction_at_index(i);
   if(is_delayed_slot(current))
     i--;

   /* main loop */
   for(; i>=0; i--){
     current = get_instruction_at_index(i);
     
     /* recherche du RAW1 */
     for(j=i-1; j>=0; j--){
       tmp = get_instruction_at_index(j);
       if(tmp->is_dep_RAW1(current)){
	 add_dep_link(tmp, current, RAW);
	 break;
       }
     }

     /* recherche du RAW2 */
     for(j=i-1; j>=0; j--){
       tmp = get_instruction_at_index(j);
       if(tmp->is_dep_RAW2(current)){
	 add_dep_link(tmp, current, RAW);
	 break;
       }
     }

     /* recherche du WAR1 */
     for(j=i-1; j>=0; j--){
       tmp = get_instruction_at_index(j);
       if(tmp->is_dep_WAR1(current)){
	 add_dep_link(tmp, current, WAR);
	 break;
       }
     }

     /* recherche du WAR2 */
     for(j=i-1; j>=0; j--){
       tmp = get_instruction_at_index(j);
       if(tmp->is_dep_WAR2(current)){
	 add_dep_link(tmp, current, WAR);
	 break;
       }
     }

     /* recherche du WAW */
     for(j=i-1; j>=0; j--){
       tmp = get_instruction_at_index(j);
       if(tmp->is_dep_WAW(current)){
	 add_dep_link(tmp, current, WAW);
	 break;
       }
     }

     /* recherche du MEM */
     for(j=i-1; j>=0; j--){
       tmp = get_instruction_at_index(j);
       if(tmp->is_dep_MEM(current)){
	 add_dep_link(tmp, current, MEMDEP);
	 break;
       }
     }
     
   }
   
   /**** FIN: TP3 Question2 ****/
     
   // NE PAS ENLEVER : cette fonction ne doit être appelée qu'une seule fois
   dep_done = true;
   return;
}