Exemple #1
0
void
CirMgr::strash()
{
  HashMap<myStrashKey, CirGate*> myHash;

  for (size_t i = 0, dfsSize = _dfsOrder.size(); i < dfsSize; ++i)
  {
    CirGate* gate = _dfsOrder.at(i);

    if (gate->getTypeStr() != "AIG") {
      continue;
    }

    CirGate* existedGate = new Aig();
    myStrashKey key(gate);

    if (myHash.check(key, existedGate)) {
      cout << "Strashing: " << existedGate->getId() << " merging " << gate->getId() << "..." << endl;

      AigGateV newFanin(existedGate, 0);
      gate->connectFaninToEachFanout(newFanin);

      // clean up
      deleteAndCleanUpGate(gate);

      /* _dfsOrder.erase(_dfsOrder.begin() + i); */
      /* --i, --dfsSize; */
    } else {
      myHash.insert(key, gate);
    }
  }

  _dfsOrder.clear();
  topoSort();
}
Exemple #2
0
void CirMgr::printFloatGates() const{

	vector<int> v1;
	vector<int> v2;
	
	for(vector<CirGateV*>::const_iterator it = output.begin(); it!=output.end(); it++){
	
		CirGate *gate = (*it)->gate();
		bool missingFanin = gate->_faninList.size()<1;
		bool faninUndef = gate->_faninList[0]->isUndef();
		if(missingFanin || faninUndef) v1.push_back(gate->getId());
	
	}		
	for(vector<CirGateV*>::const_iterator it = aig.begin(); it!=aig.end(); it++){
	
		CirGate *gate = (*it)->gate();
		bool missingFanin = gate->_faninList.size()<2;
		bool faninUndef = gate->_faninList[0]->isUndef() || gate->_faninList[1]->isUndef();
		if(missingFanin || faninUndef) v1.push_back(gate->getId());
	
	}	

	if(v1.size()!=0){

		cout << "Gates with floating fanin(s):";
		for(vector<int>::iterator it=v1.begin(); it!=v1.end(); it++) cout << " " << (*it);

	}

	for(vector<CirGateV*>::const_iterator it = input.begin(); it!=input.end(); it++){
		
		CirGate *gate = (*it)->gate();
		bool missingFanout = gate->_fanoutList.size()==0;
		if(missingFanout) v2.push_back(gate->getId());

	}
	for(vector<CirGateV*>::const_iterator it = aig.begin(); it!=aig.end(); it++){
	
		CirGate *gate = (*it)->gate();
		bool missingFanout = gate->_fanoutList.size()==0;
		if(missingFanout) v2.push_back(gate->getId());
	
	}	

	if(v2.size()!=0){

		cout << "\nGates defined but not used :";
		for(vector<int>::iterator it=v2.begin(); it!=v2.end(); it++) cout << " " << (*it);

	}

}
Exemple #3
0
// Remove unused gates
// DFS list should NOT be changed
// UNDEF, float and unused list may be changed
void CirMgr::sweep()
{   bool flag[_gateList.size()];
    memset(flag, 0, sizeof(flag));
    vector<CirGate*> delList;

    flag[0] = true; // CONST should not be removed.
    for (int i = 0; i < _dfsList.size(); ++i) flag[_dfsList[i]->getId()] = true; // Those in _dfsList just let it be visited
    for (int i = 0; i < _piList.size(); ++i) flag[_piList[i]->getId()] = true;

    for (int i = 0, n = _gateList.size(); i < n; i++)
        if (flag[i])
        {     for (unsigned j = 0; j < _gateList[i]->_fanout.size(); j++)
            {   CirGate* ptr = (CirGate*)(_gateList[i]->_fanout[j] & ~(size_t)(0x1));
                if (!flag[ptr->getId()]) { _gateList[i]->_fanout.erase(_gateList[i]->_fanout.begin()+j); j--; }
            }
        }
        else if (_gateList[i] && _gateList[i]->getType() == AIG_GATE)
        {   --_params[4];     //  number
            cout << "Sweeeping: ";
            delList.push_back(_gateList[i]);
            cout << _gateList[i]->getTypeStr() << "(" << i << ")";
            _gateList[i] = 0;
            cout << " removed..." << endl;
        }
        else if (_gateList[i])
        {   delList.push_back(_gateList[i]);
            cout << "Sweeeping: ";
            cout << _gateList[i]->getTypeStr() << "(" << i << ")";
            cout << " removed..." << endl;
            _gateList[i] = 0;
        }
    for (int i = 0; i < delList.size(); ++i)  delete delList[i];

}
void CirGate::reportAndRecord(int level, int recurseN, int type){ // 1 fanin, 2 fanout

	if(level >= 0){
	
		printSelfForReport();
		if(level >= 1){ 

			vector<CirGateV*> *v;
			if(type==1) v=&_faninList;
			else if(type==2) v=&_fanoutList;
			for(vector<CirGateV*>::iterator it=v->begin(); it!=v->end(); it++){ // print fanin
			
				cout << endl;
				cout << setw(2*(recurseN+1)) << " ";
				CirGate *gate = (*it)->gate();
				if((*it)->isUndef()){
				
					cout << "UNDEF " << gate->getId();
					cout.flush();

				}
				else if(gate->getFlag()==true){
				
					gate->printSelfForReport();
					cout << " (*)";
					cout.flush();

				}
				else{

					if((*it)->isInv()) cout << "!";
					gate->reportAndRecord(level-1, recurseN+1, type);
					cout.flush();
				
				}

			}	

			_flag=true;

		}

	}

}