Skip to content

Commit acaa07e

Browse files
committed
Propagate vOrigins through all ABC9 engines
Extend origin tracking to cover the complete abc9 optimization pipeline. Add Gia_ManOriginsDupVec for functions that use Vec_Int_t copy vectors instead of the Value field. Engines instrumented: - &dc2, &dch: Round-trip recovery (giaAig.c) - &if: iCopy-based propagation in SopBalance/DsdBalance (giaIf.c), plus DupHashMapping/DupUnhashMapping for timing paths - &jf, &lf: OriginsDupVec in Jf_ManDeriveGia/Lf_ManDeriveMappingGia - &syn2, &synch2: Sub-operations (Jf/Lf mappers) + round-trip recovery in Gia_ManAigSynch2Choices, DupFromBarBufs/DupToBarBufs for box designs (giaScript.c) - &sweep: Gia_ManFraigReduceGia, Gia_ManDupWithBoxes (giaSweep.c) - &scorr: Gia_ManCorrReduce (cecCorr.c) - &mfs: Custom propagation via vMfs2Old/vMfs2Gia (giaMfs.c) - Supporting: Gia_ManDupCollapse/DupNormalize/DupUnnormalize (giaTim.c), DupUnshuffleInputs/DupMoveLast (giaTim.c), EquivToChoices (giaEquiv.c), DupMuxes (giaMuxes.c), BalanceInt (giaBalAig.c), DauMergePart (dauGia.c), DupWithAttributes (giaDup.c) Add bounds checks in Gia_ObjOrigin and Gia_ObjSetOrigin for GIAs that grow after vOrigins is allocated (e.g., AreaBalance adding nodes). Coverage verified by static analysis finding all Gia_Man_t* functions that call Gia_ManStart without Gia_ManOriginsDup — 23 functions covered, remaining 167 are outside the abc9 pipeline. Co-developed-by: Claude Code v2.1.58 (claude-opus-4-6)
1 parent 53534b5 commit acaa07e

11 files changed

Lines changed: 107 additions & 9 deletions

File tree

