Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 230 lines (197 sloc) 7.426 kb
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
1 /*
ec49f10 Stephen Williams Revert bad merge from vhdl branch
authored
2 * Copyright (c) 1999-2010 Stephen Williams (steve@icarus.com)
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
3 *
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
f5aafc3 Arun Persaud updated FSF-address
arunpersaud authored
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
18 */
19
b825f8d Create a config.h.in file to hold all the config
steve authored
20 # include "config.h"
21
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
22 /*
23 * This functor scans the design looking for dangling objects and
24 * excess local signals. These deletions are not necessarily required
25 * for proper functioning of anything, but they can clean up the
26 * appearance of design files that are generated.
27 */
28 # include "functor.h"
29 # include "netlist.h"
58ec62c Rewrite find_similar_event to support doing
steve authored
30 # include "compiler.h"
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
31
32 class nodangle_f : public functor_t {
33 public:
74c4303 Clean up unneeded NetEvent objects.
steve authored
34 void event(Design*des, NetEvent*ev);
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
35 void signal(Design*des, NetNet*sig);
ec0d12b Killing some signals might make others killable.
steve authored
36
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
37 unsigned iteration;
58ec62c Rewrite find_similar_event to support doing
steve authored
38 unsigned stotal, etotal;
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
39 bool scontinue, econtinue;
40 bool scomplete, ecomplete;
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
41 };
42
bb5ca97 Cary R. Fix some -Wextra warnings and some other bug fixes/enhancements.
caryr authored
43 void nodangle_f::event(Design*, NetEvent*ev)
74c4303 Clean up unneeded NetEvent objects.
steve authored
44 {
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
45 if (ecomplete) return;
46
58ec62c Rewrite find_similar_event to support doing
steve authored
47 /* If there are no references to this event, then go right
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
48 ahead and delete it. There is no use looking further at
58ec62c Rewrite find_similar_event to support doing
steve authored
49 it. */
f1cc9d8 Support event names as expressions elements.
steve authored
50 if ((ev->nwait() + ev->ntrig() + ev->nexpr()) == 0) {
58ec62c Rewrite find_similar_event to support doing
steve authored
51 delete ev;
52 etotal += 1;
53 return;
c1c0168 Globally merge redundant event objects.
steve authored
54 }
55
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
56 if (iteration == 0) {
57 /* Try to remove duplicate probes from the event. This
58 is done as a separate initial pass to ensure similar
59 events are detected as soon as possible in subsequent
60 iterations. */
61 for (unsigned idx = 0 ; idx < ev->nprobe() ; idx += 1) {
62 unsigned jdx = idx + 1;
63 while (jdx < ev->nprobe()) {
64 NetEvProbe*ip = ev->probe(idx);
65 NetEvProbe*jp = ev->probe(jdx);
66
67 if (ip->edge() != jp->edge()) {
68 jdx += 1;
69 continue;
70 }
71
72 bool fully_connected = true;
73 for (unsigned jpin = 0; jpin < jp->pin_count(); jpin += 1) {
74 unsigned ipin = 0;
75 bool connected_flag = false;
76 for (ipin = 0 ; ipin < ip->pin_count(); ipin += 1)
77 if (connected(ip->pin(ipin), jp->pin(jpin))) {
78 connected_flag = true;
79 break;
80 }
81
82 if (!connected_flag) {
83 fully_connected = false;
84 break;
85 }
86 }
87
88 if (fully_connected) {
89 delete jp;
90 } else {
91 jdx += 1;
92 }
93 }
94 }
95 econtinue = true;
96 } else {
97 /* Postpone examining events in an automatic scope until the
98 third (optional) pass. This will mean similar events are
99 biased towards being stored in static scopes. */
100 if (ev->scope()->is_auto()) {
101 if (iteration == 1) {
102 econtinue = true;
103 return;
104 }
105 } else {
106 if (iteration == 2) {
107 return;
108 }
109 }
110
111 /* Try to find all the events that are similar to me, and
112 replace their references with references to me. */
113 list<NetEvent*> match;
114 ev->find_similar_event(match);
115 for (list<NetEvent*>::iterator idx = match.begin()
225ca1e Cary R. Change iterators to use prefix ++ since it is more efficient.
caryr authored
116 ; idx != match.end() ; ++ idx ) {
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
117
118 NetEvent*tmp = *idx;
119 assert(tmp != ev);
120 tmp ->replace_event(ev);
121 }
d98b7ff Remove duplicate NetEvProbe objects in nodangle.
steve authored
122 }
74c4303 Clean up unneeded NetEvent objects.
steve authored
123 }
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
124
bb5ca97 Cary R. Fix some -Wextra warnings and some other bug fixes/enhancements.
caryr authored
125 void nodangle_f::signal(Design*, NetNet*sig)
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
126 {
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
127 if (scomplete) return;
128
bfad382 Carry Verilog 2001 attributes with processes,
steve authored
129 /* Cannot delete signals referenced in an expression
130 or an l-value. */
131 if (sig->get_refs() > 0)
e96e8c6 NetESignal object no longer need to be NetNode
steve authored
132 return;
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
133
ec49f10 Stephen Williams Revert bad merge from vhdl branch
authored
134 /* Cannot delete the ports of tasks, functions or modules. There
135 are too many places where they are referenced. */
136 if ((sig->port_type() != NetNet::NOT_A_PORT) &&
137 ((sig->scope()->type() == NetScope::TASK) ||
138 (sig->scope()->type() == NetScope::FUNC) ||
139 (sig->scope()->type() == NetScope::MODULE)))
629a02c Fix binding of dangling function ports. do not elide them.
steve authored
140 return;
141
a9595fe Do not elide ports of cells.
steve authored
142 /* Can't delete ports of cells. */
143 if ((sig->port_type() != NetNet::NOT_A_PORT)
177b6ff Addtrbute keys are perm_strings.
steve authored
144 && (sig->scope()->attribute(perm_string::literal("ivl_synthesis_cell")) != verinum()))
a9595fe Do not elide ports of cells.
steve authored
145 return;
146
ff58461 Delete unreferenced signals no matter what.
steve authored
147 /* Check to see if the signal is completely unconnected. If
148 all the bits are unlinked, then delete it. */
5b9857f Larry Doolittle Refactor two NetPins related methods
ldoolitt authored
149 if (! sig->is_linked()) {
acfb5c1 Over agressive signal elimination in constant probadation.
steve authored
150 delete sig;
58ec62c Rewrite find_similar_event to support doing
steve authored
151 stotal += 1;
acfb5c1 Over agressive signal elimination in constant probadation.
steve authored
152 return;
153 }
154
ff58461 Delete unreferenced signals no matter what.
steve authored
155 /* The remaining things can only be done to synthesized
156 signals, not ones that appear in the original Verilog. */
157 if (! sig->local_flag())
158 return;
159
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
160 /* Check to see if there is some significant signal connected
161 to every pin of this signal. */
162 unsigned significant_flags = 0;
163 for (unsigned idx = 0 ; idx < sig->pin_count() ; idx += 1) {
583868e Redesign Links to include the Nexus class that
steve authored
164 Nexus*nex = sig->pin(idx).nexus();
165
166 for (Link*cur = nex->first_nlink()
167 ; cur ; cur = cur->next_nlink()) {
168
169 if (cur == &sig->pin(idx))
170 continue;
171
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
172 NetNet*cursig = dynamic_cast<NetNet*>(cur->get_obj());
173 if (cursig == 0)
174 continue;
583868e Redesign Links to include the Nexus class that
steve authored
175
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
176 if (cursig->local_flag())
177 continue;
583868e Redesign Links to include the Nexus class that
steve authored
178
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
179 significant_flags += 1;
180 break;
181 }
58ec62c Rewrite find_similar_event to support doing
steve authored
182
183 if (significant_flags <= idx)
184 break;
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
185 }
186
187 /* If every pin is connected to another significant signal,
188 then I can delete this one. */
ec0d12b Killing some signals might make others killable.
steve authored
189 if (significant_flags == sig->pin_count()) {
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
190 delete sig;
58ec62c Rewrite find_similar_event to support doing
steve authored
191 stotal += 1;
ec0d12b Killing some signals might make others killable.
steve authored
192 }
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
193 }
194
195 void nodangle(Design*des)
196 {
197 nodangle_f fun;
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
198 fun.iteration = 0;
58ec62c Rewrite find_similar_event to support doing
steve authored
199 fun.stotal = 0;
200 fun.etotal = 0;
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
201 fun.scomplete = false;
202 fun.ecomplete = false;
ec0d12b Killing some signals might make others killable.
steve authored
203 do {
1985bc5 Stephen Williams More verbose detail for nodangle functor.
authored
204 if (verbose_flag) {
205 cout << " ... scan for dangling signal and event nodes. "
206 << "(scomplete=" << (fun.scomplete? "T" : "F")
207 << ", ecomplete=" << (fun.ecomplete? "T" : "F")
208 << ")" << endl << flush;
209 }
210
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
211 fun.scontinue = false;
212 fun.econtinue = false;
ec0d12b Killing some signals might make others killable.
steve authored
213 des->functor(&fun);
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
214 fun.iteration += 1;
215 fun.scomplete = !fun.scontinue;
216 fun.ecomplete = !fun.econtinue;
58ec62c Rewrite find_similar_event to support doing
steve authored
217
218 if (verbose_flag) {
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
219 cout << " ... " << fun.iteration << " iterations"
58ec62c Rewrite find_similar_event to support doing
steve authored
220 << " deleted " << fun.stotal << " dangling signals"
1985bc5 Stephen Williams More verbose detail for nodangle functor.
authored
221 << " and " << fun.etotal << " events." << endl << flush;
58ec62c Rewrite find_similar_event to support doing
steve authored
222 }
223
647b3e5 Bias storage of events towards static scopes.
Martin Whitaker authored
224 } while (fun.scontinue || fun.econtinue);
58ec62c Rewrite find_similar_event to support doing
steve authored
225
1985bc5 Stephen Williams More verbose detail for nodangle functor.
authored
226 if (verbose_flag) {
227 cout << " ... done" << endl << flush;
228 }
9d6392f Turn NetTmp objects into normal local NetNet objects,
steve authored
229 }
Something went wrong with that request. Please try again.