abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sswConstr.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [sswConstr.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Inductive prover with constraints.]
8 
9  Synopsis [One round of SAT sweeping.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - September 1, 2008.]
16 
17  Revision [$Id: sswConstr.c,v 1.00 2008/09/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "sswInt.h"
22 #include "sat/cnf/cnf.h"
23 #include "misc/bar/bar.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Constructs initialized timeframes with constraints as POs.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
48 {
49  Aig_Man_t * pFrames;
50  Aig_Obj_t * pObj, * pObjLi, * pObjLo;
51  int i, f;
52 // assert( Saig_ManConstrNum(p) > 0 );
53  assert( Aig_ManRegNum(p) > 0 );
55  // start the fraig package
56  pFrames = Aig_ManStart( Aig_ManObjNumMax(p) * nFrames );
57  // create latches for the first frame
58  Saig_ManForEachLo( p, pObj, i )
59  Aig_ObjSetCopy( pObj, Aig_ManConst0(pFrames) );
60  // add timeframes
61  for ( f = 0; f < nFrames; f++ )
62  {
63  // map constants and PIs
65  Saig_ManForEachPi( p, pObj, i )
66  Aig_ObjSetCopy( pObj, Aig_ObjCreateCi(pFrames) );
67  // add internal nodes of this frame
68  Aig_ManForEachNode( p, pObj, i )
69  Aig_ObjSetCopy( pObj, Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ) );
70  // transfer to the primary output
71  Aig_ManForEachCo( p, pObj, i )
72  Aig_ObjSetCopy( pObj, Aig_ObjChild0Copy(pObj) );
73  // create constraint outputs
74  Saig_ManForEachPo( p, pObj, i )
75  {
76  if ( i < Saig_ManPoNum(p) - Saig_ManConstrNum(p) )
77  continue;
78  Aig_ObjCreateCo( pFrames, Aig_Not( Aig_ObjCopy(pObj) ) );
79  }
80  // transfer latch inputs to the latch outputs
81  Saig_ManForEachLiLo( p, pObjLi, pObjLo, i )
82  Aig_ObjSetCopy( pObjLo, Aig_ObjCopy(pObjLi) );
83  }
84  // remove dangling nodes
85  Aig_ManCleanup( pFrames );
86  return pFrames;
87 }
88 
89 /**Function*************************************************************
90 
91  Synopsis [Finds one satisfiable assignment of the timeframes.]
92 
93  Description []
94 
95  SideEffects []
96 
97  SeeAlso []
98 
99 ***********************************************************************/
100 int Ssw_ManSetConstrPhases( Aig_Man_t * p, int nFrames, Vec_Int_t ** pvInits )
101 {
102  Aig_Man_t * pFrames;
103  sat_solver * pSat;
104  Cnf_Dat_t * pCnf;
105  Aig_Obj_t * pObj;
106  int i, RetValue;
107  if ( pvInits )
108  *pvInits = NULL;
109 // assert( p->nConstrs > 0 );
110  // derive the timeframes
111  pFrames = Ssw_FramesWithConstraints( p, nFrames );
112  // create CNF
113  pCnf = Cnf_Derive( pFrames, 0 );
114  // create SAT solver
115  pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
116  if ( pSat == NULL )
117  {
118  Cnf_DataFree( pCnf );
119  Aig_ManStop( pFrames );
120  return 1;
121  }
122  // solve
123  RetValue = sat_solver_solve( pSat, NULL, NULL,
124  (ABC_INT64_T)1000000, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
125  if ( RetValue == l_True && pvInits )
126  {
127  *pvInits = Vec_IntAlloc( 1000 );
128  Aig_ManForEachCi( pFrames, pObj, i )
129  Vec_IntPush( *pvInits, sat_solver_var_value(pSat, pCnf->pVarNums[Aig_ObjId(pObj)]) );
130 
131 // Aig_ManForEachCi( pFrames, pObj, i )
132 // Abc_Print( 1, "%d", Vec_IntEntry(*pvInits, i) );
133 // Abc_Print( 1, "\n" );
134  }
135  sat_solver_delete( pSat );
136  Cnf_DataFree( pCnf );
137  Aig_ManStop( pFrames );
138  if ( RetValue == l_False )
139  return 1;
140  if ( RetValue == l_True )
141  return 0;
142  return -1;
143 }
144 
145 /**Function*************************************************************
146 
147  Synopsis [Performs fraiging for one node.]
148 
149  Description [Returns the fraiged node.]
150 
151  SideEffects []
152 
153  SeeAlso []
154 
155 ***********************************************************************/
156 int Ssw_ManSetConstrPhases_( Aig_Man_t * p, int nFrames, Vec_Int_t ** pvInits )
157 {
158  Vec_Int_t * vLits;
159  sat_solver * pSat;
160  Cnf_Dat_t * pCnf;
161  Aig_Obj_t * pObj;
162  int i, f, iVar, RetValue, nRegs;
163  if ( pvInits )
164  *pvInits = NULL;
165  assert( p->nConstrs > 0 );
166  // create CNF
167  nRegs = p->nRegs; p->nRegs = 0;
168  pCnf = Cnf_Derive( p, Aig_ManCoNum(p) );
169  p->nRegs = nRegs;
170  // create SAT solver
171  pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, nFrames, 0 );
172  assert( pSat->size == nFrames * pCnf->nVars );
173  // collect constraint literals
174  vLits = Vec_IntAlloc( 100 );
175  Saig_ManForEachLo( p, pObj, i )
176  {
177  assert( pCnf->pVarNums[Aig_ObjId(pObj)] >= 0 );
178  Vec_IntPush( vLits, toLitCond(pCnf->pVarNums[Aig_ObjId(pObj)], 1) );
179  }
180  for ( f = 0; f < nFrames; f++ )
181  {
182  Saig_ManForEachPo( p, pObj, i )
183  {
184  if ( i < Saig_ManPoNum(p) - Saig_ManConstrNum(p) )
185  continue;
186  assert( pCnf->pVarNums[Aig_ObjId(pObj)] >= 0 );
187  iVar = pCnf->pVarNums[Aig_ObjId(pObj)] + pCnf->nVars*f;
188  Vec_IntPush( vLits, toLitCond(iVar, 1) );
189  }
190  }
191  RetValue = sat_solver_solve( pSat, (int *)Vec_IntArray(vLits),
192  (int *)Vec_IntArray(vLits) + Vec_IntSize(vLits),
193  (ABC_INT64_T)1000000, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
194  if ( RetValue == l_True && pvInits )
195  {
196  *pvInits = Vec_IntAlloc( 1000 );
197  for ( f = 0; f < nFrames; f++ )
198  {
199  Saig_ManForEachPi( p, pObj, i )
200  {
201  iVar = pCnf->pVarNums[Aig_ObjId(pObj)] + pCnf->nVars*f;
202  Vec_IntPush( *pvInits, sat_solver_var_value(pSat, iVar) );
203  }
204  }
205  }
206  sat_solver_delete( pSat );
207  Vec_IntFree( vLits );
208  Cnf_DataFree( pCnf );
209  if ( RetValue == l_False )
210  return 1;
211  if ( RetValue == l_True )
212  return 0;
213  return -1;
214 }
215 
216 /**Function*************************************************************
217 
218  Synopsis [Performs fraiging for one node.]
219 
220  Description [Returns the fraiged node.]
221 
222  SideEffects []
223 
224  SeeAlso []
225 
226 ***********************************************************************/
228 {
229  Aig_Obj_t * pObj;
230  int i;
231  Aig_ManForEachObj( p, pObj, i )
232  Abc_Print( 1, "%d", pObj->fPhase );
233  Abc_Print( 1, "\n" );
234 }
235 
236 /**Function*************************************************************
237 
238  Synopsis [Performs fraiging for one node.]
239 
240  Description [Returns the fraiged node.]
241 
242  SideEffects []
243 
244  SeeAlso []
245 
246 ***********************************************************************/
248 {
249  Aig_Obj_t * pObj, * pObjLi;
250  int f, i, iLits, RetValue1, RetValue2;
251  int nFrames = Vec_IntSize(p->vInits) / Saig_ManPiNum(p->pAig);
252  assert( Vec_IntSize(p->vInits) % Saig_ManPiNum(p->pAig) == 0 );
253  // assign register outputs
254  Saig_ManForEachLi( p->pAig, pObj, i )
255  pObj->fMarkB = 0;
256  // simulate the timeframes
257  iLits = 0;
258  for ( f = 0; f < nFrames; f++ )
259  {
260  // set the PI simulation information
261  Aig_ManConst1(p->pAig)->fMarkB = 1;
262  Saig_ManForEachPi( p->pAig, pObj, i )
263  pObj->fMarkB = Vec_IntEntry( p->vInits, iLits++ );
264  Saig_ManForEachLiLo( p->pAig, pObjLi, pObj, i )
265  pObj->fMarkB = pObjLi->fMarkB;
266  // simulate internal nodes
267  Aig_ManForEachNode( p->pAig, pObj, i )
268  pObj->fMarkB = ( Aig_ObjFanin0(pObj)->fMarkB ^ Aig_ObjFaninC0(pObj) )
269  & ( Aig_ObjFanin1(pObj)->fMarkB ^ Aig_ObjFaninC1(pObj) );
270  // assign the COs
271  Aig_ManForEachCo( p->pAig, pObj, i )
272  pObj->fMarkB = ( Aig_ObjFanin0(pObj)->fMarkB ^ Aig_ObjFaninC0(pObj) );
273  // check the outputs
274  Saig_ManForEachPo( p->pAig, pObj, i )
275  {
276  if ( i < Saig_ManPoNum(p->pAig) - Saig_ManConstrNum(p->pAig) )
277  {
278  if ( pObj->fMarkB && Saig_ManConstrNum(p->pAig) )
279  Abc_Print( 1, "output %d failed in frame %d.\n", i, f );
280  }
281  else
282  {
283  if ( pObj->fMarkB && Saig_ManConstrNum(p->pAig) )
284  Abc_Print( 1, "constraint %d failed in frame %d.\n", i, f );
285  }
286  }
287  // transfer
288  if ( f == 0 )
289  { // copy markB into phase
290  Aig_ManForEachObj( p->pAig, pObj, i )
291  pObj->fPhase = pObj->fMarkB;
292  }
293  else
294  { // refine classes
295  RetValue1 = Ssw_ClassesRefineConst1( p->ppClasses, 0 );
296  RetValue2 = Ssw_ClassesRefine( p->ppClasses, 0 );
297  }
298  }
299  assert( iLits == Vec_IntSize(p->vInits) );
300 }
301 
302 
303 /**Function*************************************************************
304 
305  Synopsis [Performs fraiging for one node.]
306 
307  Description [Returns the fraiged node.]
308 
309  SideEffects []
310 
311  SeeAlso []
312 
313 ***********************************************************************/
314 int Ssw_ManSweepNodeConstr( Ssw_Man_t * p, Aig_Obj_t * pObj, int f, int fBmc )
315 {
316  Aig_Obj_t * pObjRepr, * pObjFraig, * pObjFraig2, * pObjReprFraig;
317  int RetValue;
318  // get representative of this class
319  pObjRepr = Aig_ObjRepr( p->pAig, pObj );
320  if ( pObjRepr == NULL )
321  return 0;
322  // get the fraiged node
323  pObjFraig = Ssw_ObjFrame( p, pObj, f );
324  // get the fraiged representative
325  pObjReprFraig = Ssw_ObjFrame( p, pObjRepr, f );
326  // check if constant 0 pattern distinquishes these nodes
327  assert( pObjFraig != NULL && pObjReprFraig != NULL );
328  assert( (pObj->fPhase == pObjRepr->fPhase) == (Aig_ObjPhaseReal(pObjFraig) == Aig_ObjPhaseReal(pObjReprFraig)) );
329  // if the fraiged nodes are the same, return
330  if ( Aig_Regular(pObjFraig) == Aig_Regular(pObjReprFraig) )
331  return 0;
332  // call equivalence checking
333  if ( Aig_Regular(pObjFraig) != Aig_ManConst1(p->pFrames) )
334  RetValue = Ssw_NodesAreEquiv( p, Aig_Regular(pObjReprFraig), Aig_Regular(pObjFraig) );
335  else
336  RetValue = Ssw_NodesAreEquiv( p, Aig_Regular(pObjFraig), Aig_Regular(pObjReprFraig) );
337  if ( RetValue == 1 ) // proved equivalent
338  {
339  pObjFraig2 = Aig_NotCond( pObjReprFraig, pObj->fPhase ^ pObjRepr->fPhase );
340  Ssw_ObjSetFrame( p, pObj, f, pObjFraig2 );
341  return 0;
342  }
343  if ( RetValue == -1 ) // timed out
344  {
345  Ssw_ClassesRemoveNode( p->ppClasses, pObj );
346  return 1;
347  }
348  // disproved equivalence
349  Ssw_SmlSavePatternAig( p, f );
350  Ssw_ManResimulateBit( p, pObj, pObjRepr );
351  assert( Aig_ObjRepr( p->pAig, pObj ) != pObjRepr );
352  if ( Aig_ObjRepr( p->pAig, pObj ) == pObjRepr )
353  {
354  Abc_Print( 1, "Ssw_ManSweepNodeConstr(): Failed to refine representative.\n" );
355  }
356  return 1;
357 }
358 
359 /**Function*************************************************************
360 
361  Synopsis [Performs fraiging for the internal nodes.]
362 
363  Description []
364 
365  SideEffects []
366 
367  SeeAlso []
368 
369 ***********************************************************************/
371 {
372  Aig_Obj_t * pObjNew, * pObjLi;
373  pObjNew = Ssw_ObjFrame( p, pObj, f );
374  if ( pObjNew )
375  return pObjNew;
376  assert( !Saig_ObjIsPi(p->pAig, pObj) );
377  if ( Saig_ObjIsLo(p->pAig, pObj) )
378  {
379  assert( f > 0 );
380  pObjLi = Saig_ObjLoToLi( p->pAig, pObj );
381  pObjNew = Ssw_ManSweepBmcConstr_rec( p, Aig_ObjFanin0(pObjLi), f-1 );
382  pObjNew = Aig_NotCond( pObjNew, Aig_ObjFaninC0(pObjLi) );
383  }
384  else
385  {
386  assert( Aig_ObjIsNode(pObj) );
389  pObjNew = Aig_And( p->pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
390  }
391  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
392  assert( pObjNew != NULL );
393  return pObjNew;
394 }
395 
396 /**Function*************************************************************
397 
398  Synopsis [Performs fraiging for the internal nodes.]
399 
400  Description []
401 
402  SideEffects []
403 
404  SeeAlso []
405 
406 ***********************************************************************/
408 {
409  Bar_Progress_t * pProgress = NULL;
410  Aig_Obj_t * pObj, * pObjNew, * pObjLi, * pObjLo;
411  int i, f, iLits;
412  abctime clk;
413 clk = Abc_Clock();
414 
415  // start initialized timeframes
416  p->pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->pPars->nFramesK );
417  Saig_ManForEachLo( p->pAig, pObj, i )
418  Ssw_ObjSetFrame( p, pObj, 0, Aig_ManConst0(p->pFrames) );
419 
420  // build the constraint outputs
421  iLits = 0;
422  for ( f = 0; f < p->pPars->nFramesK; f++ )
423  {
424  // map constants and PIs
425  Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), f, Aig_ManConst1(p->pFrames) );
426  Saig_ManForEachPi( p->pAig, pObj, i )
427  {
428  pObjNew = Aig_ObjCreateCi(p->pFrames);
429  pObjNew->fPhase = Vec_IntEntry( p->vInits, iLits++ );
430  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
431  }
432  // build the constraint cones
433  Saig_ManForEachPo( p->pAig, pObj, i )
434  {
435  if ( i < Saig_ManPoNum(p->pAig) - Saig_ManConstrNum(p->pAig) )
436  continue;
437  pObjNew = Ssw_ManSweepBmcConstr_rec( p, Aig_ObjFanin0(pObj), f );
438  pObjNew = Aig_NotCond( pObjNew, Aig_ObjFaninC0(pObj) );
439  if ( Aig_Regular(pObjNew) == Aig_ManConst1(p->pFrames) )
440  {
441  assert( Aig_IsComplement(pObjNew) );
442  continue;
443  }
444  Ssw_NodesAreConstrained( p, pObjNew, Aig_ManConst0(p->pFrames) );
445  }
446  }
447  assert( Vec_IntSize(p->vInits) == iLits + Saig_ManPiNum(p->pAig) );
448 
449  // sweep internal nodes
450  p->fRefined = 0;
451  if ( p->pPars->fVerbose )
452  pProgress = Bar_ProgressStart( stdout, Aig_ManObjNumMax(p->pAig) * p->pPars->nFramesK );
453  for ( f = 0; f < p->pPars->nFramesK; f++ )
454  {
455  // sweep internal nodes
456  Aig_ManForEachNode( p->pAig, pObj, i )
457  {
458  if ( p->pPars->fVerbose )
459  Bar_ProgressUpdate( pProgress, Aig_ManObjNumMax(p->pAig) * f + i, NULL );
460  pObjNew = Aig_And( p->pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
461  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
462  p->fRefined |= Ssw_ManSweepNodeConstr( p, pObj, f, 1 );
463  }
464  // quit if this is the last timeframe
465  if ( f == p->pPars->nFramesK - 1 )
466  break;
467  // transfer latch input to the latch outputs
468  Aig_ManForEachCo( p->pAig, pObj, i )
469  Ssw_ObjSetFrame( p, pObj, f, Ssw_ObjChild0Fra(p, pObj, f) );
470  // build logic cones for register outputs
471  Saig_ManForEachLiLo( p->pAig, pObjLi, pObjLo, i )
472  {
473  pObjNew = Ssw_ObjFrame( p, pObjLi, f );
474  Ssw_ObjSetFrame( p, pObjLo, f+1, pObjNew );
475  Ssw_CnfNodeAddToSolver( p->pMSat, Aig_Regular(pObjNew) );//
476  }
477  }
478  if ( p->pPars->fVerbose )
479  Bar_ProgressStop( pProgress );
480 
481  // cleanup
482 // Ssw_ClassesCheck( p->ppClasses );
483 p->timeBmc += Abc_Clock() - clk;
484  return p->fRefined;
485 }
486 
487 /**Function*************************************************************
488 
489  Synopsis [Performs fraiging for the internal nodes.]
490 
491  Description []
492 
493  SideEffects []
494 
495  SeeAlso []
496 
497 ***********************************************************************/
499 {
500  Aig_Obj_t * pObj, * pObjNew, * pObjLi, * pObjLo;
501  int i, f, iLits;
502  abctime clk;
503 clk = Abc_Clock();
504 
505  // start initialized timeframes
506  p->pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->pPars->nFramesK );
507  Saig_ManForEachLo( p->pAig, pObj, i )
508  Ssw_ObjSetFrame( p, pObj, 0, Aig_ManConst0(p->pFrames) );
509 
510  // build the constraint outputs
511  iLits = 0;
512  p->fRefined = 0;
513  for ( f = 0; f < p->pPars->nFramesK; f++ )
514  {
515  // map constants and PIs
516  Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), f, Aig_ManConst1(p->pFrames) );
517  Saig_ManForEachPi( p->pAig, pObj, i )
518  {
519  pObjNew = Aig_ObjCreateCi(p->pFrames);
520  pObjNew->fPhase = Vec_IntEntry( p->vInits, iLits++ );
521  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
522  }
523  // build the constraint cones
524  Saig_ManForEachPo( p->pAig, pObj, i )
525  {
526  if ( i < Saig_ManPoNum(p->pAig) - Saig_ManConstrNum(p->pAig) )
527  continue;
528  pObjNew = Ssw_ManSweepBmcConstr_rec( p, Aig_ObjFanin0(pObj), f );
529  pObjNew = Aig_NotCond( pObjNew, Aig_ObjFaninC0(pObj) );
530  if ( Aig_Regular(pObjNew) == Aig_ManConst1(p->pFrames) )
531  {
532  assert( Aig_IsComplement(pObjNew) );
533  continue;
534  }
535  Ssw_NodesAreConstrained( p, pObjNew, Aig_ManConst0(p->pFrames) );
536  }
537 
538  // sweep internal nodes
539  Aig_ManForEachNode( p->pAig, pObj, i )
540  {
541  pObjNew = Aig_And( p->pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
542  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
543  p->fRefined |= Ssw_ManSweepNodeConstr( p, pObj, f, 1 );
544  }
545  // quit if this is the last timeframe
546  if ( f == p->pPars->nFramesK - 1 )
547  break;
548  // transfer latch input to the latch outputs
549  Aig_ManForEachCo( p->pAig, pObj, i )
550  Ssw_ObjSetFrame( p, pObj, f, Ssw_ObjChild0Fra(p, pObj, f) );
551  // build logic cones for register outputs
552  Saig_ManForEachLiLo( p->pAig, pObjLi, pObjLo, i )
553  {
554  pObjNew = Ssw_ObjFrame( p, pObjLi, f );
555  Ssw_ObjSetFrame( p, pObjLo, f+1, pObjNew );
556  Ssw_CnfNodeAddToSolver( p->pMSat, Aig_Regular(pObjNew) );//
557  }
558  }
559  assert( Vec_IntSize(p->vInits) == iLits + Saig_ManPiNum(p->pAig) );
560 
561  // cleanup
562 // Ssw_ClassesCheck( p->ppClasses );
563 p->timeBmc += Abc_Clock() - clk;
564  return p->fRefined;
565 }
566 
567 
568 
569 
570 /**Function*************************************************************
571 
572  Synopsis [Performs fraiging for the internal nodes.]
573 
574  Description []
575 
576  SideEffects []
577 
578  SeeAlso []
579 
580 ***********************************************************************/
582 {
583  Aig_Obj_t * pObjNew, * pObjLi;
584  pObjNew = Ssw_ObjFrame( p, pObj, f );
585  if ( pObjNew )
586  return pObjNew;
587  assert( !Saig_ObjIsPi(p->pAig, pObj) );
588  if ( Saig_ObjIsLo(p->pAig, pObj) )
589  {
590  assert( f > 0 );
591  pObjLi = Saig_ObjLoToLi( p->pAig, pObj );
592  pObjNew = Ssw_FramesWithClasses_rec( p, Aig_ObjFanin0(pObjLi), f-1 );
593  pObjNew = Aig_NotCond( pObjNew, Aig_ObjFaninC0(pObjLi) );
594  }
595  else
596  {
597  assert( Aig_ObjIsNode(pObj) );
600  pObjNew = Aig_And( p->pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
601  }
602  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
603  assert( pObjNew != NULL );
604  return pObjNew;
605 }
606 
607 
608 /**Function*************************************************************
609 
610  Synopsis [Performs fraiging for the internal nodes.]
611 
612  Description []
613 
614  SideEffects []
615 
616  SeeAlso []
617 
618 ***********************************************************************/
620 {
621  Bar_Progress_t * pProgress = NULL;
622  Aig_Obj_t * pObj, * pObj2, * pObjNew;
623  int nConstrPairs, i, f, iLits;
624  abctime clk;
625 //Ssw_ManPrintPolarity( p->pAig );
626 
627  // perform speculative reduction
628 clk = Abc_Clock();
629  // create timeframes
630  p->pFrames = Ssw_FramesWithClasses( p );
631  // add constants
632  nConstrPairs = Aig_ManCoNum(p->pFrames)-Aig_ManRegNum(p->pAig);
633  assert( (nConstrPairs & 1) == 0 );
634  for ( i = 0; i < nConstrPairs; i += 2 )
635  {
636  pObj = Aig_ManCo( p->pFrames, i );
637  pObj2 = Aig_ManCo( p->pFrames, i+1 );
639  }
640  // build logic cones for register inputs
641  for ( i = 0; i < Aig_ManRegNum(p->pAig); i++ )
642  {
643  pObj = Aig_ManCo( p->pFrames, nConstrPairs + i );
644  Ssw_CnfNodeAddToSolver( p->pMSat, Aig_ObjFanin0(pObj) );//
645  }
646 
647  // map constants and PIs of the last frame
648  f = p->pPars->nFramesK;
649 // iLits = 0;
650  iLits = f * Saig_ManPiNum(p->pAig);
651  Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), f, Aig_ManConst1(p->pFrames) );
652  Saig_ManForEachPi( p->pAig, pObj, i )
653  {
654  pObjNew = Aig_ObjCreateCi(p->pFrames);
655  pObjNew->fPhase = (p->vInits != NULL) && Vec_IntEntry(p->vInits, iLits++);
656  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
657  }
658  assert( Vec_IntSize(p->vInits) == iLits );
659 p->timeReduce += Abc_Clock() - clk;
660 
661  // add constraints to all timeframes
662  for ( f = 0; f <= p->pPars->nFramesK; f++ )
663  {
664  Saig_ManForEachPo( p->pAig, pObj, i )
665  {
666  if ( i < Saig_ManPoNum(p->pAig) - Saig_ManConstrNum(p->pAig) )
667  continue;
669 // if ( Aig_Regular(Ssw_ObjChild0Fra(p,pObj,f)) == Aig_ManConst1(p->pFrames) )
670  if ( Ssw_ObjChild0Fra(p,pObj,f) == Aig_ManConst0(p->pFrames) )
671  continue;
672  assert( Ssw_ObjChild0Fra(p,pObj,f) != Aig_ManConst1(p->pFrames) );
673  if ( Ssw_ObjChild0Fra(p,pObj,f) == Aig_ManConst1(p->pFrames) )
674  {
675  Abc_Print( 1, "Polarity violation.\n" );
676  continue;
677  }
678  Ssw_NodesAreConstrained( p, Ssw_ObjChild0Fra(p,pObj,f), Aig_ManConst0(p->pFrames) );
679  }
680  }
681  f = p->pPars->nFramesK;
682  // clean the solver
683  sat_solver_simplify( p->pMSat->pSat );
684 
685 
686  // sweep internal nodes
687  p->fRefined = 0;
688  Ssw_ClassesClearRefined( p->ppClasses );
689  if ( p->pPars->fVerbose )
690  pProgress = Bar_ProgressStart( stdout, Aig_ManObjNumMax(p->pAig) );
691  Aig_ManForEachObj( p->pAig, pObj, i )
692  {
693  if ( p->pPars->fVerbose )
694  Bar_ProgressUpdate( pProgress, i, NULL );
695  if ( Saig_ObjIsLo(p->pAig, pObj) )
696  p->fRefined |= Ssw_ManSweepNodeConstr( p, pObj, f, 0 );
697  else if ( Aig_ObjIsNode(pObj) )
698  {
699  pObjNew = Aig_And( p->pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
700  Ssw_ObjSetFrame( p, pObj, f, pObjNew );
701  p->fRefined |= Ssw_ManSweepNodeConstr( p, pObj, f, 0 );
702  }
703  }
704  if ( p->pPars->fVerbose )
705  Bar_ProgressStop( pProgress );
706  // cleanup
707 // Ssw_ClassesCheck( p->ppClasses );
708  return p->fRefined;
709 }
710 
711 ////////////////////////////////////////////////////////////////////////
712 /// END OF FILE ///
713 ////////////////////////////////////////////////////////////////////////
714 
715 
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition: aigObj.c:66
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static Aig_Obj_t * Aig_ObjRepr(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:330
void Ssw_CnfNodeAddToSolver(Ssw_Sat_t *p, Aig_Obj_t *pObj)
Definition: sswCnf.c:351
static int Saig_ManPoNum(Aig_Man_t *p)
Definition: saig.h:74
static int Saig_ObjIsLo(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:84
static Aig_Obj_t * Ssw_ObjChild0Fra(Ssw_Man_t *p, Aig_Obj_t *pObj, int i)
Definition: sswInt.h:185
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:165
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Aig_Obj_t * Aig_ObjChild0(Aig_Obj_t *pObj)
Definition: aig.h:310
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition: saig.h:101
int Ssw_NodesAreConstrained(Ssw_Man_t *p, Aig_Obj_t *pOld, Aig_Obj_t *pNew)
Definition: sswSat.c:196
static Aig_Obj_t * Saig_ObjLoToLi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:86
unsigned int fMarkB
Definition: aig.h:80
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver.c:1700
int Ssw_ManSweepNodeConstr(Ssw_Man_t *p, Aig_Obj_t *pObj, int f, int fBmc)
Definition: sswConstr.c:314
int nVars
Definition: cnf.h:59
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition: aigMan.c:47
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
int * pVarNums
Definition: cnf.h:63
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigObj.c:45
static Aig_Obj_t * Aig_ManConst0(Aig_Man_t *p)
Definition: aig.h:263
#define l_True
Definition: SolverTypes.h:84
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
typedefABC_NAMESPACE_HEADER_START struct Ssw_Man_t_ Ssw_Man_t
INCLUDES ///.
Definition: sswInt.h:47
static Aig_Obj_t * Aig_Not(Aig_Obj_t *p)
Definition: aig.h:247
int Ssw_ClassesRefine(Ssw_Cla_t *p, int fRecursive)
Definition: sswClass.c:1034
static abctime Abc_Clock()
Definition: abc_global.h:279
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
Definition: cnf.h:56
static int sat_solver_var_value(sat_solver *s, int v)
Definition: satSolver.h:200
int Ssw_ManSweepConstr(Ssw_Man_t *p)
Definition: sswConstr.c:619
static Aig_Obj_t * Ssw_ObjChild1Fra(Ssw_Man_t *p, Aig_Obj_t *pObj, int i)
Definition: sswInt.h:186
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:104
void Ssw_ClassesRemoveNode(Ssw_Cla_t *p, Aig_Obj_t *pObj)
Definition: sswClass.c:448
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
void Ssw_ClassesClearRefined(Ssw_Cla_t *p)
Definition: sswClass.c:243
static int Saig_ManConstrNum(Aig_Man_t *p)
Definition: saig.h:78
int Ssw_ManSweepBmcConstr(Ssw_Man_t *p)
Definition: sswConstr.c:498
static void Bar_ProgressUpdate(Bar_Progress_t *p, int nItemsCur, char *pString)
Definition: bar.h:63
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
#define Saig_ManForEachLi(p, pObj, i)
Definition: saig.h:98
ABC_NAMESPACE_IMPL_START Aig_Man_t * Ssw_FramesWithConstraints(Aig_Man_t *p, int nFrames)
DECLARATIONS ///.
Definition: sswConstr.c:47
static lit toLitCond(int v, int c)
Definition: satVec.h:143
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static Aig_Obj_t * Aig_ObjChild1Copy(Aig_Obj_t *pObj)
Definition: aig.h:313
static int Aig_ObjPhaseReal(Aig_Obj_t *pObj)
Definition: aig.h:299
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define Saig_ManForEachLo(p, pObj, i)
Definition: saig.h:96
static Aig_Obj_t * Aig_ObjChild0Copy(Aig_Obj_t *pObj)
Definition: aig.h:312
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
DECLARATIONS ///.
Definition: bar.c:36
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static void Aig_ObjSetCopy(Aig_Obj_t *pObj, Aig_Obj_t *pCopy)
Definition: aig.h:319
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Aig_Obj_t * Aig_ManCo(Aig_Man_t *p, int i)
Definition: aig.h:267
static Aig_Obj_t * Aig_ObjCopy(Aig_Obj_t *pObj)
Definition: aig.h:318
static int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
unsigned int fPhase
Definition: aig.h:78
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:463
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static void Ssw_ObjSetFrame(Ssw_Man_t *p, Aig_Obj_t *pObj, int i, Aig_Obj_t *pNode)
Definition: sswInt.h:183
static int Saig_ManPiNum(Aig_Man_t *p)
MACRO DEFINITIONS ///.
Definition: saig.h:73
Aig_Man_t * Ssw_FramesWithClasses(Ssw_Man_t *p)
Definition: sswAig.c:144
#define l_False
Definition: SolverTypes.h:85
void Cnf_DataFree(Cnf_Dat_t *p)
Definition: cnfMan.c:180
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
#define Saig_ManForEachPo(p, pObj, i)
Definition: saig.h:93
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
#define assert(ex)
Definition: util_old.h:213
int Ssw_ManSweepBmcConstr_old(Ssw_Man_t *p)
Definition: sswConstr.c:407
Aig_Obj_t * Ssw_ManSweepBmcConstr_rec(Ssw_Man_t *p, Aig_Obj_t *pObj, int f)
Definition: sswConstr.c:370
int Ssw_NodesAreEquiv(Ssw_Man_t *p, Aig_Obj_t *pOld, Aig_Obj_t *pNew)
DECLARATIONS ///.
Definition: sswSat.c:45
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
void Ssw_ManPrintPolarity(Aig_Man_t *p)
Definition: sswConstr.c:227
void Ssw_ManRefineByConstrSim(Ssw_Man_t *p)
Definition: sswConstr.c:247
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
int Ssw_ManSetConstrPhases_(Aig_Man_t *p, int nFrames, Vec_Int_t **pvInits)
Definition: sswConstr.c:156
ABC_INT64_T abctime
Definition: abc_global.h:278
void Bar_ProgressStop(Bar_Progress_t *p)
Definition: bar.c:126
void Ssw_ManResimulateBit(Ssw_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pRepr)
DECLARATIONS ///.
Definition: sswSimSat.c:45
Aig_Obj_t * Ssw_FramesWithClasses_rec(Ssw_Man_t *p, Aig_Obj_t *pObj, int f)
Definition: sswConstr.c:581
static int Saig_ObjIsPi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:82
int Aig_ManCleanup(Aig_Man_t *p)
Definition: aigMan.c:265
int Ssw_ClassesRefineConst1(Ssw_Cla_t *p, int fRecursive)
Definition: sswClass.c:1119
Bar_Progress_t * Bar_ProgressStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Definition: bar.c:66
int Ssw_ManSetConstrPhases(Aig_Man_t *p, int nFrames, Vec_Int_t **pvInits)
Definition: sswConstr.c:100
#define Saig_ManForEachPi(p, pObj, i)
Definition: saig.h:91
void Ssw_SmlSavePatternAig(Ssw_Man_t *p, int f)
Definition: sswSweep.c:136
static Aig_Obj_t * Ssw_ObjFrame(Ssw_Man_t *p, Aig_Obj_t *pObj, int i)
Definition: sswInt.h:182