src/aig/gia/gia.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ static inline int Gia_ManIsConst0Lit( int iLit ) { return (iLit ==
463463
static inline int Gia_ManIsConst1Lit( int iLit ) { return (iLit == 1); }
464464
static inline int Gia_ManIsConstLit( int iLit ) { return (iLit <= 1); }
465465

466-
static inline int Gia_ObjOrigin( Gia_Man_t * p, int iObj ) { return p->vOrigins ? Vec_IntEntry(p->vOrigins, iObj) : -1; }
467-
static inline void Gia_ObjSetOrigin( Gia_Man_t * p, int iObj, int iOrig ) { if (p->vOrigins) Vec_IntWriteEntry(p->vOrigins, iObj, iOrig); }
466+
static inline int Gia_ObjOrigin( Gia_Man_t * p, int iObj ) { return (p->vOrigins && iObj < Vec_IntSize(p->vOrigins)) ? Vec_IntEntry(p->vOrigins, iObj) : -1; }
467+
static inline void Gia_ObjSetOrigin( Gia_Man_t * p, int iObj, int iOrig ) { if (p->vOrigins && iObj < Vec_IntSize(p->vOrigins)) Vec_IntWriteEntry(p->vOrigins, iObj, iOrig); }
468468

469469
static inline Gia_Obj_t * Gia_Regular( Gia_Obj_t * p ) { return (Gia_Obj_t *)((ABC_PTRUINT_T)(p) & ~01); }
470470
static inline Gia_Obj_t * Gia_Not( Gia_Obj_t * p ) { return (Gia_Obj_t *)((ABC_PTRUINT_T)(p) ^ 01); }
@@ -1353,6 +1353,7 @@ extern Gia_Man_t * Gia_ManDupOutputGroup( Gia_Man_t * p, int iOutStart,
13531353
extern Gia_Man_t * Gia_ManDupOutputVec( Gia_Man_t * p, Vec_Int_t * vOutPres );
13541354
extern Gia_Man_t * Gia_ManDupSelectedOutputs( Gia_Man_t * p, Vec_Int_t * vOutsLeft );
13551355
extern void Gia_ManOriginsDup( Gia_Man_t * pNew, Gia_Man_t * pOld );
1356+
extern void Gia_ManOriginsDupVec( Gia_Man_t * pNew, Gia_Man_t * pOld, Vec_Int_t * vCopies );
13561357
extern void Gia_ManOriginsAfterRoundTrip( Gia_Man_t * pNew, Gia_Man_t * pOld );
13571358
extern Gia_Man_t * Gia_ManDupOrderAiger( Gia_Man_t * p );
13581359
extern Gia_Man_t * Gia_ManDupLastPis( Gia_Man_t * p, int nLastPis );

src/aig/gia/giaDup.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ void Gia_ManOriginsDup( Gia_Man_t * pNew, Gia_Man_t * pOld )
212212
pNew->vOrigins = Vec_IntStartFull( Gia_ManObjNum(pNew) );
213213
Gia_ManForEachObj( pOld, pObj, i )
214214
{
215+
if ( i >= Vec_IntSize(pOld->vOrigins) )
216+
break;
215217
if ( (int)Gia_ObjValue(pObj) != -1 )
216218
{
217219
int iNew = Abc_Lit2Var( Gia_ObjValue(pObj) );
@@ -238,6 +240,24 @@ void Gia_ManOriginsDup( Gia_Man_t * pNew, Gia_Man_t * pOld )
238240
SeeAlso []
239241
240242
***********************************************************************/
243+
void Gia_ManOriginsDupVec( Gia_Man_t * pNew, Gia_Man_t * pOld, Vec_Int_t * vCopies )
244+
{
245+
int i, iLit;
246+
if ( !pOld->vOrigins )
247+
return;
248+
pNew->vOrigins = Vec_IntStartFull( Gia_ManObjNum(pNew) );
249+
Vec_IntForEachEntry( vCopies, iLit, i )
250+
{
251+
if ( iLit != -1 )
252+
{
253+
int iNew = Abc_Lit2Var( iLit );
254+
if ( iNew < Gia_ManObjNum(pNew) && i < Vec_IntSize(pOld->vOrigins) )
255+
Vec_IntWriteEntry( pNew->vOrigins, iNew,
256+
Vec_IntEntry(pOld->vOrigins, i) );
257+
}
258+
}
259+
}
260+
241261
void Gia_ManOriginsAfterRoundTrip( Gia_Man_t * pNew, Gia_Man_t * pOld )
242262
{
243263
Gia_Obj_t * pObj;
@@ -255,16 +275,18 @@ void Gia_ManOriginsAfterRoundTrip( Gia_Man_t * pNew, Gia_Man_t * pOld )
255275
{
256276
int iNewObj = Gia_ObjId( pNew, pObj );
257277
int iOldCi = Gia_ObjId( pOld, Gia_ManCi(pOld, i) );
258-
Vec_IntWriteEntry( pNew->vOrigins, iNewObj,
259-
Vec_IntEntry(pOld->vOrigins, iOldCi) );
278+
if ( iOldCi < Vec_IntSize(pOld->vOrigins) )
279+
Vec_IntWriteEntry( pNew->vOrigins, iNewObj,
280+
Vec_IntEntry(pOld->vOrigins, iOldCi) );
260281
}
261282
// CO drivers map 1:1 (output correspondence preserved through optimization)
262283
Gia_ManForEachCo( pNew, pObj, i )
263284
{
264285
int iNewDriver = Gia_ObjFaninId0p( pNew, pObj );
265286
Gia_Obj_t * pOldCo = Gia_ManCo( pOld, i );
266287
int iOldDriver = Gia_ObjFaninId0p( pOld, pOldCo );
267-
if ( iNewDriver > 0 && Vec_IntEntry(pNew->vOrigins, iNewDriver) == -1 )
288+
if ( iNewDriver > 0 && iOldDriver < Vec_IntSize(pOld->vOrigins) &&
289+
Vec_IntEntry(pNew->vOrigins, iNewDriver) == -1 )
268290
Vec_IntWriteEntry( pNew->vOrigins, iNewDriver,
269291
Vec_IntEntry(pOld->vOrigins, iOldDriver) );
270292
}
@@ -927,11 +949,14 @@ Gia_Man_t * Gia_ManDupWithAttributes( Gia_Man_t * p )
927949
pNew->vConfigs2 = Vec_StrDup( p->vConfigs2 );
928950
if ( p->pCellStr )
929951
pNew->pCellStr = Abc_UtilStrsav( p->pCellStr );
952+
// copy origins if present
953+
if ( p->vOrigins )
954+
pNew->vOrigins = Vec_IntDup( p->vOrigins );
930955
// copy names if present
931956
if ( p->vNamesIn )
932957
pNew->vNamesIn = Vec_PtrDupStr( p->vNamesIn );
933958
if ( p->vNamesOut )
934-
pNew->vNamesOut = Vec_PtrDupStr( p->vNamesOut );
959+
pNew->vNamesOut = Vec_PtrDupStr( p->vNamesOut );
935960
return pNew;
936961
}
937962
Gia_Man_t * Gia_ManDupRemovePis( Gia_Man_t * p, int nRemPis )
@@ -4034,6 +4059,7 @@ Gia_Man_t * Gia_ManDupWithConstraints( Gia_Man_t * p, Vec_Int_t * vPoTypes )
40344059
Gia_ManForEachRi( p, pObj, i )
40354060
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
40364061
// Gia_ManDupRemapEquiv( pNew, p );
4062+
Gia_ManOriginsDup( pNew, p );
40374063
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
40384064
pNew->nConstrs = nConstr;
40394065
assert( Gia_ManIsNormalized(pNew) );

src/aig/gia/giaEquiv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ Gia_Man_t * Gia_ManEquivToChoices( Gia_Man_t * p, int nSnapshots )
20722072
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
20732073
Gia_ManRemoveBadChoices( pNew );
20742074
//Gia_ManEquivPrintClasses( pNew, 0, 0 );
2075+
Gia_ManOriginsDup( pNew, p );
20752076
pNew = Gia_ManCleanup( pTemp = pNew );
20762077
Gia_ManStop( pTemp );
20772078
//Gia_ManEquivPrintClasses( pNew, 0, 0 );

src/aig/gia/giaIf.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ Gia_Man_t * Gia_ManPerformMappingInt( Gia_Man_t * p, If_Par_t * pPars )
30243024
pNew->vOrigins = Vec_IntStartFull( Gia_ManObjNum(pNew) );
30253025
If_ManForEachObj( pIfMan, pIfObj, i )
30263026
{
3027-
if ( i < Gia_ManObjNum(p) && pIfObj->iCopy >= 0 )
3027+
if ( i < Vec_IntSize(p->vOrigins) && pIfObj->iCopy >= 0 )
30283028
{
30293029
int iNewObj = Abc_Lit2Var( pIfObj->iCopy );
30303030
if ( iNewObj < Gia_ManObjNum(pNew) )
@@ -3128,6 +3128,23 @@ Gia_Man_t * Gia_ManPerformSopBalance( Gia_Man_t * p, int nCutNum, int nRelaxRati
31283128
pIfMan = Gia_ManToIf( p, pPars );
31293129
If_ManPerformMapping( pIfMan );
31303130
pNew = Gia_ManFromIfAig( pIfMan );
3131+
// propagate origins via IF mapper iCopy correspondence
3132+
if ( p->vOrigins )
3133+
{
3134+
If_Obj_t * pIfObj = NULL;
3135+
int j;
3136+
pNew->vOrigins = Vec_IntStartFull( Gia_ManObjNum(pNew) );
3137+
If_ManForEachObj( pIfMan, pIfObj, j )
3138+
{
3139+
if ( j < Vec_IntSize(p->vOrigins) && pIfObj->iCopy >= 0 )
3140+
{
3141+
int iNewObj = Abc_Lit2Var( pIfObj->iCopy );
3142+
if ( iNewObj < Gia_ManObjNum(pNew) )
3143+
Vec_IntWriteEntry( pNew->vOrigins, iNewObj,
3144+
Vec_IntEntry(p->vOrigins, j) );
3145+
}
3146+
}
3147+
}
31313148
If_ManStop( pIfMan );
31323149
Gia_ManTransferTiming( pNew, p );
31333150
// transfer name
@@ -3161,6 +3178,23 @@ Gia_Man_t * Gia_ManPerformDsdBalance( Gia_Man_t * p, int nLutSize, int nCutNum,
31613178
If_DsdManAllocIsops( pIfMan->pIfDsdMan, pPars->nLutSize );
31623179
If_ManPerformMapping( pIfMan );
31633180
pNew = Gia_ManFromIfAig( pIfMan );
3181+
// propagate origins via IF mapper iCopy correspondence
3182+
if ( p->vOrigins )
3183+
{
3184+
If_Obj_t * pIfObj = NULL;
3185+
int j;
3186+
pNew->vOrigins = Vec_IntStartFull( Gia_ManObjNum(pNew) );
3187+
If_ManForEachObj( pIfMan, pIfObj, j )
3188+
{
3189+
if ( j < Vec_IntSize(p->vOrigins) && pIfObj->iCopy >= 0 )
3190+
{
3191+
int iNewObj = Abc_Lit2Var( pIfObj->iCopy );
3192+
if ( iNewObj < Gia_ManObjNum(pNew) )
3193+
Vec_IntWriteEntry( pNew->vOrigins, iNewObj,
3194+
Vec_IntEntry(p->vOrigins, j) );
3195+
}
3196+
}
3197+
}
31643198
If_ManStop( pIfMan );
31653199
Gia_ManTransferTiming( pNew, p );
31663200
// transfer name
@@ -3266,6 +3300,7 @@ Gia_Man_t * Gia_ManDupHashMapping( Gia_Man_t * p )
32663300
Vec_IntPush( vMapping, Abc_Lit2Var(pObj->Value) );
32673301
}
32683302
pNew->vMapping = vMapping;
3303+
Gia_ManOriginsDup( pNew, p );
32693304
return pNew;
32703305
}
32713306

@@ -3345,6 +3380,7 @@ Gia_Man_t * Gia_ManDupUnhashMapping( Gia_Man_t * p )
33453380
}
33463381
Vec_IntFree( vMap );
33473382
pNew->vMapping = vMapping;
3383+
Gia_ManOriginsDup( pNew, p );
33483384
return pNew;
33493385
}
33503386

src/aig/gia/giaJf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,11 @@ Gia_Man_t * Jf_ManDeriveMappingGia( Jf_Man_t * p )
15111511
if ( p->pPars->fGenCnf )
15121512
Jf_ManGenCnf( ABC_CONST(0xAAAAAAAAAAAAAAAA), iLit, vLeaves, vLits, vClas, vCover );
15131513
}
1514+
Gia_ManOriginsDupVec( pNew, p->pGia, vCopies );
15141515
Vec_IntFree( vCopies );
15151516
Vec_IntFree( vCover );
15161517
Vec_IntFree( vLeaves );
1517-
// finish mapping
1518+
// finish mapping
15181519
if ( Vec_IntSize(vMapping) > Gia_ManObjNum(pNew) )
15191520
Vec_IntShrink( vMapping, Gia_ManObjNum(pNew) );
15201521
else
@@ -1653,6 +1654,7 @@ Gia_Man_t * Jf_ManDeriveGia( Jf_Man_t * p )
16531654
}
16541655
if ( !p->pPars->fCutMin )
16551656
Gia_ObjComputeTruthTableStop( p->pGia );
1657+
Gia_ManOriginsDupVec( pNew, p->pGia, vCopies );
16561658
Vec_IntFree( vCopies );
16571659
Vec_IntFree( vLeaves );
16581660
Vec_IntFree( vCover );

src/aig/gia/giaLf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,7 @@ Gia_Man_t * Lf_ManDeriveMappingCoarse( Lf_Man_t * p )
17711771
Vec_IntPush( pNew->vMapping, pCut->fMux7 ? -Abc_Lit2Var(pObj->Value) : Abc_Lit2Var(pObj->Value) );
17721772
}
17731773
Gia_ManSetRegNum( pNew, Gia_ManRegNum(pGia) );
1774+
Gia_ManOriginsDup( pNew, pGia );
17741775
assert( Vec_IntCap(pNew->vMapping) == 16 || Vec_IntSize(pNew->vMapping) == Vec_IntCap(pNew->vMapping) );
17751776
return pNew;
17761777
}
@@ -1903,10 +1904,11 @@ Gia_Man_t * Lf_ManDeriveMappingGia( Lf_Man_t * p )
19031904
iLit = Lf_ManDerivePart( p, pNew, vMapping, vMapping2, vCopies, pCut, vLeaves, vCover, pObj );
19041905
Vec_IntWriteEntry( vCopies, i, Abc_LitNotCond(iLit, Abc_LitIsCompl(pCut->iFunc)) );
19051906
}
1907+
Gia_ManOriginsDupVec( pNew, p->pGia, vCopies );
19061908
Vec_IntFree( vCopies );
19071909
Vec_IntFree( vCover );
19081910
Vec_IntFree( vLeaves );
1909-
// finish mapping
1911+
// finish mapping
19101912
if ( Vec_IntSize(vMapping) > Gia_ManObjNum(pNew) )
19111913
Vec_IntShrink( vMapping, Gia_ManObjNum(pNew) );
19121914
else

