1 /**CFile****************************************************************
2
3 FileName [mapperFanout.c]
4
5 PackageName [FRAIG: Functionally reduced AND-INV graphs.]
6
7 Synopsis [Procedures to manipulate fanouts of the FRAIG nodes.]
8
9 Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
10
11 Affiliation [UC Berkeley]
12
13 Date [Ver. 2.0. Started - June 1, 2004.]
14
15 Revision [$Id: mapperFanout.c,v 1.5 2005/01/23 06:59:43 alanmi Exp $]
16
17 ***********************************************************************/
18
19 #include "mapperInt.h"
20
21 ABC_NAMESPACE_IMPL_START
22
23
24 #ifdef MAP_ALLOCATE_FANOUT
25
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33
34 /**Function*************************************************************
35
36 Synopsis [Add the fanout to the node.]
37
38 Description []
39
40 SideEffects []
41
42 SeeAlso []
43
44 ***********************************************************************/
Map_NodeAddFaninFanout(Map_Node_t * pFanin,Map_Node_t * pFanout)45 void Map_NodeAddFaninFanout( Map_Node_t * pFanin, Map_Node_t * pFanout )
46 {
47 Map_Node_t * pPivot;
48
49 // pFanins is a fanin of pFanout
50 assert( !Map_IsComplement(pFanin) );
51 assert( !Map_IsComplement(pFanout) );
52 assert( Map_Regular(pFanout->p1) == pFanin || Map_Regular(pFanout->p2) == pFanin );
53
54 pPivot = pFanin->pFanPivot;
55 if ( pPivot == NULL )
56 {
57 pFanin->pFanPivot = pFanout;
58 return;
59 }
60
61 if ( Map_Regular(pPivot->p1) == pFanin )
62 {
63 if ( Map_Regular(pFanout->p1) == pFanin )
64 {
65 pFanout->pFanFanin1 = pPivot->pFanFanin1;
66 pPivot->pFanFanin1 = pFanout;
67 }
68 else // if ( Map_Regular(pFanout->p2) == pFanin )
69 {
70 pFanout->pFanFanin2 = pPivot->pFanFanin1;
71 pPivot->pFanFanin1 = pFanout;
72 }
73 }
74 else // if ( Map_Regular(pPivot->p2) == pFanin )
75 {
76 assert( Map_Regular(pPivot->p2) == pFanin );
77 if ( Map_Regular(pFanout->p1) == pFanin )
78 {
79 pFanout->pFanFanin1 = pPivot->pFanFanin2;
80 pPivot->pFanFanin2 = pFanout;
81 }
82 else // if ( Map_Regular(pFanout->p2) == pFanin )
83 {
84 pFanout->pFanFanin2 = pPivot->pFanFanin2;
85 pPivot->pFanFanin2 = pFanout;
86 }
87 }
88 }
89
90 /**Function*************************************************************
91
92 Synopsis [Add the fanout to the node.]
93
94 Description []
95
96 SideEffects []
97
98 SeeAlso []
99
100 ***********************************************************************/
Map_NodeRemoveFaninFanout(Map_Node_t * pFanin,Map_Node_t * pFanoutToRemove)101 void Map_NodeRemoveFaninFanout( Map_Node_t * pFanin, Map_Node_t * pFanoutToRemove )
102 {
103 Map_Node_t * pFanout, * pFanout2, ** ppFanList;
104 // start the linked list of fanouts
105 ppFanList = &pFanin->pFanPivot;
106 // go through the fanouts
107 Map_NodeForEachFanoutSafe( pFanin, pFanout, pFanout2 )
108 {
109 // skip the fanout-to-remove
110 if ( pFanout == pFanoutToRemove )
111 continue;
112 // add useful fanouts to the list
113 *ppFanList = pFanout;
114 ppFanList = Map_NodeReadNextFanoutPlace( pFanin, pFanout );
115 }
116 *ppFanList = NULL;
117 }
118
119 /**Function*************************************************************
120
121 Synopsis [Returns the number of fanouts of a node.]
122
123 Description []
124
125 SideEffects []
126
127 SeeAlso []
128
129 ***********************************************************************/
Map_NodeGetFanoutNum(Map_Node_t * pNode)130 int Map_NodeGetFanoutNum( Map_Node_t * pNode )
131 {
132 Map_Node_t * pFanout;
133 int Counter = 0;
134 Map_NodeForEachFanout( pNode, pFanout )
135 Counter++;
136 return Counter;
137 }
138
139 ////////////////////////////////////////////////////////////////////////
140 /// END OF FILE ///
141 ////////////////////////////////////////////////////////////////////////
142
143 #endif
144
145 ABC_NAMESPACE_IMPL_END
146
147