ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fraCore.c
Go to the documentation of this file.
1
20
21#include "fra.h"
22
24
25
29
30/*
31 Speculating reduction in the sequential case leads to an interesting
32 situation when a counter-ex may not refine any classes. This happens
33 for non-constant equivalence classes. In such cases the representative
34 of the class (proved by simulation to be non-constant) may be reduced
35 to a constant during the speculative reduction. The fraig-representative
36 of this representative node is a constant node, even though this is a
37 non-constant class. Experiments have shown that this situation happens
38 very often at the beginning of the refinement iteration when there are
39 many spurious candidate equivalence classes (especially if heavy-duty
40 simulatation of BMC was node used at the beginning). As a result, the
41 SAT solver run may return a counter-ex that distinguishes the given
42 representative node from the constant-1 node but this counter-ex
43 does not distinguish the nodes in the non-costant class... This is why
44 there is no check of refinement after a counter-ex in the sequential case.
45*/
46
50
63{
64 Aig_Obj_t * pObj, * pChild;
65 int i, CountConst0 = 0, CountNonConst0 = 0, CountUndecided = 0;
66 if ( p->pData )
67 return 0;
68 Aig_ManForEachPoSeq( p, pObj, i )
69 {
70 pChild = Aig_ObjChild0(pObj);
71 // check if the output is constant 0
72 if ( pChild == Aig_ManConst0(p) )
73 {
74 CountConst0++;
75 continue;
76 }
77 // check if the output is constant 1
78 if ( pChild == Aig_ManConst1(p) )
79 {
80 CountNonConst0++;
81 continue;
82 }
83 // check if the output is a primary input
84 if ( Aig_ObjIsCi(Aig_Regular(pChild)) && Aig_ObjCioId(Aig_Regular(pChild)) < p->nTruePis )
85 {
86 CountNonConst0++;
87 continue;
88 }
89 // check if the output can be not constant 0
90 if ( Aig_Regular(pChild)->fPhase != (unsigned)Aig_IsComplement(pChild) )
91 {
92 CountNonConst0++;
93 continue;
94 }
95 CountUndecided++;
96 }
97/*
98 if ( p->pParams->fVerbose )
99 {
100 printf( "Miter has %d outputs. ", Aig_ManCoNum(p->pManAig) );
101 printf( "Const0 = %d. ", CountConst0 );
102 printf( "NonConst0 = %d. ", CountNonConst0 );
103 printf( "Undecided = %d. ", CountUndecided );
104 printf( "\n" );
105 }
106*/
107 if ( CountNonConst0 )
108 return 0;
109 if ( CountUndecided )
110 return -1;
111 return 1;
112}
113
126{
127 Aig_Obj_t * pObj, * pChild;
128 int i;
129 Aig_ManForEachPoSeq( p, pObj, i )
130 {
131 pChild = Aig_ObjChild0(pObj);
132 // check if the output is constant 0
133 if ( pChild == Aig_ManConst0(p) )
134 continue;
135 // check if the output is constant 1
136 if ( pChild == Aig_ManConst1(p) )
137 return i;
138 // check if the output can be not constant 0
139 if ( Aig_Regular(pChild)->fPhase != (unsigned)Aig_IsComplement(pChild) )
140 return i;
141 }
142 return -1;
143}
144
156static inline void Fra_FraigNodeSpeculate( Fra_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pObjFraig, Aig_Obj_t * pObjReprFraig )
157{
158 static int Counter = 0;
159 char FileName[20];
160 Aig_Man_t * pTemp;
161 Aig_Obj_t * pNode;
162 int i;
163 // create manager with the logic for these two nodes
164 pTemp = Aig_ManExtractMiter( p->pManFraig, pObjFraig, pObjReprFraig );
165 // dump the logic into a file
166 sprintf( FileName, "aig\\%03d.blif", ++Counter );
167 Aig_ManDumpBlif( pTemp, FileName, NULL, NULL );
168 printf( "Speculation cone with %d nodes was written into file \"%s\".\n", Aig_ManNodeNum(pTemp), FileName );
169 // clean up
170 Aig_ManStop( pTemp );
171 Aig_ManForEachObj( p->pManFraig, pNode, i )
172 pNode->pData = p;
173}
174
187{
188 Aig_Obj_t * pObj, ** ppClass;
189 int i, c;
190 assert( Aig_ManCiNum(p->pManAig) == Vec_IntSize(vCex) );
191 // make sure the input pattern is not used
192 Aig_ManForEachObj( p->pManAig, pObj, i )
193 assert( !pObj->fMarkB );
194 // simulate the cex through the AIG
195 Aig_ManConst1(p->pManAig)->fMarkB = 1;
196 Aig_ManForEachCi( p->pManAig, pObj, i )
197 pObj->fMarkB = Vec_IntEntry(vCex, i);
198 Aig_ManForEachNode( p->pManAig, pObj, i )
199 pObj->fMarkB = (Aig_ObjFanin0(pObj)->fMarkB ^ Aig_ObjFaninC0(pObj)) &
200 (Aig_ObjFanin1(pObj)->fMarkB ^ Aig_ObjFaninC1(pObj));
201 Aig_ManForEachCo( p->pManAig, pObj, i )
202 pObj->fMarkB = Aig_ObjFanin0(pObj)->fMarkB ^ Aig_ObjFaninC0(pObj);
203 // check if the classes hold
204 Vec_PtrForEachEntry( Aig_Obj_t *, p->pCla->vClasses1, pObj, i )
205 {
206 if ( pObj->fPhase != pObj->fMarkB )
207 printf( "The node %d is not constant under cex!\n", pObj->Id );
208 }
209 Vec_PtrForEachEntry( Aig_Obj_t **, p->pCla->vClasses, ppClass, i )
210 {
211 for ( c = 1; ppClass[c]; c++ )
212 if ( (ppClass[0]->fPhase ^ ppClass[c]->fPhase) != (ppClass[0]->fMarkB ^ ppClass[c]->fMarkB) )
213 printf( "The nodes %d and %d are not equal under cex!\n", ppClass[0]->Id, ppClass[c]->Id );
214// for ( c = 0; ppClass[c]; c++ )
215// if ( Fra_ObjFraig(ppClass[c],p->pPars->nFramesK) == Aig_ManConst1(p->pManFraig) )
216// printf( "A member of non-constant class has a constant repr!\n" );
217 }
218 // clean the simulation pattern
219 Aig_ManForEachObj( p->pManAig, pObj, i )
220 pObj->fMarkB = 0;
221}
222
234static inline void Fra_FraigNode( Fra_Man_t * p, Aig_Obj_t * pObj )
235{
236 Aig_Obj_t * pObjRepr, * pObjFraig, * pObjFraig2, * pObjReprFraig;
237 int RetValue;
238 assert( !Aig_IsComplement(pObj) );
239 // get representative of this class
240 pObjRepr = Fra_ClassObjRepr( pObj );
241 if ( pObjRepr == NULL || // this is a unique node
242 (!p->pPars->fDoSparse && pObjRepr == Aig_ManConst1(p->pManAig)) ) // this is a sparse node
243 return;
244 // get the fraiged node
245 pObjFraig = Fra_ObjFraig( pObj, p->pPars->nFramesK );
246 // get the fraiged representative
247 pObjReprFraig = Fra_ObjFraig( pObjRepr, p->pPars->nFramesK );
248 // if the fraiged nodes are the same, return
249 if ( Aig_Regular(pObjFraig) == Aig_Regular(pObjReprFraig) )
250 {
251 p->nSatCallsSkipped++;
252 return;
253 }
254 assert( p->pPars->nFramesK || Aig_Regular(pObjFraig) != Aig_ManConst1(p->pManFraig) );
255 // if they are proved different, the c-ex will be in p->pPatWords
256 RetValue = Fra_NodesAreEquiv( p, Aig_Regular(pObjReprFraig), Aig_Regular(pObjFraig) );
257 if ( RetValue == 1 ) // proved equivalent
258 {
259// if ( p->pPars->fChoicing )
260// Aig_ObjCreateRepr( p->pManFraig, Aig_Regular(pObjReprFraig), Aig_Regular(pObjFraig) );
261 // the nodes proved equal
262 pObjFraig2 = Aig_NotCond( pObjReprFraig, pObj->fPhase ^ pObjRepr->fPhase );
263 Fra_ObjSetFraig( pObj, p->pPars->nFramesK, pObjFraig2 );
264 return;
265 }
266 if ( RetValue == -1 ) // failed
267 {
268 if ( p->vTimeouts == NULL )
269 p->vTimeouts = Vec_PtrAlloc( 100 );
270 Vec_PtrPush( p->vTimeouts, pObj );
271 if ( !p->pPars->fSpeculate )
272 return;
273 assert( 0 );
274 // speculate
275 p->nSpeculs++;
276 pObjFraig2 = Aig_NotCond( pObjReprFraig, pObj->fPhase ^ pObjRepr->fPhase );
277 Fra_ObjSetFraig( pObj, p->pPars->nFramesK, pObjFraig2 );
278 Fra_FraigNodeSpeculate( p, pObj, Aig_Regular(pObjFraig), Aig_Regular(pObjReprFraig) );
279 return;
280 }
281 // disprove the nodes
282 p->pCla->fRefinement = 1;
283 // if we do not include the node into those disproved, we may end up
284 // merging this node with another representative, for which proof has timed out
285 if ( p->vTimeouts )
286 Vec_PtrPush( p->vTimeouts, pObj );
287 // verify that the counter-example satisfies all the constraints
288// if ( p->vCex )
289// Fra_FraigVerifyCounterEx( p, p->vCex );
290 // simulate the counter-example and return the Fraig node
292 if ( p->pManFraig->pData )
293 return;
294 if ( !p->pPars->nFramesK && Fra_ClassObjRepr(pObj) == pObjRepr )
295 printf( "Fra_FraigNode(): Error in class refinement!\n" );
296 assert( p->pPars->nFramesK || Fra_ClassObjRepr(pObj) != pObjRepr );
297}
298
311{
312// Bar_Progress_t * pProgress = NULL;
313 Aig_Obj_t * pObj, * pObjNew;
314 int i, Pos = 0;
315 int nBTracksOld;
316 // fraig latch outputs
317 Aig_ManForEachLoSeq( p->pManAig, pObj, i )
318 {
319 Fra_FraigNode( p, pObj );
320 if ( p->pPars->fUseImps )
321 Pos = Fra_ImpCheckForNode( p, p->pCla->vImps, pObj, Pos );
322 }
323 if ( p->pPars->fLatchCorr )
324 return;
325 // fraig internal nodes
326// if ( !p->pPars->fDontShowBar )
327// pProgress = Bar_ProgressStart( stdout, Aig_ManObjNumMax(p->pManAig) );
328 nBTracksOld = p->pPars->nBTLimitNode;
329 Aig_ManForEachNode( p->pManAig, pObj, i )
330 {
331// if ( pProgress )
332// Bar_ProgressUpdate( pProgress, i, NULL );
333 // derive and remember the new fraig node
334 pObjNew = Aig_And( p->pManFraig, Fra_ObjChild0Fra(pObj,p->pPars->nFramesK), Fra_ObjChild1Fra(pObj,p->pPars->nFramesK) );
335 Fra_ObjSetFraig( pObj, p->pPars->nFramesK, pObjNew );
336 Aig_Regular(pObjNew)->pData = p;
337 // quit if simulation detected a counter-example for a PO
338 if ( p->pManFraig->pData )
339 continue;
340// if ( Aig_SupportSize(p->pManAig,pObj) > 16 )
341// continue;
342 // perform fraiging
343 if ( p->pPars->nLevelMax && (int)pObj->Level > p->pPars->nLevelMax )
344 p->pPars->nBTLimitNode = 5;
345 Fra_FraigNode( p, pObj );
346 if ( p->pPars->nLevelMax && (int)pObj->Level > p->pPars->nLevelMax )
347 p->pPars->nBTLimitNode = nBTracksOld;
348 // check implications
349 if ( p->pPars->fUseImps )
350 Pos = Fra_ImpCheckForNode( p, p->pCla->vImps, pObj, Pos );
351 }
352// if ( pProgress )
353// Bar_ProgressStop( pProgress );
354 // try to prove the outputs of the miter
355 p->nNodesMiter = Aig_ManNodeNum(p->pManFraig);
356// Fra_MiterStatus( p->pManFraig );
357// if ( p->pPars->fProve && p->pManFraig->pData == NULL )
358// Fra_MiterProve( p );
359 // compress implications after processing all of them
360 if ( p->pPars->fUseImps )
361 Fra_ImpCompactArray( p->pCla->vImps );
362}
363
376{
377 Fra_Man_t * p;
378 Aig_Man_t * pManAigNew;
379 abctime clk;
380 if ( Aig_ManNodeNum(pManAig) == 0 )
381 return Aig_ManDupOrdered(pManAig);
382clk = Abc_Clock();
383 p = Fra_ManStart( pManAig, pPars );
384 p->pManFraig = Fra_ManPrepareComb( p );
385 p->pSml = Fra_SmlStart( pManAig, 0, 1, pPars->nSimWords );
386 Fra_SmlSimulate( p, 0 );
387// if ( p->pPars->fChoicing )
388// Aig_ManReprStart( p->pManFraig, Aig_ManObjNumMax(p->pManAig) );
389 // collect initial states
390 p->nLitsBeg = Fra_ClassesCountLits( p->pCla );
391 p->nNodesBeg = Aig_ManNodeNum(pManAig);
392 p->nRegsBeg = Aig_ManRegNum(pManAig);
393 // perform fraig sweep
394if ( p->pPars->fVerbose )
395Fra_ClassesPrint( p->pCla, 1 );
396 Fra_FraigSweep( p );
397 // call back the procedure to check implications
398 if ( pManAig->pImpFunc )
399 pManAig->pImpFunc( p, pManAig->pImpData );
400 // no need to filter one-hot clauses because they satisfy base case by construction
401 // finalize the fraiged manager
403 if ( p->pPars->fChoicing )
404 {
405abctime clk2 = Abc_Clock();
406 Fra_ClassesCopyReprs( p->pCla, p->vTimeouts );
407 pManAigNew = Aig_ManDupRepr( p->pManAig, 1 );
408 Aig_ManReprStart( pManAigNew, Aig_ManObjNumMax(pManAigNew) );
409 Aig_ManTransferRepr( pManAigNew, p->pManAig );
410 Aig_ManMarkValidChoices( pManAigNew );
411 Aig_ManStop( p->pManFraig );
412 p->pManFraig = NULL;
413p->timeTrav += Abc_Clock() - clk2;
414 }
415 else
416 {
417 Fra_ClassesCopyReprs( p->pCla, p->vTimeouts );
418 Aig_ManCleanup( p->pManFraig );
419 pManAigNew = p->pManFraig;
420 p->pManFraig = NULL;
421 }
422p->timeTotal = Abc_Clock() - clk;
423 // collect final stats
424 p->nLitsEnd = Fra_ClassesCountLits( p->pCla );
425 p->nNodesEnd = Aig_ManNodeNum(pManAigNew);
426 p->nRegsEnd = Aig_ManRegNum(pManAigNew);
427 Fra_ManStop( p );
428 return pManAigNew;
429}
430
442Aig_Man_t * Fra_FraigChoice( Aig_Man_t * pManAig, int nConfMax, int nLevelMax )
443{
444 Fra_Par_t Pars, * pPars = &Pars;
445 Fra_ParamsDefault( pPars );
446 pPars->nBTLimitNode = nConfMax;
447 pPars->fChoicing = 1;
448 pPars->fDoSparse = 1;
449 pPars->fSpeculate = 0;
450 pPars->fProve = 0;
451 pPars->fVerbose = 0;
452 pPars->fDontShowBar = 1;
453 pPars->nLevelMax = nLevelMax;
454 return Fra_FraigPerform( pManAig, pPars );
455}
456
468Aig_Man_t * Fra_FraigEquivence( Aig_Man_t * pManAig, int nConfMax, int fProve )
469{
470 Aig_Man_t * pFraig;
471 Fra_Par_t Pars, * pPars = &Pars;
472 Fra_ParamsDefault( pPars );
473 pPars->nBTLimitNode = nConfMax;
474 pPars->fChoicing = 0;
475 pPars->fDoSparse = 1;
476 pPars->fSpeculate = 0;
477 pPars->fProve = fProve;
478 pPars->fVerbose = 0;
479 pPars->fDontShowBar = 1;
480 pFraig = Fra_FraigPerform( pManAig, pPars );
481 return pFraig;
482}
483
487
488
490
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Aig_Man_t * Aig_ManDupRepr(Aig_Man_t *p, int fOrdered)
Definition aigRepr.c:267
Aig_Man_t * Aig_ManDupOrdered(Aig_Man_t *p)
Definition aigDup.c:277
void Aig_ManReprStart(Aig_Man_t *p, int nIdMax)
DECLARATIONS ///.
Definition aigRepr.c:45
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:104
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
void Aig_ManMarkValidChoices(Aig_Man_t *p)
Definition aigRepr.c:481
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
int Aig_ManCleanup(Aig_Man_t *p)
Definition aigMan.c:265
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
#define Aig_ManForEachPoSeq(p, pObj, i)
Definition aig.h:444
Aig_Man_t * Aig_ManExtractMiter(Aig_Man_t *p, Aig_Obj_t *pNode1, Aig_Obj_t *pNode2)
Definition aigMan.c:147
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition aig.h:441
void Aig_ManTransferRepr(Aig_Man_t *pNew, Aig_Man_t *p)
Definition aigRepr.c:211
void Aig_ManDumpBlif(Aig_Man_t *p, char *pFileName, Vec_Ptr_t *vPiNames, Vec_Ptr_t *vPoNames)
Definition aigUtil.c:746
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ush Pos
Definition deflate.h:88
Cube * p
Definition exorList.c:222
Aig_Man_t * Fra_FraigEquivence(Aig_Man_t *pManAig, int nConfMax, int fProve)
Definition fraCore.c:468
Aig_Man_t * Fra_FraigPerform(Aig_Man_t *pManAig, Fra_Par_t *pPars)
Definition fraCore.c:375
ABC_NAMESPACE_IMPL_START int Fra_FraigMiterStatus(Aig_Man_t *p)
DECLARATIONS ///.
Definition fraCore.c:62
Aig_Man_t * Fra_FraigChoice(Aig_Man_t *pManAig, int nConfMax, int nLevelMax)
Definition fraCore.c:442
void Fra_FraigVerifyCounterEx(Fra_Man_t *p, Vec_Int_t *vCex)
Definition fraCore.c:186
int Fra_FraigMiterAssertedOutput(Aig_Man_t *p)
Definition fraCore.c:125
void Fra_FraigSweep(Fra_Man_t *p)
Definition fraCore.c:310
void Fra_ClassesCopyReprs(Fra_Cla_t *p, Vec_Ptr_t *vFailed)
Definition fraClass.c:114
int Fra_ImpCheckForNode(Fra_Man_t *p, Vec_Int_t *vImps, Aig_Obj_t *pNode, int Pos)
Definition fraImp.c:503
typedefABC_NAMESPACE_HEADER_START struct Fra_Par_t_ Fra_Par_t
INCLUDES ///.
Definition fra.h:53
void Fra_SmlSimulate(Fra_Man_t *p, int fInit)
Definition fraSim.c:738
void Fra_ImpCompactArray(Vec_Int_t *vImps)
Definition fraImp.c:607
struct Fra_Man_t_ Fra_Man_t
Definition fra.h:56
Fra_Sml_t * Fra_SmlStart(Aig_Man_t *pAig, int nPref, int nFrames, int nWordsFrame)
Definition fraSim.c:813
Aig_Man_t * Fra_ManPrepareComb(Fra_Man_t *p)
Definition fraMan.c:176
void Fra_ManStop(Fra_Man_t *p)
Definition fraMan.c:240
int Fra_ClassesCountLits(Fra_Cla_t *p)
Definition fraClass.c:164
Fra_Man_t * Fra_ManStart(Aig_Man_t *pManAig, Fra_Par_t *pParams)
Definition fraMan.c:104
void Fra_SmlResimulate(Fra_Man_t *p)
Definition fraSim.c:703
void Fra_ManFinalizeComb(Fra_Man_t *p)
Definition fraMan.c:217
void Fra_ClassesPrint(Fra_Cla_t *p, int fVeryVerbose)
Definition fraClass.c:236
void Fra_ParamsDefault(Fra_Par_t *pParams)
DECLARATIONS ///.
Definition fraMan.c:45
int Fra_NodesAreEquiv(Fra_Man_t *p, Aig_Obj_t *pOld, Aig_Obj_t *pNew)
FUNCTION DEFINITIONS ///.
Definition fraSat.c:48
int Id
Definition aig.h:85
unsigned int fMarkB
Definition aig.h:80
void * pData
Definition aig.h:87
unsigned Level
Definition aig.h:82
unsigned int fPhase
Definition aig.h:78
#define assert(ex)
Definition util_old.h:213
char * sprintf()
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55