src/aig/gia/giaMfs.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,26 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
531531
if ( p->vRegInits )
532532
pNew->vRegInits = Vec_IntDup( p->vRegInits );
533533
pNew->nAnd2Delay = p->nAnd2Delay;
534+
// propagate origins via MFS ID correspondence
535+
if ( p->vOrigins )
536+
{
537+
int iOldObj;
538+
pNew->vOrigins = Vec_IntStartFull( Gia_ManObjNum(pNew) );
539+
Vec_IntForEachEntry( vMfs2Old, iOldObj, i )
540+
{
541+
if ( iOldObj >= 0 )
542+
{
543+
int iNewLit = Vec_IntEntry( vMfs2Gia, i );
544+
if ( iNewLit >= 0 )
545+
{
546+
int iNewObj = Abc_Lit2Var( iNewLit );
547+
if ( iNewObj < Gia_ManObjNum(pNew) && iOldObj < Vec_IntSize(p->vOrigins) )
548+
Vec_IntWriteEntry( pNew->vOrigins, iNewObj,
549+
Vec_IntEntry(p->vOrigins, iOldObj) );
550+
}
551+
}
552+
}
553+
}
534554

535555
// cleanup
536556
Vec_WecFree( vGroups );

src/aig/gia/giaScript.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ Gia_Man_t * Gia_ManDupFromBarBufs( Gia_Man_t * p )
315315
Gia_ManForEachCo( p, pObj, i )
316316
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
317317
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
318+
Gia_ManOriginsDup( pNew, p );
318319
return pNew;
319320
}
320321
Gia_Man_t * Gia_ManDupToBarBufs( Gia_Man_t * p, int nBarBufs )
@@ -357,6 +358,7 @@ Gia_Man_t * Gia_ManDupToBarBufs( Gia_Man_t * p, int nBarBufs )
357358
assert( Gia_ManBufNum(pNew) == nBarBufs );
358359
assert( Gia_ManCiNum(pNew) == nPiReal );
359360
assert( Gia_ManCoNum(pNew) == nPoReal );
361+
Gia_ManOriginsDup( pNew, p );
360362
return pNew;
361363
}
362364

