Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool doResourceAllocation(stack<Variable*>* simplificationStack, InterferenceGraph* ig)
- {
- vector<Variable*> promenjive;
- for (Variables::const_iterator it=ig->variables->begin(); it!=ig->variables->end(); ++it)
- promenjive.push_back(*it);
- sort(promenjive.begin(),promenjive.end()); // Sortiramo vektor: cba -> abc
- while (!simplificationStack->empty()) //uzimamo jedan po jedan cvor sa steka i "bojimo ga
- {
- bool foundReg = false;
- vector<Regs> used;
- Variable *a = simplificationStack->top(); // Pristupamo sledecem elementu
- simplificationStack->pop(); // Skidamo sa vrha element
- for (int i=0; i < ig->size; i++)
- if (ig->values[a->pos][i] == __INTERFERENCE__) // ako je element na preseku kolone(tekuci el.) i vrste(neki vec prethodno obojeni cvor)
- // jednak __INTERFERENCE__ to znaci da su ta 2 cvora u smetnji(u toj celiji matrice je __INTERFERENCE__)
- if ((promenjive[i]->assigment)!=-1)
- used.push_back((Regs)promenjive[i]->assigment);
- for (int i=0; i<=__REG_NUMBER__; i++)
- {
- Regs tmp = (Regs)i;
- if (find(used.begin(), used.end(), tmp) == used.end())
- {
- a->assigment = (Regs)i;
- foundReg = true;
- break;
- }
- }
- if (!foundReg)
- return false;
- }
- return true;
- }
- Instructions* removeMove(Instructions* instrs)
- {
- // ovo je dodatni zadatak
- Variable* v;
- for (Instructions::const_iterator it = instrs->begin(); it!=instrs->end(); ++it)
- {
- if ((*it)->type == T_MOVE)
- if (((*it)->src1->assigment == (*it)->dst->assigment) && ((*it)->src2 == NULL))
- {
- instrs->remove((*it));
- return instrs;
- }
- }
- return instrs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement