void Function::comput_succ_pred_BB(){ list<Basic_block*>::iterator it, it2; Basic_block *current; Instruction *instr; Basic_block *succ=NULL; // IMPORTANT ne pas enlever la ligne ci-dessous if (BB_pred_succ) return; int size= (int) _myBB.size(); it=_myBB.begin(); current=*it; cout<<"debut comput succ pred bb"<<endl; for (int i=0; i<size; i++){ current=*it; it2 = it; instr = (Instruction*)current->get_branch(); if(instr != NULL) { if(instr->get_opcode() != j && instr->get_opcode() != jal && instr->get_opcode() != jalr && instr->get_opcode() != jr){ Basic_block* suc1 = find_label_BB(instr->get_op_label()); it2++; Basic_block *suc2 = *it2; current->set_link_succ_pred(suc1); current->set_link_succ_pred(suc2); } else{ if(instr->get_opcode() == j){ Basic_block *suc = find_label_BB(instr->get_op_label()); current->set_link_succ_pred(suc); } else { if(instr->is_call()){ it2++; Basic_block *suc = *it2; current->set_link_succ_pred(suc); } } } it++; } else { it++; Basic_block *tmp = *it; if(tmp != NULL) current->set_link_succ_pred(tmp); } } cout<<"fin comput succ pred bb"<<endl; // ne pas enlever la ligne ci-dessous BB_pred_succ = true; return; }
// NB : penser utiliser la méthode set_link_succ_pred(Basic_block *) de la classe Basic_block void Function::comput_succ_pred_BB(){ list<Basic_block*>::iterator it, it2; Basic_block *current; Instruction *instr; int nbi; Operand* op; Basic_block *succ=NULL; int size= (int) _myBB.size(); // nombre de BB it=_myBB.begin(); //1er BB //remarque : le dernier block n'a pas de successeurs for(int i=0; i<size-1; i++) { current = *it; instr = current->get_instruction_at_index(current->get_nb_inst()-2); // si saut if(instr->is_branch()) { // saut conditionnel if(instr->is_cond_branch()) { // ajout suivant current->set_link_succ_pred(*(++it)); // label = op3 op = instr->get_op3(); } else { // label = op1 op = instr->get_op1(); it++; } // ajout du label succ = find_label_BB((dynamic_cast<OPLabel * > (op))); current->set_link_succ_pred(succ); } else { // pas de saut, ajout suivant current->set_link_succ_pred(*(++it)); } } //A REMPLIR }
void Function::comput_succ_pred_BB(){ list <Basic_block*> BBtmp; Basic_block * BB = new Basic_block(); /*Calcul des successeurs*/ for(int i=0; i<_myBB.size(); i++){ BB = get_BB(i); if(get_BB(i)->get_end()->get_line()->type_line()==line_Instru){ //si l'instru n'est pas un br alors 1 successeur le BB suivant if(get_BB(i)->get_branch()==NULL && ((i+1) < _myBB.size()) || dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_opcode()==jal || dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_opcode()==jalr ){ BB->set_successor1( get_BB(i+1)); } //si l'instru est un BR inconditiennel 1 successeur le BB pointé par le label else if(dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_opcode()==j){ if(find_label_BB(dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_op1())->get_head()){ //cout<<"coucou1"<<endl; BB->set_successor1(find_label_BB( dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_op1())); } }//cout<<"here too\n";} //si l'instru est un BR conditionnel 2 successeur le BB pointé et le BB suivant else if((dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_opcode()==beq || dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_opcode()==bne) && ((i+1)< _myBB.size())){ if(find_label_BB( dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_op3())->get_head()){ BB->set_successor1(find_label_BB( dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_op3())); } BB->set_successor2(get_BB(i+1)); //cout<<"here too too\n"; } else if(dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_opcode()!=jr && ((i+1)< _myBB.size())){ if(find_label_BB( dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_op2())->get_head()){ BB->set_successor1(find_label_BB( dynamic_cast< Instruction *> (get_BB(i)->get_branch()->get_line())->get_op2())); } BB->set_successor2(get_BB(i+1)); //cout<<"and finaly here too\n"; } //sinon pas de successeur else ; BBtmp.push_back(BB); BB = new Basic_block(); } } _myBB.clear(); list<Basic_block*>::iterator it; it=BBtmp.begin(); for (int i=0; i< BBtmp.size();i++ ){ _myBB.push_back(*it); it++; } /*Calcul des predecesseur*/ for(int i=0;i<_myBB.size(); i++){ for(int j=0; j<_myBB.size(); j++){ //cout<<"nbr de succ de BB"<<j<<" "<<get_BB(j)->get_nbr_succ()<<endl; if(get_BB(j)->get_nbr_succ()){ if(get_BB(i)->get_index() == get_BB(j)->get_successor1()->get_index()){ get_BB(i)->set_predecessor(get_BB(j)); } } if(get_BB(j)->get_nbr_succ()==2){ if(get_BB(i)->get_index() == get_BB(j)->get_successor2()->get_index()){ get_BB(i)->set_predecessor(get_BB(j)); } } } } }