@@ -396,6 +398,8 @@ Gia_Man_t * Gia_ManAigSynch2Choices( Gia_Man_t * pGia1, Gia_Man_t * pGia2, Gia_M
396398
// convert to GIA
397399
pGia = Gia_ManFromAigChoices( pMan );
398400
Aig_ManStop( pMan );
401+
// recover origins from base variant (pGia1) via CI/CO correspondence
402+
Gia_ManOriginsAfterRoundTrip( pGia, pGia1 );
399403
return pGia;
400404
}
401405
Gia_Man_t * Gia_ManAigSynch2( Gia_Man_t * pInit, void * pPars0, int nLutSize, int nRelaxRatio )

src/aig/gia/giaSweep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Gia_Man_t * Gia_ManDupWithBoxes( Gia_Man_t * p, int fSeq )
204204
assert( Gia_ManCiNum(pNew) == Tim_ManPiNum((Tim_Man_t*)pNew->pManTime) + Gia_ManCoNum(pNew->pAigExtra) );
205205
Vec_IntFree( vBoxesLeft );
206206
pNew->nAnd2Delay = p->nAnd2Delay;
207+
Gia_ManOriginsDup( pNew, p );
207208
return pNew;
208209
}
209210

@@ -368,6 +369,7 @@ Gia_Man_t * Gia_ManFraigReduceGia( Gia_Man_t * p, int * pReprs )
368369
else assert( 0 );
369370
}
370371
Gia_ManHashStop( pNew );
372+
Gia_ManOriginsDup( pNew, p );
371373
return pNew;
372374
}
373375

