int Basic_block::nb_cycles(){ /*** A COMPLETER ***/ /**** DEBUT: TP3 Question2 ****/ int nbCycles = size(); int i, j, k, gel; Instruction *current, *tmp; for(i=1; i<size(); i++){ current = get_instruction_at_index(i); /* calcul du nombre de gel */ gel = 0; for(j=0; j<current->get_nb_pred(); j++){ tmp = current->get_pred_dep(j)->inst; k = (delai(tmp->get_type(), current->get_type())) - (current->get_index() - tmp->get_index()); gel = (gel > k) ? gel : k; } nbCycles += gel; } /**** FIN: TP3 Question2 ****/ return nbCycles; }
// version personnelle bool Basic_block::is_delayed_slot(Instruction *i){ return get_instruction_at_index(i->get_index() - 1)->is_branch(); }
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; }