abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
absRef.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [absRef.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Abstraction package.]
8 
9  Synopsis [Refinement manager.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: absRef.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "sat/bsat/satSolver2.h"
22 #include "abs.h"
23 #include "absRef.h"
24 
26 
27 /*
28  Description of the refinement manager
29 
30  This refinement manager should be
31  * started by calling Rnm_ManStart()
32  this procedure takes one argument, the user's seq miter as a GIA manager
33  - the manager should have only one property output
34  - this manager should not change while the refinement manager is alive
35  - it cannot be used by external applications for any purpose
36  - when the refinement manager stop, GIA manager is the same as at the beginning
37  - in the meantime, it will have some data-structures attached to its nodes...
38  * stopped by calling Rnm_ManStop()
39  * between starting and stopping, refinements are obtained by calling Rnm_ManRefine()
40 
41  Procedure Rnm_ManRefine() takes the following arguments:
42  * the refinement manager previously started by Rnm_ManStart()
43  * counter-example (CEX) obtained by abstracting some logic of GIA
44  * mapping (vMap) of inputs of the CEX into the object IDs of the GIA manager
45  - only PI, flop outputs, and internal AND nodes can be used in vMap
46  - the ordering of objects in vMap is not important
47  - however, the index of a non-PI object in vMap is used as its priority
48  (the smaller the index, the more likely this non-PI object apears in a refinement)
49  - only the logic between PO and the objects listed in vMap is traversed by the manager
50  (as a result, GIA can be arbitrarily large, but only objects used in the abstraction
51  and the pseudo-PI, that is, objects in the cut, will be visited by the manager)
52  * flag fPropFanout defines whether value propagation is done through the fanout
53  - it this flag is enabled, theoretically refinement should be better (the result smaller)
54  * flag fVerbose may print some statistics
55 
56  The refinement manager returns a minimal-size array of integer IDs of GIA objects
57  which should be added to the abstraction to possibly prevent the given counter-example
58  - only flop output and internal AND nodes from vMap may appear in the resulting array
59  - if the resulting array is empty, the CEX is a true CEX
60  (in other words, non-PI objects are not needed to set the PO value to 1)
61 
62  Verification of the selected refinement is performed by
63  - initializing all PI objects in vMap to value 0 or 1 they have in the CEX
64  - initializing all remaining objects in vMap to value X
65  - initializing objects used in the refiment to value 0 or 1 they have in the CEX
66  - simulating through as many timeframes as required by the CEX
67  - if the PO value in the last frame is 1, the refinement is correct
68  (however, the minimality of the refinement is not currently checked)
69 
70 */
71 
72 ////////////////////////////////////////////////////////////////////////
73 /// DECLARATIONS ///
74 ////////////////////////////////////////////////////////////////////////
75 
76 /*
77 static inline int Rnm_ObjSatVar( Rnm_Man_t * p, Gia_Obj_t * pObj ) { return Vec_IntEntry( p->vSatVars, Gia_ObjId(p->pGia, pObj) ); }
78 static inline void Rnm_ObjSetSatVar( Rnm_Man_t * p, Gia_Obj_t * pObj, int c) { Vec_IntWriteEntry( p->vSatVars, Gia_ObjId(p->pGia, pObj), c ); }
79 static inline int Rnm_ObjFindOrAddSatVar( Rnm_Man_t * p, Gia_Obj_t * pObj) { if ( Rnm_ObjSatVar(p, pObj) == 0 ) { Rnm_ObjSetSatVar(p, pObj, Vec_IntSize(p->vSat2Ids)); Vec_IntPush(p->vSat2Ids, Gia_ObjId(p->pGia, pObj)); }; return 2*Rnm_ObjSatVar(p, pObj); }
80 */
81 extern void Ga2_ManCnfAddStatic( sat_solver2 * pSat, Vec_Int_t * vCnf0, Vec_Int_t * vCnf1, int * pLits, int iLitOut, int ProofId );
82 extern Vec_Int_t * Ga2_ManCnfCompute( unsigned uTruth, int nVars, Vec_Int_t * vCover );
83 
84 ////////////////////////////////////////////////////////////////////////
85 /// FUNCTION DEFINITIONS ///
86 ////////////////////////////////////////////////////////////////////////
87 
88 #if 0
89 
90 /**Function*************************************************************
91 
92  Synopsis [Performs UNSAT-core-based refinement.]
93 
94  Description []
95 
96  SideEffects []
97 
98  SeeAlso []
99 
100 ***********************************************************************/
101 void Rnm_ManRefineCollect_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vVisited, Vec_Int_t * vFlops )
102 {
103  Vec_Int_t * vLeaves;
104  Gia_Obj_t * pFanin;
105  int k;
106  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
107  return;
108  Gia_ObjSetTravIdCurrent(p, pObj);
109  if ( Gia_ObjIsCi(pObj) )
110  {
111  if ( Gia_ObjIsRo(p, pObj) )
112  Vec_IntPush( vFlops, Gia_ObjId(p, pObj) );
113  return;
114  }
115  assert( Gia_ObjIsAnd(pObj) );
116  vLeaves = Ga2_ObjLeaves( p, pObj );
117  Gia_ManForEachObjVec( vLeaves, p, pFanin, k )
118  Rnm_ManRefineCollect_rec( p, pFanin, vVisited, vFlops );
119  Vec_IntPush( vVisited, Gia_ObjId(p, pObj) );
120 }
121 
122 Vec_Int_t * Rnm_ManRefineUnsatCore( Rnm_Man_t * p, Vec_Int_t * vPPIs )
123 {
124  Vec_Int_t * vCnf0, * vCnf1;
125  Vec_Int_t * vLeaves, * vLits, * vPpi2Map;
126  Vec_Int_t * vVisited, * vFlops, * vCore, * vCoreFinal;
127  Gia_Obj_t * pObj, * pFanin;
128  int i, k, f, Status, Entry, pLits[5], iBit = p->pCex->nRegs;
129  // map PPIs into their positions in the map // CAN BE MADE FASTER
130  vPpi2Map = Vec_IntAlloc( Vec_IntSize(vPPIs) );
131  Vec_IntForEachEntry( vPPIs, Entry, i )
132  {
133  Entry = Vec_IntFind( p->vMap, Entry );
134  assert( Entry >= 0 );
135  Vec_IntPush( vPpi2Map, Entry );
136  }
137  // collect nodes between selected PPIs and CIs
138  vFlops = Vec_IntAlloc( 100 );
139  vVisited = Vec_IntAlloc( 100 );
140  Gia_ManIncrementTravId( p->pGia );
141  Gia_ManForEachObjVec( vPPIs, p->pGia, pObj, i )
142 // if ( !Gia_ObjIsRo(p->pGia, pObj) ) // SKIP PPIs that are flops
143  Rnm_ManRefineCollect_rec( p->pGia, pObj, vVisited, vFlops );
144  // create SAT variables and SAT solver
145  Vec_IntFill( p->vSat2Ids, 1, -1 );
146  assert( p->pSat == NULL );
147  p->pSat = sat_solver2_new();
148  Vec_IntFill( p->vSatVars, Gia_ManObjNum(p->pGia), 0 ); // NO NEED TO CLEAN EACH TIME
149  // assign PPI variables
150  Gia_ManForEachObjVec( vFlops, p->pGia, pObj, i )
151  Rnm_ObjFindOrAddSatVar( p, pObj );
152  // assign other variables
153  Gia_ManForEachObjVec( vVisited, p->pGia, pObj, i )
154  {
155  vLeaves = Ga2_ObjLeaves( p->pGia, pObj );
156  Gia_ManForEachObjVec( vLeaves, p->pGia, pFanin, k )
157  pLits[k] = Rnm_ObjFindOrAddSatVar( p, pFanin );
158  vCnf0 = Ga2_ManCnfCompute( Ga2_ObjTruth(p->pGia, pObj), Vec_IntSize(vLeaves), p->vIsopMem );
159  vCnf1 = Ga2_ManCnfCompute( ~Ga2_ObjTruth(p->pGia, pObj), Vec_IntSize(vLeaves), p->vIsopMem );
160  Ga2_ManCnfAddStatic( p->pSat, vCnf0, vCnf1, pLits, Rnm_ObjFindOrAddSatVar(p, pObj), Rnm_ObjFindOrAddSatVar(p, pObj)/2 );
161  Vec_IntFree( vCnf0 );
162  Vec_IntFree( vCnf1 );
163  }
164 
165 // printf( "\n" );
166 
167  p->pSat->pPrf2 = Prf_ManAlloc();
168  Prf_ManRestart( p->pSat->pPrf2, NULL, sat_solver2_nlearnts(p->pSat), Vec_IntSize(p->vSat2Ids) );
169 
170  // iterate UNSAT core computation for each timeframe
171  vLits = Vec_IntAlloc( 100 );
172  vCoreFinal = Vec_IntAlloc( 100 );
173  for ( f = 0; f <= p->pCex->iFrame; f++, iBit += p->pCex->nPis )
174  {
175  // collect values of PPIs in this timeframe
176  Vec_IntClear( vLits );
177  Gia_ManForEachObjVec( vPPIs, p->pGia, pObj, i )
178  {
179  Entry = Abc_InfoHasBit( p->pCex->pData, iBit + Vec_IntEntry(vPpi2Map, i) );
180  Vec_IntPush( vLits, Abc_LitNotCond( Rnm_ObjFindOrAddSatVar(p, pObj), !Entry ) );
181  }
182 
183  // handle the first timeframe in a special vay
184  if ( f == 0 )
185  Gia_ManForEachObjVec( vFlops, p->pGia, pObj, i )
186  if ( Vec_IntFind( vPPIs, Gia_ObjId(p->pGia, pObj) ) == -1 )
187  Vec_IntPush( vLits, Abc_LitNotCond( Rnm_ObjFindOrAddSatVar(p, pObj), 1 ) );
188 /*
189  // uniqify literals and detect special conflicts
190  Vec_IntUniqify( vLits );
191  Vec_IntForEachEntryStart( vLits, Entry, i, 1 )
192  if ( Vec_IntEntry(vLits, i-1) == Abc_LitNot(Entry) )
193  break;
194  if ( i < Vec_IntSize(vLits) )
195  printf( "triv_unsat " );
196  else
197 */
198 
199  Status = sat_solver2_solve( p->pSat, Vec_IntArray(vLits), Vec_IntLimit(vLits), (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
200  if ( Status != l_False )
201  continue;
202  vCore = (Vec_Int_t *)Sat_ProofCore( p->pSat );
203 // vCore = Vec_IntAlloc( 0 );
204  // add to the UNSAT core
205  Vec_IntAppend( vCoreFinal, vCore );
206 
207 // printf( "Frame %d : ", f );
208 // Vec_IntPrint( vCore );
209  Vec_IntFree( vCore );
210  }
211  assert( iBit == p->pCex->nBits );
212  Vec_IntUniqify( vCoreFinal );
213  Vec_IntFree( vLits );
214  Prf_ManStopP( &p->pSat->pPrf2 );
215  sat_solver2_delete( p->pSat );
216  p->pSat = NULL;
217 
218  // translate from entry into ID
219  Vec_IntForEachEntry( vCoreFinal, Entry, i )
220  {
221  assert( Vec_IntEntry(p->vSat2Ids, Entry) >= 0 );
222  assert( Vec_IntEntry(p->vSat2Ids, Entry) < Gia_ManObjNum(p->pGia) );
223  Vec_IntWriteEntry( vCoreFinal, i, Vec_IntEntry(p->vSat2Ids, Entry) );
224  }
225  // if there are flop outputs, add them
226  Gia_ManForEachObjVec( vPPIs, p->pGia, pObj, i )
227  if ( Gia_ObjIsRo(p->pGia, pObj) )
228  Vec_IntPush( vCoreFinal, Gia_ObjId(p->pGia, pObj) );
229  Vec_IntUniqify( vCoreFinal );
230 
231 // printf( "\n" );
232 // Vec_IntPrint( vPPIs );
233 // Vec_IntPrint( vCoreFinal );
234 
235 // printf( "\n" );
236 
237  // clean SAT variable numbers
238  Gia_ManForEachObjVec( vVisited, p->pGia, pObj, i )
239  {
240  Rnm_ObjSetSatVar( p, pObj, 0 );
241  vLeaves = Ga2_ObjLeaves( p->pGia, pObj );
242  Gia_ManForEachObjVec( vLeaves, p->pGia, pFanin, k )
243  Rnm_ObjSetSatVar( p, pFanin, 0 );
244  }
245  Vec_IntFree( vFlops );
246  Vec_IntFree( vVisited );
247  Vec_IntFree( vPpi2Map );
248  return vCoreFinal;
249 }
250 
251 #endif
252 
253 /**Function*************************************************************
254 
255  Synopsis [Creates a new manager.]
256 
257  Description []
258 
259  SideEffects []
260 
261  SeeAlso []
262 
263 ***********************************************************************/
265 {
266  Rnm_Man_t * p;
267  assert( Gia_ManPoNum(pGia) == 1 );
268  p = ABC_CALLOC( Rnm_Man_t, 1 );
269  p->pGia = pGia;
270  p->vObjs = Vec_IntAlloc( 100 );
271  p->vCounts = Vec_StrStart( Gia_ManObjNum(pGia) );
272  p->vFanins = Vec_IntAlloc( 1000 );
273 // p->vSatVars = Vec_IntAlloc( 0 );
274 // p->vSat2Ids = Vec_IntAlloc( 1000 );
275 // p->vIsopMem = Vec_IntAlloc( 0 );
276  p->nObjsAlloc = 10000;
277  p->pObjs = ABC_ALLOC( Rnm_Obj_t, p->nObjsAlloc );
278  if ( p->pGia->vFanout == NULL )
280  Gia_ManCleanValue(pGia);
281  Gia_ManCleanMark0(pGia);
282  Gia_ManCleanMark1(pGia);
283  return p;
284 }
285 void Rnm_ManStop( Rnm_Man_t * p, int fProfile )
286 {
287  if ( !p ) return;
288  // print runtime statistics
289  if ( fProfile && p->nCalls )
290  {
291  double MemGia = sizeof(Gia_Man_t) + sizeof(Gia_Obj_t) * p->pGia->nObjsAlloc + sizeof(int) * p->pGia->nTravIdsAlloc;
292  double MemOther = sizeof(Rnm_Man_t) + sizeof(Rnm_Obj_t) * p->nObjsAlloc + sizeof(int) * Vec_IntCap(p->vObjs);
293  abctime timeOther = p->timeTotal - p->timeFwd - p->timeBwd - p->timeVer;
294  printf( "Abstraction refinement runtime statistics:\n" );
295  ABC_PRTP( "Sensetization", p->timeFwd, p->timeTotal );
296  ABC_PRTP( "Justification", p->timeBwd, p->timeTotal );
297  ABC_PRTP( "Verification ", p->timeVer, p->timeTotal );
298  ABC_PRTP( "Other ", timeOther, p->timeTotal );
299  ABC_PRTP( "TOTAL ", p->timeTotal, p->timeTotal );
300  printf( "Total calls = %d. Average refine = %.1f. GIA mem = %.3f MB. Other mem = %.3f MB.\n",
301  p->nCalls, 1.0*p->nRefines/p->nCalls, MemGia/(1<<20), MemOther/(1<<20) );
302  }
303 
307 // Gia_ManSetPhase(p->pGia);
308 // Vec_IntFree( p->vIsopMem );
309 // Vec_IntFree( p->vSatVars );
310 // Vec_IntFree( p->vSat2Ids );
311  Vec_StrFree( p->vCounts );
312  Vec_IntFree( p->vFanins );
313  Vec_IntFree( p->vObjs );
314  ABC_FREE( p->pObjs );
315  ABC_FREE( p );
316 }
318 {
319  return (double)(sizeof(Rnm_Man_t) + sizeof(Rnm_Obj_t) * p->nObjsAlloc + sizeof(int) * Vec_IntCap(p->vObjs));
320 }
321 
322 
323 /**Function*************************************************************
324 
325  Synopsis [Collect internal objects to be used in value propagation.]
326 
327  Description [Resulting array vObjs contains RO, AND, PO/RI in a topo order.]
328 
329  SideEffects []
330 
331  SeeAlso []
332 
333 ***********************************************************************/
334 void Rnm_ManCollect_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vObjs, int nAddOn )
335 {
336  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
337  return;
338  Gia_ObjSetTravIdCurrent(p, pObj);
339  if ( Gia_ObjIsCo(pObj) )
340  Rnm_ManCollect_rec( p, Gia_ObjFanin0(pObj), vObjs, nAddOn );
341  else if ( Gia_ObjIsAnd(pObj) )
342  {
343  Rnm_ManCollect_rec( p, Gia_ObjFanin0(pObj), vObjs, nAddOn );
344  Rnm_ManCollect_rec( p, Gia_ObjFanin1(pObj), vObjs, nAddOn );
345  }
346  else if ( !Gia_ObjIsRo(p, pObj) )
347  assert( 0 );
348  pObj->Value = Vec_IntSize(vObjs) + nAddOn;
349  Vec_IntPush( vObjs, Gia_ObjId(p, pObj) );
350 }
352 {
353  Gia_Obj_t * pObj = NULL;
354  int i;
355  // mark const/PIs/PPIs
358  Gia_ManConst0(p->pGia)->Value = 0;
359  Gia_ManForEachObjVec( p->vMap, p->pGia, pObj, i )
360  {
361  assert( Gia_ObjIsCi(pObj) || Gia_ObjIsAnd(pObj) );
362  Gia_ObjSetTravIdCurrent( p->pGia, pObj );
363  pObj->Value = 1 + i;
364  }
365  // collect objects
366  Vec_IntClear( p->vObjs );
367  Rnm_ManCollect_rec( p->pGia, Gia_ManPo(p->pGia, 0), p->vObjs, 1 + Vec_IntSize(p->vMap) );
368  Gia_ManForEachObjVec( p->vObjs, p->pGia, pObj, i )
369  if ( Gia_ObjIsRo(p->pGia, pObj) )
370  Rnm_ManCollect_rec( p->pGia, Gia_ObjRoToRi(p->pGia, pObj), p->vObjs, 1 + Vec_IntSize(p->vMap) );
371  // the last object should be a CO
372  assert( Gia_ObjIsCo(pObj) );
373  assert( (int)pObj->Value == Vec_IntSize(p->vMap) + Vec_IntSize(p->vObjs) );
374 }
376 {
377  Gia_Obj_t * pObj;
378  int i;
379  Gia_ManForEachObjVec( p->vMap, p->pGia, pObj, i )
380  pObj->Value = 0;
381  Gia_ManForEachObjVec( p->vObjs, p->pGia, pObj, i )
382  pObj->Value = 0;
383 }
384 
385 /**Function*************************************************************
386 
387  Synopsis [Performs sensitization analysis.]
388 
389  Description []
390 
391  SideEffects []
392 
393  SeeAlso []
394 
395 ***********************************************************************/
397 {
398  Rnm_Obj_t * pRnm, * pRnm0, * pRnm1;
399  Gia_Obj_t * pObj;
400  int f, i, iBit = p->pCex->nRegs;
401  // const0 is initialized automatically in all timeframes
402  for ( f = 0; f <= p->pCex->iFrame; f++, iBit += p->pCex->nPis )
403  {
404  Gia_ManForEachObjVec( p->vMap, p->pGia, pObj, i )
405  {
406  assert( Gia_ObjIsCi(pObj) || Gia_ObjIsAnd(pObj) );
407  pRnm = Rnm_ManObj( p, pObj, f );
408  pRnm->Value = Abc_InfoHasBit( p->pCex->pData, iBit + i );
409  if ( !Gia_ObjIsPi(p->pGia, pObj) ) // this is PPI
410  {
411  assert( pObj->Value > 0 );
412  pRnm->Prio = pObj->Value;
413  pRnm->fPPi = 1;
414  }
415  }
416  Gia_ManForEachObjVec( p->vObjs, p->pGia, pObj, i )
417  {
418  assert( Gia_ObjIsRo(p->pGia, pObj) || Gia_ObjIsAnd(pObj) || Gia_ObjIsCo(pObj) );
419  pRnm = Rnm_ManObj( p, pObj, f );
420  assert( !pRnm->fPPi );
421  if ( Gia_ObjIsRo(p->pGia, pObj) )
422  {
423  if ( f == 0 )
424  continue;
425  pRnm0 = Rnm_ManObj( p, Gia_ObjRoToRi(p->pGia, pObj), f-1 );
426  pRnm->Value = pRnm0->Value;
427  pRnm->Prio = pRnm0->Prio;
428  continue;
429  }
430  if ( Gia_ObjIsCo(pObj) )
431  {
432  pRnm0 = Rnm_ManObj( p, Gia_ObjFanin0(pObj), f );
433  pRnm->Value = (pRnm0->Value ^ Gia_ObjFaninC0(pObj));
434  pRnm->Prio = pRnm0->Prio;
435  continue;
436  }
437  assert( Gia_ObjIsAnd(pObj) );
438  pRnm0 = Rnm_ManObj( p, Gia_ObjFanin0(pObj), f );
439  pRnm1 = Rnm_ManObj( p, Gia_ObjFanin1(pObj), f );
440  pRnm->Value = (pRnm0->Value ^ Gia_ObjFaninC0(pObj)) & (pRnm1->Value ^ Gia_ObjFaninC1(pObj));
441  if ( pRnm->Value == 1 )
442  pRnm->Prio = Abc_MaxInt( pRnm0->Prio, pRnm1->Prio );
443  else if ( (pRnm0->Value ^ Gia_ObjFaninC0(pObj)) == 0 && (pRnm1->Value ^ Gia_ObjFaninC1(pObj)) == 0 )
444  pRnm->Prio = Abc_MinInt( pRnm0->Prio, pRnm1->Prio ); // choice
445  else if ( (pRnm0->Value ^ Gia_ObjFaninC0(pObj)) == 0 )
446  pRnm->Prio = pRnm0->Prio;
447  else
448  pRnm->Prio = pRnm1->Prio;
449  }
450  }
451  assert( iBit == p->pCex->nBits );
452  pRnm = Rnm_ManObj( p, Gia_ManPo(p->pGia, 0), p->pCex->iFrame );
453  if ( pRnm->Value != 1 )
454  printf( "Output value is incorrect.\n" );
455  return pRnm->Prio;
456 }
457 
458 
459 /**Function*************************************************************
460 
461  Synopsis [Drive implications of the given node towards primary outputs.]
462 
463  Description []
464 
465  SideEffects []
466 
467  SeeAlso []
468 
469 ***********************************************************************/
470 void Rnm_ManJustifyPropFanout_rec( Rnm_Man_t * p, Gia_Obj_t * pObj, int f, Vec_Int_t * vSelect )
471 {
472  Rnm_Obj_t * pRnm0, * pRnm1, * pRnm = Rnm_ManObj( p, pObj, f );
473  Gia_Obj_t * pFanout = NULL;
474  int i, k;//, Id = Gia_ObjId(p->pGia, pObj);
475  assert( pRnm->fVisit == 0 );
476  pRnm->fVisit = 1;
477  if ( Rnm_ManObj( p, pObj, 0 )->fVisitJ == 0 )
478  {
479  Rnm_ManObj( p, pObj, 0 )->fVisitJ = 1;
480  p->nVisited++;
481  }
482  if ( pRnm->fPPi )
483  {
484  assert( (int)pRnm->Prio > 0 );
485  for ( i = p->pCex->iFrame; i >= 0; i-- )
486  if ( !Rnm_ManObj(p, pObj, i)->fVisit )
487  Rnm_ManJustifyPropFanout_rec( p, pObj, i, vSelect );
488  Vec_IntPush( vSelect, Gia_ObjId(p->pGia, pObj) );
489  return;
490  }
491  if ( (Gia_ObjIsCo(pObj) && f == p->pCex->iFrame) || Gia_ObjIsPo(p->pGia, pObj) )
492  return;
493  if ( Gia_ObjIsRi(p->pGia, pObj) )
494  {
495  pFanout = Gia_ObjRiToRo(p->pGia, pObj);
496  if ( !Rnm_ManObj(p, pFanout, f+1)->fVisit )
497  Rnm_ManJustifyPropFanout_rec( p, pFanout, f+1, vSelect );
498  return;
499  }
500  assert( Gia_ObjIsRo(p->pGia, pObj) || Gia_ObjIsAnd(pObj) );
501  Gia_ObjForEachFanoutStatic( p->pGia, pObj, pFanout, k )
502  {
503  Rnm_Obj_t * pRnmF;
504  if ( pFanout->Value == 0 )
505  continue;
506  pRnmF = Rnm_ManObj(p, pFanout, f);
507  if ( pRnmF->fPPi || pRnmF->fVisit )
508  continue;
509  if ( Gia_ObjIsCo(pFanout) )
510  {
511  Rnm_ManJustifyPropFanout_rec( p, pFanout, f, vSelect );
512  continue;
513  }
514  assert( Gia_ObjIsAnd(pFanout) );
515  pRnm0 = Rnm_ManObj( p, Gia_ObjFanin0(pFanout), f );
516  pRnm1 = Rnm_ManObj( p, Gia_ObjFanin1(pFanout), f );
517  if ( ((pRnm0->Value ^ Gia_ObjFaninC0(pFanout)) == 0 && pRnm0->fVisit) ||
518  ((pRnm1->Value ^ Gia_ObjFaninC1(pFanout)) == 0 && pRnm1->fVisit) ||
519  ( ((pRnm0->Value ^ Gia_ObjFaninC0(pFanout)) == 1 && pRnm0->fVisit) &&
520  ((pRnm1->Value ^ Gia_ObjFaninC1(pFanout)) == 1 && pRnm1->fVisit) ) )
521  Rnm_ManJustifyPropFanout_rec( p, pFanout, f, vSelect );
522  }
523 }
524 void Rnm_ManJustify_rec( Rnm_Man_t * p, Gia_Obj_t * pObj, int f, Vec_Int_t * vSelect )
525 {
526  Rnm_Obj_t * pRnm = Rnm_ManObj( p, pObj, f );
527  int i;//, Id = Gia_ObjId(p->pGia, pObj);
528  if ( pRnm->fVisit )
529  return;
530  if ( p->fPropFanout )
531  Rnm_ManJustifyPropFanout_rec( p, pObj, f, vSelect );
532  else
533  {
534  pRnm->fVisit = 1;
535  if ( Rnm_ManObj( p, pObj, 0 )->fVisitJ == 0 )
536  {
537  Rnm_ManObj( p, pObj, 0 )->fVisitJ = 1;
538  p->nVisited++;
539  }
540  }
541  if ( pRnm->fPPi )
542  {
543  assert( (int)pRnm->Prio > 0 );
544  if ( p->fPropFanout )
545  {
546  for ( i = p->pCex->iFrame; i >= 0; i-- )
547  if ( !Rnm_ManObj(p, pObj, i)->fVisit )
548  Rnm_ManJustifyPropFanout_rec( p, pObj, i, vSelect );
549  }
550  else
551  {
552  Vec_IntPush( vSelect, Gia_ObjId(p->pGia, pObj) );
553 // for ( i = p->pCex->iFrame; i >= 0; i-- )
554 // Rnm_ManObj(p, pObj, i)->fVisit = 1;
555  }
556  return;
557  }
558  if ( Gia_ObjIsPi(p->pGia, pObj) || Gia_ObjIsConst0(pObj) )
559  return;
560  if ( Gia_ObjIsRo(p->pGia, pObj) )
561  {
562  if ( f > 0 )
563  Rnm_ManJustify_rec( p, Gia_ObjFanin0(Gia_ObjRoToRi(p->pGia, pObj)), f-1, vSelect );
564  return;
565  }
566  if ( Gia_ObjIsAnd(pObj) )
567  {
568  Rnm_Obj_t * pRnm0 = Rnm_ManObj( p, Gia_ObjFanin0(pObj), f );
569  Rnm_Obj_t * pRnm1 = Rnm_ManObj( p, Gia_ObjFanin1(pObj), f );
570  if ( pRnm->Value == 1 )
571  {
572  if ( pRnm0->Prio > 0 )
573  Rnm_ManJustify_rec( p, Gia_ObjFanin0(pObj), f, vSelect );
574  if ( pRnm1->Prio > 0 )
575  Rnm_ManJustify_rec( p, Gia_ObjFanin1(pObj), f, vSelect );
576  }
577  else // select one value
578  {
579  if ( (pRnm0->Value ^ Gia_ObjFaninC0(pObj)) == 0 && (pRnm1->Value ^ Gia_ObjFaninC1(pObj)) == 0 )
580  {
581  if ( pRnm0->Prio <= pRnm1->Prio ) // choice
582  {
583  if ( pRnm0->Prio > 0 )
584  Rnm_ManJustify_rec( p, Gia_ObjFanin0(pObj), f, vSelect );
585  }
586  else
587  {
588  if ( pRnm1->Prio > 0 )
589  Rnm_ManJustify_rec( p, Gia_ObjFanin1(pObj), f, vSelect );
590  }
591  }
592  else if ( (pRnm0->Value ^ Gia_ObjFaninC0(pObj)) == 0 )
593  {
594  if ( pRnm0->Prio > 0 )
595  Rnm_ManJustify_rec( p, Gia_ObjFanin0(pObj), f, vSelect );
596  }
597  else if ( (pRnm1->Value ^ Gia_ObjFaninC1(pObj)) == 0 )
598  {
599  if ( pRnm1->Prio > 0 )
600  Rnm_ManJustify_rec( p, Gia_ObjFanin1(pObj), f, vSelect );
601  }
602  else assert( 0 );
603  }
604  }
605  else assert( 0 );
606 }
607 
608 /**Function*************************************************************
609 
610  Synopsis [Performs refinement.]
611 
612  Description []
613 
614  SideEffects []
615 
616  SeeAlso []
617 
618 ***********************************************************************/
619 void Rnm_ManVerifyUsingTerSim( Gia_Man_t * p, Abc_Cex_t * pCex, Vec_Int_t * vMap, Vec_Int_t * vObjs, Vec_Int_t * vRes )
620 {
621  Gia_Obj_t * pObj;
622  int i, f, iBit = pCex->nRegs;
624  for ( f = 0; f <= pCex->iFrame; f++, iBit += pCex->nPis )
625  {
626  Gia_ManForEachObjVec( vMap, p, pObj, i )
627  {
628  pObj->Value = Abc_InfoHasBit( pCex->pData, iBit + i );
629  if ( !Gia_ObjIsPi(p, pObj) )
630  Gia_ObjTerSimSetX( pObj );
631  else if ( pObj->Value )
632  Gia_ObjTerSimSet1( pObj );
633  else
634  Gia_ObjTerSimSet0( pObj );
635  }
636  Gia_ManForEachObjVec( vRes, p, pObj, i ) // vRes is subset of vMap
637  {
638  if ( pObj->Value )
639  Gia_ObjTerSimSet1( pObj );
640  else
641  Gia_ObjTerSimSet0( pObj );
642  }
643  Gia_ManForEachObjVec( vObjs, p, pObj, i )
644  {
645  if ( Gia_ObjIsCo(pObj) )
646  Gia_ObjTerSimCo( pObj );
647  else if ( Gia_ObjIsAnd(pObj) )
648  Gia_ObjTerSimAnd( pObj );
649  else if ( f == 0 )
650  Gia_ObjTerSimSet0( pObj );
651  else
652  Gia_ObjTerSimRo( p, pObj );
653  }
654  }
655  Gia_ManForEachObjVec( vMap, p, pObj, i )
656  pObj->Value = 0;
657  pObj = Gia_ManPo( p, 0 );
658  if ( !Gia_ObjTerSimGet1(pObj) )
659  Abc_Print( 1, "\nRefinement verification has failed!!!\n" );
660 }
661 
662 /**Function*************************************************************
663 
664  Synopsis [Computes the refinement for a given counter-example.]
665 
666  Description []
667 
668  SideEffects []
669 
670  SeeAlso []
671 
672 ***********************************************************************/
673 Vec_Int_t * Rnm_ManRefine( Rnm_Man_t * p, Abc_Cex_t * pCex, Vec_Int_t * vMap, int fPropFanout, int fNewRefinement, int fVerbose )
674 {
675  int fVerify = 1;
676  Vec_Int_t * vGoodPPis, * vNewPPis;
677  abctime clk, clk2 = Abc_Clock();
678  int RetValue;
679  p->nCalls++;
680 // Gia_ManCleanValue( p->pGia );
681  // initialize
682  p->pCex = pCex;
683  p->vMap = vMap;
684  p->fPropFanout = fPropFanout;
685  p->fVerbose = fVerbose;
686  // collects used objects
687  Rnm_ManCollect( p );
688  // initialize datastructure
689  p->nObjsFrame = 1 + Vec_IntSize(vMap) + Vec_IntSize(p->vObjs);
690  p->nObjs = p->nObjsFrame * (pCex->iFrame + 1);
691  if ( p->nObjs > p->nObjsAlloc )
692  p->pObjs = ABC_REALLOC( Rnm_Obj_t, p->pObjs, (p->nObjsAlloc = p->nObjs + 10000) );
693  memset( p->pObjs, 0, sizeof(Rnm_Obj_t) * p->nObjs );
694  // propagate priorities
695  clk = Abc_Clock();
696  vGoodPPis = Vec_IntAlloc( 100 );
697  if ( Rnm_ManSensitize( p ) ) // the CEX is not a true CEX
698  {
699  p->timeFwd += Abc_Clock() - clk;
700  // select refinement
701  clk = Abc_Clock();
702  p->nVisited = 0;
703  Rnm_ManJustify_rec( p, Gia_ObjFanin0(Gia_ManPo(p->pGia, 0)), pCex->iFrame, vGoodPPis );
704  RetValue = Vec_IntUniqify( vGoodPPis );
705 // assert( RetValue == 0 );
706  p->timeBwd += Abc_Clock() - clk;
707  }
708 
709  // verify (empty) refinement
710  // (only works when post-processing is not applied)
711  if ( fVerify )
712  {
713  clk = Abc_Clock();
714  Rnm_ManVerifyUsingTerSim( p->pGia, p->pCex, p->vMap, p->vObjs, vGoodPPis );
715  p->timeVer += Abc_Clock() - clk;
716  }
717 
718  // at this point array vGoodPPis contains the set of important PPIs
719  if ( Vec_IntSize(vGoodPPis) > 0 ) // spurious CEX resulting in a non-trivial refinement
720  {
721  // filter selected set
722  if ( !fNewRefinement ) // default
723  vNewPPis = Rnm_ManFilterSelected( p, vGoodPPis );
724  else // this is enabled when &gla is called with -r (&gla -r)
725  vNewPPis = Rnm_ManFilterSelectedNew( p, vGoodPPis );
726 
727  // replace the PPI array if necessary
728  if ( Vec_IntSize(vNewPPis) > 0 ) // something to select, replace current refinement
729  Vec_IntFree( vGoodPPis ), vGoodPPis = vNewPPis;
730  else // if there is nothing to select, do not change the current refinement array
731  Vec_IntFree( vNewPPis );
732  }
733 
734  // clean values
735  // we cannot do this before, because we need to remember what objects
736  // belong to the abstraction when we do Rnm_ManFilterSelected()
737  Rnm_ManCleanValues( p );
738 
739 // Vec_IntReverseOrder( vGoodPPis );
740  p->timeTotal += Abc_Clock() - clk2;
741  p->nRefines += Vec_IntSize(vGoodPPis);
742  return vGoodPPis;
743 }
744 
745 ////////////////////////////////////////////////////////////////////////
746 /// END OF FILE ///
747 ////////////////////////////////////////////////////////////////////////
748 
749 
751 
double Rnm_ManMemoryUsage(Rnm_Man_t *p)
Definition: absRef.c:317
int nObjsAlloc
Definition: gia.h:102
char * memset()
static int sat_solver2_nlearnts(sat_solver2 *s)
Definition: satSolver2.h:200
static unsigned Ga2_ObjTruth(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: abs.h:115
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static void Gia_ObjTerSimCo(Gia_Obj_t *pObj)
Definition: gia.h:797
static void Gia_ObjTerSimRo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:808
static void Gia_ObjTerSimSet0(Gia_Obj_t *pObj)
Definition: gia.h:770
void * Sat_ProofCore(sat_solver2 *s)
Definition: satSolver2.c:1985
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Int_t * vFanins
Definition: absRef.h:69
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Gia_ObjIsTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:533
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
abctime timeFwd
Definition: absRef.h:86
void Rnm_ManCollect_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vObjs, int nAddOn)
Definition: absRef.c:334
Vec_Int_t * Ga2_ManCnfCompute(unsigned uTruth, int nVars, Vec_Int_t *vCover)
Definition: absGla.c:630
void Rnm_ManCleanValues(Rnm_Man_t *p)
Definition: absRef.c:375
Rnm_Man_t * Rnm_ManStart(Gia_Man_t *pGia)
FUNCTION DEFINITIONS ///.
Definition: absRef.c:264
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
void sat_solver2_delete(sat_solver2 *s)
Definition: satSolver2.c:1225
Vec_Int_t * Rnm_ManFilterSelectedNew(Rnm_Man_t *p, Vec_Int_t *vOldPPis)
Definition: absRefSelect.c:207
void Gia_ManCleanValue(Gia_Man_t *p)
Definition: giaUtil.c:310
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
void Rnm_ManJustifyPropFanout_rec(Rnm_Man_t *p, Gia_Obj_t *pObj, int f, Vec_Int_t *vSelect)
Definition: absRef.c:470
static int Gia_ObjIsConst0(Gia_Obj_t *pObj)
Definition: gia.h:430
Gia_Man_t * pGia
Definition: absRef.h:59
static int Vec_IntFind(Vec_Int_t *p, int Entry)
Definition: vecInt.h:895
int fPropFanout
Definition: absRef.h:62
abctime timeOther
Definition: llb3Image.c:82
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
sat_solver2 * sat_solver2_new(void)
Definition: satSolver2.c:1109
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int * Vec_IntLimit(Vec_Int_t *p)
Definition: vecInt.h:336
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
for(p=first;p->value< newval;p=p->next)
Definition: gia.h:75
void Gia_ManCleanMark1(Gia_Man_t *p)
Definition: giaUtil.c:272
abctime timeTotal
Definition: absRef.h:89
Vec_Int_t * vFanout
Definition: gia.h:130
#define ABC_PRTP(a, t, T)
Definition: abc_global.h:223
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int nVisited
Definition: absRef.h:84
void Rnm_ManCollect(Rnm_Man_t *p)
Definition: absRef.c:351
void Rnm_ManStop(Rnm_Man_t *p, int fProfile)
Definition: absRef.c:285
Vec_Int_t * vObjs
Definition: absRef.h:66
void Rnm_ManJustify_rec(Rnm_Man_t *p, Gia_Obj_t *pObj, int f, Vec_Int_t *vSelect)
Definition: absRef.c:524
static Prf_Man_t * Prf_ManAlloc()
FUNCTION DECLARATIONS ///.
Definition: satProof2.h:81
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
static int Gia_ObjIsRo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:443
ABC_NAMESPACE_IMPL_START void Ga2_ManCnfAddStatic(sat_solver2 *pSat, Vec_Int_t *vCnf0, Vec_Int_t *vCnf1, int *pLits, int iLitOut, int ProofId)
DECLARATIONS ///.
struct Rnm_Man_t_ Rnm_Man_t
Definition: absRef.h:55
static Gia_Obj_t * Gia_ObjRoToRi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:446
void Gia_ManStaticFanoutStop(Gia_Man_t *p)
Definition: giaFanout.c:290
static int Gia_ObjIsRi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:444
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static void Gia_ObjSetTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:531
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
if(last==0)
Definition: sparse_int.h:34
void Gia_ManStaticFanoutStart(Gia_Man_t *p)
Definition: giaFanout.c:238
int nObjs
Definition: absRef.h:79
static int Vec_IntUniqify(Vec_Int_t *p)
Definition: vecInt.h:1314
static Vec_Str_t * Vec_StrStart(int nSize)
Definition: vecStr.h:95
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntAppend(Vec_Int_t *vVec1, Vec_Int_t *vVec2)
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
abctime timeBwd
Definition: absRef.h:87
Vec_Str_t * vCounts
Definition: absRef.h:68
static int Vec_IntCap(Vec_Int_t *p)
Definition: vecInt.h:368
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define Gia_ObjForEachFanoutStatic(p, pObj, pFanout, i)
Definition: gia.h:946
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition: gia.h:988
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int nObjsFrame
Definition: absRef.h:81
static void Prf_ManRestart(Prf_Man_t *p, Vec_Int_t *vId2Pr, int iFirst, int nWidth)
Definition: satProof2.h:120
Rnm_Obj_t * pObjs
Definition: absRef.h:78
static int Gia_ObjTerSimGet1(Gia_Obj_t *pObj)
Definition: gia.h:776
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
abctime timeVer
Definition: absRef.h:88
static Vec_Int_t * Ga2_ObjLeaves(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: abs.h:117
int Rnm_ManSensitize(Rnm_Man_t *p)
Definition: absRef.c:396
Abc_Cex_t * pCex
Definition: absRef.h:60
static Gia_Obj_t * Gia_ObjRiToRo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:447
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
static void Gia_ObjTerSimSet1(Gia_Obj_t *pObj)
Definition: gia.h:771
Vec_Int_t * Rnm_ManFilterSelected(Rnm_Man_t *p, Vec_Int_t *vOldPPis)
Definition: absRefSelect.c:126
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define l_False
Definition: SolverTypes.h:85
int nObjsAlloc
Definition: absRef.h:80
int nTravIdsAlloc
Definition: gia.h:154
int nCalls
Definition: absRef.h:82
static int Gia_ObjIsPo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:442
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
int sat_solver2_solve(sat_solver2 *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver2.c:1835
static void Prf_ManStopP(Prf_Man_t **p)
Definition: satProof2.h:99
void Rnm_ManVerifyUsingTerSim(Gia_Man_t *p, Abc_Cex_t *pCex, Vec_Int_t *vMap, Vec_Int_t *vObjs, Vec_Int_t *vRes)
Definition: absRef.c:619
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
static Rnm_Obj_t * Rnm_ManObj(Rnm_Man_t *p, Gia_Obj_t *pObj, int f)
Definition: absRef.h:93
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
struct Gia_Man_t_ Gia_Man_t
Definition: gia.h:94
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
typedefABC_NAMESPACE_HEADER_START struct Rnm_Obj_t_ Rnm_Obj_t
INCLUDES ///.
Definition: absRef.h:45
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
Vec_Int_t * vMap
Definition: absRef.h:61
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int fVerbose
Definition: absRef.h:63
Vec_Int_t * Rnm_ManRefine(Rnm_Man_t *p, Abc_Cex_t *pCex, Vec_Int_t *vMap, int fPropFanout, int fNewRefinement, int fVerbose)
Definition: absRef.c:673
static void Gia_ObjTerSimSetX(Gia_Obj_t *pObj)
Definition: gia.h:772
int nRefines
Definition: absRef.h:83
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static void Gia_ObjTerSimAnd(Gia_Obj_t *pObj)
Definition: gia.h:785
static int Gia_ObjIsPi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:441