Esempio n. 1
0
void CirGate::netflow(int &cnt, bool flag[]) const
{   assert(getTypeStr() != "UNDEF");
    if (flag[_id]) return;
    for (int i = 0; i < _fanin.size(); ++i)
    {   CirGate* ptr = (CirGate*)(_fanin[i] & ~(size_t)(0x1));
        if (ptr->getTypeStr() != "UNDEF")
            ptr->netflow(cnt, flag);
    }

    flag[_id] = true; // Visited
    cout << "["<< cnt++ << "] ";
    if (getTypeStr() == "CONST")
        cout << "CONST0";
    else if (getTypeStr() == "AIG")
        cout << "AIG";
    else if (getTypeStr() == "PI")
        cout << "PI ";
    else if (getTypeStr() == "PO")
        cout << "PO ";
    if (_id) cout << " " << _id;
    for (int i = 0; i < _fanin.size(); ++i)
    {   cout << " ";
        CirGate* ptr = (CirGate*)(_fanin[i] & ~(size_t)0x1);
        if (ptr->getTypeStr() == "UNDEF") cout << "*";
        if (_fanin[i] & 1) cout << "!";
        cout << ptr->_id;
    }
    if (getTypeStr() == "PI" && ((CirPiGate*)this)->_name != "") cout << " (" << ((CirPiGate*)this)->_name << ")";
    if (getTypeStr() == "PO" && ((CirPoGate*)this)->_name != "") cout << " (" << ((CirPoGate*)this)->_name << ")";
    cout << endl;
}
Esempio n. 2
0
void
CirGate::reportFaninInternal(int level, int indent, bool invert, list<const CirGate*> *reported) const
{
   assert (level >= 0);
   cout << string(indent, ' ') << (invert?"!":"") << this->getTypeStr() << ' ' << this->getID();
   if(level == 0)
   {
      cout << '\n';
      return;
   }
   // #1Gp9L6MI (EE_DSnP) by ypf791
   if(this->gateType == CONST_GATE || this->gateType == PI_GATE || this->gateType == UNDEF_GATE)
   {
      level = 0;
   }
   else if(find(reported->begin(), reported->end(), this) != reported->end())
   {
      cout << " (*)";
      level = 0;
   }
   cout << '\n';
   if(level == 0)
   {
      return;
   }
   reported->push_back(this);
   for(vector<unsigned int>::const_iterator it = fanin.begin();it != fanin.end();it++)
   {
      CirGate* g = cirMgr->getGate((*it)/2);
      if(g)
      {
         g->reportFaninInternal(level-1, indent+2, (*it)%2, reported);
      }
   }
}
Esempio n. 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];

}
Esempio n. 4
0
void CirGate::netflow(bool flag[], vector<CirGate*>& list, bool checkDel) const
{   if (flag[_id]) return;
    if (checkDel && getType() == PI_GATE) return ;
    for (int i = 0; i < _fanin.size(); ++i)
    {   CirGate* ptr = (CirGate*)(_fanin[i] & ~(size_t)(0x1));
        if (checkDel || ptr->getType() != UNDEF_GATE)
            ptr->netflow(flag, list, checkDel);
    }

    flag[_id] = true; // Visited
    list.push_back((CirGate*)this);
}
Esempio n. 5
0
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;

		}

	}

}
Esempio n. 6
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);

	}

}
Esempio n. 7
0
void CirGate::fanoutFlow(int depth, int &level, bool neg, std::set<int> &s) const
{   // indent
    for (int i = 0; i < depth; ++i) cout << "  ";

    if (neg) cout << "!";

    cout << getTypeStr() << " " << _id;
    if (depth < level)
    {
        if (s.find(_id) != s.end()) cout << " (*)" << endl;
        else
        {   cout << endl;
            if (_fanout.size()) s.insert(_id);
            for (int i = 0; i < _fanout.size(); ++i)
            {   CirGate* ptr = (CirGate*)(_fanout[i] & ~(size_t)(0x1));
                ptr->fanoutFlow(depth+1, level, _fanout[i]&1, s);
            }
        }
    }
    else cout << endl;
}
Esempio n. 8
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();
}
Esempio n. 9
0
void
CirGate::reportFanoutInternal(int level, int indent, bool invert, list<const CirGate*> *reported) const
{
   assert (level >= 0);
   bool topLevel = false;
   if(!reported)
   {
      topLevel = true;
      reported = new list<const CirGate*>;
   }
   cout << string(indent, ' ') << (invert?"!":"") << this->getTypeStr() << ' ' << this->getID();
   if(level == 0)
   {
      cout << '\n';
      return;
   }
   if(find(reported->begin(), reported->end(), this) != reported->end())
   {
      cout << " (*)";
      level = 0;
   }
   cout << '\n';
   if(level == 0)
   {
      return;
   }
   reported->push_back(this);
   for(vector<unsigned int>::const_iterator it = fanout.begin();it != fanout.end();it++)
   {
      CirGate* g = cirMgr->getGate(*it);
      if(g)
      {
         g->reportFanoutInternal(level-1, indent+2, this->isInvert(g), reported);
      }
   }
   if(topLevel)
   {
      delete reported;
   }
}
Esempio n. 10
0
void
CirCut::genCutFunc()
{
   CirGate* gate;
   // set supports
   CirGate::incDfsFlag();
   for(unsigned i=0, n=size(); i<n; ++i){
      gate = cirMgr->getGateById(getLeaf(i));
      if(gate->getFecPhase())
         gate->setGateFunc(~bddMgr->getSupport(i+1));
      else
         gate->setGateFunc( bddMgr->getSupport(i+1));
   }
   // generate function
   gate = cirMgr->getGateById(getRoot());
   gate->genGateFunc();
   if(gate->getFecPhase())
      setFunc(~gate->getGateFunc());
   else
      setFunc( gate->getGateFunc());
}