src/aig/gia/giaTim.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ Gia_Man_t * Gia_ManDupUnshuffleInputs( Gia_Man_t * p )
241241
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
242242
pNew->nConstrs = p->nConstrs;
243243
assert( Gia_ManIsNormalized(pNew) );
244+
Gia_ManOriginsDup( pNew, p );
244245
Gia_ManDupRemapEquiv( pNew, p );
245246
return pNew;
246247
}
@@ -779,6 +780,7 @@ Gia_Man_t * Gia_ManDupMoveLast( Gia_Man_t * p, int iInsert, int nItems )
779780
else assert( 0 );
780781
}
781782
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
783+
Gia_ManOriginsDup( pNew, p );
782784
return pNew;
783785
}
784786

@@ -905,6 +907,7 @@ Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * v
905907
assert( curCo == Gia_ManCoNum(p) );
906908
Gia_ManSetRegNum( pNew, (fSeq && p->vRegClasses) ? Vec_IntSize(p->vRegClasses) : Gia_ManRegNum(p) );
907909
Gia_ManHashStop( pNew );
910+
Gia_ManOriginsDup( pNew, p );
908911
pNew = Gia_ManCleanup( pTemp = pNew );
909912
Gia_ManCleanupRemap( p, pTemp );
910913
Gia_ManStop( pTemp );

0 commit comments

Comments
 (0)